From a7665044cb15e847b1459cdbc72e293a08e3e14f Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Mon, 11 Mar 2024 15:20:27 -0500 Subject: [PATCH] Kit conversion overhaul. --- .../conversion/ConversionKit.java | 25 ++++++++ .../ultimatekits/conversion/Convert.java | 61 +++++++++---------- .../ultimatekits/conversion/Hook.java | 6 +- .../conversion/hooks/CMIHook.java | 44 +++++++------ .../conversion/hooks/DefaultHook.java | 60 +++++++----------- .../conversion/hooks/EssentialsHook.java | 61 ++++++++----------- .../conversion/hooks/UltimateCoreHook.java | 23 ++----- 7 files changed, 128 insertions(+), 152 deletions(-) create mode 100644 src/main/java/com/craftaro/ultimatekits/conversion/ConversionKit.java diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/ConversionKit.java b/src/main/java/com/craftaro/ultimatekits/conversion/ConversionKit.java new file mode 100644 index 0000000..f5af181 --- /dev/null +++ b/src/main/java/com/craftaro/ultimatekits/conversion/ConversionKit.java @@ -0,0 +1,25 @@ +package com.craftaro.ultimatekits.conversion; + +import org.bukkit.inventory.ItemStack; + +import java.util.LinkedHashSet; +import java.util.Set; + +public class ConversionKit { + + private final Set itemStack = new LinkedHashSet<>(); + private final long delay; + + public ConversionKit(Set itemStack, long delay) { + this.itemStack.addAll(itemStack); + this.delay = delay; + } + + public Set getItemStacks() { + return this.itemStack; + } + + public long getDelay() { + return this.delay; + } +} diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/Convert.java b/src/main/java/com/craftaro/ultimatekits/conversion/Convert.java index f78d775..3045269 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/Convert.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/Convert.java @@ -12,67 +12,62 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.List; -import java.util.Set; +import java.util.Map; public class Convert { + public static void runKitConversions(UltimateKits plugin) { if (!plugin.getKitConfig().contains("Kits")) { if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { try { Class.forName("com.earth2me.essentials.metrics.MetricsListener"); } catch (ClassNotFoundException ex) { - convertKits(new EssentialsHook()); + convertKits(plugin, new EssentialsHook()); } } - if (Bukkit.getPluginManager().isPluginEnabled("UltimateCore")) { - convertKits(new UltimateCoreHook()); - } - if (Bukkit.getPluginManager().isPluginEnabled("CMI")) { - convertKits(new CMIHook()); - } - } - if (!isInJsonFormat()) { - convertKits(new DefaultHook()); + if (Bukkit.getPluginManager().isPluginEnabled("UltimateCore")) + convertKits(plugin, new UltimateCoreHook()); + if (Bukkit.getPluginManager().isPluginEnabled("CMI")) + convertKits(plugin, new CMIHook()); } + if (!isInJsonFormat(plugin)) + convertKits(plugin, new DefaultHook()); } - private static void convertKits(Hook hook) { + private static void convertKits(UltimateKits plugin, Hook hook) { try { - Set kits = hook.getKits(); - for (String kit : kits) { - Kit kitObj = UltimateKits.getInstance().getKitManager().addKit(new Kit(kit)); - if (kitObj == null) { + Map kits = hook.getKits(); + for (Map.Entry entry : kits.entrySet()) { + Kit kitObj = plugin.getKitManager().addKit(new Kit(entry.getKey())); + if (kitObj == null) continue; - } - for (ItemStack item : hook.getItems(kit)) { - if (item == null || item.getType() == Material.AIR) { + + ConversionKit cvt = entry.getValue(); + + for (ItemStack item : cvt.getItemStacks()) { + if (item == null || item.getType() == Material.AIR) continue; - } kitObj.getContents().add(new KitItem(item)); } - kitObj.setDelay(hook.getDelay(kit)); + kitObj.setDelay(cvt.getDelay()); } - UltimateKits.getInstance().saveKits(true); + plugin.saveKits(true); } catch (NoSuchMethodError | NoClassDefFoundError e) { System.out.println("UltimateKits conversion failed."); } } - private static boolean isInJsonFormat() { - if (!UltimateKits.getInstance().getKitConfig().contains("Kits")) { + private static boolean isInJsonFormat(UltimateKits plugin) { + if (!plugin.getKitConfig().contains("Kits")) return false; - } - for (String kit : UltimateKits.getInstance().getKitConfig().getConfigurationSection("Kits").getKeys(false)) { - if (UltimateKits.getInstance().getKitConfig().contains("Kits." + kit + ".items")) { - List itemList = UltimateKits.getInstance().getKitConfig().getStringList("Kits." + kit + ".items"); - if (!itemList.isEmpty()) { - if (itemList.get(0).startsWith("{")) { + for (String kit : plugin.getKitConfig().getConfigurationSection("Kits").getKeys(false)) + if (plugin.getKitConfig().contains("Kits." + kit + ".items")) { + List itemList = plugin.getKitConfig().getStringList("Kits." + kit + ".items"); + if (!itemList.isEmpty()) + if (itemList.get(0).startsWith("{")) return true; - } - } } - } return false; } diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/Hook.java b/src/main/java/com/craftaro/ultimatekits/conversion/Hook.java index 38623aa..5dcec93 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/Hook.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/Hook.java @@ -2,12 +2,10 @@ package com.craftaro.ultimatekits.conversion; import org.bukkit.inventory.ItemStack; +import java.util.Map; import java.util.Set; public interface Hook { - Set getKits(); - Set getItems(String kitName); - - long getDelay(String kitName); + Map getKits(); } diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java index b5dc445..b44ea60 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/CMIHook.java @@ -2,46 +2,44 @@ package com.craftaro.ultimatekits.conversion.hooks; import com.Zrips.CMI.CMI; import com.Zrips.CMI.Modules.Kits.Kit; +import com.craftaro.ultimatekits.conversion.ConversionKit; import com.craftaro.ultimatekits.conversion.Hook; import com.craftaro.ultimatekits.kit.type.KitContentCommand; import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class CMIHook implements Hook { + private final CMI cmi; public CMIHook() { this.cmi = (CMI) Bukkit.getPluginManager().getPlugin("CMI"); } - public Set getItems(String kitName) { - Set stacks = new HashSet<>(); - try { - Kit kit = this.cmi.getKitsManager().getKit(kitName, true); + @Override + public Map getKits() { + Map kits = new LinkedHashMap<>(); + for (String kitName : this.cmi.getKitsManager().getKitMap().keySet()) { + Set stacks = new HashSet<>(); + try { + Kit kit = this.cmi.getKitsManager().getKit(kitName, true); - for (ItemStack item : kit.getItems()) { - if (item != null) { - stacks.add(item); + for (ItemStack item : kit.getItems()) { + if (item != null) { + stacks.add(item); + } } - } - for (String command : kit.getCommands()) { - stacks.add(new KitContentCommand(command).getItemForDisplay()); + for (String command : kit.getCommands()) { + stacks.add(new KitContentCommand(command).getItemForDisplay()); + } + } catch (Exception ex) { + ex.printStackTrace(); } - } catch (Exception ex) { - ex.printStackTrace(); + kits.put(kitName, new ConversionKit(stacks, this.cmi.getKitsManager().getKit(kitName, true).getDelay())); } - return stacks; - } - - public Set getKits() { - return this.cmi.getKitsManager().getKitMap().keySet(); - } - - public long getDelay(String kitName) { - return this.cmi.getKitsManager().getKit(kitName, true).getDelay(); + return kits; } } diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/DefaultHook.java b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/DefaultHook.java index 6d19a12..81071c0 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/DefaultHook.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/DefaultHook.java @@ -1,35 +1,18 @@ package com.craftaro.ultimatekits.conversion.hooks; import com.craftaro.core.compatibility.ServerVersion; -import com.craftaro.core.utils.TextUtils; +import com.craftaro.ultimatekits.conversion.ConversionKit; import com.craftaro.ultimatekits.conversion.Hook; import com.craftaro.ultimatekits.utils.ItemSerializer; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class DefaultHook implements Hook { - public Set getItems(String kitName) { - Set items = new HashSet<>(); - - for (Kits kit : Kits.values()) { - if (!kit.name().equalsIgnoreCase(kitName)) { - continue; - } - - for (String string : kit.items) { - items.add(ItemSerializer.deserializeItemStackFromJson(string)); - } - } - - return items; - } - - public Set getKits() { - Set kits = new HashSet<>(); - + @Override + public Map getKits() { + Map kits = new LinkedHashMap<>(); for (Kits kit : Kits.values()) { if (kit == Kits.BRIANNA_1_12 && ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) continue; @@ -38,22 +21,15 @@ public class DefaultHook implements Hook { if (kit == Kits.BRIANNA_1_16 && ServerVersion.isServerVersionBelow(ServerVersion.V1_16)) continue; - kits.add(kit.getName()); + Set items = new LinkedHashSet<>(); + for (String string : kit.items) + items.add(ItemSerializer.deserializeItemStackFromJson(string)); + kits.put(kit.getName(), new ConversionKit(items, kit.getDelay())); } return kits; } - public long getDelay(String kitName) { - for (Kits kit : Kits.values()) { - if (!kit.name().equalsIgnoreCase(kitName)) { - continue; - } - return kit.delay; - } - return 0; - } - public enum Kits { TOOLS(10, "{id:\"minecraft:stone_pickaxe\",Count:1b}", "{id:\"minecraft:stone_axe\",Count:1b}", @@ -65,14 +41,14 @@ public class DefaultHook implements Hook { "{id:\"minecraft:diamond_shovel\",Count:1b,tag:{Enchantments:[{lvl:1s,id:\"minecraft:efficiency\"}]}}", "{id:\"minecraft:diamond_hoe\",Count:1b,tag:{Enchantments:[{lvl:3s,id:\"minecraft:unbreaking\"}]}}"), - BRIANNA_1_12(0, "{id:\"minecraft:skull\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[0:{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzHRIAw/6gQeiODJnOm4PAB2vPnUv0VFAP2awbikJeOSuK3WZsvcUN78+hXLFFtvBUt/oGKpsTj5P//2+qH7QLqmrxFD72jGpmyS8Fp6AHuQqzeHn40isvKT2+oTItFb3wQ3H2QgudGxEhOX6Onz0M2xmH61+HF5ajPS+/2hUl5kjRk8uRLc2AJD162dECdYOUJ8/j47Fl9pJXG1dcG6cGMuRlDAim3AqfdJFTW0CI78YEpTTGZcLL+O+/yUMQD9hOQqjP7y63YIOZ9kAZ7DRzu5hQaHLevhUcTwZnkqs+F9eUuQR00y8PoVoSEOMrV4LIWAJFutdziNZX9I7MI9tJ0x96imA18yYC9Skwx7JHurC1wpdtSqS/F7gCeU3+2QiFufxX9ft9BPHSBX7z08nqQkwxYh0O/06OX+H0NJTLwYrK+hoTXT1A5dNrJIHzGuK9/qUaitH4yz0zv5aGd3vVytdKCULFqOTiqur1QYPvF9sI2fhvfcHqUc30yU1di0Ws5SOQzCAFLOypjUH1ezQMOK+Xy3ixB0a8HXI9RL8ewOvKaVepbWS1vomNNWfiCgpudbLW8x6bPvQLmZn8YWPjCAL0WFycnw8lm6JDg=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]},Name:\"Brianna\"}},Damage:3s}}"), + BRIANNA_1_12(0, "{id:\"minecraft:skull\",Count:1b,tag:{display:{Name:'{\"text\":\"Brianna\"}'},SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[0:{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzHRIAw/6gQeiODJnOm4PAB2vPnUv0VFAP2awbikJeOSuK3WZsvcUN78+hXLFFtvBUt/oGKpsTj5P//2+qH7QLqmrxFD72jGpmyS8Fp6AHuQqzeHn40isvKT2+oTItFb3wQ3H2QgudGxEhOX6Onz0M2xmH61+HF5ajPS+/2hUl5kjRk8uRLc2AJD162dECdYOUJ8/j47Fl9pJXG1dcG6cGMuRlDAim3AqfdJFTW0CI78YEpTTGZcLL+O+/yUMQD9hOQqjP7y63YIOZ9kAZ7DRzu5hQaHLevhUcTwZnkqs+F9eUuQR00y8PoVoSEOMrV4LIWAJFutdziNZX9I7MI9tJ0x96imA18yYC9Skwx7JHurC1wpdtSqS/F7gCeU3+2QiFufxX9ft9BPHSBX7z08nqQkwxYh0O/06OX+H0NJTLwYrK+hoTXT1A5dNrJIHzGuK9/qUaitH4yz0zv5aGd3vVytdKCULFqOTiqur1QYPvF9sI2fhvfcHqUc30yU1di0Ws5SOQzCAFLOypjUH1ezQMOK+Xy3ixB0a8HXI9RL8ewOvKaVepbWS1vomNNWfiCgpudbLW8x6bPvQLmZn8YWPjCAL0WFycnw8lm6JDg=\",Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}},Damage:3s}}"), - BRIANNA_1_13(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:\"2626974f-5838-44c6-994d-f6c723d40b79\",Properties:{textures:[{Signature:\"tQRjs3H+5H5A8Id/Hb2a3E+VDQY8sUKQYacc9ZYDsBncagNO6imX6h6qsDmtTDtliTh8ZzH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ZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}},Damage:3}}"), - BRIANNA_1_16(0, "{id:\"minecraft:player_head\",Count:1b,tag:{SkullOwner:{Id:[I;656807503,1481976518,-1694340157,-169243065],Properties:{textures:[{Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}}}}"); + BRIANNA_1_16(0, "{id:\"minecraft:player_head\",Count:1b,tag:{display:{Name:'{\"text\":\"Brianna\"}'},SkullOwner:{Id:[I;656807503,1481976518,-1694340157,-169243065],Properties:{textures:[{Value:\"eyJ0aW1lc3RhbXAiOjE1NzA5MDI0MDg4ODEsInByb2ZpbGVJZCI6IjA2Y2NiMGU0MWM3NjQ0YjE5OGZiYzk5OTBhODcwNjAwIiwicHJvZmlsZU5hbWUiOiJCcmlhbm5hIiwic2lnbmF0dXJlUmVxdWlyZWQiOnRydWUsInRleHR1cmVzIjp7IlNLSU4iOnsidXJsIjoiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS8yN2I3MjM5Yzk2OWNhNzY0NWJmMTQzODc4M2Y1Y2FiZjdlMDhhYTViODY4OGFkODg3NWJhNzNlNTVhNDBlMjIiLCJtZXRhZGF0YSI6eyJtb2RlbCI6InNsaW0ifX19fQ==\"}]}}}}"); - public final String[] items; - public final int delay; + private final String[] items; + private final int delay; Kits(int delay, String... items) { this.items = items; @@ -92,5 +68,13 @@ public class DefaultHook implements Hook { } return ""; } + + public String[] getItems() { + return items; + } + + public int getDelay() { + return delay; + } } } diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/EssentialsHook.java b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/EssentialsHook.java index 971665b..6188cdd 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/EssentialsHook.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/EssentialsHook.java @@ -1,5 +1,6 @@ package com.craftaro.ultimatekits.conversion.hooks; +import com.craftaro.ultimatekits.conversion.ConversionKit; import com.craftaro.ultimatekits.conversion.Hook; import com.earth2me.essentials.Essentials; import com.earth2me.essentials.Kit; @@ -9,6 +10,8 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.ItemStack; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; public class EssentialsHook implements Hook { @@ -18,48 +21,32 @@ public class EssentialsHook implements Hook { this.essentials = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials"); } - public Set getItems(String kitName) { - Set stacks = new HashSet<>(); - try { - Kit kit = new Kit(kitName, this.essentials); - - for (String nonParse : kit.getItems()) { - String[] parts = nonParse.split(" +"); - ItemStack item = this.essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); - MetaItemStack metaStack = new MetaItemStack(item); - if (parts.length > 2 != nonParse.startsWith("/")) { - try { - metaStack.parseStringMeta(null, true, parts, 2, this.essentials); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - stacks.add(metaStack.getItemStack()); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - return stacks; - } - - public Set getKits() { + @Override + public Map getKits() { ConfigurationSection cs = this.essentials.getSettings().getKits(); - Set kits = new HashSet<>(); + Map kits = new LinkedHashMap<>(); try { - cs.getKeys(false); + for (String name : cs.getKeys(false)) { + Set stacks = new HashSet<>(); + Kit kitObj = new Kit(name, this.essentials); + for (String nonParse : kitObj.getItems()) { + String[] parts = nonParse.split(" +"); + ItemStack item = this.essentials.getItemDb().get(parts[0], parts.length > 1 ? Integer.parseInt(parts[1]) : 1); + MetaItemStack metaStack = new MetaItemStack(item); + if (parts.length > 2 != nonParse.startsWith("/")) { + try { + metaStack.parseStringMeta(null, true, parts, 2, this.essentials); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + stacks.add(metaStack.getItemStack()); + } + kits.put(name, new ConversionKit(stacks, Integer.toUnsignedLong((int) this.essentials.getSettings().getKit(name).getOrDefault("delay", 0)))); + } } catch (Exception e) { return kits; } - kits.addAll(cs.getKeys(false)); return kits; } - - public long getDelay(String kitName) { - Object object = this.essentials.getSettings().getKit(kitName).getOrDefault("delay", 0); - try { - return Integer.toUnsignedLong((int) object); - } catch (Exception ex) { - return (long) object; - } - } } diff --git a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/UltimateCoreHook.java b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/UltimateCoreHook.java index 38d0c34..f8090da 100644 --- a/src/main/java/com/craftaro/ultimatekits/conversion/hooks/UltimateCoreHook.java +++ b/src/main/java/com/craftaro/ultimatekits/conversion/hooks/UltimateCoreHook.java @@ -2,32 +2,21 @@ package com.craftaro.ultimatekits.conversion.hooks; import bammerbom.ultimatecore.bukkit.api.UC; import bammerbom.ultimatecore.bukkit.api.UKit; +import com.craftaro.ultimatekits.conversion.ConversionKit; import com.craftaro.ultimatekits.conversion.Hook; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class UltimateCoreHook implements Hook { + @Override - public Set getKits() { - Set list = new HashSet<>(); + public Map getKits() { + Map list = new LinkedHashMap<>(); List kits = UC.getServer().getKits(); for (UKit kit : kits) { - list.add(kit.getName()); + list.put(kit.getName(), new ConversionKit(new HashSet<>(kit.getItems()), 0)); } return list; } - - @Override - public Set getItems(String kitName) { - UKit uKit = new UKit(kitName); - return new HashSet<>(uKit.getItems()); - } - - @Override - public long getDelay(String kitName) { - return 0; - } }