The setDeathMessage isnt working

Discussion in 'Plugin Development' started by Th3Rokaz, Jan 17, 2017.

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

    Th3Rokaz

    Hello guys and i dont know why this is not working have any answers

    Code:
    @EventHandler
        public void onzombiedeath(EntityDamageByEntityEvent event) {
            if (event.getEntity().getType() == EntityType.PLAYER && event.getDamager().getType() == EntityType.ZOMBIE) {
                Player p = (Player) event.getEntity();
                Damageable dmg = p;
                if (dmg.getHealth() - event.getDamage() <= 0D) {
                    event.setDeathMessage("");
        }
        } else if (event.getEntity().getType() == EntityType.PLAYER && event.getDamager().getType() == EntityType.CREEPER) {
            Player p = (Player) event.getEntity();
            Damageable dmg = p;
            if (dmg.getHealth() - event.getDamage() <= 0D) {
                event.setDeathMessage("");
            }
    
        } else if (event.getEntity().getType() == EntityType.PLAYER && event.getDamager().getType() == EntityType.SPIDER) {
            Player p = (Player) event.getEntity();
            Damageable dmg = p;
            if (dmg.getHealth() - event.getDamage() <= 0D) {
                event.setDeathMessage("");
    }
    
      
    }
     
    Last edited by a moderator: Jan 17, 2017
  2. Offline

    Zombie_Striker

    @Th3Rokaz
    You have a lot of duplicated code. Add OR statements for the entity type and remove the Creeper/spider cases.

    Have you registered your events? Have you debugged?
     
  3. Offline

    Th3Rokaz

    dude i want to make diffrent messages for every death type yea i have registered those events
     
  4. Offline

    Zombie_Striker

    @Th3Rokaz
    Even still, you can just create a Map to store the different messages and access each method through entity types. That will reduce the amount of lines.

    Have you debugged? Does the event ever get called?
     
  5. Offline

    Th3Rokaz

    Okay i will create a map well the event works in the game but i cant debug it says this selection cannot be lauched
     
  6. Offline

    Zombie_Striker

    @Th3Rokaz
    What are you talking about? Can you post the console log?

    [edit] Did you click the debug button in eclipse? That is not the debugging you need to do. I would just recommend putting a sendmessage line right at the top of the message. It does not have to be anything special, you're just seeing if the message can be sent. If it does, you know the event is being called, meaning the problem is with the inner-code. If you do not see the message, that means you either did not register the class correctly or the instance is not even being created.
     
  7. Offline

    Th3Rokaz

    yea it works i replaced one of these event.setDeathMessage(""); to a sendmessage and the message sents
     
  8. Offline

    mehboss

    Nice your debug worked..

    @Zombie_Striker
    Make sure you mention him to call him back. :p
     
  9. Offline

    mehboss

    @bwfcwalshy
    Wrong tag? I didn't tag him because he is the creator of this thread and he will get the alert either way. ;)
    I tagged Zomb because @Th3Rokaz didn't.
     
  10. Offline

    Zombie_Striker

    @Th3Rokaz
    So, did you fix your problem? If so, mark this thread as solved. If not, can you post what the current issue is along with the updated code?
     
  11. Offline

    Th3Rokaz

  12. Offline

    Edmond506

    Why do you use EntityDamageEntityEvent if you just want to set the death message? You should use EntityDeathEvent!
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page