Supply external conversation hooks, part 31

This commit is contained in:
PikaMug 2020-08-02 04:20:56 -04:00
parent 69edce34d7
commit ddc3cf5b07
9 changed files with 467 additions and 315 deletions

View File

@ -198,7 +198,7 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
case 5: case 5:
return new WeatherPrompt(context); return new WeatherPrompt(context);
case 6: case 6:
return new ActionMobPrompt(context); return new ActionMobListPrompt(context);
case 7: case 7:
return new ActionDenizenPrompt(context); return new ActionDenizenPrompt(context);
case 8: case 8:
@ -273,9 +273,9 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
} }
} }
public class ActionMobPrompt extends ActionsEditorNumericPrompt { public class ActionMobListPrompt extends ActionsEditorNumericPrompt {
public ActionMobPrompt(ConversationContext context) { public ActionMobListPrompt(ConversationContext context) {
super(context); super(context);
} }
@ -358,11 +358,11 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
public Prompt acceptValidatedInput(ConversationContext context, Number input) { public Prompt acceptValidatedInput(ConversationContext context, Number input) {
switch (input.intValue()) { switch (input.intValue()) {
case 1: case 1:
return new QuestMobPrompt(context, 0, null); return new ActionMobPrompt(context, 0, null);
case 2: case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorMobSpawnsCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorMobSpawnsCleared"));
context.setSessionData(CK.E_MOB_TYPES, null); context.setSessionData(CK.E_MOB_TYPES, null);
return new ActionMobPrompt(context); return new ActionMobListPrompt(context);
case 3: case 3:
return new ActionMainPrompt(context); return new ActionMainPrompt(context);
default: default:
@ -371,13 +371,13 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
} }
} }
public class QuestMobPrompt extends ActionsEditorNumericPrompt { public class ActionMobPrompt extends ActionsEditorNumericPrompt {
private QuestMob questMob; private QuestMob questMob;
private Integer itemIndex = -1; private Integer itemIndex = -1;
private final Integer mobIndex; private final Integer mobIndex;
public QuestMobPrompt(ConversationContext context, int mobIndex, QuestMob questMob) { public ActionMobPrompt(ConversationContext context, int mobIndex, QuestMob questMob) {
super(context); super(context);
this.questMob = questMob; this.questMob = questMob;
this.mobIndex = mobIndex; this.mobIndex = mobIndex;
@ -542,51 +542,51 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
public Prompt acceptValidatedInput(ConversationContext context, Number input) { public Prompt acceptValidatedInput(ConversationContext context, Number input) {
switch (input.intValue()) { switch (input.intValue()) {
case 1: case 1:
return new MobNamePrompt(context, mobIndex, questMob); return new ActionMobNamePrompt(context, mobIndex, questMob);
case 2: case 2:
return new MobTypePrompt(context, mobIndex, questMob); return new ActionMobTypePrompt(context, mobIndex, questMob);
case 3: case 3:
Map<UUID, Block> selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations(); Map<UUID, Block> selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations();
selectedMobLocations.put(((Player) context.getForWhom()).getUniqueId(), null); selectedMobLocations.put(((Player) context.getForWhom()).getUniqueId(), null);
plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations); plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations);
return new MobLocationPrompt(context, mobIndex, questMob); return new ActionMobLocationPrompt(context, mobIndex, questMob);
case 4: case 4:
return new MobAmountPrompt(context, mobIndex, questMob); return new ActionMobAmountPrompt(context, mobIndex, questMob);
case 5: case 5:
itemIndex = 0; itemIndex = 0;
return new ItemStackPrompt(QuestMobPrompt.this); return new ItemStackPrompt(context, ActionMobPrompt.this);
case 6: case 6:
return new MobDropPrompt(context, 0, mobIndex, questMob); return new ActionMobDropPrompt(context, 0, mobIndex, questMob);
case 7: case 7:
itemIndex = 1; itemIndex = 1;
return new ItemStackPrompt(QuestMobPrompt.this); return new ItemStackPrompt(context, ActionMobPrompt.this);
case 8: case 8:
return new MobDropPrompt(context, 1, mobIndex, questMob); return new ActionMobDropPrompt(context, 1, mobIndex, questMob);
case 9: case 9:
itemIndex = 2; itemIndex = 2;
return new ItemStackPrompt(QuestMobPrompt.this); return new ItemStackPrompt(context, ActionMobPrompt.this);
case 10: case 10:
return new MobDropPrompt(context, 2, mobIndex, questMob); return new ActionMobDropPrompt(context, 2, mobIndex, questMob);
case 11: case 11:
itemIndex = 3; itemIndex = 3;
return new ItemStackPrompt(QuestMobPrompt.this); return new ItemStackPrompt(context, ActionMobPrompt.this);
case 12: case 12:
return new MobDropPrompt(context, 3, mobIndex, questMob); return new ActionMobDropPrompt(context, 3, mobIndex, questMob);
case 13: case 13:
itemIndex = 4; itemIndex = 4;
return new ItemStackPrompt(QuestMobPrompt.this); return new ItemStackPrompt(context, ActionMobPrompt.this);
case 14: case 14:
return new MobDropPrompt(context, 4, mobIndex, questMob); return new ActionMobDropPrompt(context, 4, mobIndex, questMob);
case 15: case 15:
if (questMob.getType() == null) { if (questMob.getType() == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobTypesFirst")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobTypesFirst"));
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} else if (questMob.getSpawnLocation() == null) { } else if (questMob.getSpawnLocation() == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobLocationFirst")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobLocationFirst"));
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} else if (questMob.getSpawnAmounts() == null) { } else if (questMob.getSpawnAmounts() == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobAmountsFirst")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("eventEditorMustSetMobAmountsFirst"));
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
if (context.getSessionData(CK.E_MOB_TYPES) == null if (context.getSessionData(CK.E_MOB_TYPES) == null
|| ((LinkedList<String>) context.getSessionData(CK.E_MOB_TYPES)).isEmpty()) { || ((LinkedList<String>) context.getSessionData(CK.E_MOB_TYPES)).isEmpty()) {
@ -602,21 +602,21 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
} }
context.setSessionData(CK.E_MOB_TYPES, list); context.setSessionData(CK.E_MOB_TYPES, list);
} }
return new ActionMobPrompt(context); return new ActionMobListPrompt(context);
case 16: case 16:
return new ActionMobPrompt(context); return new ActionMobListPrompt(context);
default: default:
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
} }
} }
public class MobNamePrompt extends ActionsEditorStringPrompt { public class ActionMobNamePrompt extends ActionsEditorStringPrompt {
private final QuestMob questMob; private final QuestMob questMob;
private final Integer mobIndex; private final Integer mobIndex;
public MobNamePrompt(ConversationContext context, int mobIndex, QuestMob questMob) { public ActionMobNamePrompt(ConversationContext context, int mobIndex, QuestMob questMob) {
super(context); super(context);
this.questMob = questMob; this.questMob = questMob;
this.mobIndex = mobIndex; this.mobIndex = mobIndex;
@ -643,24 +643,24 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
@Override @Override
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
questMob.setName(null); questMob.setName(null);
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} else { } else {
input = ChatColor.translateAlternateColorCodes('&', input); input = ChatColor.translateAlternateColorCodes('&', input);
questMob.setName(input); questMob.setName(input);
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
} }
} }
public class MobTypePrompt extends ActionsEditorStringPrompt { public class ActionMobTypePrompt extends ActionsEditorStringPrompt {
private final QuestMob questMob; private final QuestMob questMob;
private final Integer mobIndex; private final Integer mobIndex;
public MobTypePrompt(ConversationContext context, int mobIndex, QuestMob questMob) { public ActionMobTypePrompt(ConversationContext context, int mobIndex, QuestMob questMob) {
super(context); super(context);
this.questMob = questMob; this.questMob = questMob;
this.mobIndex = mobIndex; this.mobIndex = mobIndex;
@ -706,19 +706,19 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
} else { } else {
player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED player.sendMessage(ChatColor.LIGHT_PURPLE + input + " " + ChatColor.RED
+ Lang.get("eventEditorInvalidMob")); + Lang.get("eventEditorInvalidMob"));
return new MobTypePrompt(context, mobIndex, questMob); return new ActionMobTypePrompt(context, mobIndex, questMob);
} }
} }
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
} }
public class MobAmountPrompt extends ActionsEditorStringPrompt { public class ActionMobAmountPrompt extends ActionsEditorStringPrompt {
private final QuestMob questMob; private final QuestMob questMob;
private final Integer mobIndex; private final Integer mobIndex;
public MobAmountPrompt(ConversationContext context, int mobIndex, QuestMob questMob) { public ActionMobAmountPrompt(ConversationContext context, int mobIndex, QuestMob questMob) {
super(context); super(context);
this.questMob = questMob; this.questMob = questMob;
this.mobIndex = mobIndex; this.mobIndex = mobIndex;
@ -750,25 +750,25 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
int i = Integer.parseInt(input); int i = Integer.parseInt(input);
if (i < 1) { if (i < 1) {
player.sendMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("<number>", "1")); player.sendMessage(ChatColor.RED + Lang.get("invalidMinimum").replace("<number>", "1"));
return new MobAmountPrompt(context, mobIndex, questMob); return new ActionMobAmountPrompt(context, mobIndex, questMob);
} }
questMob.setSpawnAmounts(i); questMob.setSpawnAmounts(i);
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("<input>", input)); player.sendMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("<input>", input));
return new MobAmountPrompt(context, mobIndex, questMob); return new ActionMobAmountPrompt(context, mobIndex, questMob);
} }
} }
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
} }
public class MobLocationPrompt extends ActionsEditorStringPrompt { public class ActionMobLocationPrompt extends ActionsEditorStringPrompt {
private final QuestMob questMob; private final QuestMob questMob;
private final Integer mobIndex; private final Integer mobIndex;
public MobLocationPrompt(ConversationContext context, int mobIndex, QuestMob questMob) { public ActionMobLocationPrompt(ConversationContext context, int mobIndex, QuestMob questMob) {
super(context); super(context);
this.questMob = questMob; this.questMob = questMob;
this.mobIndex = mobIndex; this.mobIndex = mobIndex;
@ -805,27 +805,27 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations); plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations);
} else { } else {
player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst")); player.sendMessage(ChatColor.RED + Lang.get("eventEditorSelectBlockFirst"));
return new MobLocationPrompt(context, mobIndex, questMob); return new ActionMobLocationPrompt(context, mobIndex, questMob);
} }
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { } else if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
Map<UUID, Block> selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations(); Map<UUID, Block> selectedMobLocations = plugin.getActionFactory().getSelectedMobLocations();
selectedMobLocations.remove(player.getUniqueId()); selectedMobLocations.remove(player.getUniqueId());
plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations); plugin.getActionFactory().setSelectedMobLocations(selectedMobLocations);
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} else { } else {
return new MobLocationPrompt(context, mobIndex, questMob); return new ActionMobLocationPrompt(context, mobIndex, questMob);
} }
} }
} }
private class MobDropPrompt extends ActionsEditorStringPrompt { public class ActionMobDropPrompt extends ActionsEditorStringPrompt {
private final QuestMob questMob; private final QuestMob questMob;
private final Integer mobIndex; private final Integer mobIndex;
private final Integer invIndex; private final Integer invIndex;
public MobDropPrompt(ConversationContext context, int invIndex, int mobIndex, QuestMob questMob) { public ActionMobDropPrompt(ConversationContext context, int invIndex, int mobIndex, QuestMob questMob) {
super(context); super(context);
this.questMob = questMob; this.questMob = questMob;
this.mobIndex = mobIndex; this.mobIndex = mobIndex;
@ -854,24 +854,24 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
public Prompt acceptInput(ConversationContext context, String input) { public Prompt acceptInput(ConversationContext context, String input) {
float chance; float chance;
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) { if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
try { try {
chance = Float.parseFloat(input); chance = Float.parseFloat(input);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange") context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
.replace("<least>", "0.0").replace("<greatest>", "1.0")); .replace("<least>", "0.0").replace("<greatest>", "1.0"));
return new MobDropPrompt(context, invIndex, mobIndex, questMob); return new ActionMobDropPrompt(context, invIndex, mobIndex, questMob);
} }
if (chance > 1 || chance < 0) { if (chance > 1 || chance < 0) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange") context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
.replace("<least>", "0.0").replace("<greatest>", "1.0")); .replace("<least>", "0.0").replace("<greatest>", "1.0"));
return new MobDropPrompt(context, invIndex, mobIndex, questMob); return new ActionMobDropPrompt(context, invIndex, mobIndex, questMob);
} }
Float[] temp = questMob.getDropChances(); Float[] temp = questMob.getDropChances();
temp[invIndex] = chance; temp[invIndex] = chance;
questMob.setDropChances(temp); questMob.setDropChances(temp);
return new QuestMobPrompt(context, mobIndex, questMob); return new ActionMobPrompt(context, mobIndex, questMob);
} }
} }

