Solved NMS Events

Discussion in 'Plugin Development' started by TGRHavoc, Aug 4, 2014.

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

    TGRHavoc

    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
    1. @EventHandler
    2. public void aa(org.bukkit.event.entity.EntityDamageByEntityEvent e){
    3. if (e.getEntity() instanceof CustomVillager){
    4. Bukkit.broadcastMessage("Someone hit the villager :(");
    5. e.setCancelled(true);
    6. }
    7. }

    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
    1. Player player = (Player)sender;
    2. CraftWorld cW = (CraftWorld)player.getWorld();
    3. this.spawnVillager(new CustomVillager(cW.getHandle(), Villager.Profession.BLACKSMITH.getId(), args[0]), player.getLocation(), cW.getHandle());
    4.  

    Code:Java
    1.  
    2. public void spawnVillager(CustomVillager ent, Location l, net.minecraft.server.v1_7_R3.World world){
    3. ent.setPosition(l.getX(), l.getY(), l.getZ());
    4. world.addEntity(ent);
    5. }
    6.  
    7.  

    Any help would be appreciated :)
     
  2. Offline

    _LB

    Craftbukkit entities wrap the actual NMS Entities. You need to call the getHandle() method of the CraftEntity to get the NMS Entity.
     
    TGRHavoc likes this.
  3. Offline

    TGRHavoc

    Ahhh, thank you so much! Can't believe I didn't think of that.
     
    _LB likes this.
Thread Status:
Not open for further replies.

Share This Page