mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
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:
parent
fc7e85529c
commit
ac7f975b02
4 changed files with 33 additions and 24 deletions
|
|
@ -9,10 +9,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui;
|
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConflictGui;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Anvil api for conflict registry.
|
* Custom Anvil api for conflict registry.
|
||||||
|
|
@ -82,8 +79,8 @@ public class ConflictAPI {
|
||||||
|
|
||||||
String basePath = name + ".";
|
String basePath = name + ".";
|
||||||
|
|
||||||
Set<String> enchantments = extractEnchantments(builder);
|
List<String> enchantments = extractEnchantments(builder);
|
||||||
Set<String> excludedGroups = builder.getExcludedGroupNames();
|
List<String> excludedGroups = new ArrayList<>(builder.getExcludedGroupNames());
|
||||||
if(!enchantments.isEmpty()) config.set(basePath + "enchantments", enchantments);
|
if(!enchantments.isEmpty()) config.set(basePath + "enchantments", enchantments);
|
||||||
if(!excludedGroups.isEmpty()) config.set(basePath + "notAffectedGroups", excludedGroups);
|
if(!excludedGroups.isEmpty()) config.set(basePath + "notAffectedGroups", excludedGroups);
|
||||||
if(builder.getMaxBeforeConflict() > 0) config.set(basePath + "maxEnchantmentBeforeConflict", builder.getMaxBeforeConflict());
|
if(builder.getMaxBeforeConflict() > 0) config.set(basePath + "maxEnchantmentBeforeConflict", builder.getMaxBeforeConflict());
|
||||||
|
|
@ -101,8 +98,8 @@ public class ConflictAPI {
|
||||||
* @return Builder's stored enchantment.
|
* @return Builder's stored enchantment.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
private static Set<String> extractEnchantments(@NotNull ConflictBuilder builder){
|
private static List<String> extractEnchantments(@NotNull ConflictBuilder builder){
|
||||||
Set<String> result = new HashSet<>(builder.getEnchantmentNames());
|
List<String> result = new ArrayList<>(builder.getEnchantmentNames());
|
||||||
for (NamespacedKey enchantmentKey : builder.getEnchantmentKeys()) {
|
for (NamespacedKey enchantmentKey : builder.getEnchantmentKeys()) {
|
||||||
result.add(enchantmentKey.getKey());
|
result.add(enchantmentKey.getKey());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -325,24 +325,24 @@ public class ConflictBuilder {
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public ConflictBuilder copy() {
|
public ConflictBuilder copy() {
|
||||||
ConflictBuilder clone = new ConflictBuilder(this.name, this.source);
|
ConflictBuilder copy = new ConflictBuilder(this.name, this.source);
|
||||||
|
|
||||||
setMaxBeforeConflict(this.maxBeforeConflict);
|
setMaxBeforeConflict(this.maxBeforeConflict);
|
||||||
|
|
||||||
// Set Enchantments
|
// Set Enchantments
|
||||||
for (NamespacedKey key : this.enchantmentKeys) {
|
for (NamespacedKey key : this.enchantmentKeys) {
|
||||||
clone.addEnchantment(key);
|
copy.addEnchantment(key);
|
||||||
}
|
}
|
||||||
for (String name : this.enchantmentNames) {
|
for (String enchantName : this.enchantmentNames) {
|
||||||
clone.addEnchantment(name);
|
copy.addEnchantment(enchantName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set Groups
|
// Set Groups
|
||||||
for (String name : this.excludedGroupNames) {
|
for (String groupName : this.excludedGroupNames) {
|
||||||
clone.addExcludedGroup(name);
|
copy.addExcludedGroup(groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return clone;
|
return copy;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Build a new Enchant conflict group by this builder.
|
* Build a new Enchant conflict group by this builder.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package xyz.alexcrea.cuanvil.api;
|
package xyz.alexcrea.cuanvil.api;
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
|
import io.delilaheve.util.ConfigOptions;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
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.group.ItemGroupManager;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.EnumSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Anvil api for material group registry.
|
* Custom Anvil api for material group registry.
|
||||||
|
|
@ -39,6 +37,7 @@ public class MaterialGroupApi {
|
||||||
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
|
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
|
||||||
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
||||||
if(itemGroupManager.get(group.getName()) != null) return false;
|
if(itemGroupManager.get(group.getName()) != null) return false;
|
||||||
|
itemGroupManager.getGroupMap().put(group.getName(), group);
|
||||||
|
|
||||||
if(!writeMaterialGroup(group, false)) return false;
|
if(!writeMaterialGroup(group, false)) return false;
|
||||||
|
|
||||||
|
|
@ -46,6 +45,10 @@ public class MaterialGroupApi {
|
||||||
GroupConfigGui.INSTANCE.updateValueForGeneric(includeGroup, true);
|
GroupConfigGui.INSTANCE.updateValueForGeneric(includeGroup, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(ConfigOptions.INSTANCE.getVerboseDebugLog()){
|
||||||
|
CustomAnvil.instance.getLogger().info("Registered group " + group.getName());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,10 +103,10 @@ public class MaterialGroupApi {
|
||||||
|
|
||||||
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, groupType);
|
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, groupType);
|
||||||
if(!materialSet.isEmpty()){
|
if(!materialSet.isEmpty()){
|
||||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSet);
|
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materialSet));
|
||||||
}
|
}
|
||||||
if(!groupSet.isEmpty()){
|
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");
|
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include");
|
||||||
if(!materials.isEmpty()){
|
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.
|
* Remove a material group.
|
||||||
* Caution ! It will not be removed from depending conflict or other material group at runtime.
|
* Caution ! It will not be removed from depending conflict or other material group at runtime.
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,8 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
|
|
||||||
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>){
|
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>){
|
||||||
for (enchantment in esEnchantments) {
|
for (enchantment in esEnchantments) {
|
||||||
val conflict = ConflictBuilder("restriction_${enchantment.key.key}")
|
val conflict = ConflictBuilder("restriction_${enchantment.key.key}", CustomAnvil.instance)
|
||||||
|
conflict.addEnchantment(enchantment)
|
||||||
|
|
||||||
// enchanted book is allowed in any case.
|
// enchanted book is allowed in any case.
|
||||||
conflict.addExcludedGroup("enchanted_book")
|
conflict.addExcludedGroup("enchanted_book")
|
||||||
|
|
@ -146,7 +147,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment){
|
private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment){
|
||||||
val conflict = ConflictBuilder("${enchantment1.name}_with_${enchantment2.name}_conflict")
|
val conflict = ConflictBuilder("${enchantment1.name}_with_${enchantment2.name}_conflict", CustomAnvil.instance)
|
||||||
|
|
||||||
conflict.addEnchantment(enchantment1).addEnchantment(enchantment2)
|
conflict.addEnchantment(enchantment1).addEnchantment(enchantment2)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue