Hack-detection error

Discussion in 'Plugin Development' started by Edvio, Jul 27, 2015.

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

    Edvio

    I get a long error on the Villager bot = (Villager).e.getEntity(); part, can someone please tell me why

    Code:
            @EventHandler
            public void onVillagerDamageByHacker(EntityDamageByEntityEvent e) {
                Player hacker = (Player)e.getDamager();
                Villager bot = (Villager)e.getEntity();
                if(!hacktest.contains(hacker.getName())) {
                    e.setCancelled(true);
                }else if(hacktest.contains(hacker.getName()) && bot.getType().equals(EntityType.VILLAGER)) {
                    for (Player p : Bukkit.getOnlinePlayers()) {
                        if (p.isOp()) {
                            p.sendMessage(ChatColor.DARK_RED + "" + hacker.getName() + " is most likely hacking (FF)!");
                        }
                    }
                    }
                }
     
  2. Moved to Plugin Development
     
  3. Offline

    ShadowLAX

    @Edvio You should never cast without adding an instanceof check. Otherwise, if the entity is not able to be casted to what you cast it to, it will always throw an error.
     
  4. Offline

    RawCode

    there is no debug output in provided code, add some and try again.
     
Thread Status:
Not open for further replies.

Share This Page