mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
prepare config update for 1.21.11
This commit is contained in:
parent
9c3c2cfd2c
commit
905646cdee
7 changed files with 140 additions and 62 deletions
|
|
@ -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<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,
|
||||
|
|
@ -32,6 +34,12 @@ public class PluginUpdates {
|
|||
new Version(1, 15, 5), PUpdate_1_15_5::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
|
||||
private static void handlePluginUpdate() {
|
||||
String versionString = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(CONFIG_VERSION_PATH);
|
||||
|
|
@ -42,7 +50,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 +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 !");
|
||||
|
|
@ -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();
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
public Update_1_21() {
|
||||
super(new Version(1, 21));
|
||||
}
|
||||
|
||||
doUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
public Update_1_21_9() {
|
||||
super(new Version(1, 21, 9));
|
||||
}
|
||||
|
||||
doUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue