From e3861990a2f3d24552f133329756a313ed4abcf6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 29 Apr 2021 08:48:39 +0100 Subject: [PATCH] Added dual registration option for users using old versions prior to 7.3.0 --- .../java/com/willfp/ecoenchants/enchantments/EcoEnchant.java | 5 +++++ eco-core/core-plugin/src/main/resources/config.yml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java index ebc71783..7b9a99a0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchant.java @@ -242,6 +242,7 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche Map byName = (Map) byNameField.get(null); byKey.remove(this.getKey()); byName.remove(this.getName()); + byName.remove(this.getDisplayName()); Map byNameClone = new HashMap<>(byName); for (Map.Entry entry : byNameClone.entrySet()) { @@ -250,6 +251,10 @@ public abstract class EcoEnchant extends Enchantment implements Listener, Watche } } + if (this.getPlugin().getConfigYml().getBool("advanced.dual-registration.enabled")) { + byName.put(this.getDisplayName(), this); + } + Field f = Enchantment.class.getDeclaredField("acceptingNew"); f.setAccessible(true); f.set(null, true); diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index b198f0ce..082ce999 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -130,4 +130,9 @@ advanced: # Enabling this prevents the enchantments from being registered with the server at all when disabled. # There may be some unknown problems with this, but will fix bugs with plugins such as Slimefun. # Hard disabled enchantments will not update on /ecoreload. You will have to restart your server. + enabled: false + dual-registration: + # Fixes potential plugin conflicts/serialization issues when updating from a version before 7.3.0. + # Registers byName both the internal enchantment name (new method) and the display name (old method). + # There may be potential bugs with having duplicate enchantments, so enable this only if you need it. enabled: false \ No newline at end of file