Supply external conversation hooks, part 24

This commit is contained in:
PikaMug 2020-04-20 00:57:15 -04:00
parent b552819efe
commit 225577edb0
2 changed files with 407 additions and 205 deletions

View File

@ -17,6 +17,7 @@ import java.util.List;
import me.blackvein.quests.convo.generic.ItemStackPrompt; import me.blackvein.quests.convo.generic.ItemStackPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt; import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
import me.blackvein.quests.convo.quests.stages.StageMainPrompt; import me.blackvein.quests.convo.quests.stages.StageMainPrompt;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.util.CK; import me.blackvein.quests.util.CK;
@ -27,9 +28,7 @@ import me.blackvein.quests.util.MiscUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.conversations.ConversationContext; import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.FixedSetPrompt;
import org.bukkit.conversations.Prompt; import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -180,13 +179,13 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
protected Prompt acceptValidatedInput(ConversationContext context, Number input) { protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
switch(input.intValue()) { switch(input.intValue()) {
case 1: case 1:
return new CraftListPrompt(); return new CraftListPrompt(context);
case 2: case 2:
return new SmeltListPrompt(); return new SmeltListPrompt(context);
case 3: case 3:
return new EnchantmentListPrompt(); return new EnchantmentListPrompt(context);
case 4: case 4:
return new BrewListPrompt(); return new BrewListPrompt(context);
case 5: case 5:
try { try {
return new StageMainPrompt(stageNum, context); return new StageMainPrompt(stageNum, context);
@ -199,18 +198,76 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
} }
} }
private class CraftListPrompt extends FixedSetPrompt { public class CraftListPrompt extends QuestsEditorNumericPrompt {
public CraftListPrompt() { public CraftListPrompt(ConversationContext context) {
super("1", "2", "3"); super(context);
} }
private final int size = 3;
public int getSize() {
return size;
}
public String getTitle(ConversationContext context) {
return Lang.get("stageEditorCraftItems");
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch(number) {
case 1:
return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem");
case 2:
return ChatColor.RED + Lang.get("clear");
case 3:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@SuppressWarnings("unchecked")
public String getAdditionalText(ConversationContext context, int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
}
return text;
}
case 2:
case 3:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
// Check/add newly made item // Check/add newly made item
if (context.getSessionData("newItem") != null) { if (context.getSessionData("newItem") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) { if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
List<ItemStack> items = getItems(context); List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack")); items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items); context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
} else { } else {
@ -221,57 +278,105 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData("newItem", null); context.setSessionData("newItem", null);
context.setSessionData("tempStack", null); context.setSessionData("tempStack", null);
} }
String text = ChatColor.GOLD + "- " + Lang.get("stageEditorCraftItems") + " -\n";
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null) { QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
text += ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; context.getPlugin().getServer().getPluginManager().callEvent(event);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorDeliveryAddItem") + "\n"; String text = ChatColor.GOLD + "- " + getTitle(context) + " -\n";
} else { for (int i = 1; i <= size; i++) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ Lang.get("stageEditorDeliveryAddItem") + "\n"; + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
for (ItemStack is : getItems(context)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
}
} }
text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("clear") + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + 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 ItemStackPrompt(CraftListPrompt.this); return new ItemStackPrompt(CraftListPrompt.this);
} else if (input.equalsIgnoreCase("2")) { case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, null); context.setSessionData(pref + CK.S_CRAFT_ITEMS, null);
return new CraftListPrompt(); return new CraftListPrompt(context);
} else if (input.equalsIgnoreCase("3")) { case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context); return new ItemsPrompt(stageNum, context);
} }
return null;
}
@SuppressWarnings("unchecked")
private List<ItemStack> getItems(ConversationContext context) {
return (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
} }
} }
private class SmeltListPrompt extends FixedSetPrompt { public class SmeltListPrompt extends QuestsEditorNumericPrompt {
public SmeltListPrompt() { public SmeltListPrompt(ConversationContext context) {
super("1", "2", "3"); super(context);
}
private final int size = 3;
public int getSize() {
return size;
}
public String getTitle(ConversationContext context) {
return Lang.get("stageEditorSmeltItems");
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch(number) {
case 1:
return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem");
case 2:
return ChatColor.RED + Lang.get("clear");
case 3:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@SuppressWarnings("unchecked")
public String getAdditionalText(ConversationContext context, int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
}
return text;
}
case 2:
case 3:
return "";
default:
return null;
}
} }
@SuppressWarnings("unchecked")
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
// Check/add newly made item // Check/add newly made item
if (context.getSessionData("newItem") != null) { if (context.getSessionData("newItem") != null) {
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) { if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) {
List<ItemStack> items = getItems(context); List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack")); items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items); context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
} else { } else {
@ -282,125 +387,152 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData("newItem", null); context.setSessionData("newItem", null);
context.setSessionData("tempStack", null); context.setSessionData("tempStack", null);
} }
String text = ChatColor.GOLD + "- " + Lang.get("stageEditorSmeltItems") + " -\n";
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) == null) { QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
text += ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; context.getPlugin().getServer().getPluginManager().callEvent(event);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorDeliveryAddItem") + "\n"; String text = ChatColor.GOLD + "- " + getTitle(context) + " -\n";
} else { for (int i = 1; i <= size; i++) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ Lang.get("stageEditorDeliveryAddItem") + "\n"; + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
for (ItemStack is : getItems(context)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
}
} }
text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("clear") + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + 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 ItemStackPrompt(SmeltListPrompt.this); return new ItemStackPrompt(SmeltListPrompt.this);
} else if (input.equalsIgnoreCase("2")) { case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, null); context.setSessionData(pref + CK.S_SMELT_ITEMS, null);
return new SmeltListPrompt(); return new SmeltListPrompt(context);
} else if (input.equalsIgnoreCase("3")) { case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context); return new ItemsPrompt(stageNum, context);
} }
return null;
}
@SuppressWarnings("unchecked")
private List<ItemStack> getItems(ConversationContext context) {
return (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
} }
} }
private class EnchantmentListPrompt extends FixedSetPrompt { public class EnchantmentListPrompt extends QuestsEditorNumericPrompt {
public EnchantmentListPrompt() { public EnchantmentListPrompt(ConversationContext context) {
super("1", "2", "3", "4", "5"); super(context);
}
private final int size = 5;
public int getSize() {
return size;
}
public String getTitle(ConversationContext context) {
return Lang.get("stageEditorEnchantItems");
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
case 2:
case 3:
return ChatColor.BLUE;
case 4:
return ChatColor.RED;
case 5:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch(number) {
case 1:
case 2:
case 3:
return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem");
case 4:
return ChatColor.RED + Lang.get("clear");
case 5:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@SuppressWarnings("unchecked")
public String getAdditionalText(ConversationContext context, int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (String s : (List<String>) context.getSessionData(pref + CK.S_ENCHANT_TYPES)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n";
}
return text;
}
case 2:
if (context.getSessionData(pref + CK.S_ENCHANT_NAMES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (String s : (List<String>) context.getSessionData(pref + CK.S_ENCHANT_NAMES)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + ItemUtil.getPrettyItemName(s) + "\n";
}
return text;
}
case 3:
if (context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (int i : (List<Integer>) context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n";
}
return text;
}
case 4:
case 5:
return "";
default:
return null;
}
} }
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = ChatColor.GOLD + "- " + Lang.get("stageEditorEnchantItems") + " -\n"; QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) { context.getPlugin().getServer().getPluginManager().callEvent(event);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorSetEnchantments") + " (" + Lang.get("noneSet") + ")\n"; String text = ChatColor.GOLD + "- " + getTitle(context) + " -\n";
text += ChatColor.GRAY + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GRAY + " - " for (int i = 1; i <= size; i++) {
+ Lang.get("stageEditorSetItemNames") + " (" + Lang.get("noneSet") + ")\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
text += ChatColor.GRAY + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.GRAY + " - " + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
+ Lang.get("stageEditorSetEnchantAmounts") + " (" + Lang.get("noneSet") + ")\n";
text += ChatColor.RED + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("clear") + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("done");
} else {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorSetEnchantments") + "\n";
for (String s : getEnchantTypes(context)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n";
}
if (context.getSessionData(pref + CK.S_ENCHANT_NAMES) == null) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorSetItemNames") + " (" + Lang.get("noneSet") + ")\n";
} else {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorSetItemNames") + "\n";
for (String s : getEnchantItems(context)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + ItemUtil.getPrettyItemName(s) + "\n";
}
}
if (context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS) == null) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorSetEnchantAmounts") + " (" + Lang.get("noneSet") + ")\n";
} else {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorSetEnchantAmounts") + "\n";
for (int i : getEnchantAmounts(context)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n";
}
}
text += ChatColor.RED + "" + ChatColor.BOLD + "4" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("clear") + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "5" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("done");
} }
return text; return text;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected Prompt acceptValidatedInput(ConversationContext context, String input) { protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
if (input.equalsIgnoreCase("1")) { switch(input.intValue()) {
return new EnchantTypesPrompt(); case 1:
} else if (input.equalsIgnoreCase("2")) { return new EnchantTypesPrompt(context);
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) { case 2:
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoEnchantments")); return new EnchantItemsPrompt(context);
return new EnchantmentListPrompt(); case 3:
} else { return new EnchantAmountsPrompt(context);
return new EnchantItemsPrompt(); case 4:
}
} else if (input.equalsIgnoreCase("3")) {
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("stageEditorNoEnchantments"));
return new EnchantmentListPrompt();
} else {
return new EnchantAmountsPrompt();
}
} else if (input.equalsIgnoreCase("4")) {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_ENCHANT_TYPES, null); context.setSessionData(pref + CK.S_ENCHANT_TYPES, null);
context.setSessionData(pref + CK.S_ENCHANT_NAMES, null); context.setSessionData(pref + CK.S_ENCHANT_NAMES, null);
context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null); context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null);
return new EnchantmentListPrompt(); return new EnchantmentListPrompt(context);
} else if (input.equalsIgnoreCase("5")) { case 5:
int one; int one;
int two; int two;
int three; int three;
@ -423,34 +555,34 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
return new ItemsPrompt(stageNum, context); return new ItemsPrompt(stageNum, context);
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
return new EnchantmentListPrompt(); return new EnchantmentListPrompt(context);
} }
default:
return new ItemsPrompt(stageNum, context);
} }
return null;
}
@SuppressWarnings("unchecked")
private List<String> getEnchantTypes(ConversationContext context) {
return (List<String>) context.getSessionData(pref + CK.S_ENCHANT_TYPES);
}
@SuppressWarnings("unchecked")
private List<String> getEnchantItems(ConversationContext context) {
return (List<String>) context.getSessionData(pref + CK.S_ENCHANT_NAMES);
}
@SuppressWarnings("unchecked")
private List<Integer> getEnchantAmounts(ConversationContext context) {
return (List<Integer>) context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS);
} }
} }
private class EnchantTypesPrompt extends StringPrompt { public class EnchantTypesPrompt extends QuestsEditorStringPrompt {
public EnchantTypesPrompt(ConversationContext context) {
super(context);
}
@Override
public String getTitle(ConversationContext context) {
return Lang.get("stageEditorEnchantments");
}
@Override
public String getQueryText(ConversationContext context) {
return Lang.get("stageEditorEnchantTypePrompt");
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
String text = ChatColor.LIGHT_PURPLE + "- " + ChatColor.DARK_PURPLE + Lang.get("stageEditorEnchantments") String text = ChatColor.LIGHT_PURPLE + "- " + ChatColor.DARK_PURPLE + getTitle(context)
+ ChatColor.LIGHT_PURPLE + " -\n"; + ChatColor.LIGHT_PURPLE + " -\n";
for (int i = 0; i < Enchantment.values().length; i++) { for (int i = 0; i < Enchantment.values().length; i++) {
if (i == Enchantment.values().length - 1) { if (i == Enchantment.values().length - 1) {
@ -460,7 +592,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
} }
} }
text = text.substring(0, text.length() - 1); text = text.substring(0, text.length() - 1);
return text + "\n" + ChatColor.YELLOW + Lang.get("stageEditorEnchantTypePrompt"); return text + "\n" + ChatColor.YELLOW + getQueryText(context);
} }
@Override @Override
@ -473,25 +605,39 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
enchTypes.add(s); enchTypes.add(s);
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + " " + Lang.get("listDuplicate")); context.getForWhom().sendRawMessage(ChatColor.RED + " " + Lang.get("listDuplicate"));
return new EnchantTypesPrompt(); return new EnchantTypesPrompt(context);
} }
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " " context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " "
+ Lang.get("stageEditorInvalidEnchantment")); + Lang.get("stageEditorInvalidEnchantment"));
return new EnchantTypesPrompt(); return new EnchantTypesPrompt(context);
} }
} }
context.setSessionData(pref + CK.S_ENCHANT_TYPES, enchTypes); context.setSessionData(pref + CK.S_ENCHANT_TYPES, enchTypes);
} }
return new EnchantmentListPrompt(); return new EnchantmentListPrompt(context);
} }
} }
private class EnchantItemsPrompt extends StringPrompt { public class EnchantItemsPrompt extends QuestsEditorStringPrompt {
public EnchantItemsPrompt(ConversationContext context) {
super(context);
}
@Override
public String getTitle(ConversationContext context) {
return null;
}
@Override
public String getQueryText(ConversationContext context) {
return Lang.get("stageEditorItemNamesPrompt");
}
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("stageEditorItemNamesPrompt"); return ChatColor.YELLOW + getQueryText(context);
} }
@Override @Override
@ -502,34 +648,43 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
for (String s : args) { for (String s : args) {
try { try {
if (Material.matchMaterial(s) != null) { if (Material.matchMaterial(s) != null) {
//if (names.contains(s) == false) { names.add(s);
names.add(s);
/*} else {
context.getForWhom().sendRawMessage(ChatColor.RED + " " + Lang.get("listDuplicate"));
return new EnchantItemsPrompt();
}*/
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " " context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " "
+ Lang.get("stageEditorInvalidItemName")); + Lang.get("stageEditorInvalidItemName"));
return new EnchantItemsPrompt(); return new EnchantItemsPrompt(context);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
+ Lang.get("stageEditorNotListofNumbers")); + Lang.get("stageEditorNotListofNumbers"));
return new EnchantItemsPrompt(); return new EnchantItemsPrompt(context);
} }
} }
context.setSessionData(pref + CK.S_ENCHANT_NAMES, names); context.setSessionData(pref + CK.S_ENCHANT_NAMES, names);
} }
return new EnchantmentListPrompt(); return new EnchantmentListPrompt(context);
} }
} }
private class EnchantAmountsPrompt extends StringPrompt { public class EnchantAmountsPrompt extends QuestsEditorStringPrompt {
public EnchantAmountsPrompt(ConversationContext context) {
super(context);
}
@Override
public String getTitle(ConversationContext context) {
return null;
}
@Override
public String getQueryText(ConversationContext context) {
return Lang.get("stageEditorEnchantAmountsPrompt");
}
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("stageEditorEnchantAmountsPrompt"); return ChatColor.YELLOW + getQueryText(context);
} }
@Override @Override
@ -544,32 +699,90 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
} else { } else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum") context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum")
.replace("<number>", "1")); .replace("<number>", "1"));
return new EnchantAmountsPrompt(); return new EnchantAmountsPrompt(context);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
+ Lang.get("stageEditorNotListofNumbers")); + Lang.get("stageEditorNotListofNumbers"));
return new EnchantAmountsPrompt(); return new EnchantAmountsPrompt(context);
} }
} }
context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts); context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts);
} }
return new EnchantmentListPrompt(); return new EnchantmentListPrompt(context);
} }
} }
private class BrewListPrompt extends FixedSetPrompt { public class BrewListPrompt extends QuestsEditorNumericPrompt {
public BrewListPrompt() { public BrewListPrompt(ConversationContext context) {
super("1", "2", "3"); super(context);
}
private final int size = 3;
public int getSize() {
return size;
}
public String getTitle(ConversationContext context) {
return Lang.get("stageEditorBrewPotions");
}
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
public String getSelectionText(ConversationContext context, int number) {
switch(number) {
case 1:
return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem");
case 2:
return ChatColor.RED + Lang.get("clear");
case 3:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@SuppressWarnings("unchecked")
public String getAdditionalText(ConversationContext context, int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
}
return text;
}
case 2:
case 3:
return "";
default:
return null;
}
} }
@SuppressWarnings("unchecked")
@Override @Override
public String getPromptText(ConversationContext context) { public String getPromptText(ConversationContext context) {
// Check/add newly made item // Check/add newly made item
if (context.getSessionData("newItem") != null) { if (context.getSessionData("newItem") != null) {
if (context.getSessionData(pref + CK.S_BREW_ITEMS) != null) { if (context.getSessionData(pref + CK.S_BREW_ITEMS) != null) {
List<ItemStack> items = getItems(context); List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack")); items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items); context.setSessionData(pref + CK.S_BREW_ITEMS, items);
} else { } else {
@ -580,42 +793,32 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData("newItem", null); context.setSessionData("newItem", null);
context.setSessionData("tempStack", null); context.setSessionData("tempStack", null);
} }
String text = ChatColor.GOLD + "- " + Lang.get("stageEditorBrewPotions") + " -\n";
if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) { QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
text += ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; context.getPlugin().getServer().getPluginManager().callEvent(event);
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("stageEditorDeliveryAddItem") + "\n"; String text = ChatColor.GOLD + "- " + getTitle(context) + " -\n";
} else { for (int i = 1; i <= size; i++) {
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ Lang.get("stageEditorDeliveryAddItem") + "\n"; + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
for (ItemStack is : getItems(context)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
}
} }
text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - "
+ Lang.get("clear") + "\n";
text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + 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 ItemStackPrompt(BrewListPrompt.this); return new ItemStackPrompt(BrewListPrompt.this);
} else if (input.equalsIgnoreCase("2")) { case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_BREW_ITEMS, null); context.setSessionData(pref + CK.S_BREW_ITEMS, null);
return new BrewListPrompt(); return new BrewListPrompt(context);
} else if (input.equalsIgnoreCase("3")) { case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context); return new ItemsPrompt(stageNum, context);
} }
return null;
}
@SuppressWarnings("unchecked")
private List<ItemStack> getItems(ConversationContext context) {
return (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
} }
} }
} }

View File

@ -243,7 +243,6 @@ stageEditorNoDenizen: "Denizen is not installed!"
stageEditorPositiveAmount: "You must enter a positive number!" stageEditorPositiveAmount: "You must enter a positive number!"
stageEditorNotListofNumbers: "is not a list of numbers!" stageEditorNotListofNumbers: "is not a list of numbers!"
stageEditorNoDelaySet: "You must set a delay first!" stageEditorNoDelaySet: "You must set a delay first!"
stageEditorNoEnchantments: "You must set enchantments first!"
stageEditorNoItems: "You must add items first!" stageEditorNoItems: "You must add items first!"
stageEditorNoDeliveryMessage: "You must set at least one delivery message!" stageEditorNoDeliveryMessage: "You must set at least one delivery message!"
stageEditorNoNPCs: "You must set NPC IDs first!" stageEditorNoNPCs: "You must set NPC IDs first!"