EntityDamageByEntity troubles

Discussion in 'Plugin Development' started by Shzylo, Aug 12, 2013.

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

    Shzylo

    I am using my plugin to implement left-clicking mobs for the damage to take place also, but all the console does it throw an endless error (it never stops spamming it!) Here is my code:
    Code:
    @EventHandler
    public void onEntityLeftClick(EntityDamageByEntityEvent e) {
        Player p = (Player) e.getDamager();
        Entity ent = e.getEntity();
        World w = ent.getWorld();
     
        if (p instanceof Player) {
            if (p.getItemInHand().getType().equals(Material.SULPHUR)) {
                if (ent instanceof Sheep) {
                    Sheep sheep = (Sheep) ent;
                    onDamageEntity(sheep, p, dmg, w);
                }
            }
        }
    }
    Here is my onDamageEntity method:
    Code:
    private void onDamageEntity(LivingEntity e, Player p, int dmg, World w) {
        if (e instanceof LivingEntity) {
            ((LivingEntity) e).damage(dmg, p);
            ...
        }
    }
     
  2. Shzylo
    That's probably because you're assuming the damager is player, that will throw an error every time an entity damages another entity, and damager is not player.
     
  3. Offline

    xxMOxMOxx

    Add a line saying
    Code:
    if(e.getDamager instanceof Player){
     
Thread Status:
Not open for further replies.

Share This Page