View File

@ -242,7 +242,7 @@ public class PlayerPrompt extends FixedSetPrompt {
@Override @Override
protected Prompt acceptValidatedInput(ConversationContext context, String input) { protected Prompt acceptValidatedInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase("1")) { if (input.equalsIgnoreCase("1")) {
return new ItemStackPrompt(ItemListPrompt.this); return new ItemStackPrompt(context, ItemListPrompt.this);
} else if (input.equalsIgnoreCase("2")) { } else if (input.equalsIgnoreCase("2")) {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorItemsCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("eventEditorItemsCleared"));
context.setSessionData(CK.E_ITEMS, null); context.setSessionData(CK.E_ITEMS, null);

View File

@ -226,7 +226,7 @@ public class PlayerPrompt 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 ItemStackPrompt(ItemsInMainHandListPrompt.this); return new ItemStackPrompt(context, ItemsInMainHandListPrompt.this);
case 2: case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("conditionEditorConditionCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("conditionEditorConditionCleared"));
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, null); context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, null);

View File

@ -21,17 +21,19 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.bukkit.Bukkit;
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.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.util.ConfigUtil; import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.Lang;
@ -48,34 +50,123 @@ import me.blackvein.quests.util.RomanNumeral;
* Stores lore in "tempLore" context data<p> * Stores lore in "tempLore" context data<p>
* Stores metadata in "tempMeta" context data * Stores metadata in "tempMeta" context data
*/ */
public class ItemStackPrompt extends FixedSetPrompt { public class ItemStackPrompt extends QuestsEditorNumericPrompt {
private final Prompt oldPrompt; private final Prompt oldPrompt;
public ItemStackPrompt(Prompt old) { public ItemStackPrompt(ConversationContext context, Prompt old) {
super("0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); super(context);
oldPrompt = old; oldPrompt = old;
} }
private final int size = 10;
public int getSize() {
return size;
}
public String getTitle(ConversationContext context) {
return Lang.get("createItemTitle");
}
@SuppressWarnings("unchecked")
public ChatColor getNumberColor(ConversationContext context, int number) {
switch (number) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
return ChatColor.YELLOW;
case 6:
if ((LinkedHashMap<String, Object>) context.getSessionData("tempMeta") != null) {
return ChatColor.YELLOW;
} else {
return ChatColor.GRAY;
}
case 7:
return ChatColor.BLUE;
case 8:
return ChatColor.RED;
case 9:
return ChatColor.GREEN;
default:
return null;
}
}
@SuppressWarnings("unchecked")
public String getSelectionText(ConversationContext context, int number) {
switch (number) {
case 0:
return ChatColor.YELLOW + Lang.get("itemCreateLoadHand");
case 1:
return ChatColor.YELLOW + Lang.get("itemCreateSetName");
case 2:
return ChatColor.YELLOW + Lang.get("itemCreateSetAmount");
case 3:
return ChatColor.YELLOW + Lang.get("itemCreateSetDurab");
case 4:
return ChatColor.YELLOW + Lang.get("itemCreateSetEnchs");
case 5:
return ChatColor.YELLOW + Lang.get("itemCreateSetDisplay");
case 6:
return ChatColor.YELLOW + Lang.get("itemCreateSetLore");
case 7:
if ((LinkedHashMap<String, Object>) context.getSessionData("tempMeta") != null) {
return ChatColor.DARK_GREEN + Lang.get("itemCreateSetClearMeta");
} else {
return ChatColor.GRAY + Lang.get("itemCreateSetClearMeta");
}
case 8:
return ChatColor.RED + Lang.get("cancel");
case 9:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
public String getAdditionalText(ConversationContext context, int number) {
switch (number) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public String getPromptText(ConversationContext cc) { public String getPromptText(ConversationContext context) {
String menu = ChatColor.YELLOW + Lang.get("createItemTitle") + "\n"; QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
LinkedHashMap<String, Object> map = null; Bukkit.getServer().getPluginManager().callEvent(event);
if (cc.getSessionData("tempName") != null) {
String stackData = getItemData(cc); String text = ChatColor.YELLOW + getTitle(context) + "\n";
if (context.getSessionData("tempName") != null) {
String stackData = getItemData(context);
if (stackData != null) { if (stackData != null) {
menu += stackData; text += stackData;
if (cc.getSessionData("tempMeta") != null) { if (context.getSessionData("tempMeta") != null) {
map = (LinkedHashMap<String, Object>) cc.getSessionData("tempMeta"); LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) context.getSessionData("tempMeta");
if (!map.isEmpty()) { if (!map.isEmpty()) {
for (String key : map.keySet()) { for (String key : map.keySet()) {
if (key.equals("pages")) { if (key.equals("pages")) {
List<String> pages = (List<String>) map.get(key); List<String> pages = (List<String>) map.get(key);
menu += ChatColor.GRAY + "\u2515 " + ChatColor.DARK_GREEN + key + "=" + pages.size() text += ChatColor.GRAY + "\u2515 " + ChatColor.DARK_GREEN + key + "=" + pages.size()
+ "\n"; + "\n";
} else { } else {
menu += ChatColor.GRAY + "\u2515 " + ChatColor.DARK_GREEN + key + "=" + map.get(key) text += ChatColor.GRAY + "\u2515 " + ChatColor.DARK_GREEN + key + "=" + map.get(key)
+ "\n"; + "\n";
} }
} }
@ -83,86 +174,53 @@ public class ItemStackPrompt extends FixedSetPrompt {
} }
} }
} else { } else {
menu += "\n"; text += "\n";
} }
menu += ChatColor.GOLD + "" + ChatColor.BOLD + "0. " + ChatColor.RESET + "" + ChatColor.YELLOW for (int i = 0; i <= size; i++) {
+ Lang.get("itemCreateLoadHand") + "\n"; text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "1. " + ChatColor.RESET + "" + ChatColor.GOLD + getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
+ Lang.get("itemCreateSetName") + "\n";
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "2. " + ChatColor.RESET + "" + ChatColor.GOLD
+ Lang.get("itemCreateSetAmount") + "\n";
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "3. " + ChatColor.RESET + "" + ChatColor.GOLD
+ Lang.get("itemCreateSetDurab") + "\n";
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "4. " + ChatColor.RESET + "" + ChatColor.GOLD
+ Lang.get("itemCreateSetEnchs") + "\n";
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "5. " + ChatColor.RESET + "" + ChatColor.ITALIC
+ ChatColor.GOLD + Lang.get("itemCreateSetDisplay") + "\n";
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "6. " + ChatColor.RESET + "" + ChatColor.ITALIC
+ ChatColor.GOLD + Lang.get("itemCreateSetLore") + "\n";
if (map != null) {
if (!map.isEmpty()) {
menu += ChatColor.YELLOW + "" + ChatColor.BOLD + "7. " + ChatColor.RESET + "" + ChatColor.DARK_GREEN
+ Lang.get("itemCreateSetClearMeta") + "\n";
} else {
menu += ChatColor.GRAY + "" + ChatColor.BOLD + "7. " + ChatColor.RESET + "" + ChatColor.GRAY
+ Lang.get("itemCreateSetClearMeta") + "\n";
}
} else {
menu += ChatColor.GRAY + "" + ChatColor.BOLD + "7. " + ChatColor.RESET + "" + ChatColor.GRAY
+ Lang.get("itemCreateSetClearMeta") + "\n";
} }
menu += ChatColor.RED + "" + ChatColor.BOLD + "8. " + ChatColor.RESET + "" + ChatColor.RED return text;
+ Lang.get("cancel") + "\n";
menu += ChatColor.GREEN + "" + ChatColor.BOLD + "9. " + ChatColor.RESET + "" + ChatColor.GREEN
+ Lang.get("done") + "\n";
return menu;
} }
@SuppressWarnings({ "unchecked", "deprecation" }) @SuppressWarnings({ "unchecked", "deprecation" })
@Override @Override
protected Prompt acceptValidatedInput(ConversationContext cc, String input) { protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
if (input.equalsIgnoreCase("0")) { switch (input.intValue()) {
cc.setSessionData("tempMeta", null); case 0:
context.setSessionData("tempMeta", null);
Player player = (Player) cc.getForWhom(); Player player = (Player) context.getForWhom();
ItemStack is = player.getItemInHand(); ItemStack is = player.getItemInHand();
if (is == null || is.getType().equals(Material.AIR)) { if (is == null || is.getType().equals(Material.AIR)) {
player.sendMessage(ChatColor.RED + Lang.get("itemCreateNoItem")); player.sendMessage(ChatColor.RED + Lang.get("itemCreateNoItem"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} else { } else {
cc.setSessionData("tempName", is.getType().name()); context.setSessionData("tempName", is.getType().name());
cc.setSessionData("tempAmount", is.getAmount()); context.setSessionData("tempAmount", is.getAmount());
cc.setSessionData("tempData", null); context.setSessionData("tempData", null);
cc.setSessionData("tempEnchantments", null); context.setSessionData("tempEnchantments", null);
cc.setSessionData("tempDisplay", null); context.setSessionData("tempDisplay", null);
cc.setSessionData("tempLore", null); context.setSessionData("tempLore", null);
if (is.getDurability() != 0) { if (is.getDurability() != 0) {
cc.setSessionData("tempData", is.getDurability()); context.setSessionData("tempData", is.getDurability());
} }
if (is.getEnchantments() != null && is.getEnchantments().isEmpty() == false) { if (is.getEnchantments() != null && is.getEnchantments().isEmpty() == false) {
cc.setSessionData("tempEnchantments", new HashMap<Enchantment, Integer>(is.getEnchantments())); context.setSessionData("tempEnchantments", new HashMap<Enchantment, Integer>(is.getEnchantments()));
} }
if (is.hasItemMeta()) { if (is.hasItemMeta()) {
ItemMeta meta = is.getItemMeta(); ItemMeta meta = is.getItemMeta();
if (meta.hasDisplayName()) { if (meta.hasDisplayName()) {
String display = meta.getDisplayName().replace(ChatColor.COLOR_CHAR, '&'); String display = meta.getDisplayName().replace(ChatColor.COLOR_CHAR, '&');
cc.setSessionData("tempDisplay", display); context.setSessionData("tempDisplay", display);
} }
if (meta.hasLore()) { if (meta.hasLore()) {
LinkedList<String> lore = new LinkedList<String>(); LinkedList<String> lore = new LinkedList<String>();
lore.addAll(meta.getLore()); lore.addAll(meta.getLore());
cc.setSessionData("tempLore", lore); context.setSessionData("tempLore", lore);
} }
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>(); LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
map.putAll(meta.serialize()); map.putAll(meta.serialize());
/*for (String key : map.keySet()) {
String s = map.get(key).toString();
if (s.contains("minecraft:")) {
map.put(key, s.replace("minecraft:", "minecraft|"));
}
}*/
if (map.containsKey("lore")) { if (map.containsKey("lore")) {
map.remove("lore"); map.remove("lore");
} }
@ -170,86 +228,86 @@ public class ItemStackPrompt extends FixedSetPrompt {
map.remove("display-name"); map.remove("display-name");
} }
if (map != null && !map.isEmpty()) { if (map != null && !map.isEmpty()) {
cc.setSessionData("tempMeta", map); context.setSessionData("tempMeta", map);
} }
} }
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("1")) { case 1:
cc.setSessionData("tempMeta", null); context.setSessionData("tempMeta", null);
return new NamePrompt(); return new ItemNamePrompt(context);
} else if (input.equalsIgnoreCase("2")) { case 2:
if (cc.getSessionData("tempName") != null) { if (context.getSessionData("tempName") != null) {
return new AmountPrompt(); return new ItemAmountPrompt(context);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoName")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoName"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("3")) { case 3:
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempName") != null && context.getSessionData("tempAmount") != null) {
return new DataPrompt(); return new ItemDataPrompt(context);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("4")) { case 4:
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempName") != null && context.getSessionData("tempAmount") != null) {
return new EnchantmentPrompt(); return new ItemEnchantmentPrompt(context);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("5")) { case 5:
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempName") != null && context.getSessionData("tempAmount") != null) {
return new DisplayPrompt(); return new ItemDisplayPrompt(context);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("6")) { case 6:
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempName") != null && context.getSessionData("tempAmount") != null) {
return new LorePrompt(); return new ItemLorePrompt(context);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("7")) { case 7:
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempName") != null && context.getSessionData("tempAmount") != null) {
cc.setSessionData("tempMeta", null); context.setSessionData("tempMeta", null);
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else if (input.equalsIgnoreCase("8")) { case 8:
cc.setSessionData("tempStack", null); context.setSessionData("tempStack", null);
cc.setSessionData("tempName", null); context.setSessionData("tempName", null);
cc.setSessionData("tempAmount", null); context.setSessionData("tempAmount", null);
cc.setSessionData("tempData", null); context.setSessionData("tempData", null);
cc.setSessionData("tempEnchantments", null); context.setSessionData("tempEnchantments", null);
cc.setSessionData("tempDisplay", null); context.setSessionData("tempDisplay", null);
cc.setSessionData("tempLore", null); context.setSessionData("tempLore", null);
cc.setSessionData("tempMeta", null); context.setSessionData("tempMeta", null);
} else if (input.equalsIgnoreCase("9")) { case 9:
if (cc.getSessionData("tempName") != null && cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempName") != null && context.getSessionData("tempAmount") != null) {
String name = (String) cc.getSessionData("tempName"); String name = (String) context.getSessionData("tempName");
int amount = (Integer) cc.getSessionData("tempAmount"); int amount = (Integer) context.getSessionData("tempAmount");
short data = -1; short data = -1;
Map<Enchantment, Integer> enchs = null; Map<Enchantment, Integer> enchs = null;
String display = null; String display = null;
List<String> lore = null; List<String> lore = null;
if (cc.getSessionData("tempData") != null) { if (context.getSessionData("tempData") != null) {
data = (Short) cc.getSessionData("tempData"); data = (Short) context.getSessionData("tempData");
} }
if (cc.getSessionData("tempEnchantments") != null) { if (context.getSessionData("tempEnchantments") != null) {
enchs = (Map<Enchantment, Integer>) cc.getSessionData("tempEnchantments"); enchs = (Map<Enchantment, Integer>) context.getSessionData("tempEnchantments");
} }
if (cc.getSessionData("tempDisplay") != null) { if (context.getSessionData("tempDisplay") != null) {
display = ChatColor.translateAlternateColorCodes('&', (String) cc.getSessionData("tempDisplay")); display = ChatColor.translateAlternateColorCodes('&', (String) context.getSessionData("tempDisplay"));
} }
if (cc.getSessionData("tempLore") != null) { if (context.getSessionData("tempLore") != null) {
lore = new ArrayList<String>(); lore = new ArrayList<String>();
LinkedList<String> loadedLore = (LinkedList<String>) cc.getSessionData("tempLore"); LinkedList<String> loadedLore = (LinkedList<String>) context.getSessionData("tempLore");
for (String line : loadedLore) { for (String line : loadedLore) {
lore.add(ChatColor.translateAlternateColorCodes('&', line)); lore.add(ChatColor.translateAlternateColorCodes('&', line));
} }
@ -262,9 +320,9 @@ public class ItemStackPrompt extends FixedSetPrompt {
} }
ItemMeta meta = stack.getItemMeta(); ItemMeta meta = stack.getItemMeta();
if ((Map<String, Object>) cc.getSessionData("tempMeta") != null) { if ((Map<String, Object>) context.getSessionData("tempMeta") != null) {
meta = ItemUtil.deserializeItemMeta(meta.getClass(), (Map<String, Object>) cc meta = ItemUtil.deserializeItemMeta(meta.getClass(),
.getSessionData("tempMeta")); (Map<String, Object>) context.getSessionData("tempMeta"));
} }
if (enchs != null) { if (enchs != null) {
@ -280,269 +338,363 @@ public class ItemStackPrompt extends FixedSetPrompt {
} }
stack.setItemMeta(meta); stack.setItemMeta(meta);
cc.setSessionData("tempStack", stack); context.setSessionData("tempStack", stack);
cc.setSessionData("newItem", Boolean.TRUE); context.setSessionData("newItem", Boolean.TRUE);
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateNoNameAmount"));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
}
default:
try {
return oldPrompt;
} catch (Exception e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateCriticalError"));
return Prompt.END_OF_CONVERSATION;
} }
}
try {
return oldPrompt;
} catch (Exception e) {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateCriticalError"));
return Prompt.END_OF_CONVERSATION;
} }
} }
private class NamePrompt extends StringPrompt { public class ItemNamePrompt extends QuestsEditorStringPrompt {
public ItemNamePrompt(ConversationContext context) {
super(context);
}
@Override @Override
public String getPromptText(ConversationContext cc) { public String getTitle(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("itemCreateEnterName"); return null;
} }
@Override @Override
public Prompt acceptInput(ConversationContext cc, String input) { public String getQueryText(ConversationContext context) {
return Lang.get("itemCreateEnterName");
}
@Override
public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
String s = input.replace(":", ""); String s = input.replace(":", "");
Material mat = Material.matchMaterial(s.toUpperCase().replace(" ", "_")); Material mat = Material.matchMaterial(s.toUpperCase().replace(" ", "_"));
if (mat == null) { if (mat == null) {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidName")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidName"));
return new NamePrompt(); return new ItemNamePrompt(context);
} else { } else {
cc.setSessionData("tempName", mat.name()); context.setSessionData("tempName", mat.name());
cc.setSessionData("tempAmount", 1); context.setSessionData("tempAmount", 1);
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} else { } else {
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} }
} }
private class AmountPrompt extends StringPrompt { public class ItemAmountPrompt extends QuestsEditorStringPrompt {
public ItemAmountPrompt(ConversationContext context) {
super(context);
}
@Override @Override
public String getPromptText(ConversationContext cc) { public String getTitle(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("itemCreateEnterAmount"); return null;
} }
@Override @Override
public Prompt acceptInput(ConversationContext cc, String input) { public String getQueryText(ConversationContext context) {
return Lang.get("itemCreateEnterAmount");
}
@Override
public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
try { try {
int amt = Integer.parseInt(input); int amt = Integer.parseInt(input);
if (amt < 1 || amt > 64) { if (amt < 1 || amt > 64) {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange") context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidRange")
.replace("<least>", "1").replace("<greatest>", "64")); .replace("<least>", "1").replace("<greatest>", "64"));
return new AmountPrompt(); return new ItemAmountPrompt(context);
} else { } else {
cc.setSessionData("tempAmount", Integer.parseInt(input)); context.setSessionData("tempAmount", Integer.parseInt(input));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new AmountPrompt(); return new ItemAmountPrompt(context);
} }
} else { } else {
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} }
} }
private class DataPrompt extends StringPrompt { public class ItemDataPrompt extends QuestsEditorStringPrompt {
public ItemDataPrompt(ConversationContext context) {
super(context);
}
@Override @Override
public String getPromptText(ConversationContext cc) { public String getTitle(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("itemCreateEnterDurab"); return null;
} }
@Override @Override
public Prompt acceptInput(ConversationContext cc, String input) { public String getQueryText(ConversationContext context) {
return Lang.get("itemCreateEnterDurab");
}
@Override
public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) { && input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
try { try {
int amt = Integer.parseInt(input); int amt = Integer.parseInt(input);
if (amt < 1) { if (amt < 1) {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidDurab")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidDurab"));
return new DataPrompt(); return new ItemDataPrompt(context);
} else { } else {
cc.setSessionData("tempData", Short.parseShort(input)); context.setSessionData("tempData", Short.parseShort(input));
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
if (input.equals("*")) { if (input.equals("*")) {
cc.setSessionData("tempData", Short.parseShort("999")); // wildcard value context.setSessionData("tempData", Short.parseShort("999")); // wildcard value
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidInput"));
return new DataPrompt(); return new ItemDataPrompt(context);
} }
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) { } else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
cc.setSessionData("tempData", null); context.setSessionData("tempData", null);
} }
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} }
private class EnchantmentPrompt extends StringPrompt { public class ItemEnchantmentPrompt extends QuestsEditorStringPrompt {
public ItemEnchantmentPrompt(ConversationContext context) {
super(context);
}
@Override
public String getTitle(ConversationContext context) {
return Lang.get("enchantmentsTitle");
}
@Override @Override
public String getPromptText(ConversationContext cc) { public String getQueryText(ConversationContext context) {
String text = ChatColor.LIGHT_PURPLE + Lang.get("enchantmentsTitle") + "\n"; return Lang.get("itemCreateEnterEnch");
}
@Override
public String getPromptText(ConversationContext context) {
String text = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n";
for (Enchantment e : Enchantment.values()) { for (Enchantment e : Enchantment.values()) {
text += ChatColor.GREEN + ItemUtil.getPrettyEnchantmentName(e) + ", "; text += ChatColor.GREEN + ItemUtil.getPrettyEnchantmentName(e) + ", ";
} }
text = text.substring(0, text.length() - 2); text = text.substring(0, text.length() - 2);
return text + "\n" + ChatColor.YELLOW + Lang.get("itemCreateEnterEnch"); return text + "\n" + ChatColor.YELLOW + getQueryText(context);
} }
@Override @Override
public Prompt acceptInput(ConversationContext cc, String input) { public Prompt acceptInput(ConversationContext context, String input) {
String s = input.replace(":", ""); String s = input.replace(":", "");
if (s.equalsIgnoreCase(Lang.get("cmdClear")) == false if (s.equalsIgnoreCase(Lang.get("cmdClear")) == false
&& s.equalsIgnoreCase(Lang.get("cmdCancel")) == false) { && s.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
Enchantment e = ItemUtil.getEnchantmentFromPrettyName(MiscUtil.getCapitalized(s)); Enchantment e = ItemUtil.getEnchantmentFromPrettyName(MiscUtil.getCapitalized(s));
if (e != null) { if (e != null) {
cc.setSessionData("tempEnchant", e); context.setSessionData("tempEnchant", e);
return new LevelPrompt(ItemUtil.getPrettyEnchantmentName(e)); return new ItemEnchantmentLevelPrompt(context, ItemUtil.getPrettyEnchantmentName(e));
} else { } else {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidEnch")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateInvalidEnch"));
return new EnchantmentPrompt(); return new ItemEnchantmentPrompt(context);
} }
} else if (s.equalsIgnoreCase(Lang.get("cmdClear"))) { } else if (s.equalsIgnoreCase(Lang.get("cmdClear"))) {
cc.setSessionData("tempEnchantments", null); context.setSessionData("tempEnchantments", null);
} }
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
}
}
public class ItemEnchantmentLevelPrompt extends QuestsEditorStringPrompt {
final String enchantment;
protected ItemEnchantmentLevelPrompt(ConversationContext context, String ench) {
super(context);
enchantment = ench;
}
@Override
public String getTitle(ConversationContext context) {
return null;
} }
protected class LevelPrompt extends StringPrompt { @Override
public String getQueryText(ConversationContext context) {
return Lang.get("itemCreateEnterLevel").replace("<enchantment>", enchantment);
}
final String enchantment; @Override
public String getPromptText(ConversationContext context) {
return ChatColor.AQUA + getQueryText(context);
}
protected LevelPrompt(String ench) { @Override
enchantment = ench; public Prompt acceptInput(ConversationContext context, String input) {
} try {
int num = Integer.parseInt(input);
@Override if (num < 1) {
public String getPromptText(ConversationContext cc) { context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum")
String text = Lang.get("itemCreateEnterLevel"); .replace("<number>", "1"));
text = text.replace("<enchantment>", enchantment); return new ItemEnchantmentLevelPrompt(context, enchantment);
return ChatColor.AQUA + text; } else {
} if (context.getSessionData("tempEnchantments") != null) {
@SuppressWarnings("unchecked")
@Override Map<Enchantment, Integer> enchs
public Prompt acceptInput(ConversationContext cc, String input) { = (Map<Enchantment, Integer>) context.getSessionData("tempEnchantments");
try { enchs.put((Enchantment) context.getSessionData("tempEnchant"), num);
int num = Integer.parseInt(input); context.setSessionData("tempEnchantments", enchs);
if (num < 1) {
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum")
.replace("<number>", "1"));
return new LevelPrompt(enchantment);
} else { } else {
if (cc.getSessionData("tempEnchantments") != null) { Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
@SuppressWarnings("unchecked") enchs.put((Enchantment) context.getSessionData("tempEnchant"), num);
Map<Enchantment, Integer> enchs context.setSessionData("tempEnchantments", enchs);
= (Map<Enchantment, Integer>) cc.getSessionData("tempEnchantments");
enchs.put((Enchantment) cc.getSessionData("tempEnchant"), num);
cc.setSessionData("tempEnchantments", enchs);
} else {
Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
enchs.put((Enchantment) cc.getSessionData("tempEnchant"), num);
cc.setSessionData("tempEnchantments", enchs);
}
return new ItemStackPrompt(oldPrompt);
} }
} catch (NumberFormatException e) { return new ItemStackPrompt(context, oldPrompt);
cc.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("<input>", input));
return new LevelPrompt(enchantment);
} }
} catch (NumberFormatException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqNotANumber").replace("<input>", input));
return new ItemEnchantmentLevelPrompt(context, enchantment);
} }
} }
} }
private class DisplayPrompt extends StringPrompt { public class ItemDisplayPrompt extends QuestsEditorStringPrompt {
public ItemDisplayPrompt(ConversationContext context) {
super(context);
}
@Override @Override
public String getPromptText(ConversationContext cc) { public String getTitle(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("itemCreateEnterDisplay"); return null;
} }
@Override @Override
public Prompt acceptInput(ConversationContext cc, String input) { public String getQueryText(ConversationContext context) {
return Lang.get("itemCreateEnterDisplay");
}
@Override
public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
String s = input.replace(":", ""); String s = input.replace(":", "");
if (s.equalsIgnoreCase(Lang.get("cmdCancel")) == false if (s.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& s.equalsIgnoreCase(Lang.get("cmdClear")) == false) { && s.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
s = ConfigUtil.parseString(s); s = ConfigUtil.parseString(s);
cc.setSessionData("tempDisplay", s); context.setSessionData("tempDisplay", s);
} else if (s.equalsIgnoreCase(Lang.get("cmdClear"))) { } else if (s.equalsIgnoreCase(Lang.get("cmdClear"))) {
cc.setSessionData("tempDisplay", null); context.setSessionData("tempDisplay", null);
} }
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} }
private class LorePrompt extends StringPrompt { public class ItemLorePrompt extends QuestsEditorStringPrompt {
public ItemLorePrompt(ConversationContext context) {
super(context);
}
@Override @Override
public String getPromptText(ConversationContext cc) { public String getTitle(ConversationContext context) {
return ChatColor.YELLOW + Lang.get("itemCreateEnterLore"); return null;
} }
@Override @Override
public Prompt acceptInput(ConversationContext cc, String input) { public String getQueryText(ConversationContext context) {
return Lang.get("itemCreateEnterLore");
}
@Override
public String getPromptText(ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(ConversationContext context, String input) {
String s = input.replace(":", ""); String s = input.replace(":", "");
if (s.equalsIgnoreCase(Lang.get("cmdCancel")) == false if (s.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& s.equalsIgnoreCase(Lang.get("cmdClear")) == false) { && s.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
s = ConfigUtil.parseString(s); s = ConfigUtil.parseString(s);
LinkedList<String> lore = new LinkedList<String>(); LinkedList<String> lore = new LinkedList<String>();
lore.addAll(Arrays.asList(s.split(Lang.get("charSemi")))); lore.addAll(Arrays.asList(s.split(Lang.get("charSemi"))));
cc.setSessionData("tempLore", lore); context.setSessionData("tempLore", lore);
} else if (s.equalsIgnoreCase("clear")) { } else if (s.equalsIgnoreCase("clear")) {
cc.setSessionData("tempLore", null); context.setSessionData("tempLore", null);
} }
return new ItemStackPrompt(oldPrompt); return new ItemStackPrompt(context, oldPrompt);
} }
} }
private String getItemData(ConversationContext cc) { private String getItemData(ConversationContext context) {
if (cc.getSessionData("tempName") != null) { if (context.getSessionData("tempName") != null) {
String item; String item;
if (cc.getSessionData("tempDisplay") == null) { if (context.getSessionData("tempDisplay") == null) {
String name = (String) cc.getSessionData("tempName"); String name = (String) context.getSessionData("tempName");
item = ChatColor.AQUA + ItemUtil.getPrettyItemName(name); item = ChatColor.AQUA + ItemUtil.getPrettyItemName(name);
if (cc.getSessionData("tempData") != null) { if (context.getSessionData("tempData") != null) {
item += ":" + ChatColor.BLUE + (Short) cc.getSessionData("tempData"); item += ":" + ChatColor.BLUE + (Short) context.getSessionData("tempData");
} }
} else { } else {
item = ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + (String) cc.getSessionData("tempDisplay") item = ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + (String) context.getSessionData("tempDisplay")
+ ChatColor.RESET + "" + ChatColor.GRAY + " ("; + ChatColor.RESET + "" + ChatColor.GRAY + " (";
String name = (String) cc.getSessionData("tempName"); String name = (String) context.getSessionData("tempName");
item += ChatColor.AQUA + ItemUtil.getPrettyItemName(name); item += ChatColor.AQUA + ItemUtil.getPrettyItemName(name);
if (cc.getSessionData("tempData") != null) { if (context.getSessionData("tempData") != null) {
item += ":" + ChatColor.BLUE + (Short) cc.getSessionData("tempData"); item += ":" + ChatColor.BLUE + (Short) context.getSessionData("tempData");
} }
item += ChatColor.GRAY + ")"; item += ChatColor.GRAY + ")";
} }
if (cc.getSessionData("tempAmount") != null) { if (context.getSessionData("tempAmount") != null) {
item += ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + (Integer) cc.getSessionData("tempAmount"); item += ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + (Integer) context.getSessionData("tempAmount");
} else { } else {
item += ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + "1"; item += ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + "1";
} }
item += "\n"; item += "\n";
if (cc.getSessionData("tempEnchantments") != null) { if (context.getSessionData("tempEnchantments") != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<Enchantment, Integer> enchantments Map<Enchantment, Integer> enchantments
= (Map<Enchantment, Integer>) cc.getSessionData("tempEnchantments"); = (Map<Enchantment, Integer>) context.getSessionData("tempEnchantments");
for (Entry<Enchantment, Integer> e : enchantments.entrySet()) { for (Entry<Enchantment, Integer> e : enchantments.entrySet()) {
item += ChatColor.GRAY + " - " + ChatColor.RED + ItemUtil.getPrettyEnchantmentName(e.getKey()) item += ChatColor.GRAY + " - " + ChatColor.RED + ItemUtil.getPrettyEnchantmentName(e.getKey())
+ " " + RomanNumeral.getNumeral(e.getValue()) + "\n"; + " " + RomanNumeral.getNumeral(e.getValue()) + "\n";
} }
} }
if (cc.getSessionData("tempLore") != null) { if (context.getSessionData("tempLore") != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<String> lore = (List<String>) cc.getSessionData("tempLore"); List<String> lore = (List<String>) context.getSessionData("tempLore");
item += ChatColor.DARK_GREEN + "(Lore)\n\""; item += ChatColor.DARK_GREEN + "(Lore)\n\"";
for (String s : lore) { for (String s : lore) {
if (lore.indexOf(s) != (lore.size() - 1)) { if (lore.indexOf(s) != (lore.size() - 1)) {

View File

@ -783,7 +783,7 @@ public class QuestMainPrompt 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 ItemStackPrompt(QuestGuiDisplayPrompt.this); return new ItemStackPrompt(context, QuestGuiDisplayPrompt.this);
case 2: case 2:
context.setSessionData(CK.Q_GUIDISPLAY, null); context.setSessionData(CK.Q_GUIDISPLAY, null);
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("questGUICleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("questGUICleared"));

View File

@ -312,7 +312,7 @@ 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 ItemStackPrompt(ItemsCraftListPrompt.this); return new ItemStackPrompt(context, ItemsCraftListPrompt.this);
case 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);
@ -421,7 +421,7 @@ 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 ItemStackPrompt(ItemsSmeltListPrompt.this); return new ItemStackPrompt(context, ItemsSmeltListPrompt.this);
case 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);
@ -838,7 +838,7 @@ 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 ItemStackPrompt(ItemsBrewListPrompt.this); return new ItemStackPrompt(context, ItemsBrewListPrompt.this);
case 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);
@ -947,7 +947,7 @@ 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 ItemStackPrompt(ItemsConsumeListPrompt.this); return new ItemStackPrompt(context, ItemsConsumeListPrompt.this);
case 2: case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, null); context.setSessionData(pref + CK.S_CONSUME_ITEMS, null);

View File

@ -327,7 +327,7 @@ public class NpcsPrompt 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 ItemStackPrompt(NpcsDeliveryListPrompt.this); return new ItemStackPrompt(context, NpcsDeliveryListPrompt.this);
case 2: case 2:
return new NpcDeliveryNpcsPrompt(context); return new NpcDeliveryNpcsPrompt(context);
case 3: case 3:

View File

@ -703,7 +703,7 @@ public class RequirementsPrompt 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 ItemStackPrompt(RequirementsItemListPrompt.this); return new ItemStackPrompt(context, RequirementsItemListPrompt.this);
case 2: case 2:
if (context.getSessionData(CK.REQ_ITEMS) == null) { if (context.getSessionData(CK.REQ_ITEMS) == null) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqMustAddItem")); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("reqMustAddItem"));

View File

@ -690,7 +690,7 @@ public class RewardsPrompt 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 ItemStackPrompt(RewardsItemListPrompt.this); return new ItemStackPrompt(context, RewardsItemListPrompt.this);
case 2: case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewItemsCleared")); context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewItemsCleared"));
context.setSessionData(CK.REW_ITEMS, null); context.setSessionData(CK.REW_ITEMS, null);