NEW Command Event, sorta resolves #118

This commit is contained in:
HappyPikachu 2018-01-17 02:48:24 -05:00
parent 031af51829
commit 6f9b150818
10 changed files with 252 additions and 32 deletions

View File

@ -46,6 +46,7 @@ import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerFishEvent.State;
@ -316,6 +317,33 @@ public class PlayerListener implements Listener {
}
}
}
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent evt) {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
if (quester.currentQuests.isEmpty() == false) {
for (Quest quest : quester.currentQuests.keySet()) {
Stage currentStage = quester.getCurrentStage(quest);
if (currentStage == null) {
plugin.getLogger().severe("currentStage was null for " + quester.id.toString() + " on command");
continue;
}
if (currentStage.commandEvents.isEmpty() == false) {
String command = evt.getMessage();
for (String s : currentStage.commandEvents.keySet()) {
if (command.equalsIgnoreCase("/" + s)) {
if (quester.getQuestData(quest).eventFired.get(s) == null || quester.getQuestData(quest).eventFired.get(s) == false) {
currentStage.commandEvents.get(s).fire(quester, quest);
quester.getQuestData(quest).eventFired.put(s, true);
}
}
}
}
}
}
}
}
@EventHandler
public void onBlockDamage(BlockDamageEvent evt) {

View File

@ -1078,6 +1078,8 @@ public class QuestFactory implements ConversationAbandonedListener {
String disconnectEvent;
LinkedList<String> chatEvents;
LinkedList<String> chatEventTriggers;
LinkedList<String> commandEvents;
LinkedList<String> commandEventTriggers;
Long delay;
String overrideDisplay;
String delayMessage;
@ -1136,6 +1138,8 @@ public class QuestFactory implements ConversationAbandonedListener {
disconnectEvent = null;
chatEvents = null;
chatEventTriggers = null;
commandEvents = null;
commandEventTriggers = null;
delay = null;
overrideDisplay = null;
delayMessage = null;
@ -1236,6 +1240,10 @@ public class QuestFactory implements ConversationAbandonedListener {
chatEvents = (LinkedList<String>) cc.getSessionData(pref + CK.S_CHAT_EVENTS);
chatEventTriggers = (LinkedList<String>) cc.getSessionData(pref + CK.S_CHAT_EVENT_TRIGGERS);
}
if (cc.getSessionData(pref + CK.S_COMMAND_EVENTS) != null) {
commandEvents = (LinkedList<String>) cc.getSessionData(pref + CK.S_COMMAND_EVENTS);
commandEventTriggers = (LinkedList<String>) cc.getSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS);
}
if (cc.getSessionData(pref + CK.S_DELAY) != null) {
delay = (Long) cc.getSessionData(pref + CK.S_DELAY);
delayMessage = (String) cc.getSessionData(pref + CK.S_DELAY_MESSAGE);
@ -1344,6 +1352,10 @@ public class QuestFactory implements ConversationAbandonedListener {
stage.set("chat-events", chatEvents);
stage.set("chat-event-triggers", chatEventTriggers);
}
if (commandEvents != null && commandEvents.isEmpty() == false) {
stage.set("command-events", commandEvents);
stage.set("command-event-triggers", commandEventTriggers);
}
if (delay != null) {
stage.set("delay", delay.intValue() / 1000);
}
@ -1693,6 +1705,16 @@ public class QuestFactory implements ConversationAbandonedListener {
cc.setSessionData(pref + CK.S_CHAT_EVENTS, chatEvents);
cc.setSessionData(pref + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers);
}
if (stage.commandEvents != null) {
LinkedList<String> commandEvents = new LinkedList<String>();
LinkedList<String> commandEventTriggers = new LinkedList<String>();
for (String s : stage.commandEvents.keySet()) {
commandEventTriggers.add(s);
commandEvents.add(stage.commandEvents.get(s).getName());
}
cc.setSessionData(pref + CK.S_COMMAND_EVENTS, commandEvents);
cc.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers);
}
if (stage.delay != -1) {
cc.setSessionData(pref + CK.S_DELAY, stage.delay);
if (stage.delayMessage != null) {
@ -1712,7 +1734,6 @@ public class QuestFactory implements ConversationAbandonedListener {
cc.setSessionData(pref + CK.S_START_MESSAGE, stage.startMessage);
}
}
//
}
private class SelectDeletePrompt extends StringPrompt {

View File

@ -348,6 +348,11 @@ public class Quester {
questData.get(q).eventFired.put(chatTrigger, false);
}
}
if (stage.commandEvents.isEmpty() == false) {
for (String commandTrigger : stage.commandEvents.keySet()) {
questData.get(q).eventFired.put(commandTrigger, false);
}
}
if (q.initialEvent != null) {
q.initialEvent.fire(this, q);
}
@ -1790,14 +1795,25 @@ public class Quester {
questSec.set("stage-delay", questData.delayTimeLeft);
}
if (questData.eventFired.isEmpty() == false) {
LinkedList<String> triggers = new LinkedList<String>();
LinkedList<String> chatTriggers = new LinkedList<String>();
for (String trigger : questData.eventFired.keySet()) {
if (questData.eventFired.get(trigger) == true) {
triggers.add(trigger);
chatTriggers.add(trigger);
}
}
if (triggers.isEmpty() == false) {
questSec.set("chat-triggers", triggers);
if (chatTriggers.isEmpty() == false) {
questSec.set("chat-triggers", chatTriggers);
}
}
if (questData.eventFired.isEmpty() == false) {
LinkedList<String> commandTriggers = new LinkedList<String>();
for (String commandTrigger : questData.eventFired.keySet()) {
if (questData.eventFired.get(commandTrigger) == true) {
commandTriggers.add(commandTrigger);
}
}
if (commandTriggers.isEmpty() == false) {
questSec.set("command-triggers", commandTriggers);
}
}
}
@ -2153,13 +2169,24 @@ public class Quester {
getQuestData(quest).delayTimeLeft = questSec.getLong("stage-delay");
}
if (getCurrentStage(quest).chatEvents.isEmpty() == false) {
for (String trig : getCurrentStage(quest).chatEvents.keySet()) {
getQuestData(quest).eventFired.put(trig, false);
for (String chatTrig : getCurrentStage(quest).chatEvents.keySet()) {
getQuestData(quest).eventFired.put(chatTrig, false);
}
}
if (questSec.contains("chat-triggers")) {
List<String> triggers = questSec.getStringList("chat-triggers");
for (String s : triggers) {
List<String> chatTriggers = questSec.getStringList("chat-triggers");
for (String s : chatTriggers) {
getQuestData(quest).eventFired.put(s, true);
}
}
if (getCurrentStage(quest).commandEvents.isEmpty() == false) {
for (String commandTrig : getCurrentStage(quest).commandEvents.keySet()) {
getQuestData(quest).eventFired.put(commandTrig, false);
}
}
if (questSec.contains("command-triggers")) {
List<String> commandTriggers = questSec.getStringList("command-triggers");
for (String s : commandTriggers) {
getQuestData(quest).eventFired.put(s, true);
}
}
@ -2288,8 +2315,12 @@ public class Quester {
newData.set(questName + ".stage-delay", questSec.getLong("stage-delay"));
}
if (questSec.contains("chat-triggers")) {
List<String> triggers = questSec.getStringList("chat-triggers");
newData.set(questName + ".chat-triggers", triggers);
List<String> chatTriggers = questSec.getStringList("chat-triggers");
newData.set(questName + ".chat-triggers", chatTriggers);
}
if (questSec.contains("command-triggers")) {
List<String> commandTriggers = questSec.getStringList("command-triggers");
newData.set(questName + ".command-triggers", commandTriggers);
}
return newData;
}

View File

@ -3266,6 +3266,35 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
stageFailed("chat-events in Stage " + s2 + " of Quest " + quest.name + " is not in list format!");
}
}
if (config.contains("quests." + questName + ".stages.ordered." + s2 + ".command-events")) {
if (config.isList("quests." + questName + ".stages.ordered." + s2 + ".command-events")) {
if (config.contains("quests." + questName + ".stages.ordered." + s2 + ".command-event-triggers")) {
if (config.isList("quests." + questName + ".stages.ordered." + s2 + ".command-event-triggers")) {
List<String> commandEvents = config.getStringList("quests." + questName + ".stages.ordered." + s2 + ".command-events");
List<String> commandEventTriggers = config.getStringList("quests." + questName + ".stages.ordered." + s2 + ".command-event-triggers");
boolean loadEventFailed = false;
for (int i = 0; i < commandEvents.size(); i++) {
Event evt = Event.loadEvent(commandEvents.get(i), this);
if (evt != null) {
oStage.commandEvents.put(commandEventTriggers.get(i), evt);
} else {
loadEventFailed = true;
stageFailed("" + commandEvents.get(i) + " inside of command-events: in Stage " + s2 + " of Quest " + quest.name + " failed to load.");
}
}
if (loadEventFailed) {
break;
}
} else {
stageFailed("command-event-triggers in Stage " + s2 + " of Quest " + quest.name + " is not in list format!");
}
} else {
stageFailed("Stage " + s2 + " of Quest " + quest.name + " is missing command-event-triggers!");
}
} else {
stageFailed("command-events in Stage " + s2 + " of Quest " + quest.name + " is not in list format!");
}
}
if (config.contains("quests." + questName + ".stages.ordered." + s2 + ".delay")) {
if (config.getLong("quests." + questName + ".stages.ordered." + s2 + ".delay", -999) != -999) {
oStage.delay = config.getInt("quests." + questName + ".stages.ordered." + s2 + ".delay") * 1000;

View File

@ -117,6 +117,7 @@ public class Stage {
public Event startEvent = null;
public Event deathEvent = null;
public Map<String, Event> chatEvents = new HashMap<String, Event>();
public Map<String, Event> commandEvents = new HashMap<String, Event>();
public Event disconnectEvent = null;
public Event finishEvent = null;
public long delay = -1;
@ -278,6 +279,9 @@ public class Stage {
if (other.chatEvents.equals(chatEvents) == false) {
return false;
}
if (other.commandEvents.equals(commandEvents) == false) {
return false;
}
if (other.delay != delay) {
return false;
}

View File

@ -3127,7 +3127,7 @@ public class CreateStagePrompt extends FixedSetPrompt {
private class EventListPrompt extends FixedSetPrompt {
public EventListPrompt() {
super("1", "2", "3", "4", "5", "6");
super("1", "2", "3", "4", "5", "6", "7");
}
@SuppressWarnings("unchecked")
@ -3164,15 +3164,20 @@ public class CreateStagePrompt extends FixedSetPrompt {
text += ChatColor.AQUA + " - " + event + ChatColor.BLUE + " (" + Lang.get("stageEditorTriggeredBy") + ": \"" + chatEventTriggers.get(chatEvents.indexOf(event)) + "\")\n";
}
}
text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.BLUE + " - " + Lang.get("back");
if (context.getSessionData(pref + CK.S_COMMAND_EVENTS) == null) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("stageEditorCommandEvents") + " (" + Lang.get("noneSet") + ")\n";
} else {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "6" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("stageEditorCommandEvents") + "\n";
LinkedList<String> commandEvents = (LinkedList<String>) context.getSessionData(pref + CK.S_COMMAND_EVENTS);
LinkedList<String> commandEventTriggers = (LinkedList<String>) context.getSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS);
for (String event : commandEvents) {
text += ChatColor.AQUA + " - " + event + ChatColor.BLUE + " (" + Lang.get("stageEditorTriggeredBy") + ": \"" + commandEventTriggers.get(commandEvents.indexOf(event)) + "\")\n";
}
}
text += ChatColor.BLUE + "" + ChatColor.BOLD + "7" + ChatColor.RESET + ChatColor.BLUE + " - " + Lang.get("back");
return text;
}
/*
* en.put("stageEditorStageEvents", "Stage Events"); en.put("stageEditorStartEvent", "Start Event"); en.put("stageEditorFinishEvent",
* "Finish Event"); en.put("stageEditorChatEvents", "Chat Events"); en.put("stageEditorDeathEvent", "Death Event");
* en.put("stageEditorDisconnectEvent", "Disconnect Event");
*/
@Override
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase("1")) {
@ -3186,6 +3191,8 @@ public class CreateStagePrompt extends FixedSetPrompt {
} else if (input.equalsIgnoreCase("5")) {
return new ChatEventPrompt();
} else if (input.equalsIgnoreCase("6")) {
return new CommandEventPrompt();
} else if (input.equalsIgnoreCase("7")) {
return new CreateStagePrompt(stageNum, questFactory, citizens);
} else {
return new EventListPrompt();
@ -3459,6 +3466,93 @@ public class CreateStagePrompt extends FixedSetPrompt {
}
}
}
private class CommandEventPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
String text = ChatColor.DARK_GREEN + "- " + Lang.get("stageEditorCommandEvents") + " -\n";
if (questFactory.quests.events.isEmpty()) {
text += ChatColor.RED + "- " + Lang.get("none");
} else {
for (Event e : questFactory.quests.events) {
text += ChatColor.GREEN + "- " + e.getName() + "\n";
}
}
return text + ChatColor.YELLOW + Lang.get("stageEditorCommandEventsPrompt");
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
Player player = (Player) context.getForWhom();
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
Event found = null;
for (Event e : questFactory.quests.events) {
if (e.getName().equalsIgnoreCase(input)) {
found = e;
break;
}
}
if (found == null) {
player.sendMessage(ChatColor.RED + input + ChatColor.YELLOW + " " + Lang.get("stageEditorInvalidEvent"));
return new CommandEventPrompt();
} else {
context.setSessionData(pref + CK.S_COMMAND_TEMP_EVENT, found.getName());
return new CommandEventTriggerPrompt();
}
} else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new EventListPrompt();
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(pref + CK.S_COMMAND_EVENTS, null);
context.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, null);
player.sendMessage(ChatColor.YELLOW + Lang.get("stageEditorCommandEventsCleared"));
return new EventListPrompt();
} else {
return new CommandEventPrompt();
}
}
}
private class CommandEventTriggerPrompt extends StringPrompt {
@Override
public String getPromptText(ConversationContext context) {
String tempEvent = (String) context.getSessionData(pref + CK.S_COMMAND_TEMP_EVENT);
String text = ChatColor.GOLD + "- " + Lang.get("stageEditorCommandTrigger") + " -\n";
text += ChatColor.YELLOW + Lang.get("stageEditorCommandEventsTriggerPromptA") + " " + ChatColor.AQUA + tempEvent + " " + ChatColor.YELLOW + Lang.get("stageEditorCommandEventsTriggerPromptB");
return text;
}
@SuppressWarnings("unchecked")
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
if (context.getSessionData(pref + CK.S_COMMAND_EVENTS) == null) {
LinkedList<String> commandEvents = new LinkedList<String>();
LinkedList<String> commandEventTriggers = new LinkedList<String>();
String event = (String) context.getSessionData(pref + CK.S_COMMAND_TEMP_EVENT);
commandEvents.add(event);
commandEventTriggers.add(input.trim());
context.setSessionData(pref + CK.S_COMMAND_EVENTS, commandEvents);
context.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers);
return new EventListPrompt();
} else {
LinkedList<String> commandEvents = (LinkedList<String>) context.getSessionData(pref + CK.S_COMMAND_EVENTS);
LinkedList<String> commandEventTriggers = (LinkedList<String>) context.getSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS);
String event = (String) context.getSessionData(pref + CK.S_COMMAND_TEMP_EVENT);
commandEvents.add(event);
commandEventTriggers.add(input.trim());
context.setSessionData(pref + CK.S_COMMAND_EVENTS, commandEvents);
context.setSessionData(pref + CK.S_COMMAND_EVENT_TRIGGERS, commandEventTriggers);
return new EventListPrompt();
}
} else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new EventListPrompt();
} else {
return new CommandEventTriggerPrompt();
}
}
}
private class DelayPrompt extends StringPrompt {

View File

@ -104,6 +104,9 @@ public class CK {
public static final String S_CHAT_EVENTS = "chatEvents";
public static final String S_CHAT_EVENT_TRIGGERS = "chatEventTriggers";
public static final String S_CHAT_TEMP_EVENT = "chatTempEvent";
public static final String S_COMMAND_EVENTS = "commandEvents";
public static final String S_COMMAND_EVENT_TRIGGERS = "commandEventTriggers";
public static final String S_COMMAND_TEMP_EVENT = "commandTempEvent";
public static final String S_DEATH_EVENT = "deathEvent";
public static final String S_DISCONNECT_EVENT = "disconnectEvent";
public static final String S_DELAY = "delay";

View File

@ -1,6 +1,6 @@
events:
ExampleEvent:
message: '<red>Event happened!'
ApplyPotion:
message: "<blue>You received potion effects!"
potion-effect-types:
- Speed
- Jump
@ -10,17 +10,21 @@ events:
potion-effect-amplifiers:
- 3
- 2
GoodJob:
message: "<green>Good job!"
NiceFinish:
message: "<green>Nice work!"
DeathFail:
fail-quest: true
FishingStart:
RodStart:
message: "<yellow>Type 'rod' in chat to get a fishing rod!"
RodEvent:
GiveRod:
message: "<green>Here you go!"
items:
- name-fishing_rod:amount-1
TimerEvent:
TimerStart:
timer: 40
CancelTimer:
cancel-timer: true
cancel-timer: true
RunCommand:
message: "<red>Did you mean 'help'?"
commands:
- help

View File

@ -38,14 +38,14 @@ quests:
- Pig
mob-amounts:
- 3
finish-event: GoodJob
finish-event: NiceFinish
2:
death-event: DeathFail
mobs-to-kill:
- Zombie
mob-amounts:
- 2
finish-event: GoodJob
finish-event: NiceFinish
3:
death-event: DeathFail
mobs-to-kill:
@ -68,10 +68,10 @@ quests:
stages:
ordered:
1:
start-event: FishingStart
start-event: RodStart
death-event: DeathFail
chat-events:
- "RodEvent"
- "GiveRod"
chat-event-triggers:
- "rod"
fish-to-catch: 5
@ -90,7 +90,7 @@ quests:
- 10
break-block-durability:
- 0
start-event: TimerEvent
start-event: TimerStart
finish-event: CancelTimer
rewards:
items:

View File

@ -152,8 +152,11 @@ stageEditorFinishEvent: "Finish Event"
stageEditorFinishEventCleared: "Finish Event cleared."
stageEditorChatEvents: "Chat Events"
stageEditorChatTrigger: "Chat Trigger"
stageEditorTriggeredBy: "Triggered by"
stageEditorChatEventsCleared: "Chat Events cleared."
stageEditorCommandEvents: "Command Events"
stageEditorCommandTrigger: "Command Trigger"
stageEditorCommandEventsCleared: "Command Events cleared."
stageEditorTriggeredBy: "Triggered by"
stageEditorDeathEvent: "Death Event"
stageEditorDeathEventCleared: "Death Event cleared."
stageEditorDisconnectEvent: "Disconnect Event"
@ -229,6 +232,9 @@ stageEditorEventsPrompt: "Enter an event name, or enter 'clear' to clear the eve
stageEditorChatEventsPrompt: "Enter an event name to add, or enter 'clear' to clear all chat events, or 'cancel' to return"
stageEditorChatEventsTriggerPromptA: "Enter a chat trigger for"
stageEditorChatEventsTriggerPromptB: "or enter 'cancel' to return."
stageEditorCommandEventsPrompt: "Enter an event name to add, or enter 'clear' to clear all command events, or 'cancel' to return"
stageEditorCommandEventsTriggerPromptA: "Enter a command trigger for"
stageEditorCommandEventsTriggerPromptB: "or enter 'cancel' to return."
stageEditorDelayPrompt: "Enter time (in seconds), or enter 'clear' to clear the delay, or 'cancel' to return"
stageEditorDelayMessagePrompt: "Enter delay message, or enter 'clear' to clear the message, or 'cancel' to return"
stageEditorScriptPrompt: "Enter script name, or enter 'clear' to clear the script, or 'cancel' to return"