mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-28 13:45:32 +01:00
Supply external conversation hooks, part 8. Per #570
This commit is contained in:
parent
073f2b11ac
commit
d0750e97fd
@ -0,0 +1,30 @@
|
|||||||
|
package me.blackvein.quests.events.editor.quests;
|
||||||
|
|
||||||
|
import org.bukkit.conversations.ConversationContext;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
import me.blackvein.quests.QuestFactory;
|
||||||
|
|
||||||
|
public class QuestsEditorPostOpenPlannerPromptEvent extends QuestsEditorEvent {
|
||||||
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
private final QuestFactory factory;
|
||||||
|
|
||||||
|
public QuestsEditorPostOpenPlannerPromptEvent(QuestFactory factory, ConversationContext context) {
|
||||||
|
super(context);
|
||||||
|
this.context = context;
|
||||||
|
this.factory = factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public QuestFactory getQuestFactory() {
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
}
|
@ -20,88 +20,148 @@ import java.util.TimeZone;
|
|||||||
|
|
||||||
import me.blackvein.quests.QuestFactory;
|
import me.blackvein.quests.QuestFactory;
|
||||||
import me.blackvein.quests.Quests;
|
import me.blackvein.quests.Quests;
|
||||||
|
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenPlannerPromptEvent;
|
||||||
import me.blackvein.quests.util.CK;
|
import me.blackvein.quests.util.CK;
|
||||||
import me.blackvein.quests.util.Lang;
|
import me.blackvein.quests.util.Lang;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
import org.bukkit.conversations.FixedSetPrompt;
|
import org.bukkit.conversations.NumericPrompt;
|
||||||
import org.bukkit.conversations.Prompt;
|
import org.bukkit.conversations.Prompt;
|
||||||
import org.bukkit.conversations.StringPrompt;
|
import org.bukkit.conversations.StringPrompt;
|
||||||
|
|
||||||
public class PlannerPrompt extends FixedSetPrompt {
|
public class PlannerPrompt extends NumericPrompt {
|
||||||
|
|
||||||
private final Quests plugin;
|
private final Quests plugin;
|
||||||
private final QuestFactory factory;
|
private final QuestFactory factory;
|
||||||
|
|
||||||
public PlannerPrompt(Quests plugin, QuestFactory qf) {
|
public PlannerPrompt(Quests plugin, QuestFactory qf) {
|
||||||
super("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
factory = qf;
|
factory = qf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final int size = 5;
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle(ConversationContext context) {
|
||||||
|
return ChatColor.DARK_AQUA + Lang.get("plannerTitle").replace("<quest>", ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_AQUA);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatColor getNumberColor(ConversationContext context, int number) {
|
||||||
|
switch (number) {
|
||||||
|
case 1:
|
||||||
|
return ChatColor.BLUE;
|
||||||
|
case 2:
|
||||||
|
return ChatColor.BLUE;
|
||||||
|
case 3:
|
||||||
|
if (context.getSessionData(CK.PLN_START_DATE) == null || context.getSessionData(CK.PLN_END_DATE) == null) {
|
||||||
|
return ChatColor.GRAY;
|
||||||
|
} else {
|
||||||
|
return ChatColor.BLUE;
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
return ChatColor.BLUE;
|
||||||
|
case 5:
|
||||||
|
return ChatColor.GREEN;
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSelectionText(ConversationContext context, int number) {
|
||||||
|
switch (number) {
|
||||||
|
case 1:
|
||||||
|
return ChatColor.YELLOW + Lang.get("plnStart");
|
||||||
|
case 2:
|
||||||
|
return ChatColor.YELLOW + Lang.get("plnEnd");
|
||||||
|
case 3:
|
||||||
|
if (context.getSessionData(CK.PLN_START_DATE) == null || context.getSessionData(CK.PLN_END_DATE) == null) {
|
||||||
|
return ChatColor.GRAY + Lang.get("plnRepeat");
|
||||||
|
} else {
|
||||||
|
return ChatColor.YELLOW + Lang.get("plnRepeat");
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
return ChatColor.YELLOW + Lang.get("plnCooldown");
|
||||||
|
case 5:
|
||||||
|
return ChatColor.YELLOW + Lang.get("done");
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdditionalText(ConversationContext context, int number) {
|
||||||
|
switch (number) {
|
||||||
|
case 1:
|
||||||
|
if (context.getSessionData(CK.PLN_START_DATE) == null) {
|
||||||
|
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||||
|
} else {
|
||||||
|
return ChatColor.YELLOW + " - " + getPrettyDate((String) context.getSessionData(CK.PLN_START_DATE));
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
if (context.getSessionData(CK.PLN_END_DATE) == null) {
|
||||||
|
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||||
|
} else {
|
||||||
|
return ChatColor.YELLOW + " - " + getPrettyDate((String) context.getSessionData(CK.PLN_END_DATE));
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
if (context.getSessionData(CK.PLN_START_DATE) == null || context.getSessionData(CK.PLN_END_DATE) == null) {
|
||||||
|
return ChatColor.GRAY + "(" + Lang.get("stageEditorOptional") + ")";
|
||||||
|
} else {
|
||||||
|
if (context.getSessionData(CK.PLN_REPEAT_CYCLE) == null) {
|
||||||
|
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||||
|
} else {
|
||||||
|
return ChatColor.YELLOW + "(" + Quests.getTime((Long) context.getSessionData(CK.PLN_REPEAT_CYCLE)) + ChatColor.RESET + ChatColor.YELLOW + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
if (context.getSessionData(CK.PLN_COOLDOWN) == null) {
|
||||||
|
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||||
|
} else {
|
||||||
|
return ChatColor.YELLOW + "(" + Quests.getTime((Long) context.getSessionData(CK.PLN_COOLDOWN)) + ChatColor.RESET + ChatColor.YELLOW + ")";
|
||||||
|
}
|
||||||
|
case 5:
|
||||||
|
return "";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPromptText(ConversationContext context) {
|
public String getPromptText(ConversationContext context) {
|
||||||
String text;
|
QuestsEditorPostOpenPlannerPromptEvent event = new QuestsEditorPostOpenPlannerPromptEvent(factory, context);
|
||||||
String lang = Lang.get("plannerTitle");
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
lang = lang.replace("<quest>", ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_AQUA);
|
|
||||||
text = ChatColor.DARK_AQUA + lang + "\n";
|
String text = getTitle(context) + "\n";
|
||||||
if (context.getSessionData(CK.PLN_START_DATE) == null) {
|
for (int i = 1; i <= size; i++) {
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnStart") + " "
|
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - " + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
|
||||||
+ ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n";
|
}
|
||||||
} else {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnStart") + "\n";
|
|
||||||
text += " - " + getPrettyDate((String) context.getSessionData(CK.PLN_START_DATE)) + "\n";
|
|
||||||
}
|
|
||||||
if (context.getSessionData(CK.PLN_END_DATE) == null) {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnEnd") + " "
|
|
||||||
+ ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n";
|
|
||||||
} else {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnEnd") + "\n";
|
|
||||||
text += " - " + getPrettyDate((String) context.getSessionData(CK.PLN_END_DATE)) + "\n";
|
|
||||||
}
|
|
||||||
if (context.getSessionData(CK.PLN_START_DATE) == null || context.getSessionData(CK.PLN_END_DATE) == null) {
|
|
||||||
text += ChatColor.GRAY + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.GRAY + " - " + Lang.get("plnRepeat") + " "
|
|
||||||
+ ChatColor.GRAY + "(" + Lang.get("stageEditorOptional") + ")\n";
|
|
||||||
} else {
|
|
||||||
if (context.getSessionData(CK.PLN_REPEAT_CYCLE) == null) {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnRepeat") + " "
|
|
||||||
+ ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n";
|
|
||||||
} else {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnRepeat") + " ("
|
|
||||||
+ Quests.getTime((Long) context.getSessionData(CK.PLN_REPEAT_CYCLE)) + ChatColor.RESET + ChatColor.YELLOW + ")\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (context.getSessionData(CK.PLN_COOLDOWN) == null) {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnCooldown") + " "
|
|
||||||
+ ChatColor.GRAY + "(" + Lang.get("noneSet") + ")\n";
|
|
||||||
} else {
|
|
||||||
text += ChatColor.BLUE + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("plnCooldown") + " ("
|
|
||||||
+ Quests.getTime((Long) context.getSessionData(CK.PLN_COOLDOWN)) + ChatColor.RESET + ChatColor.YELLOW + ")\n";
|
|
||||||
}
|
|
||||||
text += ChatColor.GREEN + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done");
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Prompt acceptValidatedInput(ConversationContext context, String input) {
|
protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
|
||||||
if (input.equalsIgnoreCase("1")) {
|
switch (input.intValue()) {
|
||||||
|
case 1:
|
||||||
return new DateTimePrompt(plugin, PlannerPrompt.this, "start");
|
return new DateTimePrompt(plugin, PlannerPrompt.this, "start");
|
||||||
} else if (input.equalsIgnoreCase("2")) {
|
case 2:
|
||||||
return new DateTimePrompt(plugin, PlannerPrompt.this, "end");
|
return new DateTimePrompt(plugin, PlannerPrompt.this, "end");
|
||||||
} else if (input.equalsIgnoreCase("3")) {
|
case 3:
|
||||||
if (context.getSessionData(CK.PLN_START_DATE) != null && context.getSessionData(CK.PLN_END_DATE) != null) {
|
if (context.getSessionData(CK.PLN_START_DATE) != null && context.getSessionData(CK.PLN_END_DATE) != null) {
|
||||||
return new RepeatPrompt();
|
return new RepeatPrompt();
|
||||||
} else {
|
} else {
|
||||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption"));
|
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidOption"));
|
||||||
return new PlannerPrompt(plugin, factory);
|
return new PlannerPrompt(plugin, factory);
|
||||||
}
|
}
|
||||||
} else if (input.equalsIgnoreCase("4")) {
|
case 4:
|
||||||
return new CooldownPrompt();
|
return new CooldownPrompt();
|
||||||
} else if (input.equalsIgnoreCase("5")) {
|
case 5:
|
||||||
return factory.returnToMenu();
|
return factory.returnToMenu();
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RepeatPrompt extends StringPrompt {
|
private class RepeatPrompt extends StringPrompt {
|
||||||
|
Loading…
Reference in New Issue
Block a user