Solved Removing zombie target

Discussion in 'Spigot Plugin Development' started by MaveCrit, Apr 25, 2017.

  1. Hello there!
    So I have a little problem.
    I have a custom NMS zombie but well, thats not the problem.
    I made my own EntityTarget"Event" because I need some more functions than the original has.

    What I'm trying to do:
    The zombies should attack a person in a radius of 10 (Done)
    After 10 seconds they should run back to their old point (Done)

    BUT:
    They wouldn't attack a second time cause the ".getTarget" does NOT return null.
    I tried to set the target to null using ".setTarget(null)" but well, that does not seems to work.

    How can I remove a target from a zombie?
     
  2. have you tried to block the spigot EntityTargetEvent until your zombies should go away ?
     
  3. yep

    Code (Text):
        @EventHandler
        public void onAttack(EntityTargetEvent e) {
            Entity en = e.getEntity();
            Entity target = e.getTarget();
            if (en instanceof Zombie) {
                if (target instanceof Player) {
                    Zombie z = (Zombie) en;
                    Player p = (Player) target;

                    final Location test = targetLocation;
                    EntityZombie cz = ((CraftZombie) z).getHandle();
                    if (cz instanceof CustomZombie) {
                        e.setCancelled(true);
                    }
                }
            }
        }
     
  4. have you used something like an output message to check if the event has been really cancelled?
     
  5. Nevermind.. Just didn't cleared the pathfinders.. :D