mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
migrate pickaxes, shovels and hoe to there own group
This commit is contained in:
parent
012e6b1368
commit
0adc84df89
3 changed files with 84 additions and 21 deletions
|
|
@ -1,8 +1,14 @@
|
||||||
package xyz.alexcrea.cuanvil.update.plugin;
|
package xyz.alexcrea.cuanvil.update.plugin;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import xyz.alexcrea.cuanvil.api.MaterialGroupApi;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
|
||||||
|
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -24,10 +30,66 @@ public class PUpdate_1_11_0 {
|
||||||
"bane_of_arthropods"
|
"bane_of_arthropods"
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
private static final Material[] PICKAXES = new Material[]{
|
||||||
FileConfiguration config = ConfigHolder.DEFAULT_CONFIG.getConfig();
|
Material.WOODEN_PICKAXE, Material.STONE_PICKAXE,
|
||||||
|
Material.IRON_PICKAXE, Material.DIAMOND_PICKAXE,
|
||||||
|
Material.GOLDEN_PICKAXE, Material.NETHERITE_PICKAXE
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Material[] SHOVELS = new Material[]{
|
||||||
|
Material.WOODEN_SHOVEL, Material.STONE_SHOVEL,
|
||||||
|
Material.IRON_SHOVEL, Material.DIAMOND_SHOVEL,
|
||||||
|
Material.GOLDEN_SHOVEL, Material.NETHERITE_SHOVEL
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final Material[] HOES = new Material[]{
|
||||||
|
Material.WOODEN_HOE, Material.STONE_HOE,
|
||||||
|
Material.IRON_HOE, Material.DIAMOND_HOE,
|
||||||
|
Material.GOLDEN_HOE, Material.NETHERITE_HOE
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||||
|
handleToolsMigration();
|
||||||
|
handleMaceMigration(toSave);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleToolsMigration() {
|
||||||
// We migrate the mace conflict if exist and unmodified
|
// We migrate the mace conflict if exist and unmodified
|
||||||
|
AbstractMaterialGroup tools = MaterialGroupApi.getGroup("tools");
|
||||||
|
|
||||||
|
migrateTools(tools, "pickaxes", PICKAXES);
|
||||||
|
migrateTools(tools, "shovels", SHOVELS);
|
||||||
|
migrateTools(tools, "hoes", HOES);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void migrateTools(
|
||||||
|
@Nullable AbstractMaterialGroup tools,
|
||||||
|
@NotNull String toolset,
|
||||||
|
@NotNull Material[] toolMats) {
|
||||||
|
|
||||||
|
// Create new group
|
||||||
|
IncludeGroup group = new IncludeGroup(toolset);
|
||||||
|
group.addAll(toolMats);
|
||||||
|
|
||||||
|
MaterialGroupApi.addMaterialGroup(group, true);
|
||||||
|
|
||||||
|
// Try to see if all the materials was in the tools group. and if so, replace it with the new group
|
||||||
|
if (tools == null) return;
|
||||||
|
if (!(tools instanceof IncludeGroup include)) return;
|
||||||
|
|
||||||
|
List<Material> mats = List.of(toolMats);
|
||||||
|
Set<Material> matSet = include.getNonGroupInheritedMaterials();
|
||||||
|
if (!matSet.containsAll(mats)) return;
|
||||||
|
|
||||||
|
mats.forEach(matSet::remove);
|
||||||
|
tools.addToPolicy(group);
|
||||||
|
MaterialGroupApi.writeMaterialGroup(tools);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleMaceMigration(@Nonnull Set<ConfigHolder> toSave) {
|
||||||
|
// We migrate the mace conflict if exist and unmodified
|
||||||
|
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
|
||||||
|
|
||||||
if (!config.isConfigurationSection("sword_enchant_conflict")) return;
|
if (!config.isConfigurationSection("sword_enchant_conflict")) return;
|
||||||
if (!config.isConfigurationSection("mace_enchant_conflict")) return;
|
if (!config.isConfigurationSection("mace_enchant_conflict")) return;
|
||||||
|
|
||||||
|
|
@ -48,7 +110,8 @@ public class PUpdate_1_11_0 {
|
||||||
ConfigurationSection sword_conflict = config.getConfigurationSection("sword_enchant_conflict");
|
ConfigurationSection sword_conflict = config.getConfigurationSection("sword_enchant_conflict");
|
||||||
if (sword_conflict.getInt("maxEnchantmentBeforeConflict", 0) != 1) return;
|
if (sword_conflict.getInt("maxEnchantmentBeforeConflict", 0) != 1) return;
|
||||||
|
|
||||||
if (sword_conflict.isList("notAffectedGroups") && !sword_conflict.getList("notAffectedGroups").isEmpty()) return;
|
if (sword_conflict.isList("notAffectedGroups") && !sword_conflict.getList("notAffectedGroups").isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
enchantments = sword_conflict.getStringList("enchantments");
|
enchantments = sword_conflict.getStringList("enchantments");
|
||||||
if (enchantments.size() != 3) return;
|
if (enchantments.size() != 3) return;
|
||||||
|
|
@ -61,7 +124,7 @@ public class PUpdate_1_11_0 {
|
||||||
"minecraft:density", "minecraft:breach");
|
"minecraft:density", "minecraft:breach");
|
||||||
|
|
||||||
config.set("mace_enchant_conflict", null);
|
config.set("mace_enchant_conflict", null);
|
||||||
|
toSave.add(ConfigHolder.DEFAULT_CONFIG);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -101,19 +101,6 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
|
|
||||||
private fun writeMissingGroups(){
|
private fun writeMissingGroups(){
|
||||||
// Write group that do not exist on custom anvil.
|
// Write group that do not exist on custom anvil.
|
||||||
// (Tools group regroup most of the tool items. I did not create a seperated group for theses)
|
|
||||||
val pickaxes = IncludeGroup("pickaxes")
|
|
||||||
pickaxes.addAll(Material.WOODEN_PICKAXE, Material.STONE_PICKAXE, Material.IRON_PICKAXE, Material.DIAMOND_PICKAXE, Material.GOLDEN_PICKAXE, Material.NETHERITE_PICKAXE)
|
|
||||||
MaterialGroupApi.addMaterialGroup(pickaxes)
|
|
||||||
|
|
||||||
val shovels = IncludeGroup("shovels")
|
|
||||||
shovels.addAll(Material.WOODEN_SHOVEL, Material.STONE_SHOVEL, Material.IRON_SHOVEL, Material.DIAMOND_SHOVEL, Material.GOLDEN_SHOVEL, Material.NETHERITE_SHOVEL)
|
|
||||||
MaterialGroupApi.addMaterialGroup(shovels)
|
|
||||||
|
|
||||||
val hoes = IncludeGroup("hoes")
|
|
||||||
hoes.addAll(Material.WOODEN_HOE, Material.STONE_HOE, Material.IRON_HOE, Material.DIAMOND_HOE, Material.GOLDEN_HOE, Material.NETHERITE_HOE)
|
|
||||||
MaterialGroupApi.addMaterialGroup(hoes)
|
|
||||||
|
|
||||||
val shield = IncludeGroup("shield")
|
val shield = IncludeGroup("shield")
|
||||||
shield.addToPolicy(Material.SHIELD)
|
shield.addToPolicy(Material.SHIELD)
|
||||||
MaterialGroupApi.addMaterialGroup(shield)
|
MaterialGroupApi.addMaterialGroup(shield)
|
||||||
|
|
@ -125,7 +112,6 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
val trinkets = IncludeGroup("trinkets")
|
val trinkets = IncludeGroup("trinkets")
|
||||||
trinkets.addToPolicy(Material.ROTTEN_FLESH)
|
trinkets.addToPolicy(Material.ROTTEN_FLESH)
|
||||||
MaterialGroupApi.addMaterialGroup(trinkets)
|
MaterialGroupApi.addMaterialGroup(trinkets)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>){
|
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>){
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ wearable:
|
||||||
groups:
|
groups:
|
||||||
- armors
|
- armors
|
||||||
|
|
||||||
tools:
|
pickaxes:
|
||||||
type: include
|
type: include
|
||||||
items:
|
items:
|
||||||
- wooden_pickaxe
|
- wooden_pickaxe
|
||||||
|
|
@ -135,19 +135,33 @@ tools:
|
||||||
- diamond_pickaxe
|
- diamond_pickaxe
|
||||||
- golden_pickaxe
|
- golden_pickaxe
|
||||||
- netherite_pickaxe
|
- netherite_pickaxe
|
||||||
|
|
||||||
|
shovels:
|
||||||
|
type: include
|
||||||
|
items:
|
||||||
- wooden_shovel
|
- wooden_shovel
|
||||||
- stone_shovel
|
- stone_shovel
|
||||||
- iron_shovel
|
- iron_shovel
|
||||||
- diamond_shovel
|
- diamond_shovel
|
||||||
- golden_shovel
|
- golden_shovel
|
||||||
- netherite_shovel
|
- netherite_shovel
|
||||||
|
|
||||||
|
hoes:
|
||||||
|
type: include
|
||||||
|
items:
|
||||||
- wooden_hoe
|
- wooden_hoe
|
||||||
- stone_hoe
|
- stone_hoe
|
||||||
- iron_hoe
|
- iron_hoe
|
||||||
- diamond_hoe
|
- diamond_hoe
|
||||||
- golden_hoe
|
- golden_hoe
|
||||||
- netherite_hoe
|
- netherite_hoe
|
||||||
|
|
||||||
|
tools:
|
||||||
|
type: include
|
||||||
groups:
|
groups:
|
||||||
|
- pickaxes
|
||||||
|
- shovels
|
||||||
|
- hoes
|
||||||
- axes
|
- axes
|
||||||
|
|
||||||
enchanted_book:
|
enchanted_book:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue