Simply does not make sense.

Discussion in 'Plugin Development' started by Windwaker, Aug 23, 2011.

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

    Windwaker

    Please someone tell me why this doesn't do what it is supposed to! It's supposed to double the damage given to another player with a diamond axe. I see no reason for it not to work.

    Code:java
    1.  
    2. public void onEntityDamage(EntityDamageEvent event){
    3. if(event instanceof EntityDamageByEntityEvent){
    4. EntityDamageByEntityEvent eve = (EntityDamageByEntityEvent) event;
    5. if(eve.getDamager() instanceof Player){
    6. if(event.getEntity() instanceof Player){
    7. Player entity = (Player)event.getEntity();
    8. if(event.getCause().equals(Material.DIAMOND_AXE)){
    9. entity.damage(7);
     
  2. Offline

    Pandemoneus

    You can't use
    Code:java
    1.  
    2. if(event.getCause().equals(Material.DIAMOND_AXE)
    3.  

    as damage causes are other things than materials (check the bukkit API for a list of damage causes).
    Rather try
    Code:java
    1.  
    2. if(eve.getDamager().getItemInHand().getType() == Material.DIAMOND_AXE)
    3.  


    I also suggest, if you just want to double the damage, using
    Code:java
    1.  
    2. entity.damage(event.getDamage());
    3.  

    so you deal the actual damage done again (you know, damage might be reduced by armor, etc).
     
  3. Offline

    Windwaker

    @Pandemoneus

    Thanks a lot :)

    I had tried it with getItemInHand but forgot to add getType... *facepalm*

    ... Actually ....

    This isn't working ... no error ... just doesn't do anything...

    Code:java
    1.  
    2. public void onEntityDamage(EntityDamageEvent event){
    3. if(event instanceof EntityDamageByEntityEvent){
    4. EntityDamageByEntityEvent eve = (EntityDamageByEntityEvent) event;
    5. if(eve.getDamager() instanceof Player){
    6. if(event.getEntity() instanceof Player){
    7. Player entity = (Player)event.getEntity();
    8. Player player = (Player)eve.getDamager();
    9. if(player.getItemInHand().getType() == Material.DIAMOND_AXE){
    10. entity.damage(event.getDamage());
    11.  
    12. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  4. Offline

    nisovin

    Did you register the event?
     
  5. Offline

    Windwaker

    Yep
     
  6. Offline

    Pandemoneus

    Add some messages in between to see which parts are even reached.
     
  7. Offline

    vildaberper

    I should be equals() and not ==.
     
  8. Offline

    Windwaker

    Does it matter?
     
  9. Offline

    Pandemoneus

    Doesn't matter for enums.
     
  10. Offline

    Windwaker

    Thats what I thought
     
Thread Status:
Not open for further replies.

Share This Page