@EventHandler public void onTarget(EntityTargetEvent event) { EntityUtil entity = (EntityUtil) event.getEntity(); if (entity.checkInVillage()) { event.setCancelled(true); } }
@Override public void onEntityTarget(EntityTargetEvent event) { if (event instanceof NpcEntityTargetEvent) { NpcEntityTargetEvent nevent = (NpcEntityTargetEvent) event; BasicHumanNpc npc = parent.HumanNPCList.getBasicHumanNpc(event.getEntity()); if (npc != null && event.getTarget() instanceof Player) { if (nevent.getNpcReason() == NpcTargetReason.CLOSEST_PLAYER) { Player p = (Player) event.getTarget(); p.sendMessage("<" + npc.getName() + "> Hello friend, I'm an NPC!"); event.setCancelled(true); } else if (nevent.getNpcReason() == NpcTargetReason.NPC_RIGHTCLICKED) { Player p = (Player) event.getTarget(); p.sendMessage("<" + npc.getName() + "> You right-clicked me!"); event.setCancelled(true); } else if (nevent.getNpcReason() == NpcTargetReason.NPC_BOUNCED) { Player p = (Player) event.getTarget(); p.sendMessage("<" + npc.getName() + "> Stop bouncing on me!"); event.setCancelled(true); } } } }
@EventHandler(priority = EventPriority.HIGHEST) public void onEntityTarget(final EntityTargetEvent event) { if (event.isCancelled()) { return; } if (!(event.getTarget() instanceof Player)) { return; } final User user = ess.getUser(event.getTarget()); if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) && prot.getSettingBool(ProtectConfig.prevent_entitytarget) && !user.isAuthorized("essentials.protect.entitytarget.bypass")) { event.setCancelled(true); return; } }