mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
fix turtle scule unit repair and force migratation of sweeping edge
This commit is contained in:
parent
45dd92e0f4
commit
f1c3cf46e1
11 changed files with 143 additions and 22 deletions
|
|
@ -2,10 +2,7 @@ package xyz.alexcrea.cuanvil.update;
|
|||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
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.minecraft.*;
|
||||
import xyz.alexcrea.cuanvil.update.plugin.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
|
@ -32,10 +29,12 @@ public class UpdateHandler {
|
|||
new Version(1, 8, 0), PUpdate_1_8_0::handleUpdate,
|
||||
new Version(1, 11, 0), PUpdate_1_11_0::handleUpdate,
|
||||
new Version(1, 15, 5), PUpdate_1_15_5::handleUpdate,
|
||||
new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate
|
||||
new Version(1, 15, 6), PUpdate_1_15_6::handleUpdate,
|
||||
new Version(1, 17, 7), PUpdate_1_17_7::handleUpdate
|
||||
);
|
||||
|
||||
private static final List<MCUpdate> mcUpdateMap = List.of(
|
||||
new Update_1_20_5(),
|
||||
new Update_1_21(),
|
||||
new Update_1_21_9(),
|
||||
new Update_1_21_11()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.update;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -33,4 +34,20 @@ public class UpdateUtils {
|
|||
|
||||
}
|
||||
|
||||
public static boolean removeFromList(FileConfiguration config, String path, String toRemove) {
|
||||
List<String> groups = new ArrayList<>(config.getStringList(path));
|
||||
if (!groups.remove(toRemove)) return false;
|
||||
|
||||
config.set(path, groups);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void mergeSections(ConfigurationSection source, ConfigurationSection target) {
|
||||
for (String key : source.getKeys(false)) {
|
||||
if(target.contains(key)) continue;
|
||||
target.set(key, source.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
package xyz.alexcrea.cuanvil.update.minecraft;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.update.Version;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.*;
|
||||
|
||||
public class Update_1_20_5 extends MCUpdate {
|
||||
|
||||
public Update_1_20_5() {
|
||||
super(new Version(1, 20, 5));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doUpdate() {
|
||||
var tosave = new HashSet<ConfigHolder>();
|
||||
updateName(tosave);
|
||||
|
||||
for (ConfigHolder holder : tosave) {
|
||||
holder.saveToDisk(true);
|
||||
}
|
||||
}
|
||||
|
||||
private static String SWEEPING_ENCHANTS = "restriction_sweeping_edge.enchantments";
|
||||
|
||||
public static void updateName(@NotNull Set<ConfigHolder> tosave) {
|
||||
var config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
||||
var unitConfig = ConfigHolder.UNIT_REPAIR_HOLDER.getConfig();
|
||||
var conflict = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||
|
||||
// Rename sweeping to sweeping_edge
|
||||
migrateEnchantLimit(config, "minecraft:sweeping");
|
||||
migrateEnchantLimit(config, "sweeping");
|
||||
|
||||
migrateEnchantValues(config, "minecraft:sweeping");
|
||||
migrateEnchantValues(config, "sweeping");
|
||||
|
||||
if (removeFromList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping"))
|
||||
addAbsentToList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping_edge");
|
||||
if (removeFromList(conflict, SWEEPING_ENCHANTS, "sweeping"))
|
||||
addAbsentToList(conflict, SWEEPING_ENCHANTS, "minecraft:sweeping_edge");
|
||||
|
||||
// Rename scute to turtle_scute
|
||||
migrateUnitRepair(unitConfig, "minecraft:scute");
|
||||
migrateUnitRepair(unitConfig, "scute");
|
||||
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.reload();
|
||||
|
||||
tosave.add(ConfigHolder.DEFAULT_CONFIG);
|
||||
tosave.add(ConfigHolder.UNIT_REPAIR_HOLDER);
|
||||
tosave.add(ConfigHolder.CONFLICT_HOLDER);
|
||||
}
|
||||
|
||||
private static void migrateEnchantLimit(FileConfiguration config, String path) {
|
||||
var finalPath = "enchant_limits." + path;
|
||||
if (!config.isInt(finalPath)) return;
|
||||
var value = config.getInt(finalPath);
|
||||
|
||||
config.set(finalPath, null);
|
||||
if (!config.contains("enchant_limits.minecraft:sweeping_edge")) return;
|
||||
if (!config.contains("enchant_limits.sweeping_edge")) return;
|
||||
|
||||
config.set("enchant_limits.minecraft:sweeping_edge", value);
|
||||
}
|
||||
|
||||
private static void migrateEnchantValues(FileConfiguration config, String path) {
|
||||
migrateEnchantValues(config, path, "item");
|
||||
migrateEnchantValues(config, path, "book");
|
||||
}
|
||||
|
||||
private static void migrateEnchantValues(FileConfiguration config, String path, String child) {
|
||||
var finalPath = "enchant_values." + path + "." + child;
|
||||
if (config.isInt(finalPath)) return;
|
||||
var value = config.getInt(finalPath);
|
||||
|
||||
config.set(finalPath, null);
|
||||
if (!config.contains("enchant_values.minecraft:sweeping_edge." + child)) return;
|
||||
if (!config.contains("enchant_values.sweeping_edge." + child)) return;
|
||||
|
||||
config.set("enchant_values.minecraft:sweeping_edge." + child, value);
|
||||
}
|
||||
|
||||
private static void migrateUnitRepair(FileConfiguration config, String path) {
|
||||
var section = config.getConfigurationSection(path);
|
||||
if (section == null) return;
|
||||
|
||||
config.set(path, null);
|
||||
var turtle_scute = config.getConfigurationSection("minecraft:turtle_scute");
|
||||
if (turtle_scute == null) config.set("minecraft:turtle_scute", section);
|
||||
else mergeSections(section, turtle_scute);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package xyz.alexcrea.cuanvil.update.plugin;
|
||||
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.update.UpdateUtils;
|
||||
import xyz.alexcrea.cuanvil.update.Version;
|
||||
import xyz.alexcrea.cuanvil.update.minecraft.Update_1_20_5;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Set;
|
||||
|
||||
public class PUpdate_1_17_7 {
|
||||
|
||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||
// fix only needed for 1.20.5 and above
|
||||
Version current = UpdateUtils.currentMinecraftVersion();
|
||||
if (new Version(1, 20, 5).greaterThan(current)) return;
|
||||
|
||||
Update_1_20_5.updateName(toSave);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue