Quests/core/src/main/java/me/blackvein/quests/convo/quests/objectives/ItemsPrompt.java

849 lines
35 KiB
Java

/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.convo.quests.objectives;
import me.blackvein.quests.convo.generic.ItemStackPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.stages.StageMainPrompt;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
import java.util.List;
public class ItemsPrompt extends QuestsEditorNumericPrompt {
private final int stageNum;
private final String pref;
public ItemsPrompt(final int stageNum, final ConversationContext context) {
super(context);
this.stageNum = stageNum;
this.pref = "stage" + stageNum;
}
private final int size = 6;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorItems");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
case 2:
case 3:
case 4:
case 5:
return ChatColor.BLUE;
case 6:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final int number) {
switch(number) {
case 1:
return ChatColor.YELLOW + Lang.get("stageEditorCraftItems");
case 2:
return ChatColor.YELLOW + Lang.get("stageEditorSmeltItems");
case 3:
return ChatColor.YELLOW + Lang.get("stageEditorEnchantItems");
case 4:
return ChatColor.YELLOW + Lang.get("stageEditorBrewPotions");
case 5:
return ChatColor.YELLOW + Lang.get("stageEditorConsumeItems");
case 6:
return ChatColor.GREEN + Lang.get("done");
default:
return null;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount());
}
}
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount());
}
}
return text.toString();
}
case 3:
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount());
}
}
return text.toString();
}
case 4:
if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount());
}
}
return text.toString();
}
case 5:
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount());
}
}
return text.toString();
}
case 6:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
} else if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
}
ItemStackPrompt.clearSessionData(context);
}
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -");
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemsCraftListPrompt(context);
case 2:
return new ItemsSmeltListPrompt(context);
case 3:
return new ItemsEnchantListPrompt(context);
case 4:
return new ItemsBrewListPrompt(context);
case 5:
return new ItemsConsumeListPrompt(context);
case 6:
try {
return new StageMainPrompt(stageNum, context);
} catch (final Exception e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("itemCreateCriticalError"));
return Prompt.END_OF_CONVERSATION;
}
default:
return new ItemsPrompt(stageNum, context);
}
}
public class ItemsCraftListPrompt extends QuestsEditorNumericPrompt {
public ItemsCraftListPrompt(final ConversationContext context) {
super(context);
}
private final int size = 3;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorCraftItems");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final 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;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final List<ItemStack> craftItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
if (craftItems != null) {
for (final ItemStack is : craftItems) {
text.append("\n").append(ChatColor.GRAY).append(" - ")
.append(ItemUtil.getDisplayString(is));
}
}
return text.toString();
}
case 2:
case 3:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context) + " -");
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsCraftListPrompt.this);
case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, null);
return new ItemsCraftListPrompt(context);
default:
return new ItemsPrompt(stageNum, context);
}
}
}
public class ItemsSmeltListPrompt extends QuestsEditorNumericPrompt {
public ItemsSmeltListPrompt(final ConversationContext context) {
super(context);
}
private final int size = 3;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorSmeltItems");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final 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;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final List<ItemStack> smeltItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
if (smeltItems != null) {
for (final ItemStack is : smeltItems) {
text.append("\n").append(ChatColor.GRAY).append(" - ")
.append(ItemUtil.getDisplayString(is));
}
}
return text.toString();
}
case 2:
case 3:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context) + " -");
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsSmeltListPrompt.this);
case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, null);
return new ItemsSmeltListPrompt(context);
default:
return new ItemsPrompt(stageNum, context);
}
}
}
public class ItemsEnchantListPrompt extends QuestsEditorNumericPrompt {
public ItemsEnchantListPrompt(final ConversationContext context) {
super(context);
}
private final int size = 3;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorEnchantItems");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final 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;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final List<ItemStack> enchantItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
if (enchantItems != null) {
for (final ItemStack is : enchantItems) {
text.append("\n").append(ChatColor.GRAY).append(" - ")
.append(ItemUtil.getDisplayString(is));
}
}
return text.toString();
}
case 2:
case 3:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context) + " -");
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsEnchantListPrompt.this);
case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, null);
return new ItemsEnchantListPrompt(context);
default:
return new ItemsPrompt(stageNum, context);
}
}
}
public class ItemsBrewListPrompt extends QuestsEditorNumericPrompt {
public ItemsBrewListPrompt(final ConversationContext context) {
super(context);
}
private final int size = 3;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorBrewPotions");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final 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;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final List<ItemStack> brewItems = (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
if (brewItems != null) {
for (final ItemStack is : brewItems) {
text.append("\n").append(ChatColor.GRAY).append(" - ")
.append(ItemUtil.getDisplayString(is));
}
}
return text.toString();
}
case 2:
case 3:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_BREW_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context) + " -");
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsBrewListPrompt.this);
case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_BREW_ITEMS, null);
return new ItemsBrewListPrompt(context);
default:
return new ItemsPrompt(stageNum, context);
}
}
}
public class ItemsConsumeListPrompt extends QuestsEditorNumericPrompt {
public ItemsConsumeListPrompt(final ConversationContext context) {
super(context);
}
private final int size = 3;
@Override
public int getSize() {
return size;
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorConsumeItems");
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.RED;
case 3:
return ChatColor.GREEN;
default:
return null;
}
}
@Override
public String getSelectionText(final ConversationContext context, final 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;
}
}
@Override
@SuppressWarnings("unchecked")
public String getAdditionalText(final ConversationContext context, final int number) {
switch(number) {
case 1:
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
final StringBuilder text = new StringBuilder();
final List<ItemStack> consumeItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
if (consumeItems != null) {
for (final ItemStack is : consumeItems) {
text.append("\n").append(ChatColor.GRAY).append(" - ")
.append(ItemUtil.getDisplayString(is));
}
}
return text.toString();
}
case 2:
case 3:
return "";
default:
return null;
}
}
@SuppressWarnings("unchecked")
@Override
public @NotNull String getBasicPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context) + " -");
for (int i = 1; i <= size; i++) {
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsConsumeListPrompt.this);
case 2:
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, null);
return new ItemsConsumeListPrompt(context);
default:
return new ItemsPrompt(stageNum, context);
}
}
}
}