diff --git a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java index a2717d9..8a7e35b 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/ArmoredElytra.java @@ -26,21 +26,16 @@ import java.util.EnumMap; import java.util.Map; import java.util.logging.Level; -// TODO: Figure out if the config really does read the list of enchantments accurately. A bug report with a customized config seemed to load the default settings... -// TODO: Verify enchantments on startup. -// TODO: Enchanting should require XP. - public class ArmoredElytra extends JavaPlugin implements Listener { private static final MinecraftVersion minecraftVersion = MinecraftVersion .get(Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]); - private static ArmoredElytra instance; + private static ArmoredElytra INSTANCE; private Messages messages; private ConfigLoader config; private final Map armorTierNames = new EnumMap<>(ArmorTier.class); - private boolean upToDate; private UpdateManager updateManager; private INBTEditor nbtEditor; @@ -48,7 +43,7 @@ public class ArmoredElytra extends JavaPlugin implements Listener @Override public void onEnable() { - instance = this; + INSTANCE = this; if (minecraftVersion.isOlderThan(MinecraftVersion.v1_15)) { myLogger(Level.SEVERE, "Trying to run this plugin on an unsupported version... ABORT!"); @@ -87,22 +82,8 @@ public class ArmoredElytra extends JavaPlugin implements Listener myLogger(Level.INFO, "Stats disabled, not loading stats :(... Please consider enabling it! I am a simple man, seeing higher user numbers helps me stay motivated!"); - // Load the files for the correct version of Minecraft. - if (compatibleMCVer()) - { - Bukkit.getPluginManager() - .registerEvents(new EventHandlers(this, config.craftingInSmithingTable()), this); - getCommand("ArmoredElytra").setExecutor(new CommandHandler(this)); - } - else - { - Bukkit.getPluginManager().registerEvents(new LoginHandler(this, - "The Armored Elytra plugin failed to start correctly! Please send the startup log to pim16aap2!"), - this); - myLogger(Level.WARNING, - "Plugin failed to load! Either your version isn't supported or something went horribly wrong! Please contact pim16aap2!"); - return; - } + Bukkit.getPluginManager().registerEvents(new EventHandlers(this, config.craftingInSmithingTable()), this); + getCommand("ArmoredElytra").setExecutor(new CommandHandler(this)); // Load the plugin normally if not in uninstall mode. if (!config.uninstallMode()) @@ -179,29 +160,12 @@ public class ArmoredElytra extends JavaPlugin implements Listener player.hasPermission("armoredelytra.craft." + ArmorTier.getName(armorTier)); } - public static MinecraftVersion getMinecraftVersion() - { - return minecraftVersion; - } - public boolean playerHasWearPerm(Player player, ArmorTier armorTier) { return getConfigLoader().bypassWearPerm() || player.hasPermission("armoredelytra.wear." + ArmorTier.getName(armorTier)); } - // Returns true if this is the latest version of this plugin. - public boolean isUpToDate() - { - return upToDate; - } - - // Get this. - public ArmoredElytra getPlugin() - { - return this; - } - // Returns the config handler. public ConfigLoader getConfigLoader() { @@ -281,15 +245,9 @@ public class ArmoredElytra extends JavaPlugin implements Listener return updateManager; } - // Check + initialize for the correct version of Minecraft. - public boolean compatibleMCVer() - { - return minecraftVersion.isNewerThan(MinecraftVersion.v1_8); - } - public static ArmoredElytra getInstance() { - return instance; + return INSTANCE; } public String getArmoredElytraName(ArmorTier tier) @@ -301,9 +259,4 @@ public class ArmoredElytra extends JavaPlugin implements Listener } return armorTierNames.get(tier).getLongName(); } - - public void setUpToDate(boolean upToDate) - { - this.upToDate = upToDate; - } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/enchantment/EnchantmentManager.java b/src/main/java/nl/pim16aap2/armoredElytra/enchantment/EnchantmentManager.java index 3facecd..c47f18b 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/enchantment/EnchantmentManager.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/enchantment/EnchantmentManager.java @@ -9,17 +9,15 @@ import java.util.List; public class EnchantmentManager { - private final ArmoredElytra armoredElytra; private final List containers = new ArrayList<>(); private Integer count = null; public EnchantmentManager(final ItemStack is) { - armoredElytra = ArmoredElytra.getInstance(); EnchantmentPlatformManager.get().getPlatforms().forEach(platform -> containers.add(platform.getEnchantments(is))); - Collection filter = armoredElytra.getConfigLoader().allowedEnchantments(); + Collection filter = ArmoredElytra.getInstance().getConfigLoader().allowedEnchantments(); containers.forEach(container -> container.filter(filter)); } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/CommandHandler.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/CommandHandler.java index 37cc248..35f5773 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/CommandHandler.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/CommandHandler.java @@ -97,10 +97,9 @@ public class CommandHandler implements CommandExecutor { ItemStack newElytra; final String tier = args[1]; - if (Bukkit.getPlayer(args[0]) != null) + player = Bukkit.getPlayer(args[0]); + if (player != null) { - player = Bukkit.getPlayer(args[0]); - ArmorTier armorTier = ArmorTier.valueOfName(tier.toLowerCase()); if (armorTier == null) return false; diff --git a/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java b/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java index feb2e5f..5c51e42 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/handlers/EventHandlers.java @@ -45,18 +45,8 @@ public class EventHandlers implements Listener private void initializeArmorEquipEvent() { - Bukkit.getPluginManager().registerEvents(new ArmorListener(new ArrayList()), plugin); - try - { - // Older versions did not have this event. So try to load it if possible, but - // don't worry - // about it not working. - Class.forName("org.bukkit.event.block.BlockDispenseArmorEvent"); - plugin.getServer().getPluginManager().registerEvents(new DispenserArmorListener(), plugin); - } - catch (Exception ignored) - { - } + Bukkit.getPluginManager().registerEvents(new ArmorListener(new ArrayList<>()), plugin); + Bukkit.getPluginManager().registerEvents(new DispenserArmorListener(), plugin); } private void moveChestplateToInventory(Player player) diff --git a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java index e465aa5..221254d 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/nbtEditor/NBTEditor.java @@ -14,19 +14,8 @@ import org.bukkit.persistence.PersistentDataType; import java.util.Collection; import java.util.UUID; -// TODO: Consider using static UUIDs, to ensure attributes aren't stacked. public class NBTEditor implements INBTEditor { -// private static final Map namespaceKeys; -// -// static -// { -// final Map namespaceKeysTmp = new EnumMap(ArmorTier.class); -// for (final ArmorTier tier : ArmorTier.values()) -// namespaceKeysTmp.put(tier, new NamespacedKey(ArmoredElytra.getInstance(), "ARMORTIER_" + tier.name())); -// namespaceKeys = Collections.unmodifiableMap(namespaceKeysTmp); -// } - private static final NamespacedKey armorTierKey = new NamespacedKey(ArmoredElytra.getInstance(), "ARMOR_TIER_LEVEL"); diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java index fe9f9c0..4bd6099 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/ArmorTier.java @@ -23,9 +23,9 @@ public enum ArmorTier private final double knockbackResistance; private final Material repair; private final String name; - private static Map map = new HashMap<>(); - private static Map armorValueMap = new HashMap<>(); - private static Map armorIDMap = new HashMap<>(); + private static final Map map = new HashMap<>(); + private static final Map armorValueMap = new HashMap<>(); + private static final Map armorIDMap = new HashMap<>(); ArmorTier(int tierID, int armor, int toughness, double knockbackResistance, Material repair, String name) { @@ -101,6 +101,7 @@ public enum ArmorTier // This value is the same as netherite's tier. However, with the introduction of the NETHERITE armor tier, // a new system was introduced that doesn't rely on the armor value for determining the armortier. // Therefore, when using the old backup system, it is always going to be the diamond tier instead. + // While no new elytras cna be created using the old system, some may still be around from when it was still used. armorValueMap.put(ArmorTier.DIAMOND.armor, ArmorTier.DIAMOND); } } diff --git a/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java b/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java index d6315d9..7c91b51 100644 --- a/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java +++ b/src/main/java/nl/pim16aap2/armoredElytra/util/Util.java @@ -35,8 +35,6 @@ public class Util { ArmorTier ret = ArmorTier.NONE; XMaterial xmat = XMaterial.matchXMaterial(mat); - if (xmat == null) - return ret; switch (xmat) { @@ -70,13 +68,10 @@ public class Util try { XMaterial xmat = XMaterial.matchXMaterial(mat); - if (xmat == null) - return false; - if (xmat == XMaterial.LEATHER_CHESTPLATE || xmat == XMaterial.GOLDEN_CHESTPLATE || + + return xmat == XMaterial.LEATHER_CHESTPLATE || xmat == XMaterial.GOLDEN_CHESTPLATE || xmat == XMaterial.CHAINMAIL_CHESTPLATE || xmat == XMaterial.IRON_CHESTPLATE || - xmat == XMaterial.DIAMOND_CHESTPLATE || xmat == XMaterial.NETHERITE_CHESTPLATE) - return true; - return false; + xmat == XMaterial.DIAMOND_CHESTPLATE || xmat == XMaterial.NETHERITE_CHESTPLATE; } catch (IllegalArgumentException e) { @@ -86,7 +81,6 @@ public class Util } // Function that returns which/how many protection enchantments there are. - // TODO: Use bit flags for this. public static int getProtectionEnchantmentsVal(Map enchantments) { int ret = 0;