Entity setTarget

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

  1. Offline


    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);

    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")){

  2. Offline


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


    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. Offline


Share This Page