mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Merged main changes.
This commit is contained in:
parent
cbb3bb5a54
commit
91ea6115be
3 changed files with 0 additions and 131 deletions
|
|
@ -1,29 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.update;
|
|
||||||
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class UpdateUtils {
|
|
||||||
public final static String MINECRAFT_VERSION_PATH = "lowMinecraftVersion";
|
|
||||||
|
|
||||||
static int[] readVersionFromString(String versionString){
|
|
||||||
String[] partialVersion = versionString.split("\\.");
|
|
||||||
int[] versionParts = new int[]{0, 0, 0};
|
|
||||||
|
|
||||||
for (int i = 0; i < Math.min(3, partialVersion.length); i++) {
|
|
||||||
versionParts[i] = Integer.parseInt(partialVersion[i]);
|
|
||||||
}
|
|
||||||
return versionParts;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void addToStringList(FileConfiguration config, String path, String... toAdd){
|
|
||||||
List<String> groups = new ArrayList<>(config.getStringList(path));
|
|
||||||
groups.addAll(Arrays.asList(toAdd));
|
|
||||||
config.set(path, groups);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.update;
|
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
|
||||||
|
|
||||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addToStringList;
|
|
||||||
|
|
||||||
// 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 {
|
|
||||||
|
|
||||||
public static void handleUpdate(){
|
|
||||||
// Assume if version path is not null then it's 1.21
|
|
||||||
String oldVersion = ConfigHolder.DEFAULT_CONFIG.getConfig().getString(UpdateUtils.MINECRAFT_VERSION_PATH);
|
|
||||||
if(oldVersion != null){
|
|
||||||
int[] versionParts = UpdateUtils.readVersionFromString(oldVersion);
|
|
||||||
|
|
||||||
// Test 1.21
|
|
||||||
if((versionParts[0] >= 1) && (versionParts[1] >= 21)){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String versionString = Bukkit.getServer().getBukkitVersion().split("-")[0];
|
|
||||||
int[] versionParts = UpdateUtils.readVersionFromString(versionString);
|
|
||||||
|
|
||||||
// Test 1.21
|
|
||||||
if((versionParts[0] >= 1) && (versionParts[1] >= 21)){
|
|
||||||
doUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void doUpdate() {
|
|
||||||
CustomAnvil.instance.getLogger().info("Updating config to support 1.21 ...");
|
|
||||||
|
|
||||||
FileConfiguration baseConfig = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
|
||||||
FileConfiguration groupConfig = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
|
||||||
FileConfiguration conflictConfig = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
|
||||||
|
|
||||||
// Add mace to groups
|
|
||||||
groupConfig.set("mace.type", "include");
|
|
||||||
addToStringList(groupConfig, "mace.items", "mace");
|
|
||||||
|
|
||||||
addToStringList(groupConfig, "can_unbreak.groups", "mace");
|
|
||||||
|
|
||||||
// Add new enchant conflicts
|
|
||||||
addToStringList(conflictConfig, "restriction_density.enchantments", "density");
|
|
||||||
addToStringList(conflictConfig, "restriction_density.notAffectedGroups", "mace");
|
|
||||||
|
|
||||||
addToStringList(conflictConfig, "restriction_breach.enchantments", "breach");
|
|
||||||
addToStringList(conflictConfig, "restriction_breach.notAffectedGroups", "mace");
|
|
||||||
|
|
||||||
addToStringList(conflictConfig, "restriction_wind_burst.enchantments", "wind_burst");
|
|
||||||
addToStringList(conflictConfig, "restriction_wind_burst.notAffectedGroups", "mace");
|
|
||||||
|
|
||||||
// Add mace to conflicts
|
|
||||||
addToStringList(conflictConfig, "restriction_fire_aspect.notAffectedGroups", "mace");
|
|
||||||
addToStringList(conflictConfig, "restriction_smite.notAffectedGroups", "mace");
|
|
||||||
addToStringList(conflictConfig, "restriction_bane_of_arthropods.notAffectedGroups", "mace");
|
|
||||||
|
|
||||||
addToStringList(conflictConfig, "mace_enchant_conflict.enchantments", "density", "breach", "smite", "bane_of_arthropods");
|
|
||||||
conflictConfig.set("mace_enchant_conflict.maxEnchantmentBeforeConflict", 1);
|
|
||||||
|
|
||||||
// Add level limit
|
|
||||||
baseConfig.set("enchant_limits.density", 5);
|
|
||||||
baseConfig.set("enchant_limits.breach", 4);
|
|
||||||
baseConfig.set("enchant_limits.wind_burst", 3);
|
|
||||||
|
|
||||||
// Add enchant values
|
|
||||||
baseConfig.set("enchant_values.density.item", 1);
|
|
||||||
baseConfig.set("enchant_values.density.book", 1);
|
|
||||||
|
|
||||||
baseConfig.set("enchant_values.breach.item", 4);
|
|
||||||
baseConfig.set("enchant_values.breach.book", 2);
|
|
||||||
|
|
||||||
baseConfig.set("enchant_values.wind_burst.item", 4);
|
|
||||||
baseConfig.set("enchant_values.wind_burst.book", 2);
|
|
||||||
|
|
||||||
// Set version string as 1.21
|
|
||||||
baseConfig.set(UpdateUtils.MINECRAFT_VERSION_PATH, "1.21");
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
CustomAnvil.instance.getLogger().info("Updating Done !");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -14,7 +14,6 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
|
||||||
import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
||||||
import xyz.alexcrea.cuanvil.update.Update_1_21
|
|
||||||
import xyz.alexcrea.cuanvil.util.Metrics
|
import xyz.alexcrea.cuanvil.util.Metrics
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
|
|
@ -132,9 +131,6 @@ class CustomAnvil : JavaPlugin() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// temporary: handle 1.21 update
|
|
||||||
Update_1_21.handleUpdate()
|
|
||||||
|
|
||||||
// Register enchantment of compatible plugin and load configuration change.
|
// Register enchantment of compatible plugin and load configuration change.
|
||||||
DependencyManager.handleCompatibilityConfig()
|
DependencyManager.handleCompatibilityConfig()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue