Solved Removing Target from LivingEntity

Discussion in 'Spigot Plugin Development' started by Alex_qp, Jul 29, 2018.

  1. Hey there,

    I want a LivingEntity (PigZombie) to untarget a player after a certain amount of ticks. So my idea was to schedule a task which removes the target of the entity. But using PigZombie#setTarget(null) does not function.

    All I could find was cancelling the event but I cannot do that cause of the above problem.

    Thanks in advance for helping!
    Alex
     
  2. never mind I figured it out:

    1) Create a BukkitRunnable and schedule it like you wish.
    2) there you can change the target to what you like

    If you change the target to null it will spam your EntityTargetLivingEntityEvent every tick (if the player who should get targeted is still in range) so this may be something to keep in mind. You can prevent this by spawning an entity, set the target to it and kill it right afterwards (I did this 100 blocks above the entity)