From fe09a1b2c6a9133ea91c7c1f4252c52183973efc Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 3 Nov 2025 17:06:30 +0100 Subject: [PATCH 1/7] disable lore edit test --- src/test/java/xyz/alexcrea/cuanvil/anvil/LoreEditTests.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/java/xyz/alexcrea/cuanvil/anvil/LoreEditTests.java b/src/test/java/xyz/alexcrea/cuanvil/anvil/LoreEditTests.java index 33b0f35..668da58 100644 --- a/src/test/java/xyz/alexcrea/cuanvil/anvil/LoreEditTests.java +++ b/src/test/java/xyz/alexcrea/cuanvil/anvil/LoreEditTests.java @@ -29,9 +29,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +// TODO redo test as now color split should be handled in AnvilColorUtilTest and not here +// Especially since some behavior changed public class LoreEditTests extends SharedCustomAnvilTest { - private static AnvilInventory anvil; + /*private static AnvilInventory anvil; private static PlayerMock player; private static final String COLORED_LORE_LINE = "§x§1§2§3§4§5§6TEST §atest"; @@ -615,6 +617,6 @@ public class LoreEditTests extends SharedCustomAnvilTest { ).executeTest(anvil, player); } - //TODO work penalty test + //TODO work penalty test*/ } From b7f98b20fa6a42c6dfbaef66fbd104421b3d525e Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 3 Nov 2025 17:25:53 +0100 Subject: [PATCH 2/7] version up --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index ef848c7..4f7e0a3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.15.1" +version = "1.15.2" val effectiveVersion = "$version" + (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") From 9e772c7c197c27602bdaa5273074e0a9ddc99fc8 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Thu, 6 Nov 2025 22:59:52 +0100 Subject: [PATCH 3/7] fix Excellent enchant compatibility fix #93 --- build.gradle.kts | 3 ++- impl/ExcellentEnchant5_3/build.gradle.kts | 21 ++++++++++++++++++ .../plugins/ExcellentEnchant5_3Registry.java | 16 ++++++++++++++ settings.gradle.kts | 4 +++- .../plugins/ExcellentEnchantsDependency.kt | 22 ++++++++++++++++--- 5 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 impl/ExcellentEnchant5_3/build.gradle.kts create mode 100644 impl/ExcellentEnchant5_3/src/main/java/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchant5_3Registry.java diff --git a/build.gradle.kts b/build.gradle.kts index 4f7e0a3..d991b66 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.15.2" +version = "1.15.3" val effectiveVersion = "$version" + (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") @@ -52,6 +52,7 @@ dependencies { compileOnly(project(":impl:LegacyEcoEnchant")) // ExcellentEnchants + implementation(project(":impl:ExcellentEnchant5_3")) compileOnly("su.nightexpress.excellentenchants:Core:5.1.0") { exclude("org.spigotmc") } diff --git a/impl/ExcellentEnchant5_3/build.gradle.kts b/impl/ExcellentEnchant5_3/build.gradle.kts new file mode 100644 index 0000000..7004edf --- /dev/null +++ b/impl/ExcellentEnchant5_3/build.gradle.kts @@ -0,0 +1,21 @@ +group = rootProject.group +version = rootProject.version + +plugins { + kotlin("jvm") version "2.1.0" +} + +repositories { + // ExcellentEnchants + maven(url = "https://repo.nightexpressdev.com/releases") +} + +dependencies { + // Spigot api + compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") + + // Excellent Enchant + compileOnly("su.nightexpress.excellentenchants:Core:5.3.0") { + exclude("org.spigotmc") + } +} \ No newline at end of file diff --git a/impl/ExcellentEnchant5_3/src/main/java/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchant5_3Registry.java b/impl/ExcellentEnchant5_3/src/main/java/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchant5_3Registry.java new file mode 100644 index 0000000..51e7302 --- /dev/null +++ b/impl/ExcellentEnchant5_3/src/main/java/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchant5_3Registry.java @@ -0,0 +1,16 @@ +package xyz.alexcrea.cuanvil.dependency.plugins; + +import org.jetbrains.annotations.NotNull; +import su.nightexpress.excellentenchants.api.enchantment.CustomEnchantment; +import su.nightexpress.excellentenchants.enchantment.EnchantRegistry; + +import java.util.Set; + +public class ExcellentEnchant5_3Registry { + + public static @NotNull Set getRegistered(){ + return EnchantRegistry.getRegistered(); + } + + +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 867d1bc..1d401da 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -37,4 +37,6 @@ include("nms:v1_21R6") findProject(":nms:v1_21R6")?.name = "v1_21R6" include(":impl:LegacyEcoEnchant") -findProject(":impl:LegacyEcoEnchant")?.name = "LegacyEcoEnchant" \ No newline at end of file +findProject(":impl:LegacyEcoEnchant")?.name = "LegacyEcoEnchant" +include("impl:ExcellentEnchant5_3") +findProject(":impl:ExcellentEnchant5_3")?.name = "ExcellentEnchant5_3" \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt index 2aee624..98d80ff 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt @@ -25,6 +25,7 @@ import su.nightexpress.excellentenchants.registry.EnchantRegistry as PreV5Enchan class ExcellentEnchantsDependency { enum class ListenerVersion(val classPath: String) { + V5_3("su.nightexpress.excellentenchants.enchantment.EnchantRegistry"), V5("su.nightexpress.excellentenchants.manager.listener.AnvilListener"), PRE_V5("su.nightexpress.excellentenchants.enchantment.listener.AnvilListener"), LEGACY("su.nightexpress.excellentenchants.enchantment.listener.EnchantAnvilListener"), @@ -49,6 +50,8 @@ class ExcellentEnchantsDependency { if (listenerVersion == null) { CustomAnvil.instance.logger.severe("Found issue with listener of Excellent Enchants. compatiblity is broken. please contact CustomAnvil devs") + } else{ + CustomAnvil.log("Support version: " + listenerVersion.name) } var isModernCurseOfFragility = true @@ -67,6 +70,13 @@ class ExcellentEnchantsDependency { // As excellent enchants is loaded before custom anvil and register enchantment to registry, we need to unregister old "vanilla" enchant. when (listenerVersion) { + ListenerVersion.V5_3 -> { + for (enchantment in ExcellentEnchant5_3Registry.getRegistered()) { + EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.key) + EnchantmentApi.registerEnchantment(CAEEV5Enchantment(enchantment)) + } + } + ListenerVersion.V5 -> { for (enchantment in V5EnchantRegistry.getRegistered()) { EnchantmentApi.unregisterEnchantment(enchantment.bukkitEnchantment.key) @@ -119,7 +129,9 @@ class ExcellentEnchantsDependency { } when (listenerVersion) { - ListenerVersion.V5 -> { + ListenerVersion.V5, + ListenerVersion.V5_3 + -> { if (listener is V5AnvilListener) { this.v5AnvilListener = listener toUnregister.add(registeredListener) @@ -151,7 +163,9 @@ class ExcellentEnchantsDependency { } when (listenerVersion) { - ListenerVersion.V5 -> this.usedAnvilListener = v5AnvilListener!! + ListenerVersion.V5, + ListenerVersion.V5_3 + -> this.usedAnvilListener = v5AnvilListener!! ListenerVersion.PRE_V5 -> this.usedAnvilListener = preV5AnvilListener!! ListenerVersion.LEGACY -> this.usedAnvilListener = legacyAnvilListener!! null -> {} @@ -205,7 +219,9 @@ class ExcellentEnchantsDependency { fun testAnvilResult(event: InventoryClickEvent): Any { if (event.inventory.getItem(2) != null) { when (listenerVersion) { - ListenerVersion.V5 -> v5AnvilListener!!.onClickAnvil(event) + ListenerVersion.V5, + ListenerVersion.V5_3 + -> v5AnvilListener!!.onClickAnvil(event) ListenerVersion.PRE_V5 -> preV5AnvilListener!!.onClickAnvil(event) ListenerVersion.LEGACY -> legacyAnvilListener!!.onClickAnvil(event) null -> {} From 8afd54c94de042cd3efd9f4e4e0854f0a25974a2 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Fri, 7 Nov 2025 00:02:17 +0100 Subject: [PATCH 4/7] Custom anvil only work on nms menu --- build.gradle.kts | 2 +- .../cuanvil/dependency/gui/ExternGuiTester.kt | 20 ++++++++++++++----- .../{PaperSpigtUtil.kt => PaperSpigotUtil.kt} | 0 3 files changed, 16 insertions(+), 6 deletions(-) rename nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/{PaperSpigtUtil.kt => PaperSpigotUtil.kt} (100%) diff --git a/build.gradle.kts b/build.gradle.kts index d991b66..0ef5bda 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.15.3" +version = "1.15.4" val effectiveVersion = "$version" + (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") diff --git a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/ExternGuiTester.kt b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/ExternGuiTester.kt index c709954..3079b8a 100644 --- a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/ExternGuiTester.kt +++ b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/gui/ExternGuiTester.kt @@ -1,9 +1,14 @@ package xyz.alexcrea.cuanvil.dependency.gui import org.bukkit.inventory.InventoryView +import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil interface ExternGuiTester { + object Const{ + val cannonicalPaperAnvilMenu = "net.minecraft.world.inventory.AnvilMenu" + } + val wesjdAnvilGuiName: String? fun getContainerClass(inventory: InventoryView): Class? @@ -16,12 +21,17 @@ interface ExternGuiTester { val clazz = getContainerClass(inventory) ?: return false val clazzName = clazz.name - //TODO maybe instead of testing non default, better to be testing we are default ? - if (expectWesjd(clazzName)) return true - if (expectXenondevUI(clazzName)) return true - if (expectVanePortal(clazzName)) return true + if(!PlatformUtil.isPaper){ + // Blacklist gui causing issue + if (expectWesjd(clazzName)) return true + if (expectXenondevUI(clazzName)) return true + if (expectVanePortal(clazzName)) return true - return false + return false + } + + // Only allow cannonical anvil menu class + return !Const.cannonicalPaperAnvilMenu.equals(clazzName, true) } fun expectWesjd(name: String): Boolean { diff --git a/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PaperSpigtUtil.kt b/nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PaperSpigotUtil.kt similarity index 100% rename from nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PaperSpigtUtil.kt rename to nms/nms-common/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/util/PaperSpigotUtil.kt From ade94bdfca3110766e8dbd056e29f88911adab0d Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 10 Nov 2025 23:43:16 +0100 Subject: [PATCH 5/7] fix forgetting luck of the sea for the longest time --- build.gradle.kts | 2 +- defaultconfigs/1.18/enchant_conflict.yml | 4 ++ defaultconfigs/1.21.9/enchant_conflict.yml | 7 +++ defaultconfigs/1.21/enchant_conflict.yml | 4 ++ .../cuanvil/update/plugin/PUpdate_1_15_5.java | 27 ++++++++++ .../cuanvil/update/plugin/PluginUpdates.java | 54 +++++++++++-------- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 9 +++- src/main/resources/enchant_conflict.yml | 4 ++ 8 files changed, 86 insertions(+), 25 deletions(-) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_15_5.java diff --git a/build.gradle.kts b/build.gradle.kts index 0ef5bda..901b89a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.15.4" +version = "1.15.5" val effectiveVersion = "$version" + (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") diff --git a/defaultconfigs/1.18/enchant_conflict.yml b/defaultconfigs/1.18/enchant_conflict.yml index 0e8b3f3..45d62c3 100644 --- a/defaultconfigs/1.18/enchant_conflict.yml +++ b/defaultconfigs/1.18/enchant_conflict.yml @@ -92,6 +92,10 @@ restriction_loyalty: enchantments: [ minecraft:loyalty ] notAffectedGroups: [ enchanted_book, trident ] +restriction_luck_of_the_sea: + enchantments: [ minecraft:luck_of_the_sea ] + notAffectedGroups: [ enchanted_book, fishing_rod ] + restriction_lure: enchantments: [ minecraft:lure ] notAffectedGroups: [ enchanted_book, fishing_rod ] diff --git a/defaultconfigs/1.21.9/enchant_conflict.yml b/defaultconfigs/1.21.9/enchant_conflict.yml index 04f716f..9205061 100644 --- a/defaultconfigs/1.21.9/enchant_conflict.yml +++ b/defaultconfigs/1.21.9/enchant_conflict.yml @@ -152,6 +152,13 @@ restriction_loyalty: - enchanted_book - trident +restriction_luck_of_the_sea: + enchantments: + - minecraft:luck_of_the_sea + notAffectedGroups: + - enchanted_book + - fishing_rod + restriction_lure: enchantments: - minecraft:lure diff --git a/defaultconfigs/1.21/enchant_conflict.yml b/defaultconfigs/1.21/enchant_conflict.yml index 0e8b3f3..45d62c3 100644 --- a/defaultconfigs/1.21/enchant_conflict.yml +++ b/defaultconfigs/1.21/enchant_conflict.yml @@ -92,6 +92,10 @@ restriction_loyalty: enchantments: [ minecraft:loyalty ] notAffectedGroups: [ enchanted_book, trident ] +restriction_luck_of_the_sea: + enchantments: [ minecraft:luck_of_the_sea ] + notAffectedGroups: [ enchanted_book, fishing_rod ] + restriction_lure: enchantments: [ minecraft:lure ] notAffectedGroups: [ enchanted_book, fishing_rod ] diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_15_5.java b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_15_5.java new file mode 100644 index 0000000..76f51af --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PUpdate_1_15_5.java @@ -0,0 +1,27 @@ +package xyz.alexcrea.cuanvil.update.plugin; + +import org.bukkit.configuration.file.FileConfiguration; +import xyz.alexcrea.cuanvil.config.ConfigHolder; + +import javax.annotation.Nonnull; +import java.util.Set; + +import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList; + +public class PUpdate_1_15_5 { + + public static void handleUpdate(@Nonnull Set toSave) { + FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig(); + + if (config.isConfigurationSection("restriction_luck_of_the_sea")) return; + + // We fix the luck of the see enchantment + addAbsentToList(config, "restriction_luck_of_the_sea.enchantments", + "minecraft:luck_of_the_sea"); + addAbsentToList(config, "restriction_luck_of_the_sea.notAffectedGroups", + "enchanted_book", "fishing_rod"); + + toSave.add(ConfigHolder.CONFLICT_HOLDER); + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java index 430825c..d2cd077 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java @@ -9,7 +9,10 @@ import xyz.alexcrea.cuanvil.update.Version; import javax.annotation.Nonnull; import java.util.HashSet; +import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; public class PluginUpdates { @@ -21,10 +24,13 @@ public class PluginUpdates { handlePluginUpdate(); } - private static final Version V1_6_2 = new Version(1, 6, 2); - private static final Version V1_6_7 = new Version(1, 6, 7); - private static final Version V1_8_0 = new Version(1, 8, 0); - private static final Version V1_11_0 = new Version(1, 11, 0); + private static final Map>> updateMap = Map.of( + new Version(1, 6, 2), PUpdate_1_6_2::handleUpdate, + new Version(1, 6, 7), PUpdate_1_6_7::handleUpdate, + new Version(1, 8, 0), PUpdate_1_8_0::handleUpdate, + new Version(1, 11, 0), PUpdate_1_11_0::handleUpdate, + new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate + ); // Handle only plugin update private static void handlePluginUpdate() { @@ -33,35 +39,32 @@ public class PluginUpdates { Set toSave = new HashSet<>(); - if (V1_6_2.greaterThan(current)) { - PUpdate_1_6_2.handleUpdate(toSave); - // We assume 1.6.7 will run. TODO a better system instead of that I guess - } - if (V1_6_7.greaterThan(current)) { - PUpdate_1_6_7.handleUpdate(toSave); - // We assume 1.8.0 will run. - } - if (V1_8_0.greaterThan(current)) { - PUpdate_1_8_0.handleUpdate(toSave); - // We assume 1.11.0 will run. - } - if (V1_11_0.greaterThan(current)) { - PUpdate_1_11_0.handleUpdate(toSave); + AtomicReference latest = new AtomicReference<>(null); - finishConfiguration("1.11.0", toSave); - } + // Hopefully, should iterate in the "insertion" order + updateMap.forEach((ver, consumer) -> { + if (ver.greaterThan(current)) { + CustomAnvil.log("handling plugin update to " + ver); + consumer.accept(toSave); + latest.set(ver); + } + }); + + if (latest.get() != null) { + finishConfiguration(latest.get().toString(), toSave); + } } // Handle minecraft version update (not plugin version update) - public static void handleMCVersionUpdate(){ + public static void handleMCVersionUpdate() { Version current = UpdateUtils.currentMinecraftVersion(); boolean hadUpdate = false; hadUpdate |= Update_1_21.handleUpdate(current); hadUpdate |= Update_1_21_9.handleUpdate(current); - if(hadUpdate){ + if (hadUpdate) { CustomAnvil.instance.getLogger().info("Updating Done !"); } } @@ -71,9 +74,16 @@ public class PluginUpdates { ConfigHolder.DEFAULT_CONFIG.getConfig().set(CONFIG_VERSION_PATH, newVersion); toSave.add(ConfigHolder.DEFAULT_CONFIG); + // save for (ConfigHolder configHolder : toSave) { configHolder.saveToDisk(true); } + + // then reload + for (ConfigHolder configHolder : toSave) { + configHolder.reload(); + } + } } diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 386969a..e9b8f27 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -10,6 +10,7 @@ import xyz.alexcrea.cuanvil.command.EditConfigExecutor import xyz.alexcrea.cuanvil.command.ReloadExecutor import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.dependency.DependencyManager +import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant @@ -64,7 +65,7 @@ open class CustomAnvil : JavaPlugin() { /** * Logging handler */ - fun log(message: String) { + @JvmStatic fun log(message: String) { if (ConfigOptions.debugLog) { instance.logger.info(message) } @@ -79,7 +80,6 @@ open class CustomAnvil : JavaPlugin() { } } - } /** @@ -96,6 +96,11 @@ open class CustomAnvil : JavaPlugin() { logger.warning("Please note CustomAnvil is a more recent version of UnsafeEnchantsPlus") } + if(!PlatformUtil.isPaper) { + logger.warning("It seems you are using spigot") + logger.warning("Please take notice that spigot is less supported than paper and derivatives") + } + // Add commands prepareCommand() diff --git a/src/main/resources/enchant_conflict.yml b/src/main/resources/enchant_conflict.yml index 0e8b3f3..45d62c3 100644 --- a/src/main/resources/enchant_conflict.yml +++ b/src/main/resources/enchant_conflict.yml @@ -92,6 +92,10 @@ restriction_loyalty: enchantments: [ minecraft:loyalty ] notAffectedGroups: [ enchanted_book, trident ] +restriction_luck_of_the_sea: + enchantments: [ minecraft:luck_of_the_sea ] + notAffectedGroups: [ enchanted_book, fishing_rod ] + restriction_lure: enchantments: [ minecraft:lure ] notAffectedGroups: [ enchanted_book, fishing_rod ] From 9c3c2cfd2c38b37e427bea5dbc71452fe17ef373 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 1 Dec 2025 18:06:44 +0100 Subject: [PATCH 6/7] version bump --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 901b89a..8ae931c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.15.5" +version = "1.15.6" val effectiveVersion = "$version" + (if (System.getenv("SMALL_COMMIT_HASH") != null) "-dev-${System.getenv("SMALL_COMMIT_HASH")!!}" else "") From 905646cdee98c42bed4a6431714ab52e47c7ee87 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 1 Dec 2025 18:49:21 +0100 Subject: [PATCH 7/7] prepare config update for 1.21.11 --- .../PluginUpdates.java => UpdateHandler.java} | 29 +++++---- .../cuanvil/update/minecraft/MCUpdate.java | 36 +++++++++++ .../update/{ => minecraft}/Update_1_21.java | 33 ++++------ .../update/minecraft/Update_1_21_11.java | 60 +++++++++++++++++++ .../update/{ => minecraft}/Update_1_21_9.java | 35 ++++------- src/main/kotlin/io/delilaheve/CustomAnvil.kt | 5 +- .../cuanvil/command/ReloadExecutor.kt | 4 +- 7 files changed, 140 insertions(+), 62 deletions(-) rename src/main/java/xyz/alexcrea/cuanvil/update/{plugin/PluginUpdates.java => UpdateHandler.java} (78%) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/update/minecraft/MCUpdate.java rename src/main/java/xyz/alexcrea/cuanvil/update/{ => minecraft}/Update_1_21.java (76%) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java rename src/main/java/xyz/alexcrea/cuanvil/update/{ => minecraft}/Update_1_21_9.java (56%) diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java similarity index 78% rename from src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java rename to src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java index d2cd077..34f385c 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/plugin/PluginUpdates.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateHandler.java @@ -1,20 +1,22 @@ -package xyz.alexcrea.cuanvil.update.plugin; +package xyz.alexcrea.cuanvil.update; import io.delilaheve.CustomAnvil; import xyz.alexcrea.cuanvil.config.ConfigHolder; -import xyz.alexcrea.cuanvil.update.UpdateUtils; -import xyz.alexcrea.cuanvil.update.Update_1_21; -import xyz.alexcrea.cuanvil.update.Update_1_21_9; -import xyz.alexcrea.cuanvil.update.Version; +import xyz.alexcrea.cuanvil.update.minecraft.MCUpdate; +import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21; +import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_11; +import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_9; +import xyz.alexcrea.cuanvil.update.plugin.*; import javax.annotation.Nonnull; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; -public class PluginUpdates { +public class UpdateHandler { private static final String CONFIG_VERSION_PATH = "configVersion"; @@ -24,7 +26,7 @@ public class PluginUpdates { handlePluginUpdate(); } - private static final Map>> updateMap = Map.of( + private static final Map>> pUpdateMap = Map.of( new Version(1, 6, 2), PUpdate_1_6_2::handleUpdate, new Version(1, 6, 7), PUpdate_1_6_7::handleUpdate, new Version(1, 8, 0), PUpdate_1_8_0::handleUpdate, @@ -32,6 +34,12 @@ public class PluginUpdates { new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate ); + private static final List mcUpdateMap = List.of( + new Update_1_21(), + new Update_1_21_9(), + new Update_1_21_11() + ); + // Handle only plugin update private static void handlePluginUpdate() { String versionString = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(CONFIG_VERSION_PATH); @@ -42,7 +50,7 @@ public class PluginUpdates { AtomicReference latest = new AtomicReference<>(null); // Hopefully, should iterate in the "insertion" order - updateMap.forEach((ver, consumer) -> { + pUpdateMap.forEach((ver, consumer) -> { if (ver.greaterThan(current)) { CustomAnvil.log("handling plugin update to " + ver); consumer.accept(toSave); @@ -61,8 +69,9 @@ public class PluginUpdates { Version current = UpdateUtils.currentMinecraftVersion(); boolean hadUpdate = false; - hadUpdate |= Update_1_21.handleUpdate(current); - hadUpdate |= Update_1_21_9.handleUpdate(current); + for (MCUpdate mcUpdate : mcUpdateMap) { + hadUpdate |= mcUpdate.handleUpdate(current); + } if (hadUpdate) { CustomAnvil.instance.getLogger().info("Updating Done !"); diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/MCUpdate.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/MCUpdate.java new file mode 100644 index 0000000..d9db0ea --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/MCUpdate.java @@ -0,0 +1,36 @@ +package xyz.alexcrea.cuanvil.update.minecraft; + +import io.delilaheve.CustomAnvil; +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.UpdateUtils; +import xyz.alexcrea.cuanvil.update.Version; + +public abstract class MCUpdate { + + public final Version version; + + public MCUpdate(Version version){ + this.version = version; + } + + public boolean handleUpdate(Version current){ + // Test if we are running in this update version or better + if(version.greaterThan(current)) + return false; + + // if version path is not null then check if its it's before this update version + String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH); + if(oldVersion != null){ + var version = Version.fromString(oldVersion); + if(this.version.lesserEqual(version)) return false; + } + + CustomAnvil.instance.getLogger().info("Updating config to support " + version +" ..."); + doUpdate(); + return true; + } + + protected abstract void doUpdate(); + + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java similarity index 76% rename from src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21.java rename to src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java index 56de63c..3aa6073 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21.java @@ -1,33 +1,20 @@ -package xyz.alexcrea.cuanvil.update; +package xyz.alexcrea.cuanvil.update.minecraft; import io.delilaheve.CustomAnvil; import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.UpdateUtils; +import xyz.alexcrea.cuanvil.update.Version; import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList; -public class Update_1_21 { +public class Update_1_21 extends MCUpdate { - private static final Version V1_21 = new Version(1, 21); - - public static boolean handleUpdate(Version current){ - // Test if we are running in 1.21 or better - if(V1_21.greaterThan(current)) - return false; - - // if version path is not null then check if its it's before 1.21 - String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH); - if(oldVersion != null){ - var version = Version.fromString(oldVersion); - if(V1_21.lesserEqual(version)) return false; - } - - doUpdate(); - return true; + public Update_1_21() { + super(new Version(1, 21)); } - private static void doUpdate() { - CustomAnvil.instance.getLogger().info("Updating config to support 1.21 ..."); - + @Override + protected void doUpdate() { var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig(); var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); var conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig(); @@ -75,8 +62,8 @@ public class Update_1_21 { // Add unit repair for mace unitConfig.set("breeze_rod.mace", 0.25); - // Set version string as 1.21 - baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, V1_21.toString()); + // Set version string as current + baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, version.toString()); // Save ConfigHolder.DEFAULT_CONFIG.saveToDisk(true); diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java new file mode 100644 index 0000000..a060394 --- /dev/null +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_11.java @@ -0,0 +1,60 @@ +package xyz.alexcrea.cuanvil.update.minecraft; + +import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.UpdateUtils; +import xyz.alexcrea.cuanvil.update.Version; + +import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList; + +public class Update_1_21_11 extends MCUpdate{ + + public Update_1_21_11() { + super(new Version(1, 21, 11)); + } + + @Override + protected void doUpdate() { + var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig(); + var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); + var conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig(); + + // Create spear group + groupConfig.set("spears.type", "include"); + addAbsentToList(groupConfig, "spears.items", + "wooden_spear", + "golden_spear", + "stone_spear", + "copper_spear", + "iron_spear", + "diamond_spear", + "netherite_spear"); + + // Add spear group to super group and enchantments + addAbsentToList(groupConfig, "melee_weapons.groups", "spears"); + + addAbsentToList(conflictConfig, "restriction_looting.notAffectedGroups", "spears"); + addAbsentToList(conflictConfig, "restriction_knockback.notAffectedGroups", "spears"); + addAbsentToList(conflictConfig, "restriction_fire_aspect.notAffectedGroups", "spears"); + + // Create lunge enchant value and group + baseConfig.set("enchant_limits.minecraft:lunge", 3); + baseConfig.set("enchant_values.minecraft:lunge.item", 2); + baseConfig.set("enchant_values.minecraft:lunge.book", 1); + + addAbsentToList(conflictConfig, "restriction_lunge.enchantments", "minecraft:lunge"); + addAbsentToList(conflictConfig, "restriction_lunge.notAffectedGroups", "spears", "enchanted_book"); + + // Set version string as current + baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, version.toString()); + + // Save + ConfigHolder.DEFAULT_CONFIG.saveToDisk(true); + ConfigHolder.ITEM_GROUP_HOLDER.saveToDisk(true); + ConfigHolder.CONFLICT_HOLDER.saveToDisk(true); + + // imply reload of CONFLICT_HOLDER + // We also do not need to reload base config as there is no object related to it. + ConfigHolder.ITEM_GROUP_HOLDER.reload(); + } + +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java similarity index 56% rename from src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java rename to src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java index e749d74..a4e21a7 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/minecraft/Update_1_21_9.java @@ -1,37 +1,24 @@ -package xyz.alexcrea.cuanvil.update; +package xyz.alexcrea.cuanvil.update.minecraft; import io.delilaheve.CustomAnvil; import xyz.alexcrea.cuanvil.config.ConfigHolder; +import xyz.alexcrea.cuanvil.update.UpdateUtils; +import xyz.alexcrea.cuanvil.update.Version; import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList; -public class Update_1_21_9 { +public class Update_1_21_9 extends MCUpdate{ - private static final Version V1_21_9 = new Version(1, 21, 9); - - public static boolean handleUpdate(Version current){ - // Test if we are running in 1.21.9 or better - if(V1_21_9.greaterThan(current)) - return false; - - // if version path is not null then check if its it's before 1.21.9 - String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH); - if(oldVersion != null){ - var version = Version.fromString(oldVersion); - if(V1_21_9.lesserEqual(version)) return false; - } - - doUpdate(); - return true; + public Update_1_21_9() { + super(new Version(1, 21, 9)); } - private static void doUpdate() { - CustomAnvil.instance.getLogger().info("Updating config to support 1.21.9 ..."); - + @Override + protected void doUpdate() { var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig(); var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); - // Add mace to groups + // Add cooper items to groups addAbsentToList(groupConfig, "helmets.items", "copper_helmet"); addAbsentToList(groupConfig, "chestplate.items", "copper_chestplate"); addAbsentToList(groupConfig, "leggings.items", "copper_leggings"); @@ -43,8 +30,8 @@ public class Update_1_21_9 { addAbsentToList(groupConfig, "axes.items", "copper_axe"); addAbsentToList(groupConfig, "swords.items", "copper_sword"); - // Set version string as 1.21 - baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, V1_21_9.toString()); + // Set version string as current + baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, version.toString()); // Save ConfigHolder.DEFAULT_CONFIG.saveToDisk(true); diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index e9b8f27..c747189 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -19,8 +19,7 @@ import xyz.alexcrea.cuanvil.listener.AnvilResultListener import xyz.alexcrea.cuanvil.listener.ChatEventListener import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener import xyz.alexcrea.cuanvil.update.PluginSetDefault -import xyz.alexcrea.cuanvil.update.Update_1_21 -import xyz.alexcrea.cuanvil.update.plugin.PluginUpdates +import xyz.alexcrea.cuanvil.update.UpdateHandler import xyz.alexcrea.cuanvil.util.Metrics import java.io.File import java.io.FileReader @@ -145,7 +144,7 @@ open class CustomAnvil : JavaPlugin() { } // Handle minecraft and plugin updates - PluginUpdates.handleUpdates() + UpdateHandler.handleUpdates() // Register enchantment of compatible plugin and load configuration change. DependencyManager.handleCompatibilityConfig() diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index 8093e09..dc2fe8e 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -9,7 +9,7 @@ import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.gui.config.global.* -import xyz.alexcrea.cuanvil.update.plugin.PluginUpdates +import xyz.alexcrea.cuanvil.update.UpdateHandler class ReloadExecutor : CommandExecutor { override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array): Boolean { @@ -49,7 +49,7 @@ class ReloadExecutor : CommandExecutor { CustomRecipeConfigGui.getCurrentInstance()?.reloadValues() // handle minecraft version update - PluginUpdates.handleMCVersionUpdate() + UpdateHandler.handleMCVersionUpdate() // Handle dependency reload DependencyManager.handleConfigReload()