renamed material group to item type group

This commit is contained in:
alexcrea 2025-07-27 08:06:18 +02:00
parent 0516b5daaa
commit dedca9b940
Signed by: alexcrea
GPG key ID: E346CD16413450E3
19 changed files with 139 additions and 142 deletions

View file

@ -276,7 +276,7 @@ public class ConflictBuilder {
* @return this conflict builder instance. * @return this conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group) { public ConflictBuilder addExcludedGroup(@NotNull AbstractItemTypeGroup group) {
return addExcludedGroup(group.getName()); return addExcludedGroup(group.getName());
} }
@ -315,7 +315,7 @@ public class ConflictBuilder {
* @return This conflict builder instance. * @return This conflict builder instance.
*/ */
@NotNull @NotNull
public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group) { public ConflictBuilder removeExcludedGroup(@NotNull AbstractItemTypeGroup group) {
return removeExcludedGroup(group.getName()); return removeExcludedGroup(group.getName());
} }
@ -352,7 +352,7 @@ public class ConflictBuilder {
* @return An Enchant conflict group with this builder parameters. * @return An Enchant conflict group with this builder parameters.
*/ */
public EnchantConflictGroup build() { public EnchantConflictGroup build() {
AbstractMaterialGroup materials = extractGroups(); AbstractItemTypeGroup materials = extractGroups();
EnchantConflictGroup conflict = new EnchantConflictGroup(getName(), materials, getMaxBeforeConflict()); EnchantConflictGroup conflict = new EnchantConflictGroup(getName(), materials, getMaxBeforeConflict());
appendEnchantments(conflict); appendEnchantments(conflict);
@ -436,12 +436,12 @@ public class ConflictBuilder {
* *
* @return The abstract material group from the builder. * @return The abstract material group from the builder.
*/ */
protected AbstractMaterialGroup extractGroups() { protected AbstractItemTypeGroup extractGroups() {
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
IncludeGroup group = new IncludeGroup(EnchantConflictManager.DEFAULT_GROUP_NAME); IncludeItemTypeGroup group = new IncludeItemTypeGroup(EnchantConflictManager.DEFAULT_GROUP_NAME);
for (String groupName : getExcludedGroupNames()) { for (String groupName : getExcludedGroupNames()) {
AbstractMaterialGroup materialGroup = itemGroupManager.get(groupName); AbstractItemTypeGroup materialGroup = itemGroupManager.get(groupName);
if (materialGroup == null) { if (materialGroup == null) {
CustomAnvil.instance.getLogger().warning("Material group " + groupName + " do not exist but is ask by conflict " + getName()); CustomAnvil.instance.getLogger().warning("Material group " + groupName + " do not exist but is ask by conflict " + getName());

View file

@ -8,9 +8,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.dependency.DependencyManager; import xyz.alexcrea.cuanvil.dependency.DependencyManager;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup; import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.ExcludeGroup; import xyz.alexcrea.cuanvil.group.ExcludeItemTypeGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
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;
@ -36,7 +36,7 @@ public class MaterialGroupApi {
* @param group The group to add * @param group The group to add
* @return true if successful. * @return true if successful.
*/ */
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group) { public static boolean addMaterialGroup(@NotNull AbstractItemTypeGroup group) {
return addMaterialGroup(group, false); return addMaterialGroup(group, false);
} }
@ -49,7 +49,7 @@ public class MaterialGroupApi {
* @param overrideDeleted If we should write even if the group was previously deleted. * @param overrideDeleted If we should write even if the group was previously deleted.
* @return true if successful. * @return true if successful.
*/ */
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group, boolean overrideDeleted) { public static boolean addMaterialGroup(@NotNull AbstractItemTypeGroup group, boolean overrideDeleted) {
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
// Test if it exists/existed // Test if it exists/existed
@ -61,7 +61,7 @@ public class MaterialGroupApi {
if (!writeMaterialGroup(group, false)) return false; if (!writeMaterialGroup(group, false)) return false;
if (group instanceof IncludeGroup includeGroup) { if (group instanceof IncludeItemTypeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance(); GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
if (configGui != null) configGui.updateValueForGeneric(includeGroup, true); if (configGui != null) configGui.updateValueForGeneric(includeGroup, true);
} }
@ -76,25 +76,25 @@ public class MaterialGroupApi {
/** /**
* Write a material group to the config file and plan an update of groups. * Write a material group to the config file and plan an update of groups.
* <p> * <p>
* You may want to use {@link #addMaterialGroup(AbstractMaterialGroup)} instead as it is more performance in most case as this function will reload every conflict. * You may want to use {@link #addMaterialGroup(AbstractItemTypeGroup)} instead as it is more performance in most case as this function will reload every conflict.
* *
* @param group the group to write * @param group the group to write
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group) { public static boolean writeMaterialGroup(@NotNull AbstractItemTypeGroup group) {
return writeMaterialGroup(group, true); return writeMaterialGroup(group, true);
} }
/** /**
* Write a material group to the config file. * Write a material group to the config file.
* <p> * <p>
* You should use {@link #addMaterialGroup(AbstractMaterialGroup)} or {@link #writeMaterialGroup(AbstractMaterialGroup)} instead * You should use {@link #addMaterialGroup(AbstractItemTypeGroup)} or {@link #writeMaterialGroup(AbstractItemTypeGroup)} instead
* *
* @param group the group to write * @param group the group to write
* @param updatePlanned if we should plan a global update for material groups * @param updatePlanned if we should plan a global update for material groups
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group, boolean updatePlanned) { public static boolean writeMaterialGroup(@NotNull AbstractItemTypeGroup group, boolean updatePlanned) {
String name = group.getName(); String name = group.getName();
if (name.contains(".")) { if (name.contains(".")) {
CustomAnvil.instance.getLogger().warning("Group " + name + " contain . in its name but should not. this material group is ignored."); CustomAnvil.instance.getLogger().warning("Group " + name + " contain . in its name but should not. this material group is ignored.");
@ -102,9 +102,9 @@ public class MaterialGroupApi {
} }
boolean changed; boolean changed;
if (group instanceof IncludeGroup includeGroup) { if (group instanceof IncludeItemTypeGroup includeGroup) {
changed = writeKnownGroup("include", includeGroup); changed = writeKnownGroup("include", includeGroup);
} else if (group instanceof ExcludeGroup excludeGroup) { } else if (group instanceof ExcludeItemTypeGroup excludeGroup) {
//TODO work on it when exclude group is reworked //TODO work on it when exclude group is reworked
throw new UnsupportedOperationException("exclude group is temporarily disable for the time being. sorry"); throw new UnsupportedOperationException("exclude group is temporarily disable for the time being. sorry");
// This code do not do what is intended ? idk why do it exist // This code do not do what is intended ? idk why do it exist
@ -120,12 +120,12 @@ public class MaterialGroupApi {
return true; return true;
} }
private static boolean writeKnownGroup(@NotNull String groupType, @NotNull AbstractMaterialGroup group) { private static boolean writeKnownGroup(@NotNull String groupType, @NotNull AbstractItemTypeGroup group) {
FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
String basePath = group.getName() + "."; String basePath = group.getName() + ".";
Set<ItemType> itemSets = group.getNonGroupInheritedMaterials(); Set<ItemType> itemSets = group.getNonGroupInheritedMaterials();
Set<AbstractMaterialGroup> groupSet = group.getGroups(); Set<AbstractItemTypeGroup> groupSet = group.getGroups();
boolean empty = true; boolean empty = true;
if (!itemSets.isEmpty()) { if (!itemSets.isEmpty()) {
@ -150,7 +150,7 @@ public class MaterialGroupApi {
return true; return true;
} }
private static boolean writeUnknownGroup(@NotNull AbstractMaterialGroup group) { private static boolean writeUnknownGroup(@NotNull AbstractItemTypeGroup group) {
FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
String basePath = group.getName() + "."; String basePath = group.getName() + ".";
@ -168,8 +168,8 @@ public class MaterialGroupApi {
return types.stream().map(item -> item.getKey().getKey().toLowerCase()).toList(); return types.stream().map(item -> item.getKey().getKey().toLowerCase()).toList();
} }
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) { public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractItemTypeGroup> groups) {
return groups.stream().map(AbstractMaterialGroup::getName).toList(); return groups.stream().map(AbstractItemTypeGroup::getName).toList();
} }
/** /**
@ -180,9 +180,9 @@ public class MaterialGroupApi {
* @param group The recipe to remove * @param group The recipe to remove
* @return True if the group was present. * @return True if the group was present.
*/ */
public static boolean removeGroup(@NotNull AbstractMaterialGroup group) { public static boolean removeGroup(@NotNull AbstractItemTypeGroup group) {
// Remove from registry // Remove from registry
AbstractMaterialGroup removed = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName()); AbstractItemTypeGroup removed = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName());
if (removed == null) return false; if (removed == null) return false;
// Delete and save to file // Delete and save to file
@ -190,7 +190,7 @@ public class MaterialGroupApi {
prepareSaveTask(); prepareSaveTask();
// Remove from gui // Remove from gui
if (group instanceof IncludeGroup includeGroup) { if (group instanceof IncludeItemTypeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance(); GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
if (configGui != null) configGui.removeGeneric(includeGroup); if (configGui != null) configGui.removeGeneric(includeGroup);
} }
@ -234,7 +234,7 @@ public class MaterialGroupApi {
* @return the abstract group of this name. null if not found. * @return the abstract group of this name. null if not found.
*/ */
@Nullable @Nullable
public static AbstractMaterialGroup getGroup(@NotNull String groupName) { public static AbstractItemTypeGroup getGroup(@NotNull String groupName) {
return ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().get(groupName); return ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().get(groupName);
} }
@ -244,7 +244,7 @@ public class MaterialGroupApi {
* @return An immutable map of group name as its key and group as mapped value. * @return An immutable map of group name as its key and group as mapped value.
*/ */
@NotNull @NotNull
public static Map<String, AbstractMaterialGroup> getRegisteredGroups() { public static Map<String, AbstractItemTypeGroup> getRegisteredGroups() {
return Collections.unmodifiableMap(ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap()); return Collections.unmodifiableMap(ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap());
} }

View file

@ -1,6 +1,6 @@
package xyz.alexcrea.cuanvil.gui.config; package xyz.alexcrea.cuanvil.gui.config;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup; import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.ArrayList; import java.util.ArrayList;
@ -10,22 +10,22 @@ import java.util.Set;
public interface SelectGroupContainer { public interface SelectGroupContainer {
Set<AbstractMaterialGroup> getSelectedGroups(); Set<AbstractItemTypeGroup> getSelectedGroups();
boolean setSelectedGroups(Set<AbstractMaterialGroup> groups); boolean setSelectedGroups(Set<AbstractItemTypeGroup> groups);
Set<AbstractMaterialGroup> illegalGroups(); Set<AbstractItemTypeGroup> illegalGroups();
static List<String> getGroupLore(SelectGroupContainer container, String containerType, String groupAction){ static List<String> getGroupLore(SelectGroupContainer container, String containerType, String groupAction){
// Prepare group lore // Prepare group lore
ArrayList<String> groupLore = new ArrayList<>(); ArrayList<String> groupLore = new ArrayList<>();
groupLore.add("§7Allow you to select a list of §3Groups §7that this " + containerType + " should " + groupAction); groupLore.add("§7Allow you to select a list of §3Groups §7that this " + containerType + " should " + groupAction);
Set<AbstractMaterialGroup> grouos = container.getSelectedGroups(); Set<AbstractItemTypeGroup> grouos = container.getSelectedGroups();
if (grouos.isEmpty()) { if (grouos.isEmpty()) {
groupLore.add("§7There is no "+groupAction+"d group for this "+containerType+"."); groupLore.add("§7There is no "+groupAction+"d group for this "+containerType+".");
} else { } else {
groupLore.add("§7List of "+groupAction+"d groups for this "+containerType+":"); groupLore.add("§7List of "+groupAction+"d groups for this "+containerType+":");
Iterator<AbstractMaterialGroup> groupIterator = grouos.iterator(); Iterator<AbstractItemTypeGroup> groupIterator = grouos.iterator();
boolean greaterThanMax = grouos.size() > 5; boolean greaterThanMax = grouos.size() > 5;
int maxindex = (greaterThanMax ? 4 : grouos.size()); int maxindex = (greaterThanMax ? 4 : grouos.size());

View file

@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup; import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.list.elements.EnchantConflictSubSettingGui; import xyz.alexcrea.cuanvil.gui.config.list.elements.EnchantConflictSubSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
@ -48,7 +48,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
// Create new empty conflict and display it to the admin // Create new empty conflict and display it to the admin
EnchantConflictGroup conflict = new EnchantConflictGroup( EnchantConflictGroup conflict = new EnchantConflictGroup(
name, name,
new IncludeGroup("new_group"), new IncludeItemTypeGroup("new_group"),
0); 0);
ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict); ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);

View file

@ -8,9 +8,9 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup; import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.GroupType; import xyz.alexcrea.cuanvil.group.GroupType;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import xyz.alexcrea.cuanvil.group.ItemGroupManager; import xyz.alexcrea.cuanvil.group.ItemGroupManager;
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui; import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.list.elements.GroupConfigSubSettingGui; import xyz.alexcrea.cuanvil.gui.config.list.elements.GroupConfigSubSettingGui;
@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> { public class GroupConfigGui extends MappedGuiListConfigGui<IncludeItemTypeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
private static GroupConfigGui INSTANCE; private static GroupConfigGui INSTANCE;
@ -44,7 +44,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
} }
@Override @Override
protected ItemStack createItemForGeneric(IncludeGroup group) { protected ItemStack createItemForGeneric(IncludeItemTypeGroup group) {
ItemStack item = group.getRepresentativeMaterial().createItemStack(); ItemStack item = group.getRepresentativeMaterial().createItemStack();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
assert meta != null; assert meta != null;
@ -62,19 +62,19 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
} }
@Override @Override
protected Collection<IncludeGroup> getEveryDisplayableInstanceOfGeneric() { protected Collection<IncludeItemTypeGroup> getEveryDisplayableInstanceOfGeneric() {
ArrayList<IncludeGroup> includeGroups = new ArrayList<>(); ArrayList<IncludeItemTypeGroup> includeGroups = new ArrayList<>();
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) { for (AbstractItemTypeGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
if (group instanceof IncludeGroup) { if (group instanceof IncludeItemTypeGroup) {
includeGroups.add((IncludeGroup) group); includeGroups.add((IncludeItemTypeGroup) group);
} }
} }
return includeGroups; return includeGroups;
} }
@Override @Override
protected LazyElement<GroupConfigSubSettingGui> newInstanceOfGui(IncludeGroup group, GuiItem item) { protected LazyElement<GroupConfigSubSettingGui> newInstanceOfGui(IncludeItemTypeGroup group, GuiItem item) {
return new LazyElement<>(item, () -> new GroupConfigSubSettingGui(this, group)); return new LazyElement<>(item, () -> new GroupConfigSubSettingGui(this, group));
} }
@ -84,14 +84,14 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
} }
@Override @Override
protected IncludeGroup createAndSaveNewEmptyGeneric(String name) { protected IncludeItemTypeGroup createAndSaveNewEmptyGeneric(String name) {
ItemGroupManager manager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager manager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
if (manager.getGroupMap().containsKey(name)) return null; if (manager.getGroupMap().containsKey(name)) return null;
ConfigurationSection config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig(); ConfigurationSection config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
config.set(name + "." + ItemGroupManager.GROUP_TYPE_PATH, GroupType.INCLUDE.getGroupID()); config.set(name + "." + ItemGroupManager.GROUP_TYPE_PATH, GroupType.INCLUDE.getGroupID());
return (IncludeGroup) manager.createGroup(config, name); return (IncludeItemTypeGroup) manager.createGroup(config, name);
} }
} }

View file

@ -11,7 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.enchant.CAEnchantment; import xyz.alexcrea.cuanvil.enchant.CAEnchantment;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup; import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup; import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.group.EnchantConflictManager; import xyz.alexcrea.cuanvil.group.EnchantConflictManager;
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer; import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
@ -282,12 +282,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Select group container methods // Select group container methods
@Override @Override
public Set<AbstractMaterialGroup> getSelectedGroups() { public Set<AbstractItemTypeGroup> getSelectedGroups() {
return this.enchantConflict.getCantConflictGroup().getGroups(); return this.enchantConflict.getCantConflictGroup().getGroups();
} }
@Override @Override
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) { public boolean setSelectedGroups(Set<AbstractItemTypeGroup> groups) {
if (!this.shouldWork) { if (!this.shouldWork) {
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.toString() + " groups but sub config is destroyed"); CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.toString() + " groups but sub config is destroyed");
return false; return false;
@ -299,7 +299,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Save on file configuration // Save on file configuration
String[] groupsNames = new String[groups.size()]; String[] groupsNames = new String[groups.size()];
int index = 0; int index = 0;
for (AbstractMaterialGroup group : groups) { for (AbstractItemTypeGroup group : groups) {
groupsNames[index++] = group.getName(); groupsNames[index++] = group.getName();
} }
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict + ".notAffectedGroups", groupsNames); ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict + ".notAffectedGroups", groupsNames);
@ -319,7 +319,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
} }
@Override @Override
public Set<AbstractMaterialGroup> illegalGroups() { public Set<AbstractItemTypeGroup> illegalGroups() {
return Collections.emptySet(); return Collections.emptySet();
} }

View file

@ -33,13 +33,13 @@ import java.util.function.Supplier;
public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implements SelectGroupContainer, SelectItemTypeContainer { public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implements SelectGroupContainer, SelectItemTypeContainer {
private final GroupConfigGui parent; private final GroupConfigGui parent;
private final IncludeGroup group; private final IncludeItemTypeGroup group;
private final PatternPane pane; private final PatternPane pane;
private boolean usable = true; private boolean usable = true;
public GroupConfigSubSettingGui( public GroupConfigSubSettingGui(
@NotNull GroupConfigGui parent, @NotNull GroupConfigGui parent,
@NotNull IncludeGroup group) { @NotNull IncludeItemTypeGroup group) {
super(3, super(3,
"§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §rConfig"); "§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §rConfig");
this.parent = parent; this.parent = parent;
@ -184,12 +184,12 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
} }
// return a string containing every instance of where this group is used // return a string containing every instance of where this group is used
public static List<String> getUsedLocations(AbstractMaterialGroup group) { public static List<String> getUsedLocations(AbstractItemTypeGroup group) {
ArrayList<String> usageList = new ArrayList<>(); ArrayList<String> usageList = new ArrayList<>();
// Test used by another group // Test used by another group
ItemGroupManager groupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager groupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
for (AbstractMaterialGroup otherGroup : groupManager.getGroupMap().values()) { for (AbstractItemTypeGroup otherGroup : groupManager.getGroupMap().values()) {
if (otherGroup.getGroups().contains(group)) { if (otherGroup.getGroups().contains(group)) {
usageList.add("group " + otherGroup.getName()); usageList.add("group " + otherGroup.getName());
} }
@ -270,12 +270,12 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// ---------------------------- // ----------------------------
@Override @Override
public Set<AbstractMaterialGroup> getSelectedGroups() { public Set<AbstractItemTypeGroup> getSelectedGroups() {
return this.group.getGroups(); return this.group.getGroups();
} }
@Override @Override
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) { public boolean setSelectedGroups(Set<AbstractItemTypeGroup> groups) {
// update group and referencing groups // update group and referencing groups
updateGroup(this.group, groups); updateGroup(this.group, groups);
@ -287,7 +287,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
return true; return true;
} }
private void updateGroup(@NotNull AbstractMaterialGroup group, Set<AbstractMaterialGroup> groups) { private void updateGroup(@NotNull AbstractItemTypeGroup group, Set<AbstractItemTypeGroup> groups) {
// Set live configuration // Set live configuration
group.setGroups(groups); group.setGroups(groups);
@ -295,7 +295,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
groups = group.getGroups(); // Maybe some group may have been rejected groups = group.getGroups(); // Maybe some group may have been rejected
String[] groupNames = new String[groups.size()]; String[] groupNames = new String[groups.size()];
int index = 0; int index = 0;
for (AbstractMaterialGroup otherGroup : groups) { for (AbstractItemTypeGroup otherGroup : groups) {
groupNames[index++] = otherGroup.getName(); groupNames[index++] = otherGroup.getName();
} }
@ -308,10 +308,10 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
} }
@Override @Override
public Set<AbstractMaterialGroup> illegalGroups() { public Set<AbstractItemTypeGroup> illegalGroups() {
Set<AbstractMaterialGroup> illegal = new HashSet<>(); Set<AbstractItemTypeGroup> illegal = new HashSet<>();
for (AbstractMaterialGroup otherGroup : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) { for (AbstractItemTypeGroup otherGroup : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
if (otherGroup.isReferencing(this.group)) { if (otherGroup.isReferencing(this.group)) {
illegal.add(otherGroup); illegal.add(otherGroup);
} }
@ -372,24 +372,24 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// End of SelectMaterialContainer related methods // End of SelectMaterialContainer related methods
// ---------------------------- // ----------------------------
private void updateDirectReferencingGroups(AbstractMaterialGroup referenceTo) { private void updateDirectReferencingGroups(AbstractItemTypeGroup referenceTo) {
Collection<AbstractMaterialGroup> everyStoredGroups = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values(); Collection<AbstractItemTypeGroup> everyStoredGroups = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values();
List<EnchantConflictGroup> everyConflicts = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList(); List<EnchantConflictGroup> everyConflicts = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
HashSet<AbstractMaterialGroup> toUpdate = new HashSet<>(); HashSet<AbstractItemTypeGroup> toUpdate = new HashSet<>();
HashSet<AbstractMaterialGroup> updateFuture = new HashSet<>(); HashSet<AbstractItemTypeGroup> updateFuture = new HashSet<>();
HashSet<AbstractMaterialGroup> conflictGroupPlanned = new HashSet<>(); HashSet<AbstractItemTypeGroup> conflictGroupPlanned = new HashSet<>();
updateFuture.add(referenceTo); updateFuture.add(referenceTo);
while (!updateFuture.isEmpty()) { while (!updateFuture.isEmpty()) {
HashSet<AbstractMaterialGroup> temp = updateFuture; HashSet<AbstractItemTypeGroup> temp = updateFuture;
updateFuture = toUpdate; updateFuture = toUpdate;
updateFuture.clear(); updateFuture.clear();
toUpdate = temp; toUpdate = temp;
for (AbstractMaterialGroup testGroup : toUpdate) { for (AbstractItemTypeGroup testGroup : toUpdate) {
// Update other stored group // Update other stored group
for (AbstractMaterialGroup otherGroup : everyStoredGroups) { for (AbstractItemTypeGroup otherGroup : everyStoredGroups) {
if (otherGroup.getGroups().contains(testGroup)) { if (otherGroup.getGroups().contains(testGroup)) {
otherGroup.updateMaterials(); otherGroup.updateMaterials();
updateFuture.add(otherGroup); updateFuture.add(otherGroup);
@ -398,22 +398,22 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// plan update for conflict groups // plan update for conflict groups
for (EnchantConflictGroup everyConflict : everyConflicts) { for (EnchantConflictGroup everyConflict : everyConflicts) {
AbstractMaterialGroup conflictGroup = everyConflict.getCantConflictGroup(); AbstractItemTypeGroup conflictGroup = everyConflict.getCantConflictGroup();
if (conflictGroup.getGroups().contains(testGroup)) { if (conflictGroup.getGroups().contains(testGroup)) {
conflictGroupPlanned.add(conflictGroup); conflictGroupPlanned.add(conflictGroup);
} }
} }
// Update parent & local by extension // Update parent & local by extension
if (testGroup instanceof IncludeGroup) { if (testGroup instanceof IncludeItemTypeGroup) {
this.parent.updateValueForGeneric((IncludeGroup) testGroup, false); this.parent.updateValueForGeneric((IncludeItemTypeGroup) testGroup, false);
} }
} }
} }
this.parent.update(); this.parent.update();
// Update conflict group // Update conflict group
for (AbstractMaterialGroup conflictGroup : conflictGroupPlanned) { for (AbstractItemTypeGroup conflictGroup : conflictGroupPlanned) {
conflictGroup.updateMaterials(); conflictGroup.updateMaterials();
} }

View file

@ -14,7 +14,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup; import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer; import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
import xyz.alexcrea.cuanvil.gui.config.list.ElementListConfigGui; import xyz.alexcrea.cuanvil.gui.config.list.ElementListConfigGui;
@ -32,7 +32,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
SelectGroupContainer groupContainer; SelectGroupContainer groupContainer;
int page; int page;
Set<AbstractMaterialGroup> selectedGroups; Set<AbstractItemTypeGroup> selectedGroups;
public GroupSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectGroupContainer groupContainer, int page) { public GroupSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectGroupContainer groupContainer, int page) {
super(6, title, parent); super(6, title, parent);
@ -71,8 +71,8 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
filledEnchant.align(OutlinePane.Alignment.BEGIN); filledEnchant.align(OutlinePane.Alignment.BEGIN);
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL); filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
Set<AbstractMaterialGroup> illegalGroup = this.groupContainer.illegalGroups(); Set<AbstractItemTypeGroup> illegalGroup = this.groupContainer.illegalGroups();
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) { for (AbstractItemTypeGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
if (illegalGroup.contains(group)) { if (illegalGroup.contains(group)) {
continue; continue;
} }
@ -83,7 +83,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
} }
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group) { private GuiItem getGuiItemFromGroup(AbstractItemTypeGroup group) {
boolean isIn = this.selectedGroups.contains(group); boolean isIn = this.selectedGroups.contains(group);
ItemStack item = group.getRepresentativeMaterial().createItemStack(); ItemStack item = group.getRepresentativeMaterial().createItemStack();
@ -122,7 +122,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
item.setItemMeta(meta); item.setItemMeta(meta);
} }
private Consumer<InventoryClickEvent> getGroupItemConsumer(AbstractMaterialGroup group, GuiItem guiItem) { private Consumer<InventoryClickEvent> getGroupItemConsumer(AbstractItemTypeGroup group, GuiItem guiItem) {
return event -> { return event -> {
event.setCancelled(true); event.setCancelled(true);
@ -148,7 +148,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
@Override @Override
public boolean hadChange() { public boolean hadChange() {
Set<AbstractMaterialGroup> baseGroup = this.groupContainer.getSelectedGroups(); Set<AbstractItemTypeGroup> baseGroup = this.groupContainer.getSelectedGroups();
return baseGroup.size() != this.selectedGroups.size() || return baseGroup.size() != this.selectedGroups.size() ||
!baseGroup.containsAll(this.selectedGroups); !baseGroup.containsAll(this.selectedGroups);
} }

View file

@ -7,8 +7,8 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.api.MaterialGroupApi; 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.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.List; import java.util.List;
@ -56,7 +56,7 @@ public class PUpdate_1_11_0 {
private static void handleToolsMigration() { 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"); AbstractItemTypeGroup tools = MaterialGroupApi.getGroup("tools");
migrateTools(tools, "pickaxes", PICKAXES); migrateTools(tools, "pickaxes", PICKAXES);
migrateTools(tools, "shovels", SHOVELS); migrateTools(tools, "shovels", SHOVELS);
@ -64,19 +64,19 @@ public class PUpdate_1_11_0 {
} }
private static void migrateTools( private static void migrateTools(
@Nullable AbstractMaterialGroup tools, @Nullable AbstractItemTypeGroup tools,
@NotNull String toolset, @NotNull String toolset,
@NotNull ItemType[] toolMats) { @NotNull ItemType[] toolMats) {
// Create new group // Create new group
IncludeGroup group = new IncludeGroup(toolset); IncludeItemTypeGroup group = new IncludeItemTypeGroup(toolset);
group.addAll(toolMats); group.addAll(toolMats);
MaterialGroupApi.addMaterialGroup(group, true); 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 // 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 == null) return;
if (!(tools instanceof IncludeGroup include)) return; if (!(tools instanceof IncludeItemTypeGroup include)) return;
List<ItemType> types = List.of(toolMats); List<ItemType> types = List.of(toolMats);
Set<ItemType> typeSet = include.getNonGroupInheritedMaterials(); Set<ItemType> typeSet = include.getNonGroupInheritedMaterials();

View file

@ -15,7 +15,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.dependency.DependencyManager
import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment
import xyz.alexcrea.cuanvil.enchant.wrapped.CAIncompatibleAllEnchant import xyz.alexcrea.cuanvil.enchant.wrapped.CAIncompatibleAllEnchant
import xyz.alexcrea.cuanvil.group.IncludeGroup import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup
import xyz.alexcrea.cuanvil.update.UpdateUtils import xyz.alexcrea.cuanvil.update.UpdateUtils
import xyz.alexcrea.cuanvil.update.Version import xyz.alexcrea.cuanvil.update.Version
import java.io.InputStreamReader import java.io.InputStreamReader
@ -144,7 +144,7 @@ object DataPackDependency {
var group = MaterialGroupApi.getGroup(groupName) var group = MaterialGroupApi.getGroup(groupName)
val exist = group != null val exist = group != null
if (group == null) group = IncludeGroup(groupName) if (group == null) group = IncludeItemTypeGroup(groupName)
for (name in section.getStringList("items")) { for (name in section.getStringList("items")) {
val key = NamespacedKey.fromString(name.lowercase()) val key = NamespacedKey.fromString(name.lowercase())

View file

@ -17,7 +17,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
import xyz.alexcrea.cuanvil.enchant.bulk.EnchantSquaredBulkOperation import xyz.alexcrea.cuanvil.enchant.bulk.EnchantSquaredBulkOperation
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEnchantSquaredEnchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEnchantSquaredEnchantment
import xyz.alexcrea.cuanvil.group.IncludeGroup import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup
import java.util.* import java.util.*
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
@ -104,15 +104,15 @@ 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.
val shield = IncludeGroup("shield") val shield = IncludeItemTypeGroup("shield")
shield.addToPolicy(ItemType.SHIELD) shield.addToPolicy(ItemType.SHIELD)
MaterialGroupApi.addMaterialGroup(shield) MaterialGroupApi.addMaterialGroup(shield)
val elytra = IncludeGroup("elytra") val elytra = IncludeItemTypeGroup("elytra")
elytra.addToPolicy(ItemType.ELYTRA) elytra.addToPolicy(ItemType.ELYTRA)
MaterialGroupApi.addMaterialGroup(elytra) MaterialGroupApi.addMaterialGroup(elytra)
val trinkets = IncludeGroup("trinkets") val trinkets = IncludeItemTypeGroup("trinkets")
trinkets.addToPolicy(ItemType.ROTTEN_FLESH) trinkets.addToPolicy(ItemType.ROTTEN_FLESH)
MaterialGroupApi.addMaterialGroup(trinkets) MaterialGroupApi.addMaterialGroup(trinkets)
} }

View file

@ -1,10 +1,9 @@
package xyz.alexcrea.cuanvil.group package xyz.alexcrea.cuanvil.group
import com.google.common.collect.ImmutableSet
import org.bukkit.inventory.ItemType import org.bukkit.inventory.ItemType
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
abstract class AbstractMaterialGroup(private val name: String) { abstract class AbstractItemTypeGroup(private val name: String) {
protected val includedItems by lazy { createDefaultSet() } protected val includedItems by lazy { createDefaultSet() }
/** /**
@ -22,21 +21,21 @@ abstract class AbstractMaterialGroup(private val name: String) {
/** /**
* Get if a group is referenced by this: * Get if a group is referenced by this:
*/ */
abstract fun isReferencing(other: AbstractMaterialGroup): Boolean abstract fun isReferencing(other: AbstractItemTypeGroup): Boolean
/** /**
* Push an item to this group to follow this group policy * Push an item to this group to follow this group policy
* *
* @return this instance. * @return this instance.
*/ */
abstract fun addToPolicy(type: ItemType): AbstractMaterialGroup abstract fun addToPolicy(type: ItemType): AbstractItemTypeGroup
/** /**
* Push a list of items to this group to follow this group policy * Push a list of items to this group to follow this group policy
* *
* @return this instance. * @return this instance.
*/ */
fun addAll(vararg types: ItemType): AbstractMaterialGroup { fun addAll(vararg types: ItemType): AbstractItemTypeGroup {
for (type in types) { for (type in types) {
addToPolicy(type) addToPolicy(type)
} }
@ -48,14 +47,14 @@ abstract class AbstractMaterialGroup(private val name: String) {
* *
* @return this instance. * @return this instance.
*/ */
abstract fun addToPolicy(other: AbstractMaterialGroup): AbstractMaterialGroup abstract fun addToPolicy(other: AbstractItemTypeGroup): AbstractItemTypeGroup
/** /**
* Push a list of group to this group to follow this group policy * Push a list of group to this group to follow this group policy
* *
* @return this instance. * @return this instance.
*/ */
fun addAll(vararg otherList: AbstractMaterialGroup): AbstractMaterialGroup { fun addAll(vararg otherList: AbstractItemTypeGroup): AbstractItemTypeGroup {
for (group in otherList) { for (group in otherList) {
addToPolicy(group) addToPolicy(group)
} }
@ -96,12 +95,12 @@ abstract class AbstractMaterialGroup(private val name: String) {
/** /**
* Update the contained groups of this group * Update the contained groups of this group
*/ */
abstract fun setGroups(groups: MutableSet<AbstractMaterialGroup>) abstract fun setGroups(groups: MutableSet<AbstractItemTypeGroup>)
/** /**
* Get the contained group of this material group * Get the contained group of this material group
*/ */
abstract fun getGroups(): MutableSet<AbstractMaterialGroup> abstract fun getGroups(): MutableSet<AbstractItemTypeGroup>
open fun getRepresentativeMaterial(): ItemType { open fun getRepresentativeMaterial(): ItemType {
// Test inner material // Test inner material

View file

@ -7,7 +7,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
class EnchantConflictGroup( class EnchantConflictGroup(
val name: String, val name: String,
private val cantConflict: AbstractMaterialGroup, private val cantConflict: AbstractItemTypeGroup,
var minBeforeBlock: Int var minBeforeBlock: Int
) { ) {
@ -45,7 +45,7 @@ class EnchantConflictGroup(
return true return true
} }
fun getCantConflictGroup(): AbstractMaterialGroup { fun getCantConflictGroup(): AbstractItemTypeGroup {
return this.cantConflict return this.cantConflict
} }

View file

@ -148,7 +148,7 @@ class EnchantConflictManager {
} }
// Find or create the selected group for the conflict // Find or create the selected group for the conflict
val groupList = section.getStringList(CONFLICT_GROUP_PATH) val groupList = section.getStringList(CONFLICT_GROUP_PATH)
val finalGroup = IncludeGroup(DEFAULT_GROUP_NAME) val finalGroup = IncludeItemTypeGroup(DEFAULT_GROUP_NAME)
for (groupName in groupList) { for (groupName in groupList) {
finalGroup.addToPolicy(findGroup(groupName, itemManager, conflictName)) finalGroup.addToPolicy(findGroup(groupName, itemManager, conflictName))
} }
@ -161,11 +161,11 @@ class EnchantConflictManager {
groupName: String, groupName: String,
itemManager: ItemGroupManager, itemManager: ItemGroupManager,
conflictName: String conflictName: String
): AbstractMaterialGroup { ): AbstractItemTypeGroup {
val group = itemManager.get(groupName) val group = itemManager.get(groupName)
if (group == null) { if (group == null) {
CustomAnvil.instance.logger.warning("Material group $groupName do not exist but is ask by conflict $conflictName") CustomAnvil.instance.logger.warning("Material group $groupName do not exist but is ask by conflict $conflictName")
return IncludeGroup("error_placeholder") return IncludeItemTypeGroup("error_placeholder")
} }
return group return group

View file

@ -1,6 +1,5 @@
package xyz.alexcrea.cuanvil.group package xyz.alexcrea.cuanvil.group
import com.google.common.collect.ImmutableSet
import io.papermc.paper.registry.RegistryAccess import io.papermc.paper.registry.RegistryAccess
import io.papermc.paper.registry.RegistryKey import io.papermc.paper.registry.RegistryKey
import org.bukkit.inventory.ItemType import org.bukkit.inventory.ItemType
@ -8,7 +7,7 @@ import java.util.*
@Deprecated("Need rework to reduce memory cost as not enum set") @Deprecated("Need rework to reduce memory cost as not enum set")
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
class ExcludeGroup(name: String) : AbstractMaterialGroup(name) { class ExcludeItemTypeGroup(name: String) : AbstractItemTypeGroup(name) {
override fun createDefaultSet(): MutableSet<ItemType> { override fun createDefaultSet(): MutableSet<ItemType> {
val types: MutableSet<ItemType> = HashSet() val types: MutableSet<ItemType> = HashSet()
@ -17,10 +16,10 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
return types return types
} }
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet() private var includedGroup: MutableSet<AbstractItemTypeGroup> = HashSet()
private val groupItems by lazy { createDefaultSet() } private val groupItems by lazy { createDefaultSet() }
override fun isReferencing(other: AbstractMaterialGroup): Boolean { override fun isReferencing(other: AbstractItemTypeGroup): Boolean {
for (materialGroup in includedGroup.iterator()) { for (materialGroup in includedGroup.iterator()) {
if ((materialGroup == other) || (materialGroup.isReferencing(other))) { if ((materialGroup == other) || (materialGroup.isReferencing(other))) {
return true return true
@ -29,21 +28,21 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
return false return false
} }
override fun addToPolicy(type: ItemType): ExcludeGroup { override fun addToPolicy(type: ItemType): ExcludeItemTypeGroup {
includedItems.remove(type) includedItems.remove(type)
groupItems.remove(type) groupItems.remove(type)
return this return this
} }
override fun addToPolicy(other: AbstractMaterialGroup): ExcludeGroup { override fun addToPolicy(other: AbstractItemTypeGroup): ExcludeItemTypeGroup {
includedGroup.add(other) includedGroup.add(other)
groupItems.removeAll(other.getItemTypes()) groupItems.removeAll(other.getItemTypes())
return this return this
} }
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) { override fun setGroups(groups: MutableSet<AbstractItemTypeGroup>) {
groupItems.clear() groupItems.clear()
groupItems.addAll(includedItems) groupItems.addAll(includedItems)
@ -56,7 +55,7 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
} }
} }
override fun getGroups(): MutableSet<AbstractMaterialGroup> { override fun getGroups(): MutableSet<AbstractItemTypeGroup> {
return includedGroup return includedGroup
} }

View file

@ -1,19 +1,18 @@
package xyz.alexcrea.cuanvil.group package xyz.alexcrea.cuanvil.group
import com.google.common.collect.ImmutableSet
import org.bukkit.inventory.ItemType import org.bukkit.inventory.ItemType
import java.util.* import java.util.*
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
class IncludeGroup(name: String) : AbstractMaterialGroup(name) { class IncludeItemTypeGroup(name: String) : AbstractItemTypeGroup(name) {
override fun createDefaultSet(): MutableSet<ItemType> { override fun createDefaultSet(): MutableSet<ItemType> {
return HashSet() return HashSet()
} }
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet() private var includedGroup: MutableSet<AbstractItemTypeGroup> = HashSet()
private val groupItems by lazy { createDefaultSet() } private val groupItems by lazy { createDefaultSet() }
override fun isReferencing(other: AbstractMaterialGroup): Boolean { override fun isReferencing(other: AbstractItemTypeGroup): Boolean {
for (materialGroup in includedGroup.iterator()) { for (materialGroup in includedGroup.iterator()) {
if ((materialGroup == other) || (materialGroup.isReferencing(other))) { if ((materialGroup == other) || (materialGroup.isReferencing(other))) {
return true return true
@ -22,21 +21,21 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
return false return false
} }
override fun addToPolicy(type: ItemType): IncludeGroup { override fun addToPolicy(type: ItemType): IncludeItemTypeGroup {
includedItems.add(type) includedItems.add(type)
groupItems.add(type) groupItems.add(type)
return this return this
} }
override fun addToPolicy(other: AbstractMaterialGroup): IncludeGroup { override fun addToPolicy(other: AbstractItemTypeGroup): IncludeItemTypeGroup {
includedGroup.add(other) includedGroup.add(other)
groupItems.addAll(other.getItemTypes()) groupItems.addAll(other.getItemTypes())
return this return this
} }
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) { override fun setGroups(groups: MutableSet<AbstractItemTypeGroup>) {
groupItems.clear() groupItems.clear()
groupItems.addAll(includedItems) groupItems.addAll(includedItems)
@ -55,7 +54,7 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
updateMaterials() updateMaterials()
} }
override fun getGroups(): MutableSet<AbstractMaterialGroup> { override fun getGroups(): MutableSet<AbstractItemTypeGroup> {
return includedGroup return includedGroup
} }

View file

@ -24,7 +24,7 @@ class ItemGroupManager {
private val FUTURE_MATERIAL = setOf("PIGLIN_HEAD", "BRUSH") private val FUTURE_MATERIAL = setOf("PIGLIN_HEAD", "BRUSH")
} }
lateinit var groupMap: LinkedHashMap<String, AbstractMaterialGroup> lateinit var groupMap: LinkedHashMap<String, AbstractItemTypeGroup>
// Read and create material groups // Read and create material groups
fun prepareGroups(config: ConfigurationSection) { fun prepareGroups(config: ConfigurationSection) {
@ -42,7 +42,7 @@ class ItemGroupManager {
fun createGroup( fun createGroup(
config: ConfigurationSection, config: ConfigurationSection,
name: String name: String
): AbstractMaterialGroup { ): AbstractItemTypeGroup {
return createGroup(config, groupMap.keys, name) return createGroup(config, groupMap.keys, name)
} }
@ -52,16 +52,16 @@ class ItemGroupManager {
config: ConfigurationSection, config: ConfigurationSection,
keys: Set<String>, keys: Set<String>,
key: String key: String
): AbstractMaterialGroup { ): AbstractItemTypeGroup {
val groupSection = config.getConfigurationSection(key)!! val groupSection = config.getConfigurationSection(key)!!
val groupType = groupSection.getString(GROUP_TYPE_PATH, null) val groupType = groupSection.getString(GROUP_TYPE_PATH, null)
// Create Material group according to the group type // Create Material group according to the group type
val group: AbstractMaterialGroup val group: AbstractItemTypeGroup
if (groupType != null && GroupType.EXCLUDE.equal(groupType)) { if (groupType != null && GroupType.EXCLUDE.equal(groupType)) {
group = ExcludeGroup(key) group = ExcludeItemTypeGroup(key)
} else { } else {
group = IncludeGroup(key) group = IncludeItemTypeGroup(key)
if (!GroupType.INCLUDE.equal(groupType)) { if (!GroupType.INCLUDE.equal(groupType)) {
CustomAnvil.instance.logger.warning("Group $key have an invalid group type. default to Include.") CustomAnvil.instance.logger.warning("Group $key have an invalid group type. default to Include.")
} }
@ -74,7 +74,7 @@ class ItemGroupManager {
// Read Group elements // Read Group elements
private fun readGroup( private fun readGroup(
group: AbstractMaterialGroup, group: AbstractItemTypeGroup,
groupSection: ConfigurationSection, groupSection: ConfigurationSection,
config: ConfigurationSection, config: ConfigurationSection,
keys: Set<String> keys: Set<String>
@ -141,7 +141,7 @@ class ItemGroupManager {
} }
// Get the selected group or return null if it doesn't exist // Get the selected group or return null if it doesn't exist
fun get(groupName: String): AbstractMaterialGroup? { fun get(groupName: String): AbstractItemTypeGroup? {
return groupMap[groupName] return groupMap[groupName]
} }

View file

@ -3,7 +3,7 @@ package xyz.alexcrea.cuanvil.api;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import xyz.alexcrea.cuanvil.tests.SharedOnlyMockBukkit; import xyz.alexcrea.cuanvil.tests.SharedOnlyMockBukkit;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
@ -79,7 +79,7 @@ public class ConflictBuilderTests extends SharedOnlyMockBukkit {
@Test @Test
void excludedGroup_Group() { void excludedGroup_Group() {
IncludeGroup group = new IncludeGroup("group"); IncludeItemTypeGroup group = new IncludeItemTypeGroup("group");
assertTrue(builder.getExcludedGroupNames().isEmpty()); assertTrue(builder.getExcludedGroupNames().isEmpty());
assertEquals(builder, builder.addExcludedGroup(group)); assertEquals(builder, builder.addExcludedGroup(group));
@ -97,7 +97,7 @@ public class ConflictBuilderTests extends SharedOnlyMockBukkit {
builder.addEnchantment("bane_of_arthropods"); builder.addEnchantment("bane_of_arthropods");
builder.addEnchantment(NamespacedKey.fromString("bane_of_arthropods")); builder.addEnchantment(NamespacedKey.fromString("bane_of_arthropods"));
builder.addExcludedGroup("group"); builder.addExcludedGroup("group");
builder.addExcludedGroup(new IncludeGroup("group2")); builder.addExcludedGroup(new IncludeItemTypeGroup("group2"));
ConflictBuilder copy = builder.copy(); ConflictBuilder copy = builder.copy();
assertEquals("other", copy.getName()); assertEquals("other", copy.getName());

View file

@ -3,7 +3,7 @@ package xyz.alexcrea.cuanvil.api;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup; import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import xyz.alexcrea.cuanvil.tests.ConfigResetCustomAnvilTest; import xyz.alexcrea.cuanvil.tests.ConfigResetCustomAnvilTest;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
@ -15,7 +15,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
@Test @Test
void groupAddAndRemove() { void groupAddAndRemove() {
String groupName = "group"; String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName); IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName);
group.addToPolicy(ItemType.DIAMOND_PICKAXE); // We do not want it to be empty group.addToPolicy(ItemType.DIAMOND_PICKAXE); // We do not want it to be empty
// Group not being set should not exist // Group not being set should not exist
@ -48,7 +48,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
@Test @Test
void writeGroup_Reload() { void writeGroup_Reload() {
String groupName = "group"; String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName); IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName);
group.addToPolicy(ItemType.DIAMOND_PICKAXE); // We do not want it to be empty group.addToPolicy(ItemType.DIAMOND_PICKAXE); // We do not want it to be empty
// Group not being set should not exist // Group not being set should not exist
@ -70,7 +70,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
@Test @Test
void writeGroup_Empty() { void writeGroup_Empty() {
String groupName = "group"; String groupName = "group";
IncludeGroup group = new IncludeGroup(groupName); IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName);
// Add group and reload // Add group and reload
assertFalse(MaterialGroupApi.writeMaterialGroup(group)); assertFalse(MaterialGroupApi.writeMaterialGroup(group));
@ -87,7 +87,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
@Test @Test
void writeGroup_InvalidDot() { void writeGroup_InvalidDot() {
String groupName = "group.group"; String groupName = "group.group";
IncludeGroup group = new IncludeGroup(groupName); IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName);
// Try write group // Try write group
assertFalse(MaterialGroupApi.writeMaterialGroup(group)); assertFalse(MaterialGroupApi.writeMaterialGroup(group));
@ -102,7 +102,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
builder.addExcludedGroup(groupName); builder.addExcludedGroup(groupName);
EnchantConflictGroup group = builder.build(); EnchantConflictGroup group = builder.build();
IncludeGroup materialGroup = (IncludeGroup) group.getCantConflictGroup(); IncludeItemTypeGroup materialGroup = (IncludeItemTypeGroup) group.getCantConflictGroup();
return materialGroup.getGroups().size() == 1; return materialGroup.getGroups().size() == 1;
} }