What am I doing wrong?

Discussion in 'Plugin Development' started by CdoingBaddie, Sep 2, 2013.

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

    CdoingBaddie

    Code:
     @EventHandler
        public void onEntityDamage(EntityDamageByEntityEvent e){
            Entity entity = e.getDamager();
            Entity p = (Player) e.getEntity();
            Entity h = (Player) e.getDamager();
            if(entity instanceof Snowball){
               
               
                Location loc1 = p.getLocation();
                Location loc2 = h.getLocation();
                 
                p.teleport(loc2);
                h.teleport(loc1);
                }
                }
    It keeps saying it cannot be cast to org.bukkit.entity.Player
    Please help!!
     
  2. Offline

    Saposhiente

    You have to check whether e.getX() is actually a Player (using instanceof) before casting it to Player. Otherwise, if a mob hurts a player, or a player hurts a mob, you'll have an error.
     
  3. Offline

    CdoingBaddie

    How do I do that? if(e.getX() instanceof Player) ?
     
  4. Yes
    No, event.getEntity() instanceof Player
     
  5. Offline

    CdoingBaddie

    I already did that. o_o
     
Thread Status:
Not open for further replies.

Share This Page