From 64b618394451d0d886c1233dc0071878b6f1eed7 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 4 Oct 2020 12:55:48 +0100 Subject: [PATCH] Refactoring --- .../API/NMSEnchantManagerWrapper.java | 8 -- .../ecoenchants/v1_15_R1/NMSEnchant.java | 52 ----------- .../v1_15_R1/NMSEnchantManager.java | 75 --------------- .../ecoenchants/v1_16_R1/NMSEnchant.java | 58 ------------ .../v1_16_R1/NMSEnchantManager.java | 75 --------------- .../ecoenchants/v1_16_R2/NMSEnchant.java | 58 ------------ .../v1_16_R2/NMSEnchantManager.java | 75 --------------- .../ecoenchants/command/AbstractCommand.java | 2 +- .../command/commands/CommandEcoreload.java | 28 +----- .../ecoenchants/enchantments/EcoEnchant.java | 2 +- .../ecoenchants/curse/CallingCurse.java | 2 +- .../ecoenchants/curse/DecayCurse.java | 2 +- .../ecoenchants/normal/Forcefield.java | 2 +- .../ecoenchants/normal/Magnetic.java | 2 +- .../ecoenchants/special/Repairing.java | 2 +- .../enchantments/meta/EnchantmentRarity.java | 3 +- .../enchantments/meta/EnchantmentTarget.java | 2 +- .../merging/anvil/AnvilListeners.java | 2 +- .../merging/anvil/AnvilMerge.java | 2 +- .../grindstone/GrindstoneListeners.java | 2 +- .../merging/grindstone/GrindstoneMerge.java | 2 +- .../obtaining/EnchantingListeners.java | 2 +- .../obtaining/LootPopulator.java | 2 +- .../obtaining/VillagerListeners.java | 4 +- .../extensions/ExtensionManager.java | 93 +++++++++++-------- .../com/willfp/ecoenchants/loader/Loader.java | 34 +++++-- .../ecoenchants/nms/NMSEnchantManager.java | 33 ------- .../util/{ => interfaces}/EcoRunnable.java | 2 +- .../util/{ => interfaces}/Registerable.java | 2 +- 29 files changed, 103 insertions(+), 525 deletions(-) delete mode 100644 API/src/main/java/com/willfp/ecoenchants/API/NMSEnchantManagerWrapper.java delete mode 100644 NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchant.java delete mode 100644 NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchantManager.java delete mode 100644 NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchant.java delete mode 100644 NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchantManager.java delete mode 100644 NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchant.java delete mode 100644 NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchantManager.java rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/merging/anvil/AnvilListeners.java (95%) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/merging/anvil/AnvilMerge.java (99%) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/merging/grindstone/GrindstoneListeners.java (96%) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/merging/grindstone/GrindstoneMerge.java (96%) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/obtaining/EnchantingListeners.java (99%) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/obtaining/LootPopulator.java (98%) rename Plugin/src/main/java/com/willfp/ecoenchants/enchantments/{vanillasupport => support}/obtaining/VillagerListeners.java (98%) delete mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/nms/NMSEnchantManager.java rename Plugin/src/main/java/com/willfp/ecoenchants/util/{ => interfaces}/EcoRunnable.java (71%) rename Plugin/src/main/java/com/willfp/ecoenchants/util/{ => interfaces}/Registerable.java (53%) diff --git a/API/src/main/java/com/willfp/ecoenchants/API/NMSEnchantManagerWrapper.java b/API/src/main/java/com/willfp/ecoenchants/API/NMSEnchantManagerWrapper.java deleted file mode 100644 index f7e1cbfc..00000000 --- a/API/src/main/java/com/willfp/ecoenchants/API/NMSEnchantManagerWrapper.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.willfp.ecoenchants.API; - -import org.bukkit.enchantments.Enchantment; - -public interface NMSEnchantManagerWrapper { - void init(Enchantment enchantment); - void debug(); -} diff --git a/NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchant.java b/NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchant.java deleted file mode 100644 index fd754069..00000000 --- a/NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchant.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.willfp.ecoenchants.v1_15_R1; - -import net.minecraft.server.v1_15_R1.*; - -public class NMSEnchant extends Enchantment { - private org.bukkit.enchantments.Enchantment enchantment; - - public NMSEnchant(org.bukkit.enchantments.Enchantment enchantment) { - super(Enchantment.Rarity.COMMON, EnchantmentSlotType.BREAKABLE, new EnumItemSlot[]{}); - this.enchantment = enchantment; - } - - public void update(org.bukkit.enchantments.Enchantment enchantment) { - this.enchantment = enchantment; - } - - @Override - public int a(int var0) { - return Short.MAX_VALUE; - } - - @Override - public int getMaxLevel() { - return enchantment.getMaxLevel(); - } - - @Override - public boolean isTreasure() { - return true; - } - - @Override - public boolean c() { - return false; - } - - @Override - public IChatBaseComponent d(int level) { - IChatBaseComponent var1 = new ChatMessage(this.g(), new Object[0]); - if (this.c()) { - var1.a(EnumChatFormat.RED); - } else { - var1.a(EnumChatFormat.GRAY); - } - - if (level != 1 || this.getMaxLevel() != 1) { - var1.a(" ").addSibling(new ChatMessage("enchantment.level." + level, new Object[0])); - } - - return var1; - } -} diff --git a/NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchantManager.java b/NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchantManager.java deleted file mode 100644 index 21cea849..00000000 --- a/NMS/v1_15_R1/src/main/java/com/willfp/ecoenchants/v1_15_R1/NMSEnchantManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.willfp.ecoenchants.v1_15_R1; - -import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper; -import net.minecraft.server.v1_15_R1.Enchantment; -import net.minecraft.server.v1_15_R1.Enchantments; -import net.minecraft.server.v1_15_R1.IRegistry; -import net.minecraft.server.v1_15_R1.MinecraftKey; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -public class NMSEnchantManager implements NMSEnchantManagerWrapper { - private Map relatedMap = new HashMap<>(); - - - @Override - public void init(org.bukkit.enchantments.Enchantment enchantment) { - try { - Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey"); - Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName"); - byIdField.setAccessible(true); - byNameField.setAccessible(true); - Map byKey = (Map) byIdField.get(null); - Map byName = (Map) byNameField.get(null); - byKey.remove(enchantment.getKey()); - byName.remove(enchantment.getName()); - - Map byNameClone = new HashMap<>(byName); - for(Map.Entry entry : byNameClone.entrySet()) { - if(entry.getValue().getKey().equals(enchantment.getKey())) { - byName.remove(entry.getKey()); - } - } - - Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew"); - f.setAccessible(true); - f.set(null, true); - f.setAccessible(false); - - if(IRegistry.ENCHANTMENT.keySet().contains(new MinecraftKey(enchantment.getKey().getNamespace(), enchantment.getKey().getKey()))) { - byName.put(enchantment.getName(), enchantment); - byKey.put(enchantment.getKey(), enchantment); - if(relatedMap.get(enchantment) != null) { - relatedMap.get(enchantment).update(enchantment); - } - - return; - } - - relatedMap.put(enchantment, new NMSEnchant(enchantment)); - - Enchantment nmsEnchant = new NMSEnchant(enchantment); - - Method method = Enchantments.class.getDeclaredMethod("a", String.class, Enchantment.class); - method.setAccessible(true); - method.invoke(null, enchantment.getKey().getKey(), nmsEnchant); - - CraftEnchantWrapper wrappedEnchantment = new CraftEnchantWrapper(nmsEnchant, enchantment); - - org.bukkit.enchantments.Enchantment.registerEnchantment(wrappedEnchantment); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) { - e.printStackTrace(); - } - } - - @Override - public void debug() { - Bukkit.getLogger().info("IRegistry: " + IRegistry.ENCHANTMENT.keySet().toString()); - } -} diff --git a/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchant.java b/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchant.java deleted file mode 100644 index b1ce1da0..00000000 --- a/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchant.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.willfp.ecoenchants.v1_16_R1; - -import net.minecraft.server.v1_16_R1.*; - -public class NMSEnchant extends Enchantment { - private org.bukkit.enchantments.Enchantment enchantment; - - public NMSEnchant(org.bukkit.enchantments.Enchantment enchantment) { - super(Enchantment.Rarity.COMMON, EnchantmentSlotType.BREAKABLE, new EnumItemSlot[]{}); - this.enchantment = enchantment; - } - - public void update(org.bukkit.enchantments.Enchantment enchantment) { - this.enchantment = enchantment; - } - - @Override - public int a(int var0) { - return Short.MAX_VALUE; - } - - @Override - public int getMaxLevel() { - return enchantment.getMaxLevel(); - } - - @Override - public boolean isTreasure() { - return true; - } - - @Override - public boolean c() { - return false; - } - - @Override - public boolean h() { - return false; - } - - @Override - public boolean i() { - return false; - } - - @Override - public IChatBaseComponent d(int level) { - IChatMutableComponent var1 = new ChatMessage(enchantment.getName()); - var1.a(EnumChatFormat.WHITE); - - if (level != 1 || this.getMaxLevel() != 1) { - var1.c(" ").addSibling(new ChatMessage("enchantment.level." + level)); - } - - return var1; - } -} diff --git a/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchantManager.java b/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchantManager.java deleted file mode 100644 index 5065283c..00000000 --- a/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/v1_16_R1/NMSEnchantManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.willfp.ecoenchants.v1_16_R1; - -import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper; -import net.minecraft.server.v1_16_R1.Enchantment; -import net.minecraft.server.v1_16_R1.Enchantments; -import net.minecraft.server.v1_16_R1.IRegistry; -import net.minecraft.server.v1_16_R1.MinecraftKey; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -public class NMSEnchantManager implements NMSEnchantManagerWrapper { - private Map relatedMap = new HashMap<>(); - - - @Override - public void init(org.bukkit.enchantments.Enchantment enchantment) { - try { - Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey"); - Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName"); - byIdField.setAccessible(true); - byNameField.setAccessible(true); - Map byKey = (Map) byIdField.get(null); - Map byName = (Map) byNameField.get(null); - byKey.remove(enchantment.getKey()); - byName.remove(enchantment.getName()); - - Map byNameClone = new HashMap<>(byName); - for(Map.Entry entry : byNameClone.entrySet()) { - if(entry.getValue().getKey().equals(enchantment.getKey())) { - byName.remove(entry.getKey()); - } - } - - Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew"); - f.setAccessible(true); - f.set(null, true); - f.setAccessible(false); - - if(IRegistry.ENCHANTMENT.keySet().contains(new MinecraftKey(enchantment.getKey().getNamespace(), enchantment.getKey().getKey()))) { - byName.put(enchantment.getName(), enchantment); - byKey.put(enchantment.getKey(), enchantment); - if(relatedMap.get(enchantment) != null) { - relatedMap.get(enchantment).update(enchantment); - } - - return; - } - - relatedMap.put(enchantment, new NMSEnchant(enchantment)); - - Enchantment nmsEnchant = new NMSEnchant(enchantment); - - Method method = Enchantments.class.getDeclaredMethod("a", String.class, Enchantment.class); - method.setAccessible(true); - method.invoke(null, enchantment.getKey().getKey(), nmsEnchant); - - CraftEnchantWrapper wrappedEnchantment = new CraftEnchantWrapper(nmsEnchant, enchantment); - - org.bukkit.enchantments.Enchantment.registerEnchantment(wrappedEnchantment); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) { - e.printStackTrace(); - } - } - - @Override - public void debug() { - Bukkit.getLogger().info("IRegistry: " + IRegistry.ENCHANTMENT.keySet().toString()); - } -} diff --git a/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchant.java b/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchant.java deleted file mode 100644 index 12f16843..00000000 --- a/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchant.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.willfp.ecoenchants.v1_16_R2; - -import net.minecraft.server.v1_16_R2.*; - -public class NMSEnchant extends Enchantment { - private org.bukkit.enchantments.Enchantment enchantment; - - public NMSEnchant(org.bukkit.enchantments.Enchantment enchantment) { - super(Enchantment.Rarity.COMMON, EnchantmentSlotType.BREAKABLE, new EnumItemSlot[]{}); - this.enchantment = enchantment; - } - - public void update(org.bukkit.enchantments.Enchantment enchantment) { - this.enchantment = enchantment; - } - - @Override - public int a(int var0) { - return Short.MAX_VALUE; - } - - @Override - public int getMaxLevel() { - return enchantment.getMaxLevel(); - } - - @Override - public boolean isTreasure() { - return true; - } - - @Override - public boolean c() { - return false; - } - - @Override - public boolean h() { - return false; - } - - @Override - public boolean i() { - return false; - } - - @Override - public IChatBaseComponent d(int level) { - IChatMutableComponent var1 = new ChatMessage(enchantment.getName()); - var1.a(EnumChatFormat.WHITE); - - if (level != 1 || this.getMaxLevel() != 1) { - var1.c(" ").addSibling(new ChatMessage("enchantment.level." + level)); - } - - return var1; - } -} diff --git a/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchantManager.java b/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchantManager.java deleted file mode 100644 index aac50745..00000000 --- a/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/v1_16_R2/NMSEnchantManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.willfp.ecoenchants.v1_16_R2; - -import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper; -import net.minecraft.server.v1_16_R2.Enchantment; -import net.minecraft.server.v1_16_R2.Enchantments; -import net.minecraft.server.v1_16_R2.IRegistry; -import net.minecraft.server.v1_16_R2.MinecraftKey; -import org.bukkit.Bukkit; -import org.bukkit.NamespacedKey; - -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; - -public class NMSEnchantManager implements NMSEnchantManagerWrapper { - private Map relatedMap = new HashMap<>(); - - - @Override - public void init(org.bukkit.enchantments.Enchantment enchantment) { - try { - Field byIdField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byKey"); - Field byNameField = org.bukkit.enchantments.Enchantment.class.getDeclaredField("byName"); - byIdField.setAccessible(true); - byNameField.setAccessible(true); - Map byKey = (Map) byIdField.get(null); - Map byName = (Map) byNameField.get(null); - byKey.remove(enchantment.getKey()); - byName.remove(enchantment.getName()); - - Map byNameClone = new HashMap<>(byName); - for(Map.Entry entry : byNameClone.entrySet()) { - if(entry.getValue().getKey().equals(enchantment.getKey())) { - byName.remove(entry.getKey()); - } - } - - Field f = org.bukkit.enchantments.Enchantment.class.getDeclaredField("acceptingNew"); - f.setAccessible(true); - f.set(null, true); - f.setAccessible(false); - - if(IRegistry.ENCHANTMENT.keySet().contains(new MinecraftKey(enchantment.getKey().getNamespace(), enchantment.getKey().getKey()))) { - byName.put(enchantment.getName(), enchantment); - byKey.put(enchantment.getKey(), enchantment); - if(relatedMap.get(enchantment) != null) { - relatedMap.get(enchantment).update(enchantment); - } - - return; - } - - relatedMap.put(enchantment, new NMSEnchant(enchantment)); - - Enchantment nmsEnchant = new NMSEnchant(enchantment); - - Method method = Enchantments.class.getDeclaredMethod("a", String.class, Enchantment.class); - method.setAccessible(true); - method.invoke(null, enchantment.getKey().getKey(), nmsEnchant); - - CraftEnchantWrapper wrappedEnchantment = new CraftEnchantWrapper(nmsEnchant, enchantment); - - org.bukkit.enchantments.Enchantment.registerEnchantment(wrappedEnchantment); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) { - e.printStackTrace(); - } - } - - @Override - public void debug() { - Bukkit.getLogger().info("IRegistry: " + IRegistry.ENCHANTMENT.keySet().toString()); - } -} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java b/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java index b3db844c..435ff991 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/command/AbstractCommand.java @@ -1,7 +1,7 @@ package com.willfp.ecoenchants.command; import com.willfp.ecoenchants.config.ConfigManager; -import com.willfp.ecoenchants.util.Registerable; +import com.willfp.ecoenchants.util.interfaces.Registerable; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java b/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java index 7a92e24f..99070584 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/command/commands/CommandEcoreload.java @@ -1,15 +1,9 @@ package com.willfp.ecoenchants.command.commands; -import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.command.AbstractCommand; import com.willfp.ecoenchants.config.ConfigManager; -import com.willfp.ecoenchants.display.EnchantDisplay; -import com.willfp.ecoenchants.enchantments.EcoEnchants; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; -import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; -import org.bukkit.Bukkit; +import com.willfp.ecoenchants.loader.Loader; import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; import java.util.List; @@ -20,25 +14,7 @@ public final class CommandEcoreload extends AbstractCommand { @Override public void onExecute(CommandSender sender, List args) { - reload(); + Loader.reload(); sender.sendMessage(ConfigManager.getLang().getMessage("reloaded")); } - - public static void reload() { - ConfigManager.updateConfigs(); - EnchantmentRarity.update(); - EnchantmentTarget.update(); - EcoEnchants.update(); - EnchantDisplay.update(); - - EcoEnchants.getAll().forEach((ecoEnchant -> { - HandlerList.unregisterAll(ecoEnchant); - - Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> { - if(ecoEnchant.isEnabled()) { - Bukkit.getPluginManager().registerEvents(ecoEnchant, EcoEnchantsPlugin.getInstance()); - } - }, 1); - })); - } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index a7a94f51..1fa67835 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -4,7 +4,7 @@ import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.config.configs.EnchantmentConfig; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.util.Watcher; -import com.willfp.ecoenchants.util.Registerable; +import com.willfp.ecoenchants.util.interfaces.Registerable; import net.md_5.bungee.api.ChatColor; import org.apache.commons.lang.WordUtils; import org.bukkit.Material; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java index f0f3744b..0cef7352 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java @@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import com.willfp.ecoenchants.util.EcoRunnable; +import com.willfp.ecoenchants.util.interfaces.EcoRunnable; import com.willfp.ecoenchants.util.VectorUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.Monster; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java index 21ffe939..d111f92b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java @@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import com.willfp.ecoenchants.util.EcoRunnable; +import com.willfp.ecoenchants.util.interfaces.EcoRunnable; import com.willfp.ecoenchants.util.ItemDurability; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Repairable; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java index 8b712fba..edc7bf9d 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java @@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import com.willfp.ecoenchants.util.EcoRunnable; +import com.willfp.ecoenchants.util.interfaces.EcoRunnable; import com.willfp.ecoenchants.util.NumberUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.Monster; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java index 5832b7c1..7e47cc47 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java @@ -6,7 +6,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import com.willfp.ecoenchants.events.armorequip.ArmorEquipEvent; -import com.willfp.ecoenchants.util.EcoRunnable; +import com.willfp.ecoenchants.util.interfaces.EcoRunnable; import com.willfp.ecoenchants.util.VectorUtils; import org.bukkit.entity.Entity; import org.bukkit.entity.ExperienceOrb; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java index 4d674227..7c36c3db 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java @@ -5,7 +5,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; -import com.willfp.ecoenchants.util.EcoRunnable; +import com.willfp.ecoenchants.util.interfaces.EcoRunnable; import com.willfp.ecoenchants.util.ItemDurability; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Repairable; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java index fec5a6a1..0aa625f7 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentRarity.java @@ -1,7 +1,7 @@ package com.willfp.ecoenchants.enchantments.meta; import com.willfp.ecoenchants.config.ConfigManager; -import com.willfp.ecoenchants.util.Registerable; +import com.willfp.ecoenchants.util.interfaces.Registerable; import org.bukkit.ChatColor; import java.util.HashSet; @@ -117,6 +117,7 @@ public class EnchantmentRarity implements Registerable { * Update all rarities * Called on /ecoreload */ + public static void update() { Set raritiesNames = ConfigManager.getRarity().getRarities(); raritiesNames.forEach((rarity) -> { diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java index 0f65cf59..ba5c0638 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/meta/EnchantmentTarget.java @@ -2,7 +2,7 @@ package com.willfp.ecoenchants.enchantments.meta; import com.google.common.collect.ImmutableSet; import com.willfp.ecoenchants.config.ConfigManager; -import com.willfp.ecoenchants.util.Registerable; +import com.willfp.ecoenchants.util.interfaces.Registerable; import org.bukkit.Material; import java.util.HashSet; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/anvil/AnvilListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java similarity index 95% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/anvil/AnvilListeners.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java index 8806d7b6..357c4b1f 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/anvil/AnvilListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilListeners.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.merging.anvil; +package com.willfp.ecoenchants.enchantments.support.merging.anvil; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.util.Pair; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/anvil/AnvilMerge.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java similarity index 99% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/anvil/AnvilMerge.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java index 773bb310..133cb530 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/anvil/AnvilMerge.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/anvil/AnvilMerge.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.merging.anvil; +package com.willfp.ecoenchants.enchantments.support.merging.anvil; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/grindstone/GrindstoneListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java similarity index 96% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/grindstone/GrindstoneListeners.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java index 2518a8c8..e9f3bb46 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/grindstone/GrindstoneListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneListeners.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.merging.grindstone; +package com.willfp.ecoenchants.enchantments.support.merging.grindstone; import com.willfp.ecoenchants.EcoEnchantsPlugin; import org.bukkit.Bukkit; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/grindstone/GrindstoneMerge.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneMerge.java similarity index 96% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/grindstone/GrindstoneMerge.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneMerge.java index ddb2fb3f..169e5417 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/merging/grindstone/GrindstoneMerge.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/merging/grindstone/GrindstoneMerge.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.merging.grindstone; +package com.willfp.ecoenchants.enchantments.support.merging.grindstone; import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/EnchantingListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java similarity index 99% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/EnchantingListeners.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java index c16d7289..695abd7b 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/EnchantingListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/EnchantingListeners.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.obtaining; +package com.willfp.ecoenchants.enchantments.support.obtaining; import com.willfp.ecoenchants.EcoEnchantsPlugin; import com.willfp.ecoenchants.config.ConfigManager; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/LootPopulator.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java similarity index 98% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/LootPopulator.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java index f7b4778f..3ae806ca 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/LootPopulator.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/LootPopulator.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.obtaining; +package com.willfp.ecoenchants.enchantments.support.obtaining; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/VillagerListeners.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java similarity index 98% rename from Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/VillagerListeners.java rename to Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 1297066f..6fd27d01 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/vanillasupport/obtaining/VillagerListeners.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.enchantments.vanillasupport.obtaining; +package com.willfp.ecoenchants.enchantments.support.obtaining; import com.willfp.ecoenchants.config.ConfigManager; import com.willfp.ecoenchants.enchantments.EcoEnchant; @@ -50,6 +50,8 @@ public class VillagerListeners implements Listener { continue; if (!enchantment.canGetFromVillager()) continue; + if(!enchantment.isEnabled()) + continue; int level; diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/extensions/ExtensionManager.java b/Plugin/src/main/java/com/willfp/ecoenchants/extensions/ExtensionManager.java index 25c42a55..6a6a17f1 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/extensions/ExtensionManager.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/extensions/ExtensionManager.java @@ -5,9 +5,9 @@ import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.HashMap; @@ -29,53 +29,64 @@ public class ExtensionManager { } File[] extensionJars = dir.listFiles(); - if(extensionJars != null) { - for (File extensionJar : extensionJars) { - try { - if (extensionJar.isFile()) { - try { - URL url = extensionJar.toURI().toURL(); - URL[] urls = {url}; - ClassLoader cl = new URLClassLoader(urls, EcoEnchantsPlugin.class.getClassLoader()); + if(extensionJars == null) + return; - InputStream ymlIn = cl.getResourceAsStream("extension.yml"); - URL extensionYmlUrl = cl.getResource("extension.yml"); + for (File extensionJar : extensionJars) { + if(!extensionJar.isFile()) continue; - if (extensionYmlUrl == null || ymlIn == null) { - throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName()); - } - - YamlConfiguration extensionYml = YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn)); - if (!extensionYml.getKeys(false).contains("main") || !extensionYml.getKeys(false).contains("name")) { - throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName()); - } - - String mainClass = extensionYml.getString("main"); - String name = extensionYml.getString("name"); - - Class cls = cl.loadClass(mainClass); - - Object object = cls.newInstance(); - - if (object instanceof Extension) { - Extension extension = (Extension) object; - extension.onEnable(); - extensions.put(extension, name); - } else { - throw new MalformedExtensionException(extensionJar.getName() + " is invalid"); - } - } catch (IllegalAccessException | InstantiationException | IOException | ClassNotFoundException e) { - e.printStackTrace(); - } - } - } catch (MalformedExtensionException e) { - Bukkit.getLogger().info(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage()); - } + try { + loadExtension(extensionJar); + } catch (MalformedExtensionException e) { + Bukkit.getLogger().info(extensionJar.getName() + " caused MalformedExtensionException: " + e.getMessage()); } } } + private static void loadExtension(File extensionJar) throws MalformedExtensionException { + URL url = null; + try { + url = extensionJar.toURI().toURL(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + URL[] urls = {url}; + + ClassLoader cl = new URLClassLoader(urls, EcoEnchantsPlugin.class.getClassLoader()); + + InputStream ymlIn = cl.getResourceAsStream("extension.yml"); + URL extensionYmlUrl = cl.getResource("extension.yml"); + + if (extensionYmlUrl == null || ymlIn == null) { + throw new MalformedExtensionException("No extension.yml found in " + extensionJar.getName()); + } + + YamlConfiguration extensionYml = YamlConfiguration.loadConfiguration(new InputStreamReader(ymlIn)); + if (!extensionYml.getKeys(false).contains("main") || !extensionYml.getKeys(false).contains("name")) { + throw new MalformedExtensionException("Invalid extension.yml found in " + extensionJar.getName()); + } + + String mainClass = extensionYml.getString("main"); + String name = extensionYml.getString("name"); + + Class cls = null; + Object object = null; + try { + object = cls.newInstance(); + cls = cl.loadClass(mainClass); + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + e.printStackTrace(); + } + + if(!(object instanceof Extension)) + throw new MalformedExtensionException(extensionJar.getName() + " is invalid"); + + Extension extension = (Extension) object; + extension.onEnable(); + extensions.put(extension, name); + } + /** * Unload all extensions */ diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java index 9351dc76..d7f7656e 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/loader/Loader.java @@ -2,7 +2,6 @@ package com.willfp.ecoenchants.loader; import com.comphenix.protocol.ProtocolLibrary; import com.willfp.ecoenchants.EcoEnchantsPlugin; -import com.willfp.ecoenchants.enchantments.vanillasupport.merging.anvil.AnvilListeners; import com.willfp.ecoenchants.command.commands.CommandEcodebug; import com.willfp.ecoenchants.command.commands.CommandEcoreload; import com.willfp.ecoenchants.command.commands.CommandEnchantinfo; @@ -16,16 +15,17 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentRarity; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; -import com.willfp.ecoenchants.enchantments.vanillasupport.obtaining.EnchantingListeners; -import com.willfp.ecoenchants.enchantments.vanillasupport.obtaining.LootPopulator; -import com.willfp.ecoenchants.enchantments.vanillasupport.obtaining.VillagerListeners; +import com.willfp.ecoenchants.enchantments.support.merging.anvil.AnvilListeners; +import com.willfp.ecoenchants.enchantments.support.merging.grindstone.GrindstoneListeners; +import com.willfp.ecoenchants.enchantments.support.obtaining.EnchantingListeners; +import com.willfp.ecoenchants.enchantments.support.obtaining.LootPopulator; +import com.willfp.ecoenchants.enchantments.support.obtaining.VillagerListeners; import com.willfp.ecoenchants.enchantments.util.WatcherTriggers; import com.willfp.ecoenchants.events.armorequip.ArmorListener; import com.willfp.ecoenchants.events.armorequip.DispenserArmorListener; import com.willfp.ecoenchants.events.entitydeathbyentity.EntityDeathByEntityListeners; import com.willfp.ecoenchants.events.naturalexpgainevent.NaturalExpGainListeners; import com.willfp.ecoenchants.extensions.ExtensionManager; -import com.willfp.ecoenchants.enchantments.vanillasupport.merging.grindstone.GrindstoneListeners; import com.willfp.ecoenchants.integrations.anticheat.AnticheatManager; import com.willfp.ecoenchants.integrations.anticheat.plugins.AnticheatAAC; import com.willfp.ecoenchants.integrations.anticheat.plugins.AnticheatMatrix; @@ -40,13 +40,14 @@ import com.willfp.ecoenchants.listeners.PlayerJoinListener; import com.willfp.ecoenchants.nms.BlockBreak; import com.willfp.ecoenchants.nms.Cooldown; import com.willfp.ecoenchants.nms.TridentStack; -import com.willfp.ecoenchants.util.EcoRunnable; +import com.willfp.ecoenchants.util.interfaces.EcoRunnable; import com.willfp.ecoenchants.util.Logger; import com.willfp.ecoenchants.util.UpdateChecker; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.event.HandlerList; import org.bukkit.generator.BlockPopulator; import java.util.ArrayList; @@ -432,4 +433,25 @@ public class Loader { ExtensionManager.unloadExtensions(); Logger.info("§fBye! :)"); } + + /** + * Called by /ecoreload + */ + public static void reload() { + ConfigManager.updateConfigs(); + EnchantmentRarity.update(); + EnchantmentTarget.update(); + EcoEnchants.update(); + EnchantDisplay.update(); + + EcoEnchants.getAll().forEach((ecoEnchant -> { + HandlerList.unregisterAll(ecoEnchant); + + Bukkit.getScheduler().runTaskLater(EcoEnchantsPlugin.getInstance(), () -> { + if(ecoEnchant.isEnabled()) { + Bukkit.getPluginManager().registerEvents(ecoEnchant, EcoEnchantsPlugin.getInstance()); + } + }, 1); + })); + } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/nms/NMSEnchantManager.java b/Plugin/src/main/java/com/willfp/ecoenchants/nms/NMSEnchantManager.java deleted file mode 100644 index 8cd0b549..00000000 --- a/Plugin/src/main/java/com/willfp/ecoenchants/nms/NMSEnchantManager.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.willfp.ecoenchants.nms; - - -import com.willfp.ecoenchants.API.NMSEnchantManagerWrapper; -import org.bukkit.Bukkit; -import org.bukkit.enchantments.Enchantment; - -public class NMSEnchantManager { - private static NMSEnchantManagerWrapper nmsEnchantManagerWrapper; - - private static final String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - - public static boolean init() { - try { - final Class class2 = Class.forName("com.willfp.ecoenchants." + version + ".NMSEnchantManager"); - if (NMSEnchantManagerWrapper.class.isAssignableFrom(class2)) { - nmsEnchantManagerWrapper = (NMSEnchantManagerWrapper) class2.getConstructor().newInstance(); - } - } catch (Exception e) { - e.printStackTrace(); - nmsEnchantManagerWrapper = null; - } - return nmsEnchantManagerWrapper != null; - } - - public static void registerNMS(Enchantment enchantment) { - nmsEnchantManagerWrapper.init(enchantment); - } - - public static void printDebug() { - nmsEnchantManagerWrapper.debug(); - } -} diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/util/EcoRunnable.java b/Plugin/src/main/java/com/willfp/ecoenchants/util/interfaces/EcoRunnable.java similarity index 71% rename from Plugin/src/main/java/com/willfp/ecoenchants/util/EcoRunnable.java rename to Plugin/src/main/java/com/willfp/ecoenchants/util/interfaces/EcoRunnable.java index 66cb35d0..ec3c8c25 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/util/EcoRunnable.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/util/interfaces/EcoRunnable.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.util; +package com.willfp.ecoenchants.util.interfaces; /** * Interface for Enchantments with tasks diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/util/Registerable.java b/Plugin/src/main/java/com/willfp/ecoenchants/util/interfaces/Registerable.java similarity index 53% rename from Plugin/src/main/java/com/willfp/ecoenchants/util/Registerable.java rename to Plugin/src/main/java/com/willfp/ecoenchants/util/interfaces/Registerable.java index b7ac5f4e..eddd1717 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/util/Registerable.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/util/interfaces/Registerable.java @@ -1,4 +1,4 @@ -package com.willfp.ecoenchants.util; +package com.willfp.ecoenchants.util.interfaces; public interface Registerable { void register();