mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
1.21 update (#10)
This commit is contained in:
commit
015c0ec5fe
17 changed files with 143 additions and 193 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
# Custom Anvil
|
# Custom Anvil
|
||||||
|
|
||||||
**Custom Anvil** is a plugin that allows server administrators to customise every aspect of the anvil's mechanics.
|
**Custom Anvil** is a plugin that allows server administrators to customise every aspect of the anvil's mechanics.
|
||||||
It is expected to work on 1.18 to 1.20.6 minecraft servers running spigot or paper.
|
It is expected to work on 1.18 to 1.21 minecraft servers running spigot or paper.
|
||||||
(the plugin support of 1.16.5 to 1.17.1 is experimental an may encounter issues)
|
(the plugin support of 1.16.5 to 1.17.1 is experimental an may encounter issues)
|
||||||
|
|
||||||
**Custom Anvil** was previously named **Unsafe Enchants+**.
|
**Custom Anvil** was previously named **Unsafe Enchants+**.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.4.7"
|
version = "1.4.8"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
|
||||||
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
|
||||||
import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager;
|
import xyz.alexcrea.cuanvil.recipe.CustomAnvilRecipeManager;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -28,11 +27,7 @@ public abstract class ConfigHolder {
|
||||||
UNIT_REPAIR_HOLDER = new UnitRepairHolder();
|
UNIT_REPAIR_HOLDER = new UnitRepairHolder();
|
||||||
CUSTOM_RECIPE_HOLDER = new CustomAnvilCraftHolder();
|
CUSTOM_RECIPE_HOLDER = new CustomAnvilCraftHolder();
|
||||||
|
|
||||||
boolean result = reloadAllFromDisk(true);
|
return reloadAllFromDisk(true);
|
||||||
if (result) {
|
|
||||||
MetricsUtil.INSTANCE.testIfConfigIsDefault();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean reloadAllFromDisk(boolean hardfail) {
|
public static boolean reloadAllFromDisk(boolean hardfail) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ public enum EnchantmentProperties {
|
||||||
BANE_OF_ARTHROPODS(EnchantmentRarity.UNCOMMON),
|
BANE_OF_ARTHROPODS(EnchantmentRarity.UNCOMMON),
|
||||||
BINDING_CURSE(EnchantmentRarity.VERY_RARE),
|
BINDING_CURSE(EnchantmentRarity.VERY_RARE),
|
||||||
BLAST_PROTECTION(EnchantmentRarity.RARE),
|
BLAST_PROTECTION(EnchantmentRarity.RARE),
|
||||||
|
BREACH(EnchantmentRarity.RARE),
|
||||||
CHANNELING(EnchantmentRarity.VERY_RARE),
|
CHANNELING(EnchantmentRarity.VERY_RARE),
|
||||||
|
DENSITY(EnchantmentRarity.UNCOMMON),
|
||||||
DEPTH_STRIDER(EnchantmentRarity.RARE),
|
DEPTH_STRIDER(EnchantmentRarity.RARE),
|
||||||
EFFICIENCY(EnchantmentRarity.COMMON),
|
EFFICIENCY(EnchantmentRarity.COMMON),
|
||||||
FLAME(EnchantmentRarity.RARE),
|
FLAME(EnchantmentRarity.RARE),
|
||||||
|
|
@ -42,7 +44,9 @@ public enum EnchantmentProperties {
|
||||||
SWEEPING_EDGE(EnchantmentRarity.RARE),
|
SWEEPING_EDGE(EnchantmentRarity.RARE),
|
||||||
THORNS(EnchantmentRarity.VERY_RARE),
|
THORNS(EnchantmentRarity.VERY_RARE),
|
||||||
UNBREAKING(EnchantmentRarity.UNCOMMON),
|
UNBREAKING(EnchantmentRarity.UNCOMMON),
|
||||||
VANISHING_CURSE(EnchantmentRarity.VERY_RARE);
|
VANISHING_CURSE(EnchantmentRarity.VERY_RARE),
|
||||||
|
WIND_BURST(EnchantmentRarity.RARE),
|
||||||
|
;
|
||||||
|
|
||||||
private final EnchantmentRarity rarity;
|
private final EnchantmentRarity rarity;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,9 @@ public class MainConfigGui extends ChestGui {
|
||||||
|
|
||||||
private MainConfigGui() {
|
private MainConfigGui() {
|
||||||
super(3, "\u00A78Anvil Config", CustomAnvil.instance);
|
super(3, "\u00A78Anvil Config", CustomAnvil.instance);
|
||||||
|
|
||||||
init(CustomAnvil.instance.packetManager);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(PacketManager packetManager) {
|
public void init(PacketManager packetManager) {
|
||||||
Pattern pattern = new Pattern(
|
Pattern pattern = new Pattern(
|
||||||
"000000000",
|
"000000000",
|
||||||
"012304567",
|
"012304567",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -85,7 +84,6 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<String, Do
|
||||||
// Add new material
|
// Add new material
|
||||||
ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().set(parentMaterial.name().toLowerCase()+"."+materialName,0.25);
|
ConfigHolder.UNIT_REPAIR_HOLDER.getConfig().set(parentMaterial.name().toLowerCase()+"."+materialName,0.25);
|
||||||
|
|
||||||
MetricsUtil.INSTANCE.notifyChange(ConfigHolder.UNIT_REPAIR_HOLDER, "");
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
ConfigHolder.UNIT_REPAIR_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
ConfigHolder.UNIT_REPAIR_HOLDER.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -150,7 +149,6 @@ public class BoolSettingsGui extends AbstractSettingGui {
|
||||||
public boolean onSave() {
|
public boolean onSave() {
|
||||||
holder.config.getConfig().set(holder.configPath, now);
|
holder.config.getConfig().set(holder.configPath, now);
|
||||||
|
|
||||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
|
|
@ -321,7 +320,6 @@ public class DoubleSettingGui extends AbstractSettingGui {
|
||||||
this.holder.config.getConfig().set(this.holder.configPath, now.doubleValue());
|
this.holder.config.getConfig().set(this.holder.configPath, now.doubleValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -226,7 +225,6 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
|
||||||
holder.config.getConfig().set(holder.configPath + ITEM_PATH, now);
|
holder.config.getConfig().set(holder.configPath + ITEM_PATH, now);
|
||||||
holder.config.getConfig().set(holder.configPath + BOOK_PATH, nowBook);
|
holder.config.getConfig().set(holder.configPath + BOOK_PATH, nowBook);
|
||||||
|
|
||||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -264,7 +263,6 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
public boolean onSave() {
|
public boolean onSave() {
|
||||||
holder.config.getConfig().set(holder.configPath, now);
|
holder.config.getConfig().set(holder.configPath, now);
|
||||||
|
|
||||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -148,7 +147,6 @@ public class ItemSettingGui extends AbstractSettingGui {
|
||||||
public boolean onSave() {
|
public boolean onSave() {
|
||||||
holder.config.getConfig().set(holder.configPath, this.now);
|
holder.config.getConfig().set(holder.configPath, this.now);
|
||||||
|
|
||||||
MetricsUtil.INSTANCE.notifyChange(this.holder.config, this.holder.configPath);
|
|
||||||
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
if (GuiSharedConstant.TEMPORARY_DO_SAVE_TO_DISK_EVERY_CHANGE) {
|
||||||
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
return holder.config.saveToDisk(GuiSharedConstant.TEMPORARY_DO_BACKUP_EVERY_SAVE);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java
Normal file
29
src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
98
src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21.java
Normal file
98
src/main/java/xyz/alexcrea/cuanvil/update/Update_1_21.java
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
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 !");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -13,8 +13,8 @@ import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
||||||
import xyz.alexcrea.cuanvil.packet.NoProtocoLib
|
import xyz.alexcrea.cuanvil.packet.NoProtocoLib
|
||||||
import xyz.alexcrea.cuanvil.packet.PacketManager
|
import xyz.alexcrea.cuanvil.packet.PacketManager
|
||||||
import xyz.alexcrea.cuanvil.packet.ProtocoLibWrapper
|
import xyz.alexcrea.cuanvil.packet.ProtocoLibWrapper
|
||||||
|
import xyz.alexcrea.cuanvil.update.Update_1_21
|
||||||
import xyz.alexcrea.cuanvil.util.Metrics
|
import xyz.alexcrea.cuanvil.util.Metrics
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileReader
|
import java.io.FileReader
|
||||||
|
|
||||||
|
|
@ -107,13 +107,15 @@ class CustomAnvil : JavaPlugin() {
|
||||||
val success = ConfigHolder.loadConfig()
|
val success = ConfigHolder.loadConfig()
|
||||||
if (!success) return
|
if (!success) return
|
||||||
|
|
||||||
|
// temporary: handle 1.21 update
|
||||||
|
Update_1_21.handleUpdate()
|
||||||
|
|
||||||
// Load gui constants //TODO maybe something better later
|
// Load gui constants //TODO maybe something better later
|
||||||
MainConfigGui.getInstance()
|
MainConfigGui.getInstance().init(this.packetManager)
|
||||||
GuiSharedConstant.loadConstants()
|
GuiSharedConstant.loadConstants()
|
||||||
|
|
||||||
// Load metrics
|
// Load metrics
|
||||||
val metric = Metrics(this, bstatsPluginId)
|
Metrics(this, bstatsPluginId)
|
||||||
MetricsUtil.addCustomMetric(metric)
|
|
||||||
|
|
||||||
// Add commands to reload the plugin
|
// Add commands to reload the plugin
|
||||||
prepareCommand()
|
prepareCommand()
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
|
||||||
|
|
||||||
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 {
|
||||||
|
|
@ -45,9 +44,6 @@ class ReloadExecutor : CommandExecutor {
|
||||||
UnitRepairConfigGui.INSTANCE.reloadValues()
|
UnitRepairConfigGui.INSTANCE.reloadValues()
|
||||||
CustomRecipeConfigGui.INSTANCE.reloadValues()
|
CustomRecipeConfigGui.INSTANCE.reloadValues()
|
||||||
|
|
||||||
// & update metric
|
|
||||||
MetricsUtil.testIfConfigIsDefault()
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|
|
||||||
|
|
@ -1,160 +0,0 @@
|
||||||
package xyz.alexcrea.cuanvil.util
|
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
|
||||||
import io.delilaheve.util.ConfigOptions
|
|
||||||
import org.bukkit.configuration.ConfigurationSection
|
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
|
||||||
|
|
||||||
object MetricsUtil {
|
|
||||||
|
|
||||||
private const val baseConfigHash = 1000387384
|
|
||||||
private const val enchantLimitsConfigHash = -275034280
|
|
||||||
private const val enchantValuesConfigHash = -17048020
|
|
||||||
private const val enchantConflictConfigHash = 546475833
|
|
||||||
private const val itemGroupsConfigHash = 1406650190
|
|
||||||
private const val unitRepairItemConfigHash = 536871958
|
|
||||||
private const val customAnvilCraftConfigHash = 0
|
|
||||||
private const val baseConfigPieName = "isDefaultBaseConfig"
|
|
||||||
private const val enchantLimitsConfigPieName = "isDefaultEnchantLimitsConfig"
|
|
||||||
private const val enchantValuesConfigPieName = "isDefaultEnchantValuesConfig"
|
|
||||||
private const val enchantConflictConfigPieName = "isDefaultEnchantConflictConfig"
|
|
||||||
private const val itemGroupsConfigPieName = "isDefaultItemGroupsConfig"
|
|
||||||
private const val unitRepairItemConfigPieName = "isDefaultUnitRepairItemConfig"
|
|
||||||
private const val customAnvilCraftConfigPieName = "isDefaultCustomAnvilCraftConfig"
|
|
||||||
private var isDefaultBaseConfig = true
|
|
||||||
private var isDefaultEnchantLimitsConfig = true
|
|
||||||
private var isDefaultEnchantValuesConfig = true
|
|
||||||
private var isDefaultEnchantConflictConfig = true
|
|
||||||
private var isDefaultItemGroupsConfig = true
|
|
||||||
private var isDefaultUnitRepairItemConfig = true
|
|
||||||
private var isDefaultCustomAnvilCraftConfig = true
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get hash of a key, value a pair of a configuration section
|
|
||||||
*/
|
|
||||||
private fun getHashFromKey(section: ConfigurationSection, key: String): Int {
|
|
||||||
// Key is assumend to exist
|
|
||||||
val resultHash = if (section.isConfigurationSection(key)) {
|
|
||||||
val sectionResult = getConfigurationHash(section.getConfigurationSection(key)!!)
|
|
||||||
key.hashCode() xor sectionResult
|
|
||||||
} else {
|
|
||||||
key.hashCode() xor section.getString(key).hashCode()
|
|
||||||
}
|
|
||||||
return resultHash.hashCode()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get hash of a configuration section
|
|
||||||
*/
|
|
||||||
private fun getConfigurationHash(section: ConfigurationSection): Int {
|
|
||||||
var resultHash = 0
|
|
||||||
for (key in section.getKeys(false)) {
|
|
||||||
resultHash = resultHash xor getHashFromKey(section, key)
|
|
||||||
}
|
|
||||||
return resultHash
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get hash value of the default config
|
|
||||||
*/
|
|
||||||
private fun testBaseConfig(defaultConfig: ConfigurationSection): Int {
|
|
||||||
var result = 0
|
|
||||||
for (key in ConfigOptions.getBasicConfigKeys()) {
|
|
||||||
result = result xor getHashFromKey(defaultConfig, key)
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test if the used configuration is the default config
|
|
||||||
*/
|
|
||||||
fun testIfConfigIsDefault() {
|
|
||||||
// Calculate hash of config
|
|
||||||
val baseConfig = testBaseConfig(ConfigHolder.DEFAULT_CONFIG.config)
|
|
||||||
val limitEnchantConfig = getHashFromKey(ConfigHolder.DEFAULT_CONFIG.config, ConfigOptions.ENCHANT_LIMIT_ROOT)
|
|
||||||
val enchantValueConfig = getHashFromKey(ConfigHolder.DEFAULT_CONFIG.config, ConfigOptions.ENCHANT_VALUES_ROOT)
|
|
||||||
val enchantConflictConfig = getConfigurationHash(ConfigHolder.CONFLICT_HOLDER.config)
|
|
||||||
val itemGroupConfig = getConfigurationHash(ConfigHolder.ITEM_GROUP_HOLDER.config)
|
|
||||||
val unitRepairConfig = getConfigurationHash(ConfigHolder.UNIT_REPAIR_HOLDER.config)
|
|
||||||
val customRecipeConfig = getConfigurationHash(ConfigHolder.CUSTOM_RECIPE_HOLDER.config)
|
|
||||||
// Test if default
|
|
||||||
isDefaultBaseConfig = baseConfigHash == baseConfig
|
|
||||||
isDefaultEnchantLimitsConfig = enchantLimitsConfigHash == limitEnchantConfig
|
|
||||||
isDefaultEnchantValuesConfig = enchantValuesConfigHash == enchantValueConfig
|
|
||||||
isDefaultEnchantConflictConfig = enchantConflictConfigHash == enchantConflictConfig
|
|
||||||
isDefaultItemGroupsConfig = itemGroupsConfigHash == itemGroupConfig
|
|
||||||
isDefaultUnitRepairItemConfig = unitRepairItemConfigHash == unitRepairConfig
|
|
||||||
isDefaultCustomAnvilCraftConfig = customAnvilCraftConfigHash == customRecipeConfig
|
|
||||||
// If not default and debug flag active, print the hash.
|
|
||||||
if (ConfigOptions.debugLog) {
|
|
||||||
if (!isDefaultBaseConfig) {
|
|
||||||
CustomAnvil.log("baseConfig: $baseConfig")
|
|
||||||
}
|
|
||||||
if (!isDefaultEnchantLimitsConfig) {
|
|
||||||
CustomAnvil.log("limitEnchantConfig: $limitEnchantConfig")
|
|
||||||
}
|
|
||||||
if (!isDefaultEnchantValuesConfig) {
|
|
||||||
CustomAnvil.log("enchantValueConfig: $enchantValueConfig")
|
|
||||||
}
|
|
||||||
if (!isDefaultEnchantConflictConfig) {
|
|
||||||
CustomAnvil.log("enchantConflictConfig: $enchantConflictConfig")
|
|
||||||
}
|
|
||||||
if (!isDefaultItemGroupsConfig) {
|
|
||||||
CustomAnvil.log("itemGroupConfig: $itemGroupConfig")
|
|
||||||
}
|
|
||||||
if (!isDefaultUnitRepairItemConfig) {
|
|
||||||
CustomAnvil.log("unitRepairConfig: $unitRepairConfig")
|
|
||||||
}
|
|
||||||
if (!isDefaultCustomAnvilCraftConfig) {
|
|
||||||
CustomAnvil.log("customRecipeConfig: $customRecipeConfig")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun notifyChange(holder: ConfigHolder, path: String) {
|
|
||||||
if (ConfigHolder.DEFAULT_CONFIG.equals(holder)) {
|
|
||||||
if (path.startsWith(ConfigOptions.ENCHANT_LIMIT_ROOT + ".")) {
|
|
||||||
isDefaultEnchantLimitsConfig = false
|
|
||||||
} else if (path.startsWith(ConfigOptions.ENCHANT_VALUES_ROOT + ".")) {
|
|
||||||
isDefaultEnchantValuesConfig = false
|
|
||||||
} else {
|
|
||||||
isDefaultBaseConfig = false
|
|
||||||
}
|
|
||||||
} else if (ConfigHolder.CONFLICT_HOLDER.equals(holder)) {
|
|
||||||
isDefaultEnchantConflictConfig = false
|
|
||||||
} else if (ConfigHolder.ITEM_GROUP_HOLDER.equals(holder)) {
|
|
||||||
isDefaultItemGroupsConfig = false
|
|
||||||
} else if (ConfigHolder.UNIT_REPAIR_HOLDER.equals(holder)) {
|
|
||||||
isDefaultUnitRepairItemConfig = false
|
|
||||||
} else if (ConfigHolder.CUSTOM_RECIPE_HOLDER.equals(holder)) {
|
|
||||||
isDefaultCustomAnvilCraftConfig = false
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addCustomMetric(metric: Metrics) {
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(baseConfigPieName) {
|
|
||||||
isDefaultBaseConfig.toString()
|
|
||||||
})
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(enchantLimitsConfigPieName) {
|
|
||||||
isDefaultEnchantLimitsConfig.toString()
|
|
||||||
})
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(enchantValuesConfigPieName) {
|
|
||||||
isDefaultEnchantValuesConfig.toString()
|
|
||||||
})
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(enchantConflictConfigPieName) {
|
|
||||||
isDefaultEnchantConflictConfig.toString()
|
|
||||||
})
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(itemGroupsConfigPieName) {
|
|
||||||
isDefaultItemGroupsConfig.toString()
|
|
||||||
})
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(unitRepairItemConfigPieName) {
|
|
||||||
isDefaultUnitRepairItemConfig.toString()
|
|
||||||
})
|
|
||||||
metric.addCustomChart(Metrics.SimplePie(customAnvilCraftConfigPieName) {
|
|
||||||
isDefaultCustomAnvilCraftConfig.toString()
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
main: io.delilaheve.CustomAnvil
|
main: io.delilaheve.CustomAnvil
|
||||||
name: CustomAnvil
|
name: CustomAnvil
|
||||||
prefix: "Custom Anvil"
|
prefix: "Custom Anvil"
|
||||||
version: 1.4.7
|
version: 1.4.8
|
||||||
description: Allow to customise anvil mechanics
|
description: Allow to customise anvil mechanics
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue