Entity setTarget

Discussion in 'Plugin Development' started by R3YGamer, Sep 5, 2020.

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

    R3YGamer

    I want a code that setTargets of entities to null when a player is holding a specific item but the code doesn't work.

    plz help

    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityTargetEvent;
    import org.bukkit.event.entity.EntityTargetLivingEntityEvent;

    public class invisible implements Listener {

    public invisible(main plugin) {
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    }

    @EventHandler
    public void onCreatureTarget(EntityTargetLivingEntityEvent event){
    Entity entity = event.getEntity();
    if (entity instanceof Player) {
    Player player = (Player) event.getTarget();
    if (player.getInventory().getItemInMainHand().getItemMeta().getLore().contains("Invisible")){
    event.setTarget(null);
    }
    }
    }


    }
     
  2. Offline

    Newdel

    I think you mean if (event.getTarget() instanceof Player)
     
    Xp10d3 likes this.
  3. Offline

    R3YGamer

    Oh OK I will try that

    Thanks it works now <3
    Edit: moderator can you mark this thread as solved, i don't know how to

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 7, 2020
    Newdel likes this.
  4. Online

    KarimAKL

Thread Status:
Not open for further replies.

Share This Page