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.
*/
@NotNull
public ConflictBuilder addExcludedGroup(@NotNull AbstractMaterialGroup group) {
public ConflictBuilder addExcludedGroup(@NotNull AbstractItemTypeGroup group) {
return addExcludedGroup(group.getName());
}
@ -315,7 +315,7 @@ public class ConflictBuilder {
* @return This conflict builder instance.
*/
@NotNull
public ConflictBuilder removeExcludedGroup(@NotNull AbstractMaterialGroup group) {
public ConflictBuilder removeExcludedGroup(@NotNull AbstractItemTypeGroup group) {
return removeExcludedGroup(group.getName());
}
@ -352,7 +352,7 @@ public class ConflictBuilder {
* @return An Enchant conflict group with this builder parameters.
*/
public EnchantConflictGroup build() {
AbstractMaterialGroup materials = extractGroups();
AbstractItemTypeGroup materials = extractGroups();
EnchantConflictGroup conflict = new EnchantConflictGroup(getName(), materials, getMaxBeforeConflict());
appendEnchantments(conflict);
@ -436,12 +436,12 @@ public class ConflictBuilder {
*
* @return The abstract material group from the builder.
*/
protected AbstractMaterialGroup extractGroups() {
protected AbstractItemTypeGroup extractGroups() {
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()) {
AbstractMaterialGroup materialGroup = itemGroupManager.get(groupName);
AbstractItemTypeGroup materialGroup = itemGroupManager.get(groupName);
if (materialGroup == null) {
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 xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.dependency.DependencyManager;
import xyz.alexcrea.cuanvil.group.AbstractMaterialGroup;
import xyz.alexcrea.cuanvil.group.ExcludeGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup;
import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.ExcludeItemTypeGroup;
import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
@ -36,7 +36,7 @@ public class MaterialGroupApi {
* @param group The group to add
* @return true if successful.
*/
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group) {
public static boolean addMaterialGroup(@NotNull AbstractItemTypeGroup group) {
return addMaterialGroup(group, false);
}
@ -49,7 +49,7 @@ public class MaterialGroupApi {
* @param overrideDeleted If we should write even if the group was previously deleted.
* @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();
// Test if it exists/existed
@ -61,7 +61,7 @@ public class MaterialGroupApi {
if (!writeMaterialGroup(group, false)) return false;
if (group instanceof IncludeGroup includeGroup) {
if (group instanceof IncludeItemTypeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
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.
* <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
* @return true if was written successfully.
*/
public static boolean writeMaterialGroup(@NotNull AbstractMaterialGroup group) {
public static boolean writeMaterialGroup(@NotNull AbstractItemTypeGroup group) {
return writeMaterialGroup(group, true);
}
/**
* Write a material group to the config file.
* <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 updatePlanned if we should plan a global update for material groups
* @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();
if (name.contains(".")) {
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;
if (group instanceof IncludeGroup includeGroup) {
if (group instanceof IncludeItemTypeGroup 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
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
@ -120,12 +120,12 @@ public class MaterialGroupApi {
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();
String basePath = group.getName() + ".";
Set<ItemType> itemSets = group.getNonGroupInheritedMaterials();
Set<AbstractMaterialGroup> groupSet = group.getGroups();
Set<AbstractItemTypeGroup> groupSet = group.getGroups();
boolean empty = true;
if (!itemSets.isEmpty()) {
@ -150,7 +150,7 @@ public class MaterialGroupApi {
return true;
}
private static boolean writeUnknownGroup(@NotNull AbstractMaterialGroup group) {
private static boolean writeUnknownGroup(@NotNull AbstractItemTypeGroup group) {
FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
String basePath = group.getName() + ".";
@ -168,8 +168,8 @@ public class MaterialGroupApi {
return types.stream().map(item -> item.getKey().getKey().toLowerCase()).toList();
}
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) {
return groups.stream().map(AbstractMaterialGroup::getName).toList();
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractItemTypeGroup> groups) {
return groups.stream().map(AbstractItemTypeGroup::getName).toList();
}
/**
@ -180,9 +180,9 @@ public class MaterialGroupApi {
* @param group The recipe to remove
* @return True if the group was present.
*/
public static boolean removeGroup(@NotNull AbstractMaterialGroup group) {
public static boolean removeGroup(@NotNull AbstractItemTypeGroup group) {
// 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;
// Delete and save to file
@ -190,7 +190,7 @@ public class MaterialGroupApi {
prepareSaveTask();
// Remove from gui
if (group instanceof IncludeGroup includeGroup) {
if (group instanceof IncludeItemTypeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
if (configGui != null) configGui.removeGeneric(includeGroup);
}
@ -234,7 +234,7 @@ public class MaterialGroupApi {
* @return the abstract group of this name. null if not found.
*/
@Nullable
public static AbstractMaterialGroup getGroup(@NotNull String groupName) {
public static AbstractItemTypeGroup getGroup(@NotNull String 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.
*/
@NotNull
public static Map<String, AbstractMaterialGroup> getRegisteredGroups() {
public static Map<String, AbstractItemTypeGroup> getRegisteredGroups() {
return Collections.unmodifiableMap(ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap());
}

View file

@ -1,6 +1,6 @@
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 java.util.ArrayList;
@ -10,22 +10,22 @@ import java.util.Set;
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){
// Prepare group lore
ArrayList<String> groupLore = new ArrayList<>();
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()) {
groupLore.add("§7There is no "+groupAction+"d group for this "+containerType+".");
} else {
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;
int maxindex = (greaterThanMax ? 4 : grouos.size());

View file

@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import xyz.alexcrea.cuanvil.config.ConfigHolder;
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.elements.EnchantConflictSubSettingGui;
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
EnchantConflictGroup conflict = new EnchantConflictGroup(
name,
new IncludeGroup("new_group"),
new IncludeItemTypeGroup("new_group"),
0);
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.Nullable;
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.IncludeGroup;
import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import xyz.alexcrea.cuanvil.group.ItemGroupManager;
import xyz.alexcrea.cuanvil.gui.config.list.MappedGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.list.elements.GroupConfigSubSettingGui;
@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.Collection;
@SuppressWarnings("UnstableApiUsage")
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeItemTypeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
private static GroupConfigGui INSTANCE;
@ -44,7 +44,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
}
@Override
protected ItemStack createItemForGeneric(IncludeGroup group) {
protected ItemStack createItemForGeneric(IncludeItemTypeGroup group) {
ItemStack item = group.getRepresentativeMaterial().createItemStack();
ItemMeta meta = item.getItemMeta();
assert meta != null;
@ -62,19 +62,19 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
}
@Override
protected Collection<IncludeGroup> getEveryDisplayableInstanceOfGeneric() {
ArrayList<IncludeGroup> includeGroups = new ArrayList<>();
protected Collection<IncludeItemTypeGroup> getEveryDisplayableInstanceOfGeneric() {
ArrayList<IncludeItemTypeGroup> includeGroups = new ArrayList<>();
for (AbstractMaterialGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
if (group instanceof IncludeGroup) {
includeGroups.add((IncludeGroup) group);
for (AbstractItemTypeGroup group : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
if (group instanceof IncludeItemTypeGroup) {
includeGroups.add((IncludeItemTypeGroup) group);
}
}
return includeGroups;
}
@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));
}
@ -84,14 +84,14 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
}
@Override
protected IncludeGroup createAndSaveNewEmptyGeneric(String name) {
protected IncludeItemTypeGroup createAndSaveNewEmptyGeneric(String name) {
ItemGroupManager manager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
if (manager.getGroupMap().containsKey(name)) return null;
ConfigurationSection config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
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 xyz.alexcrea.cuanvil.config.ConfigHolder;
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.EnchantConflictManager;
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
@ -282,12 +282,12 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Select group container methods
@Override
public Set<AbstractMaterialGroup> getSelectedGroups() {
public Set<AbstractItemTypeGroup> getSelectedGroups() {
return this.enchantConflict.getCantConflictGroup().getGroups();
}
@Override
public boolean setSelectedGroups(Set<AbstractMaterialGroup> groups) {
public boolean setSelectedGroups(Set<AbstractItemTypeGroup> groups) {
if (!this.shouldWork) {
CustomAnvil.instance.getLogger().info("Trying to save " + enchantConflict.toString() + " groups but sub config is destroyed");
return false;
@ -299,7 +299,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
// Save on file configuration
String[] groupsNames = new String[groups.size()];
int index = 0;
for (AbstractMaterialGroup group : groups) {
for (AbstractItemTypeGroup group : groups) {
groupsNames[index++] = group.getName();
}
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict + ".notAffectedGroups", groupsNames);
@ -319,7 +319,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
}
@Override
public Set<AbstractMaterialGroup> illegalGroups() {
public Set<AbstractItemTypeGroup> illegalGroups() {
return Collections.emptySet();
}

View file

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

View file

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

View file

@ -7,8 +7,8 @@ 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.group.AbstractMaterialGroup;
import xyz.alexcrea.cuanvil.group.IncludeGroup;
import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
import javax.annotation.Nonnull;
import java.util.List;
@ -56,7 +56,7 @@ public class PUpdate_1_11_0 {
private static void handleToolsMigration() {
// 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, "shovels", SHOVELS);
@ -64,19 +64,19 @@ public class PUpdate_1_11_0 {
}
private static void migrateTools(
@Nullable AbstractMaterialGroup tools,
@Nullable AbstractItemTypeGroup tools,
@NotNull String toolset,
@NotNull ItemType[] toolMats) {
// Create new group
IncludeGroup group = new IncludeGroup(toolset);
IncludeItemTypeGroup group = new IncludeItemTypeGroup(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;
if (!(tools instanceof IncludeItemTypeGroup include)) return;
List<ItemType> types = List.of(toolMats);
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.enchant.wrapped.CABukkitEnchantment
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.Version
import java.io.InputStreamReader
@ -144,7 +144,7 @@ object DataPackDependency {
var group = MaterialGroupApi.getGroup(groupName)
val exist = group != null
if (group == null) group = IncludeGroup(groupName)
if (group == null) group = IncludeItemTypeGroup(groupName)
for (name in section.getStringList("items")) {
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.bulk.EnchantSquaredBulkOperation
import xyz.alexcrea.cuanvil.enchant.wrapped.CAEnchantSquaredEnchantment
import xyz.alexcrea.cuanvil.group.IncludeGroup
import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup
import java.util.*
@Suppress("UnstableApiUsage")
@ -104,15 +104,15 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
private fun writeMissingGroups() {
// Write group that do not exist on custom anvil.
val shield = IncludeGroup("shield")
val shield = IncludeItemTypeGroup("shield")
shield.addToPolicy(ItemType.SHIELD)
MaterialGroupApi.addMaterialGroup(shield)
val elytra = IncludeGroup("elytra")
val elytra = IncludeItemTypeGroup("elytra")
elytra.addToPolicy(ItemType.ELYTRA)
MaterialGroupApi.addMaterialGroup(elytra)
val trinkets = IncludeGroup("trinkets")
val trinkets = IncludeItemTypeGroup("trinkets")
trinkets.addToPolicy(ItemType.ROTTEN_FLESH)
MaterialGroupApi.addMaterialGroup(trinkets)
}

View file

@ -1,10 +1,9 @@
package xyz.alexcrea.cuanvil.group
import com.google.common.collect.ImmutableSet
import org.bukkit.inventory.ItemType
@Suppress("UnstableApiUsage")
abstract class AbstractMaterialGroup(private val name: String) {
abstract class AbstractItemTypeGroup(private val name: String) {
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:
*/
abstract fun isReferencing(other: AbstractMaterialGroup): Boolean
abstract fun isReferencing(other: AbstractItemTypeGroup): Boolean
/**
* Push an item to this group to follow this group policy
*
* @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
*
* @return this instance.
*/
fun addAll(vararg types: ItemType): AbstractMaterialGroup {
fun addAll(vararg types: ItemType): AbstractItemTypeGroup {
for (type in types) {
addToPolicy(type)
}
@ -48,14 +47,14 @@ abstract class AbstractMaterialGroup(private val name: String) {
*
* @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
*
* @return this instance.
*/
fun addAll(vararg otherList: AbstractMaterialGroup): AbstractMaterialGroup {
fun addAll(vararg otherList: AbstractItemTypeGroup): AbstractItemTypeGroup {
for (group in otherList) {
addToPolicy(group)
}
@ -96,12 +95,12 @@ abstract class AbstractMaterialGroup(private val name: String) {
/**
* 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
*/
abstract fun getGroups(): MutableSet<AbstractMaterialGroup>
abstract fun getGroups(): MutableSet<AbstractItemTypeGroup>
open fun getRepresentativeMaterial(): ItemType {
// Test inner material

View file

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

View file

@ -148,7 +148,7 @@ class EnchantConflictManager {
}
// Find or create the selected group for the conflict
val groupList = section.getStringList(CONFLICT_GROUP_PATH)
val finalGroup = IncludeGroup(DEFAULT_GROUP_NAME)
val finalGroup = IncludeItemTypeGroup(DEFAULT_GROUP_NAME)
for (groupName in groupList) {
finalGroup.addToPolicy(findGroup(groupName, itemManager, conflictName))
}
@ -161,11 +161,11 @@ class EnchantConflictManager {
groupName: String,
itemManager: ItemGroupManager,
conflictName: String
): AbstractMaterialGroup {
): AbstractItemTypeGroup {
val group = itemManager.get(groupName)
if (group == null) {
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

View file

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

View file

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

View file

@ -24,7 +24,7 @@ class ItemGroupManager {
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
fun prepareGroups(config: ConfigurationSection) {
@ -42,7 +42,7 @@ class ItemGroupManager {
fun createGroup(
config: ConfigurationSection,
name: String
): AbstractMaterialGroup {
): AbstractItemTypeGroup {
return createGroup(config, groupMap.keys, name)
}
@ -52,16 +52,16 @@ class ItemGroupManager {
config: ConfigurationSection,
keys: Set<String>,
key: String
): AbstractMaterialGroup {
): AbstractItemTypeGroup {
val groupSection = config.getConfigurationSection(key)!!
val groupType = groupSection.getString(GROUP_TYPE_PATH, null)
// Create Material group according to the group type
val group: AbstractMaterialGroup
val group: AbstractItemTypeGroup
if (groupType != null && GroupType.EXCLUDE.equal(groupType)) {
group = ExcludeGroup(key)
group = ExcludeItemTypeGroup(key)
} else {
group = IncludeGroup(key)
group = IncludeItemTypeGroup(key)
if (!GroupType.INCLUDE.equal(groupType)) {
CustomAnvil.instance.logger.warning("Group $key have an invalid group type. default to Include.")
}
@ -74,7 +74,7 @@ class ItemGroupManager {
// Read Group elements
private fun readGroup(
group: AbstractMaterialGroup,
group: AbstractItemTypeGroup,
groupSection: ConfigurationSection,
config: ConfigurationSection,
keys: Set<String>
@ -141,7 +141,7 @@ class ItemGroupManager {
}
// 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]
}

View file

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

View file

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