From ade94bdfca3110766e8dbd056e29f88911adab0d Mon Sep 17 00:00:00 2001 From: alexcrea Date: Mon, 10 Nov 2025 23:43:16 +0100 Subject: [PATCH] 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 ]