Solved Cast player to a EntityHuman?

Discussion in 'Plugin Development' started by TigerHix, Jun 7, 2014.

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

    TigerHix

    Code:java
    1. @Override
    2. public void damageEntity(EntityDamageByEntityEvent event) {
    3. // Some instanceof checks here, to make sure event.getDamager() is a Player
    4. ((CraftLivingEntity) event.getEntity()).getHandle().damageEntity(DamageSource.playerAttack((EntityHuman) ((CraftPlayer) event.getDamager())), damage);
    5. }


    But it doesn't seem to work.. error: CraftPlayer could not be casted to EntityHuman. Any ideas?
     
  2. Offline

    Konkz

    EDIT: Nevermind
     
  3. Offline

    fireblast709

    TigerHix EntityHuman is a superclass of EntityPlayer, thus you need to call getHandle() on the CraftPlayer first.
     
  4. Offline

    TigerHix

    fireblast709 Konkz Thanks for the quick reply. But using ((EntityHuman) ((CraftPlayer) player).getHandle()) won't work too, as it freezes the server for some seconds and bump thousand lines of errors in my console (EventException) with no further information.
     
  5. Offline

    Conarnar

    You made an infinite loop. So inside the damageEntity method, you do stuff, then you use nms to damage the entity again which called another EntityDamageByEntityEvent, which runs the damageEntity method again.
     
    NathanWolf likes this.
  6. Offline

    TigerHix

    Conarnar I see! :)

    Conarnar Solved using interface. Thanks!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
Thread Status:
Not open for further replies.

Share This Page