I've just started working with NMS code and I have successfully created a custom villager and spawned it in the world. The villager extends EntityVillager and I was wondering how I could listen to events that affect the villager (e.g. EntityDamageEvent, EntityDeathEvent etc). I have tried doing: Code:Java @EventHandler public void aa(org.bukkit.event.entity.EntityDamageByEntityEvent e){ if (e.getEntity() instanceof CustomVillager){ Bukkit.broadcastMessage("Someone hit the villager :("); e.setCancelled(true); } } however, when I put in some debug messages to see what the entity is it returns "CraftVillager" even though it is my custom Villager. How I'm spawning the villager into the world: Code:Java Player player = (Player)sender; CraftWorld cW = (CraftWorld)player.getWorld(); this.spawnVillager(new CustomVillager(cW.getHandle(), Villager.Profession.BLACKSMITH.getId(), args[0]), player.getLocation(), cW.getHandle()); Code:Java public void spawnVillager(CustomVillager ent, Location l, net.minecraft.server.v1_7_R3.World world){ ent.setPosition(l.getX(), l.getY(), l.getZ()); world.addEntity(ent); } Any help would be appreciated
Craftbukkit entities wrap the actual NMS Entities. You need to call the getHandle() method of the CraftEntity to get the NMS Entity.