From 8140ad40727c481b6e1de0a252d17ea8a0866477 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 11:42:41 +0200 Subject: [PATCH] Add all Missiles back --- src/de/steamwar/misslewars/items/Missile.java | 21 ++++++++++++++----- .../misslewars/items/SpecialItem.java | 8 +++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index dff93c8..c0e9417 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -52,13 +52,12 @@ public class Missile extends SpecialItem { private static final BlockType TNT = BlockTypes.TNT; private static final int GRAPH_SIZE = 7; private static final Random r = new Random(); - public static final List specialMissiles = new ArrayList<>(); private final Clipboard clipboard; private final ItemStack item; private final int tntCount; - private Missile(File missileFile, boolean special) { + private Missile(File missileFile) { String[] strings = missileFile.getName().split("\\."); String name = strings[0]; String material = strings[1]; @@ -85,8 +84,7 @@ public class Missile extends SpecialItem { tntCount = count; lore.add("§7TNT §8: §e" + tntCount); - item = createItem(itemType, "§c" + name, 1, lore, special); - if (special) specialMissiles.add(name); + item = createItem(itemType, "§c" + name, 1, lore, false); } private void lore(List lore, String[] args, int index, String tag) { @@ -175,7 +173,20 @@ public class Missile extends SpecialItem { } for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) { if (!missileFile.canRead() || !missileFile.isFile()) continue; - new Missile(missileFile, false); + new Missile(missileFile); + } + + otherInit(); + } + + public static void otherInit() { + File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); + if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) { + throw new SecurityException("Missiles could not be loaded"); + } + for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) { + if (!missileFile.canRead() || !missileFile.isFile()) continue; + new Missile(missileFile); } } diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index 3b22372..9152eaa 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -39,9 +39,9 @@ public abstract class SpecialItem { SpecialItem() { if (this.isMissile()) { missileItems.add(this); - return; + } else { + supportItems.add(this); } - supportItems.add(this); } public abstract ItemStack getItem(); @@ -54,7 +54,7 @@ public abstract class SpecialItem { return createItem(material, name, amount, new ArrayList<>(), false); } - public ItemStack createItem(Material material, String name, int amount, List lore, boolean special) { + public ItemStack createItem(Material material, String name, int amount, List lore, boolean enchanted) { ItemStack item = new ItemStack(material, amount); ItemMeta meta = item.getItemMeta(); assert meta != null; @@ -62,7 +62,7 @@ public abstract class SpecialItem { meta.setLore(lore); meta.setDisplayName(name); item.setItemMeta(meta); - if (special) item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 1); + if (enchanted) item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 1); return item; }