Cancel right click event if NPC has talked to someone

This commit is contained in:
fullwall 2020-04-20 21:44:50 +08:00
parent 0531fe859e
commit 06d8e92ff2
2 changed files with 4 additions and 0 deletions

View File

@ -458,6 +458,9 @@ public class EventListen implements Listener {
Player player = event.getPlayer();
NPCRightClickEvent rightClickEvent = new NPCRightClickEvent(npc, player);
Bukkit.getPluginManager().callEvent(rightClickEvent);
if (rightClickEvent.isCancelled()) {
event.setCancelled(true);
}
if (npc.hasTrait(CommandTrait.class)) {
npc.getTrait(CommandTrait.class).dispatch(player, CommandTrait.Hand.RIGHT);
}

View File

@ -140,6 +140,7 @@ public class Text extends Trait implements Runnable, Toggleable, Listener, Conve
String localPattern = itemInHandPattern.equals("default") ? Setting.TALK_ITEM.asString() : itemInHandPattern;
if (Util.matchesItemInHand(event.getClicker(), localPattern) && !shouldTalkClose()) {
sendText(event.getClicker());
event.setCancelled(true);
}
}