Feature/1.21.11 (#100)

This commit is contained in:
alexcrea 2025-12-13 15:12:14 +01:00 committed by GitHub
commit b8da163e77
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 1663 additions and 102 deletions

View file

@ -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,12 +26,19 @@ public class PluginUpdates {
handlePluginUpdate();
}
private static final Map<Version, Consumer<Set<ConfigHolder>>> updateMap = Map.of(
private static final Map<Version, Consumer<Set<ConfigHolder>>> 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,
new Version(1, 11, 0), PUpdate_1_11_0::handleUpdate,
new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate
new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate,
new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate
);
private static final List<MCUpdate> mcUpdateMap = List.of(
new Update_1_21(),
new Update_1_21_9(),
new Update_1_21_11()
);
// Handle only plugin update
@ -42,7 +51,7 @@ public class PluginUpdates {
AtomicReference<Version> 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 +70,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, hadUpdate);
}
if (hadUpdate) {
CustomAnvil.instance.getLogger().info("Updating Done !");

View file

@ -1,58 +0,0 @@
package xyz.alexcrea.cuanvil.update;
import io.delilaheve.CustomAnvil;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
public class Update_1_21_9 {
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;
}
private static void doUpdate() {
CustomAnvil.instance.getLogger().info("Updating config to support 1.21.9 ...");
var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
// Add mace to groups
addAbsentToList(groupConfig, "helmets.items", "copper_helmet");
addAbsentToList(groupConfig, "chestplate.items", "copper_chestplate");
addAbsentToList(groupConfig, "leggings.items", "copper_leggings");
addAbsentToList(groupConfig, "boots.items", "copper_boots");
addAbsentToList(groupConfig, "pickaxes.items", "copper_pickaxe");
addAbsentToList(groupConfig, "shovels.items", "copper_shovel");
addAbsentToList(groupConfig, "hoes.items", "copper_hoe");
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());
// Save
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
ConfigHolder.ITEM_GROUP_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();
}
}

View file

@ -0,0 +1,38 @@
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, boolean hadUpdate){
// 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;
}
if(!hadUpdate){
CustomAnvil.instance.getLogger().info("Updating config to support minecraft " + current +" ...");
}
doUpdate();
return true;
}
protected abstract void doUpdate();
}

View file

@ -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);

View file

@ -0,0 +1,84 @@
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();
var unitConfig = ConfigHolder.UNIT_REPAIR_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");
// Unit repair for spears
unitConfig.set("gold_ingot.golden_spear", 0.25);
unitConfig.set("copper_ingot.copper_spear", 0.25);
unitConfig.set("iron_ingot.iron_spear", 0.25);
unitConfig.set("diamond.diamond_spear", 0.25);
unitConfig.set("netherite_ingot.netherite_spear", 0.25);
unitConfig.set("cobblestone.stone_spear", 0.25);
unitConfig.set("cobbled_deepslate.stone_spear", 0.25);
unitConfig.set("oak_planks.wooden_spear", 0.25);
unitConfig.set("spruce_planks.wooden_spear", 0.25);
unitConfig.set("birch_planks.wooden_spear", 0.25);
unitConfig.set("jungle_planks.wooden_spear", 0.25);
unitConfig.set("acacia_planks.wooden_spear", 0.25);
unitConfig.set("dark_oak_planks.wooden_spear", 0.25);
unitConfig.set("mangrove_planks.wooden_spear", 0.25);
unitConfig.set("cherry_planks.wooden_spear", 0.25);
unitConfig.set("bamboo_planks.wooden_spear", 0.25);
unitConfig.set("crimson_planks.wooden_spear", 0.25);
unitConfig.set("warped_planks.wooden_spear", 0.25);
// 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);
ConfigHolder.UNIT_REPAIR_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();
}
}

View file

@ -0,0 +1,64 @@
package xyz.alexcrea.cuanvil.update.minecraft;
import org.bukkit.configuration.file.FileConfiguration;
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 extends MCUpdate{
public Update_1_21_9() {
super(new Version(1, 21, 9));
}
@Override
protected void doUpdate() {
var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
// Add cooper items to groups
addAbsentToList(groupConfig, "helmets.items", "copper_helmet");
addAbsentToList(groupConfig, "chestplate.items", "copper_chestplate");
addAbsentToList(groupConfig, "leggings.items", "copper_leggings");
addAbsentToList(groupConfig, "boots.items", "copper_boots");
addAbsentToList(groupConfig, "pickaxes.items", "copper_pickaxe");
addAbsentToList(groupConfig, "shovels.items", "copper_shovel");
addAbsentToList(groupConfig, "hoes.items", "copper_hoe");
addAbsentToList(groupConfig, "axes.items", "copper_axe");
addAbsentToList(groupConfig, "swords.items", "copper_sword");
// Add unit repair
addCopperUnitRepair(unitConfig);
// 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.UNIT_REPAIR_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();
}
public static void addCopperUnitRepair(FileConfiguration unitConfig) {
// Add unit repair
unitConfig.set("copper_ingot.copper_helmet", 0.25);
unitConfig.set("copper_ingot.copper_chestplate", 0.25);
unitConfig.set("copper_ingot.copper_leggings", 0.25);
unitConfig.set("copper_ingot.copper_boots", 0.25);
unitConfig.set("copper_ingot.copper_pickaxe", 0.25);
unitConfig.set("copper_ingot.copper_shovel", 0.25);
unitConfig.set("copper_ingot.copper_hoe", 0.25);
unitConfig.set("copper_ingot.copper_axe", 0.25);
unitConfig.set("copper_ingot.copper_sword", 0.25);
}
}

View file

@ -0,0 +1,27 @@
package xyz.alexcrea.cuanvil.update.plugin;
import org.bukkit.configuration.file.FileConfiguration;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.update.UpdateUtils;
import xyz.alexcrea.cuanvil.update.Version;
import xyz.alexcrea.cuanvil.update.minecraft.Update_1_21_9;
import javax.annotation.Nonnull;
import java.util.Set;
public class PUpdate_1_15_6 {
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
// fix only needed for 1.21.9 and above
Version current = UpdateUtils.currentMinecraftVersion();
if (new Version(1, 21, 9).greaterThan(current)) return;
FileConfiguration unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
// Add unit repair
Update_1_21_9.addCopperUnitRepair(unitConfig);
toSave.add(ConfigHolder.UNIT_REPAIR_HOLDER);
}
}

View file

@ -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()

View file

@ -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<out String>): Boolean {
@ -49,7 +49,7 @@ class ReloadExecutor : CommandExecutor {
CustomRecipeConfigGui.getCurrentInstance()?.reloadValues()
// handle minecraft version update
PluginUpdates.handleMCVersionUpdate()
UpdateHandler.handleMCVersionUpdate()
// Handle dependency reload
DependencyManager.handleConfigReload()

View file

@ -46,6 +46,7 @@ object GuiTesterSelector {
5 -> v1_21R4_ExternGuiTester()
6, 7, 8 -> v1_21R5_ExternGuiTester()
9, 10 -> v1_21R6_ExternGuiTester()
11 -> v1_21R7_ExternGuiTester()
else -> null
}

View file

@ -60,6 +60,7 @@ object PacketManagerSelector {
5 -> V1_21R4_PacketManager()
6, 7, 8 -> V1_21R5_PacketManager()
9, 10 -> V1_21R6_PacketManager()
11 -> V1_21R7_PacketManager()
else -> null
}