How to cancel death message if the player was killed with a bow

Discussion in 'Plugin Development' started by MrSnare, Jan 8, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    MrSnare

    I am trying to cancel the death message when the killer was using a bow. Can you tell me what is wrong with my code?
    Code:
    public void onPlayerDeath(PlayerDeathEvent ev){
            final Player victim = ev.getEntity();
            Bukkit.broadcastMessage("test: " + victim.getKiller());
            if(victim.getKiller() instanceof Arrow){
                final LivingEntity shooter = ((Arrow)victim.getKiller()).getShooter();
                final Player bowman = (Player) shooter;
                ev.setDeathMessage("");
            }
       
        }
     
  2. Offline

    fireblast709

    you cannot cancel the PlayerDeathEvent. You would have to calculate the death in the EntityDamageByEntityEvent (note that the getDamage() method does not account for armor, potions and enchantments) and cancel that
    misread the post
     
  3. MrSnare

    First use the PlayerDeathEvent. Then check if the bow is in killers hand. If there is a bow so something like
    Code:java
    1. evt.setDeathMessage(ChatColor.GOLD + "");

    I'll post a snippet in a minute :)

    MrSnare

    Code:java
    1.  
    2. @EventHandler
    3. public void PlayerDeath(PlayerDeathEvent evt){
    4. Player player = evt.getEntity();
    5. Player killer = player.getKiller();
    6. if(killer != null && killer.getItemInHand() == Material.BOW){
    7. evt.setDeathMessage(""); //Put a ChatColor or somethink to prevent bukkit think the message is empty
    8. system.printLn("A Player just was killed with a Bow");
    9. }
    10. }
    11.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
  4. Offline

    fireblast709

    Code:java
    1. @EventHandler
    2. public void PlayerDeath(PlayerDeathEvent evt)
    3. {
    4. Player player = evt.getEntity();
    5. Player killer = player.getKiller();
    6. if(killer != null && killer.getItemInHand() != null && killer.getItemInHand().getType() == Material.BOW)
    7. {
    8. evt.setDeathMessage("");
    9. }
    10. }
    check if the ItemStack in hand is not null, and if the type is bow. Also, setting the message to "" would cancel the death message
     
  5. Offline

    IanM_56

    Also you can use, evt.setDeathMessage(null)
     
  6. Offline

    naorpeled

    Just check the death cause and send a message : "(nothing)"
     
  7. Offline

    Tarestudio

    MrSnare
    I dont know if getting shot by bow has an unique static part of message, but if, you could just check the current death-message and set it to null on match.
     
Thread Status:
Not open for further replies.

Share This Page