Supply external conversation hooks, part 12

This commit is contained in:
PikaMug 2019-09-24 01:17:54 -04:00
parent acbebbf7f6
commit f27ad6466f
3 changed files with 23 additions and 10 deletions

View File

@ -1,18 +1,21 @@
package me.blackvein.quests.events.editor.quests; package me.blackvein.quests.events.command;
import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationContext;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester;
/** /**
* Called when the initial Quests Editor menu is opened by a player * Called when the /quests editor command is run by a player
*/ */
public class QuestsEditorPreOpenMainPromptEvent extends QuestsEditorEvent implements Cancellable { public class QuestsCommandPreQuestsEditorEvent extends QuestsCommandEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancel = false; private boolean cancel = false;
private ConversationContext context;
public QuestsEditorPreOpenMainPromptEvent(ConversationContext context) { public QuestsCommandPreQuestsEditorEvent(Quester quester, ConversationContext context) {
super(context); super(quester);
this.context = context; this.context = context;
} }
@ -34,4 +37,8 @@ public class QuestsEditorPreOpenMainPromptEvent extends QuestsEditorEvent implem
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
public ConversationContext getConversationContext() {
return context;
}
} }

View File

@ -5,6 +5,9 @@ import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester; import me.blackvein.quests.Quester;
/**
* Called when the /quests journal command is run by a player
*/
public class QuestsCommandPreQuestsJournalEvent extends QuestsCommandEvent implements Cancellable { public class QuestsCommandPreQuestsJournalEvent extends QuestsCommandEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancel = false; private boolean cancel = false;

View File

@ -30,8 +30,8 @@ import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.Requirements; import me.blackvein.quests.Requirements;
import me.blackvein.quests.Stage; import me.blackvein.quests.Stage;
import me.blackvein.quests.events.command.QuestsCommandPreQuestsEditorEvent;
import me.blackvein.quests.events.command.QuestsCommandPreQuestsJournalEvent; import me.blackvein.quests.events.command.QuestsCommandPreQuestsJournalEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPreOpenMainPromptEvent;
import me.blackvein.quests.events.quest.QuestQuitEvent; import me.blackvein.quests.events.quest.QuestQuitEvent;
import me.blackvein.quests.exceptions.InvalidStageException; import me.blackvein.quests.exceptions.InvalidStageException;
import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.ItemUtil;
@ -453,10 +453,13 @@ public class CmdExecutor implements CommandExecutor {
Conversable c = (Conversable) cs; Conversable c = (Conversable) cs;
if (!c.isConversing()) { if (!c.isConversing()) {
Conversation cn = plugin.getQuestFactory().getConversationFactory().buildConversation(c); Conversation cn = plugin.getQuestFactory().getConversationFactory().buildConversation(c);
QuestsEditorPreOpenMainPromptEvent event = new QuestsEditorPreOpenMainPromptEvent(cn.getContext()); if (cs instanceof Player) {
plugin.getServer().getPluginManager().callEvent(event); Quester quester = plugin.getQuester(((Player)cs).getUniqueId());
if (event.isCancelled()) { QuestsCommandPreQuestsEditorEvent event = new QuestsCommandPreQuestsEditorEvent(quester, cn.getContext());
return false; plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return false;
}
} }
cn.begin(); cn.begin();
} else { } else {