1.15.2 Stops mobs from following

Discussion in 'Spigot Plugin Development' started by Niqck, Mar 26, 2020.

  1. The first event works and stops me from taking damage. (context)
    But the second doesn't seem to work and mobs keep following me around. (they don't deal damage)
    What am I doing wrong?

    Code (Java):


    @EventHandler
    public void onMobDamage(EntityDamageByEntityEvent event) {
        Entity entity = event.getEntity();

        if (entity instanceof Player) {
            Player player = (Player)entity;
            if (hiddenList.contains(player.getName()))
                event.setCancelled(true);
        }

    }

    @EventHandler
    public void onMobTracking(EntityTargetLivingEntityEvent event) {
        Entity entity = event.getEntity();

        if (entity instanceof Player) {
            Player player = (Player)entity;
            if (hiddenList.contains(player.getName()))
                event.setCancelled(true);
        }
    }
     
    #1 Niqck, Mar 26, 2020
    Last edited: Mar 26, 2020
  2. Hey,

    So you mean that first event is completely working. But after one missed damage of the mob, the code is not working?

    Did I understand you well?
     
  3. Sorry, I should've written it differently.
    The first event works and I only included it for context.
    The second event doesn't work, I need the mobs to stop following me (because I'm vanished).
     
  4. Because EntityTargetLivingEntityEvent#getEntity returns the entity that is targeting something. #getTarget is the method you are looking for.
     
  5. Sorry, I can't find how to use the getTarget method. Could you explain how I am supposed to use it?
     
  6. event.getTaget(); instead of event.getEntity();