Solved How to give ENTITY_ATTACK damage to an entity?

Discussion in 'Plugin Development' started by Shzylo, Jul 28, 2013.

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

    Shzylo

    I am trying to deal some damage to an entity when they right click with sulphur(gunpowder) and I don't know how to get it to work. This is my current code:
    Code:
    Entity cow = (Cow) e.getRightClicked();
    if(e.getRightClicked() instanceof Entity) {
        if(damageAnimals) {
            if(e.getRightClicked() == cow) {
                // give the cow the damage cause of ENTITY_ATTACK?
            }
        }
    }
     
  2. Offline

    iFamasssxD

    e.damage(double);
    e.setLastDamageCause(DamageCause.ENTITY_ATTACK);
     
  3. Offline

    Shzylo

    here is all my code, because it is not allowing me to use the damage method:
    Code:
    @EventHandler
    public void onDamageEntity(PlayerInteractEntityEvent e) {
        boolean damageAnimals = plugin.getConfig().getBoolean("damage-animals", true);
        boolean damageMonsters = plugin.getConfig().getBoolean("damage-monsters", true);
        boolean damagePlayers = plugin.getConfig().getBoolean("damage-players", true);
     
        Player p = e.getPlayer();
     
        Entity cow = (Cow) e.getRightClicked();
        //Entity chicken = (Chicken) e.getRightClicked();
        if(e.getRightClicked() instanceof Entity) {
            if(damageAnimals) {
                if(e.getRightClicked() == cow) {
                   
                }
            } else if(damageMonsters) {
               
            } else if(damagePlayers) {
               
            }
        }
    }
     
  4. Offline

    iFamasssxD

    Well first you have a few problems. Your assigning the right clicked Entity before you even know what it is.
    You need to check first.
    Code:
    if(e.getRightClicked() instanceof Cow){
    Cow cow = (Cow) e.getRightClicked();
     
    if(damageAnimals){
    cow.damage(10);
    cow.setLastDamageCause(DamageCause.ENTITY_ATTACK);
      }
     
    }
    Also make sure the boolean is properly defined and was retrieved correctly. I suggest some debug messages.
     
    Shzylo likes this.
  5. Offline

    Shzylo

    I got it. I did:
    Code:
    cow.damage(1, p) //Player p;
    Thanks for the help :p
     
Thread Status:
Not open for further replies.

Share This Page