Fix value written as set in yml.

Fix material group not being added at to the registry.
Fix EnchantmentSquared restriction not having enchantment.
Added plugin's instance as conflict source.
This commit is contained in:
alexcrea 2024-07-11 00:52:13 +02:00
parent fc7e85529c
commit ac7f975b02
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 33 additions and 24 deletions

View file

@ -9,10 +9,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* Custom Anvil api for conflict registry.
@ -82,8 +79,8 @@ public class ConflictAPI {
String basePath = name + ".";
Set<String> enchantments = extractEnchantments(builder);
Set<String> excludedGroups = builder.getExcludedGroupNames();
List<String> enchantments = extractEnchantments(builder);
List<String> excludedGroups = new ArrayList<>(builder.getExcludedGroupNames());
if(!enchantments.isEmpty()) config.set(basePath + "enchantments", enchantments);
if(!excludedGroups.isEmpty()) config.set(basePath + "notAffectedGroups", excludedGroups);
if(builder.getMaxBeforeConflict() > 0) config.set(basePath + "maxEnchantmentBeforeConflict", builder.getMaxBeforeConflict());
@ -101,8 +98,8 @@ public class ConflictAPI {
* @return Builder's stored enchantment.
*/
@NotNull
private static Set<String> extractEnchantments(@NotNull ConflictBuilder builder){
Set<String> result = new HashSet<>(builder.getEnchantmentNames());
private static List<String> extractEnchantments(@NotNull ConflictBuilder builder){
List<String> result = new ArrayList<>(builder.getEnchantmentNames());
for (NamespacedKey enchantmentKey : builder.getEnchantmentKeys()) {
result.add(enchantmentKey.getKey());
}

View file

@ -325,24 +325,24 @@ public class ConflictBuilder {
*/
@NotNull
public ConflictBuilder copy() {
ConflictBuilder clone = new ConflictBuilder(this.name, this.source);
ConflictBuilder copy = new ConflictBuilder(this.name, this.source);
setMaxBeforeConflict(this.maxBeforeConflict);
// Set Enchantments
for (NamespacedKey key : this.enchantmentKeys) {
clone.addEnchantment(key);
copy.addEnchantment(key);
}
for (String name : this.enchantmentNames) {
clone.addEnchantment(name);
for (String enchantName : this.enchantmentNames) {
copy.addEnchantment(enchantName);
}
// Set Groups
for (String name : this.excludedGroupNames) {
clone.addExcludedGroup(name);
for (String groupName : this.excludedGroupNames) {
copy.addExcludedGroup(groupName);
}
return clone;
return copy;
}
/**
* Build a new Enchant conflict group by this builder.

View file

@ -1,6 +1,7 @@
package xyz.alexcrea.cuanvil.api;
import io.delilaheve.CustomAnvil;
import io.delilaheve.util.ConfigOptions;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.FileConfiguration;
@ -13,10 +14,7 @@ import xyz.alexcrea.cuanvil.group.IncludeGroup;
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* Custom Anvil api for material group registry.
@ -39,6 +37,7 @@ public class MaterialGroupApi {
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
if(itemGroupManager.get(group.getName()) != null) return false;
itemGroupManager.getGroupMap().put(group.getName(), group);
if(!writeMaterialGroup(group, false)) return false;
@ -46,6 +45,10 @@ public class MaterialGroupApi {
GroupConfigGui.INSTANCE.updateValueForGeneric(includeGroup, true);
}
if(ConfigOptions.INSTANCE.getVerboseDebugLog()){
CustomAnvil.instance.getLogger().info("Registered group " + group.getName());
}
return true;
}
@ -100,10 +103,10 @@ public class MaterialGroupApi {
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, groupType);
if(!materialSet.isEmpty()){
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSet);
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materialSet));
}
if(!groupSet.isEmpty()){
config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, groupSet);
config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, materialGroupSEtToStringList(groupSet));
}
}
@ -116,11 +119,19 @@ public class MaterialGroupApi {
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include");
if(!materials.isEmpty()){
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materials);
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materials));
}
}
public static List<String> materialSetToStringList(@NotNull Set<Material> materials){
return materials.stream().map(material -> material.getKey().getKey().toLowerCase()).toList();
}
public static List<String> materialGroupSEtToStringList(@NotNull Set<AbstractMaterialGroup> groups){
return groups.stream().map(AbstractMaterialGroup::getName).toList();
}
/**
* Remove a material group.
* Caution ! It will not be removed from depending conflict or other material group at runtime.