mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
add copper items
This commit is contained in:
parent
3ab6dbc155
commit
5bdd2f9b4c
6 changed files with 110 additions and 32 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
package xyz.alexcrea.cuanvil.update;
|
package xyz.alexcrea.cuanvil.update;
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
|
||||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
||||||
|
|
@ -12,31 +11,28 @@ public class Update_1_21 {
|
||||||
|
|
||||||
private static final Version V1_21 = new Version(1, 21);
|
private static final Version V1_21 = new Version(1, 21);
|
||||||
|
|
||||||
public static void handleUpdate(){
|
public static void handleUpdate(Version current){
|
||||||
// Assume if version path is not null then it's 1.21
|
// Test if we are running in 1.21.1
|
||||||
|
if(V1_21.greaterEqual(current))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 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);
|
String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH);
|
||||||
if(oldVersion != null){
|
if(oldVersion != null){
|
||||||
Version version = Version.fromString(oldVersion);
|
var version = Version.fromString(oldVersion);
|
||||||
|
|
||||||
// Test 1.21
|
|
||||||
if(V1_21.greaterEqual(version)) return;
|
if(V1_21.greaterEqual(version)) return;
|
||||||
}
|
}
|
||||||
Version current = UpdateUtils.currentMinecraftVersion();
|
|
||||||
|
|
||||||
// Test 1.21
|
|
||||||
if(current.greaterEqual(V1_21)){
|
|
||||||
doUpdate();
|
doUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void doUpdate() {
|
private static void doUpdate() {
|
||||||
CustomAnvil.instance.getLogger().info("Updating config to support 1.21 ...");
|
CustomAnvil.instance.getLogger().info("Updating config to support 1.21 ...");
|
||||||
|
|
||||||
FileConfiguration baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
var baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||||
FileConfiguration groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
var groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||||
FileConfiguration conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
var conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||||
FileConfiguration unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||||
|
|
||||||
// Add mace to groups
|
// Add mace to groups
|
||||||
groupConfig.set("mace.type", "include");
|
groupConfig.set("mace.type", "include");
|
||||||
|
|
@ -81,7 +77,7 @@ public class Update_1_21 {
|
||||||
unitConfig.set("breeze_rod.mace", 0.25);
|
unitConfig.set("breeze_rod.mace", 0.25);
|
||||||
|
|
||||||
// Set version string as 1.21
|
// Set version string as 1.21
|
||||||
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, "1.21");
|
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, V1_21.toString());
|
||||||
|
|
||||||
// Save
|
// Save
|
||||||
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
ConfigHolder.DEFAULT_CONFIG.saveToDisk(true);
|
||||||
|
|
@ -94,7 +90,6 @@ public class Update_1_21 {
|
||||||
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
||||||
|
|
||||||
CustomAnvil.instance.getLogger().info("Updating Done !");
|
CustomAnvil.instance.getLogger().info("Updating Done !");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
61
src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java
Normal file
61
src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21_9.java
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
package xyz.alexcrea.cuanvil.update;
|
||||||
|
|
||||||
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
|
||||||
|
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
||||||
|
|
||||||
|
// This is a temporary class that aim to handle 1.21 update.
|
||||||
|
// It will be replaced by a better system later.
|
||||||
|
public class Update_1_21_9 {
|
||||||
|
|
||||||
|
private static final Version V1_21_9 = new Version(1, 21, 9);
|
||||||
|
|
||||||
|
public static void handleUpdate(Version current){
|
||||||
|
// Test if we are running in 1.21.1.9
|
||||||
|
if(V1_21_9.greaterEqual(current))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 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.greaterEqual(version)) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
doUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
CustomAnvil.instance.getLogger().info("Updating Done !");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
package xyz.alexcrea.cuanvil.update;
|
package xyz.alexcrea.cuanvil.update;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
|
@ -48,6 +50,7 @@ public record Version(int major, int minor, int patch) {
|
||||||
this.patch <= other.patch)));
|
this.patch <= other.patch)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return major + "." + minor + "." + patch;
|
return major + "." + minor + "." + patch;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,9 @@ package xyz.alexcrea.cuanvil.update.plugin;
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
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.Version;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -12,26 +15,37 @@ public class PluginUpdates {
|
||||||
|
|
||||||
private static final String CONFIG_VERSION_PATH = "configVersion";
|
private static final String CONFIG_VERSION_PATH = "configVersion";
|
||||||
|
|
||||||
public static void handlePluginUpdate() {
|
// Handle mc version update then plugin version update
|
||||||
|
public static void handleUpdates() {
|
||||||
|
handleMCVersionUpdate();
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Handle only plugin update
|
||||||
|
private static void handlePluginUpdate() {
|
||||||
String versionString = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(CONFIG_VERSION_PATH);
|
String versionString = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(CONFIG_VERSION_PATH);
|
||||||
Version current = versionString == null ? new Version(0) : Version.fromString(versionString);
|
Version current = versionString == null ? new Version(0) : Version.fromString(versionString);
|
||||||
|
|
||||||
Set<ConfigHolder> toSave = new HashSet<>();
|
Set<ConfigHolder> toSave = new HashSet<>();
|
||||||
|
|
||||||
if (new Version(1, 6, 2).greaterThan(current)) {
|
if (V1_6_2.greaterThan(current)) {
|
||||||
PUpdate_1_6_2.handleUpdate(toSave);
|
PUpdate_1_6_2.handleUpdate(toSave);
|
||||||
// We assume 1.6.7 will run. TODO a better system instead of that I guess
|
// We assume 1.6.7 will run. TODO a better system instead of that I guess
|
||||||
}
|
}
|
||||||
if (new Version(1, 6, 7).greaterThan(current)) {
|
if (V1_6_7.greaterThan(current)) {
|
||||||
PUpdate_1_6_7.handleUpdate(toSave);
|
PUpdate_1_6_7.handleUpdate(toSave);
|
||||||
// We assume 1.8.0 will run.
|
// We assume 1.8.0 will run.
|
||||||
}
|
}
|
||||||
if (new Version(1, 8, 0).greaterThan(current)) {
|
if (V1_8_0.greaterThan(current)) {
|
||||||
PUpdate_1_8_0.handleUpdate(toSave);
|
PUpdate_1_8_0.handleUpdate(toSave);
|
||||||
// We assume 1.11.0 will run.
|
// We assume 1.11.0 will run.
|
||||||
}
|
}
|
||||||
|
if (V1_11_0.greaterThan(current)) {
|
||||||
if (new Version(1, 11, 0).greaterThan(current)) {
|
|
||||||
PUpdate_1_11_0.handleUpdate(toSave);
|
PUpdate_1_11_0.handleUpdate(toSave);
|
||||||
|
|
||||||
finishConfiguration("1.11.0", toSave);
|
finishConfiguration("1.11.0", toSave);
|
||||||
|
|
@ -39,6 +53,14 @@ public class PluginUpdates {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle minecraft version update (not plugin version update)
|
||||||
|
public static void handleMCVersionUpdate(){
|
||||||
|
Version current = UpdateUtils.currentMinecraftVersion();
|
||||||
|
|
||||||
|
Update_1_21.handleUpdate(current);
|
||||||
|
Update_1_21_9.handleUpdate(current);
|
||||||
|
}
|
||||||
|
|
||||||
private static void finishConfiguration(@Nonnull String newVersion, @Nonnull Set<ConfigHolder> toSave) {
|
private static void finishConfiguration(@Nonnull String newVersion, @Nonnull Set<ConfigHolder> toSave) {
|
||||||
CustomAnvil.instance.getLogger().info("Configuration file updated to " + newVersion);
|
CustomAnvil.instance.getLogger().info("Configuration file updated to " + newVersion);
|
||||||
ConfigHolder.DEFAULT_CONFIG.getConfig().set(CONFIG_VERSION_PATH, newVersion);
|
ConfigHolder.DEFAULT_CONFIG.getConfig().set(CONFIG_VERSION_PATH, newVersion);
|
||||||
|
|
|
||||||
|
|
@ -139,11 +139,8 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporary: handle 1.21 update
|
// Handle minecraft and plugin updates
|
||||||
Update_1_21.handleUpdate()
|
PluginUpdates.handleUpdates()
|
||||||
|
|
||||||
// plugin configuration updates
|
|
||||||
PluginUpdates.handlePluginUpdate()
|
|
||||||
|
|
||||||
// Register enchantment of compatible plugin and load configuration change.
|
// Register enchantment of compatible plugin and load configuration change.
|
||||||
DependencyManager.handleCompatibilityConfig()
|
DependencyManager.handleCompatibilityConfig()
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||||
import xyz.alexcrea.cuanvil.update.Update_1_21
|
import xyz.alexcrea.cuanvil.update.plugin.PluginUpdates
|
||||||
|
|
||||||
class ReloadExecutor : CommandExecutor {
|
class ReloadExecutor : CommandExecutor {
|
||||||
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
override fun onCommand(sender: CommandSender, cmd: Command, cmdstr: String, args: Array<out String>): Boolean {
|
||||||
|
|
@ -48,8 +48,8 @@ class ReloadExecutor : CommandExecutor {
|
||||||
UnitRepairConfigGui.getCurrentInstance()?.reloadValues()
|
UnitRepairConfigGui.getCurrentInstance()?.reloadValues()
|
||||||
CustomRecipeConfigGui.getCurrentInstance()?.reloadValues()
|
CustomRecipeConfigGui.getCurrentInstance()?.reloadValues()
|
||||||
|
|
||||||
// temporary: handle 1.21 update
|
// handle minecraft version update
|
||||||
Update_1_21.handleUpdate()
|
PluginUpdates.handleMCVersionUpdate()
|
||||||
|
|
||||||
// Handle dependency reload
|
// Handle dependency reload
|
||||||
DependencyManager.handleConfigReload()
|
DependencyManager.handleConfigReload()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue