Better stage/action item serialization, part 2. Fixes #904

This commit is contained in:
PikaMug 2019-08-10 01:12:04 -04:00
parent 3238aa797e
commit 9e0919e9fe

View File

@ -493,27 +493,28 @@ public class Action {
} }
} }
if (data.contains(actionKey + "items")) { if (data.contains(actionKey + "items")) {
if (Quests.checkList(data.getList(actionKey + "items"), String.class)) { LinkedList<ItemStack> temp = new LinkedList<ItemStack>(); // TODO - should maybe be = action.getItems() ?
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<ItemStack> items = (List<ItemStack>) data.get(actionKey + "items"); List<ItemStack> stackList = (List<ItemStack>) data.get(actionKey + "items");
if (items != null && !items.isEmpty() && items.get(0) instanceof ItemStack) { if (Quests.checkList(stackList, ItemStack.class)) {
for (ItemStack item : items) { for (ItemStack stack : stackList) {
try { if (stack != null) {
action.items.add(item); temp.add(stack);
} catch (Exception e) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + item.getType().name() + ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not formatted properly!");
return null;
} }
} }
} else { } else {
// Legacy // Legacy
for (String s : data.getStringList(actionKey + "items")) { if (Quests.checkList(stackList, String.class)) {
List<String> items = data.getStringList(actionKey + "items");
for (String item : items) {
try { try {
action.items.add(ItemUtil.readItemStack(s)); ItemStack stack = ItemUtil.readItemStack(item);
} catch (Exception e) { if (stack != null) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + s + ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not formatted properly!"); temp.add(stack);
return null;
} }
} catch (Exception e) {
plugin.getLogger().severe(ChatColor.GOLD + "[Quests] \"" + ChatColor.RED + item + ChatColor.GOLD + "\" inside " + ChatColor.GREEN + " items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not formatted properly!");
return null;
} }
} }
} else { } else {
@ -521,6 +522,8 @@ public class Action {
return null; return null;
} }
} }
action.setItems(temp);
}
if (data.contains(actionKey + "storm-world")) { if (data.contains(actionKey + "storm-world")) {
World w = plugin.getServer().getWorld(data.getString(actionKey + "storm-world")); World w = plugin.getServer().getWorld(data.getString(actionKey + "storm-world"));
if (w == null) { if (w == null) {