Cleaner data in item prompt

This commit is contained in:
PikaMug 2023-03-27 22:54:06 -04:00
parent 5344c4c6d7
commit 1f5ede8f2c
1 changed files with 40 additions and 53 deletions

View File

@ -760,60 +760,47 @@ public class ItemStackPrompt extends QuestsEditorNumericPrompt {
}
public String getItemData(final ConversationContext context) {
if (context.getSessionData("tempName") != null) {
final StringBuilder item;
if (context.getSessionData("tempDisplay") == null) {
final String name = (String) context.getSessionData("tempName");
item = new StringBuilder(ChatColor.AQUA + ItemUtil.getPrettyItemName(name));
if (context.getSessionData("tempData") != null) {
item.append(":").append(ChatColor.BLUE).append(context.getSessionData("tempData"));
}
} else {
item = new StringBuilder(ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC
+ context.getSessionData("tempDisplay") + ChatColor.RESET + "" + ChatColor.GRAY + " (");
final String name = (String) context.getSessionData("tempName");
item.append(ChatColor.AQUA).append(ItemUtil.getPrettyItemName(name));
if (context.getSessionData("tempData") != null) {
item.append(":").append(ChatColor.BLUE).append(context.getSessionData("tempData"));
}
item.append(ChatColor.GRAY).append(")");
}
if (context.getSessionData("tempAmount") != null) {
item.append(ChatColor.GRAY).append(" x ").append(ChatColor.DARK_AQUA)
.append(context.getSessionData("tempAmount"));
} else {
item.append(ChatColor.GRAY).append(" x ").append(ChatColor.DARK_AQUA).append("1");
}
if (context.getSessionData("tempEnchantments") != null) {
@SuppressWarnings("unchecked")
final Map<Enchantment, Integer> enchantments
= (Map<Enchantment, Integer>) context.getSessionData("tempEnchantments");
if (enchantments != null) {
for (final Entry<Enchantment, Integer> e : enchantments.entrySet()) {
item.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.RED)
.append(ItemUtil.getPrettyEnchantmentName(e.getKey())).append(" ")
.append(RomanNumeral.getNumeral(e.getValue()));
}
}
}
if (context.getSessionData("tempLore") != null) {
@SuppressWarnings("unchecked")
final List<String> lore = (List<String>) context.getSessionData("tempLore");
item.append("\n").append(ChatColor.DARK_GREEN).append("(Lore)\"");
if (lore != null) {
for (final String s : lore) {
if (lore.indexOf(s) != (lore.size() - 1)) {
item.append("\n").append(ChatColor.DARK_GREEN).append(ChatColor.ITALIC).append(s);
} else {
item.append("\n").append(ChatColor.DARK_GREEN).append(ChatColor.ITALIC).append(s).append("\"");
}
}
}
}
return item.toString();
} else {
return null;
final StringBuilder item = new StringBuilder();
if (context.getSessionData("tempDisplay") != null) {
item.append(ChatColor.LIGHT_PURPLE).append(ChatColor.ITALIC)
.append(context.getSessionData("tempDisplay")).append(ChatColor.RESET).append(" ");
}
if (context.getSessionData("tempName") != null) {
final String name = (String) context.getSessionData("tempName");
item.append(ChatColor.GRAY).append("(").append(ChatColor.AQUA).append(ItemUtil.getPrettyItemName(name));
if (context.getSessionData("tempData") != null) {
item.append(":").append(ChatColor.BLUE).append(context.getSessionData("tempData"));
}
item.append(ChatColor.GRAY).append(")");
}
if (context.getSessionData("tempAmount") != null) {
item.append(ChatColor.GRAY).append(" x ").append(ChatColor.DARK_AQUA)
.append(context.getSessionData("tempAmount"));
} else {
item.append(ChatColor.GRAY).append(" x ").append(ChatColor.DARK_AQUA).append("1");
}
if (context.getSessionData("tempEnchantments") != null) {
@SuppressWarnings("unchecked")
final Map<Enchantment, Integer> enchantments
= (Map<Enchantment, Integer>) context.getSessionData("tempEnchantments");
if (enchantments != null) {
for (final Entry<Enchantment, Integer> e : enchantments.entrySet()) {
item.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.RED)
.append(ItemUtil.getPrettyEnchantmentName(e.getKey())).append(" ")
.append(RomanNumeral.getNumeral(e.getValue()));
}
}
}
if (context.getSessionData("tempLore") != null) {
@SuppressWarnings("unchecked")
final List<String> lore = (List<String>) context.getSessionData("tempLore");
if (lore != null) {
for (final String s : lore) {
item.append("\n").append(ChatColor.DARK_PURPLE).append(ChatColor.ITALIC).append(s);
}
}
}
return item.toString();
}
public static void clearSessionData(final ConversationContext context) {