mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Add support for 1.21
This commit is contained in:
parent
6d3cd32705
commit
a9c65dfddc
4 changed files with 136 additions and 1 deletions
|
|
@ -7,7 +7,9 @@ public enum EnchantmentProperties {
|
|||
BANE_OF_ARTHROPODS(EnchantmentRarity.UNCOMMON),
|
||||
BINDING_CURSE(EnchantmentRarity.VERY_RARE),
|
||||
BLAST_PROTECTION(EnchantmentRarity.RARE),
|
||||
BREACH(EnchantmentRarity.RARE),
|
||||
CHANNELING(EnchantmentRarity.VERY_RARE),
|
||||
DENSITY(EnchantmentRarity.UNCOMMON),
|
||||
DEPTH_STRIDER(EnchantmentRarity.RARE),
|
||||
EFFICIENCY(EnchantmentRarity.COMMON),
|
||||
FLAME(EnchantmentRarity.RARE),
|
||||
|
|
@ -42,7 +44,9 @@ public enum EnchantmentProperties {
|
|||
SWEEPING_EDGE(EnchantmentRarity.RARE),
|
||||
THORNS(EnchantmentRarity.VERY_RARE),
|
||||
UNBREAKING(EnchantmentRarity.UNCOMMON),
|
||||
VANISHING_CURSE(EnchantmentRarity.VERY_RARE);
|
||||
VANISHING_CURSE(EnchantmentRarity.VERY_RARE),
|
||||
WIND_BURST(EnchantmentRarity.RARE),
|
||||
;
|
||||
|
||||
private final EnchantmentRarity rarity;
|
||||
|
||||
|
|
|
|||
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,6 +13,7 @@ import xyz.alexcrea.cuanvil.listener.ChatEventListener
|
|||
import xyz.alexcrea.cuanvil.packet.NoProtocoLib
|
||||
import xyz.alexcrea.cuanvil.packet.PacketManager
|
||||
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.MetricsUtil
|
||||
import java.io.File
|
||||
|
|
@ -107,6 +108,9 @@ class CustomAnvil : JavaPlugin() {
|
|||
val success = ConfigHolder.loadConfig()
|
||||
if (!success) return
|
||||
|
||||
// temporary: handle 1.21 update
|
||||
Update_1_21.handleUpdate()
|
||||
|
||||
// Load gui constants //TODO maybe something better later
|
||||
MainConfigGui.getInstance().init(this.packetManager)
|
||||
GuiSharedConstant.loadConstants()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue