Made NPC dialog event cancellable

This commit is contained in:
Luis C.M committed 2022-11-05 04:19:03 -05:00
1 parent 9c82e60a6e
commit 6782a5b9ba
3 files changed
+7 -7

No files matched your search

+3 -3
View File
@@ -139,15 +139,15 @@ public class EventHooks {
NpcAPI.EVENT_BUS.post(event);
}
public static void onNPCDialog(EntityNPCInterface npc, EntityPlayer player, int dialogId, int optionId, Dialog dialog) {
public static boolean onNPCDialog(EntityNPCInterface npc, EntityPlayer player, int dialogId, int optionId, Dialog dialog) {
if(npc == null || npc.wrappedNPC == null)
return;
return false;
NpcEvent.DialogEvent event = new NpcEvent.DialogEvent(npc.wrappedNPC, player, dialogId, optionId, dialog);
ScriptController.Instance.npcScripts.callScript(EnumScriptType.DIALOG, event);
npc.script.callScript(EnumScriptType.DIALOG, event, "player", event.getPlayer(), "dialog", event.getDialogId(), "option", event.getOptionId(), "dialogObj", event.getDialog());
NpcAPI.EVENT_BUS.post(event);
return NpcAPI.EVENT_BUS.post(event);
}
public static void onNPCDialogClosed(EntityNPCInterface npc, EntityPlayer player, int dialogId, int optionId, Dialog dialog) {
@@ -183,6 +183,9 @@ public class NoppesUtilServer {
Dialog dialog = dia.copy(player);
if (!npc.isRemote()) {
if (EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog)) {
return;
}
EventHooks.onDialogOpen(new DialogEvent.DialogOpen((IPlayer) NpcAPI.Instance().getIEntity(player), dialog));
}
@@ -204,10 +207,6 @@ public class NoppesUtilServer {
if(!data.dialogsRead.contains(dialog.id))
data.dialogsRead.add(dialog.id);
setEditingNpc(player, npc);
if (!npc.isRemote()) {
EventHooks.onNPCDialog(npc, player, dialog.id, optionId, dialog);
}
}
public static void runCommand(EntityPlayer player, String name, String command){
runCommand(player, name, command, player);
@@ -248,6 +248,7 @@ public class NpcEvent extends CustomNPCsEvent {
}
}
@Cancelable
public static class DialogEvent extends NpcEvent {
public final IPlayer player;
public final int id;