From 9e0919e9fea04f7e0418921518823b4d41c6e43b Mon Sep 17 00:00:00 2001 From: PikaMug Date: Sat, 10 Aug 2019 01:12:04 -0400 Subject: [PATCH] Better stage/action item serialization, part 2. Fixes #904 --- .../me/blackvein/quests/actions/Action.java | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/actions/Action.java b/main/src/main/java/me/blackvein/quests/actions/Action.java index 81476afc8..ce5f0b73c 100644 --- a/main/src/main/java/me/blackvein/quests/actions/Action.java +++ b/main/src/main/java/me/blackvein/quests/actions/Action.java @@ -493,33 +493,36 @@ public class Action { } } if (data.contains(actionKey + "items")) { - if (Quests.checkList(data.getList(actionKey + "items"), String.class)) { - @SuppressWarnings("unchecked") - List items = (List) data.get(actionKey + "items"); - if (items != null && !items.isEmpty() && items.get(0) instanceof ItemStack) { - for (ItemStack item : items) { + LinkedList temp = new LinkedList(); // TODO - should maybe be = action.getItems() ? + @SuppressWarnings("unchecked") + List stackList = (List) data.get(actionKey + "items"); + if (Quests.checkList(stackList, ItemStack.class)) { + for (ItemStack stack : stackList) { + if (stack != null) { + temp.add(stack); + } + } + } else { + // Legacy + if (Quests.checkList(stackList, String.class)) { + List items = data.getStringList(actionKey + "items"); + for (String item : items) { try { - action.items.add(item); + ItemStack stack = ItemUtil.readItemStack(item); + if (stack != null) { + 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!"); + 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 { - // Legacy - for (String s : data.getStringList(actionKey + "items")) { - try { - action.items.add(ItemUtil.readItemStack(s)); - } catch (Exception e) { - 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!"); - return null; - } - } + plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a list of items!"); + return null; } - } else { - plugin.getLogger().severe(ChatColor.GOLD + "[Quests] " + ChatColor.RED + "items: " + ChatColor.GOLD + "inside Action " + ChatColor.DARK_PURPLE + name + ChatColor.GOLD + " is not a list of items!"); - return null; } + action.setItems(temp); } if (data.contains(actionKey + "storm-world")) { World w = plugin.getServer().getWorld(data.getString(actionKey + "storm-world"));