progress on removing material reference

This commit is contained in:
alexcrea 2025-07-28 09:30:22 +02:00
parent 96c60a9733
commit 8cb11c3c18
Signed by: alexcrea
GPG key ID: E346CD16413450E3
23 changed files with 134 additions and 140 deletions

View file

@ -68,7 +68,7 @@ public class AnvilRecipeBuilder {
* Get if the recipe is exact count. (default 0) * Get if the recipe is exact count. (default 0)
* <p> * <p>
* Exact count mean the recipe can only be crafted 1 by 1. * Exact count mean the recipe can only be crafted 1 by 1.
* If set to false, then it will craft as much as possible in 1 go and will keep unused material onto the anvil inventory. * If set to false, then it will craft as much as possible in 1 go and will keep unused items onto the anvil inventory.
* *
* @return If the recipe is exact count. * @return If the recipe is exact count.
*/ */
@ -80,7 +80,7 @@ public class AnvilRecipeBuilder {
* Sets if the recipe is exact count. * Sets if the recipe is exact count.
* <p> * <p>
* Exact count mean the recipe can only be crafted 1 by 1. * Exact count mean the recipe can only be crafted 1 by 1.
* If set to false, then it will craft as much as possible in 1 go and will keep unused material onto the anvil inventory. * If set to false, then it will craft as much as possible in 1 go and will keep unused items onto the anvil inventory.
* *
* @param exactCount If the recipe is exact count * @param exactCount If the recipe is exact count
* @return This recipe builder instance. * @return This recipe builder instance.

View file

@ -14,7 +14,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
* A Builder for material conflict. * A Builder for enchantment conflicts.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class ConflictBuilder { public class ConflictBuilder {
@ -135,7 +135,7 @@ public class ConflictBuilder {
* This value represent how many enchantment contained on this conflict can be applied to before conflict is considered active. * This value represent how many enchantment contained on this conflict can be applied to before conflict is considered active.
* That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded. * That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded.
* <p> * <p>
* In vanilla. material restriction have this value set to 0 and enchantment conflict set to 1. * In vanilla. item type restriction have this value set to 0 and exclusive set conflict set to 1.
* *
* @return the max number of conflicting enchantment before conflict. 0 by default. * @return the max number of conflicting enchantment before conflict. 0 by default.
*/ */
@ -160,7 +160,7 @@ public class ConflictBuilder {
* This value represent how many enchantment contained on this conflict can be applied to before conflict is considered active. * This value represent how many enchantment contained on this conflict can be applied to before conflict is considered active.
* That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded. * That mean new enchantment will not be able to be added to the item and present enchantment will not have its level upgraded.
* <p> * <p>
* In vanilla. material restriction have this value set to 0 and enchantment conflict set to 1. * In vanilla. item type restriction have this value set to 0 and exclusive set conflict set to 1.
* *
* @param maxBeforeConflict The max before conflict * @param maxBeforeConflict The max before conflict
* @return This conflict builder instance. * @return This conflict builder instance.
@ -246,9 +246,9 @@ public class ConflictBuilder {
* <p> * <p>
* If left item of an anvil craft is included on one of the excluded group it will ignore this conflict. * If left item of an anvil craft is included on one of the excluded group it will ignore this conflict.
* <p> * <p>
* This allows to create conflict only for some item. Material restriction can be written like that. * This allows to create conflict only for some item. Item type restriction can be written like that.
* <p> * <p>
* For example: If we exclude a material group containing every pickaxe and add efficiency enchantment * For example: If we exclude an item group containing every pickaxe and add efficiency enchantment
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
@ -266,9 +266,9 @@ public class ConflictBuilder {
* <p> * <p>
* If left item of an anvil craft is included on one of the excluded group it will ignore this conflict. * If left item of an anvil craft is included on one of the excluded group it will ignore this conflict.
* <p> * <p>
* This allows to create conflict only for some item. Material restriction can be written like that. * This allows to create conflict only for some item. Item type restriction can be written like that.
* <p> n * <p>
* For example: If we exclude a material group containing every pickaxe and add efficiency enchantment * For example: If we exclude an item group containing every pickaxe and add efficiency enchantment
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
@ -285,9 +285,9 @@ public class ConflictBuilder {
* <p> * <p>
* If left item of an anvil craft is included on one of the excluded group it will ignore this conflict. * If left item of an anvil craft is included on one of the excluded group it will ignore this conflict.
* <p> * <p>
* This allows to create conflict only for some item. Material restriction can be written like that. * This allows to create conflict only for some item. Item type restriction can be written like that.
* <p> * <p>
* For example: If we exclude a material group containing every pickaxe and add efficiency enchantment * For example: If we exclude an item group containing every pickaxe and add efficiency enchantment
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
@ -305,9 +305,9 @@ public class ConflictBuilder {
* <p> * <p>
* If left item of an anvil craft is included on one of the excluded group it will ignore this conflict. * If left item of an anvil craft is included on one of the excluded group it will ignore this conflict.
* <p> * <p>
* This allows to create conflict only for some item. Material restriction can be written like that. * This allows to create conflict only for some item. Item type restriction can be written like that.
* <p> * <p>
* For example: If we exclude a material group containing every pickaxe and add efficiency enchantment * For example: If we exclude an item group containing every pickaxe and add efficiency enchantment
* with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0. * with {@link #setMaxBeforeConflict(int) maxBeforeConflict} set to 0.
* Then only pickaxe will be able to have efficiency. * Then only pickaxe will be able to have efficiency.
* *
@ -432,9 +432,9 @@ public class ConflictBuilder {
} }
/** /**
* Extract group abstract material group. * Extract group abstract item group.
* *
* @return The abstract material group from the builder. * @return The abstract item group from the builder.
*/ */
protected AbstractItemTypeGroup extractGroups() { protected AbstractItemTypeGroup extractGroups() {
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager(); ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();

View file

@ -20,12 +20,12 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
* Custom Anvil api for material group registry. * Custom Anvil api for item group registry.
*/ */
@SuppressWarnings({"unused"}) @SuppressWarnings({"unused"})
public class MaterialGroupApi { public class ItemGroupApi {
private MaterialGroupApi() { private ItemGroupApi() {
} }
private static Object saveChangeTask = null; private static Object saveChangeTask = null;
@ -39,8 +39,8 @@ 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 AbstractItemTypeGroup group) { public static boolean addItemGroup(@NotNull AbstractItemTypeGroup group) {
return addMaterialGroup(group, false); return addItemGroup(group, false);
} }
/** /**
@ -52,7 +52,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 AbstractItemTypeGroup group, boolean overrideDeleted) { public static boolean addItemGroup(@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
@ -62,7 +62,7 @@ public class MaterialGroupApi {
// Add group // Add group
itemGroupManager.getGroupMap().put(group.getName(), group); itemGroupManager.getGroupMap().put(group.getName(), group);
if (!writeMaterialGroup(group, false)) return false; if (!writeItemGroup(group, false)) return false;
if (group instanceof IncludeItemTypeGroup includeGroup) { if (group instanceof IncludeItemTypeGroup includeGroup) {
GroupConfigGui configGui = GroupConfigGui.getCurrentInstance(); GroupConfigGui configGui = GroupConfigGui.getCurrentInstance();
@ -77,27 +77,27 @@ public class MaterialGroupApi {
} }
/** /**
* Write a material group to the config file and plan an update of groups. * Write an item group to the config file and plan an update of groups.
* <p> * <p>
* You may want to use {@link #addMaterialGroup(AbstractItemTypeGroup)} instead as it is more performance in most case as this function will reload every conflict. * You may want to use {@link #addItemGroup(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 AbstractItemTypeGroup group) { public static boolean writeItemGroup(@NotNull AbstractItemTypeGroup group) {
return writeMaterialGroup(group, true); return writeItemGroup(group, true);
} }
/** /**
* Write a material group to the config file. * Write an item group to the config file.
* <p> * <p>
* You should use {@link #addMaterialGroup(AbstractItemTypeGroup)} or {@link #writeMaterialGroup(AbstractItemTypeGroup)} instead * You should use {@link #addItemGroup(AbstractItemTypeGroup)} or {@link #writeItemGroup(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 item groups
* @return true if was written successfully. * @return true if was written successfully.
*/ */
public static boolean writeMaterialGroup(@NotNull AbstractItemTypeGroup group, boolean updatePlanned) { public static boolean writeItemGroup(@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.");
@ -127,18 +127,18 @@ public class MaterialGroupApi {
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.getNonGroupInheritedItemTypes();
Set<AbstractItemTypeGroup> groupSet = group.getGroups(); Set<AbstractItemTypeGroup> groupSet = group.getGroups();
boolean empty = true; boolean empty = true;
if (!itemSets.isEmpty()) { if (!itemSets.isEmpty()) {
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, itemTypesSetToStringList(itemSets)); config.set(basePath + ItemGroupManager.ITEMS_LIST_PATH, itemTypesSetToStringList(itemSets));
empty = false; empty = false;
} else { } else {
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, null); config.set(basePath + ItemGroupManager.ITEMS_LIST_PATH, null);
} }
if (!groupSet.isEmpty()) { if (!groupSet.isEmpty()) {
config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, materialGroupSetToStringList(groupSet)); config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, itemGroupSetToStringList(groupSet));
empty = false; empty = false;
} else { } else {
config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, null); config.set(basePath + ItemGroupManager.GROUP_LIST_PATH, null);
@ -162,7 +162,7 @@ public class MaterialGroupApi {
if (itemTypes.isEmpty()) return false; if (itemTypes.isEmpty()) return false;
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include"); config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include");
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, itemTypesSetToStringList(itemTypes)); config.set(basePath + ItemGroupManager.ITEMS_LIST_PATH, itemTypesSetToStringList(itemTypes));
return true; return true;
} }
@ -171,13 +171,13 @@ public class MaterialGroupApi {
return types.stream().map(item -> item.getKey().toString()).toList(); return types.stream().map(item -> item.getKey().toString()).toList();
} }
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractItemTypeGroup> groups) { public static List<String> itemGroupSetToStringList(@NotNull Set<AbstractItemTypeGroup> groups) {
return groups.stream().map(AbstractItemTypeGroup::getName).toList(); return groups.stream().map(AbstractItemTypeGroup::getName).toList();
} }
/** /**
* Remove a material group. * Remove an item group.
* Caution ! It will not be removed from depending conflict or other material group at runtime. * Caution ! It will not be removed from depending conflict or other item groups at runtime.
* For that reason, it is not recommended to use this function. * For that reason, it is not recommended to use this function.
* *
* @param group The recipe to remove * @param group The recipe to remove
@ -242,7 +242,7 @@ public class MaterialGroupApi {
} }
/** /**
* Get every registered material groups. * Get every registered item groups.
* *
* @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.
*/ */

View file

@ -44,7 +44,7 @@ public class UnitRepairApi {
* Write and add a custom anvil unit repair recipe. * Write and add a custom anvil unit repair recipe.
* Will not write the recipe if it already exists or was deleted. * Will not write the recipe if it already exists or was deleted.
* *
* @param unit The unit material used to repair the bellow item. * @param unit The unit type used to repair the bellow item.
* @param repairable The item to be repaired. * @param repairable The item to be repaired.
* @param value The amount to be repaired by every unit. (1% = 0.01) * @param value The amount to be repaired by every unit. (1% = 0.01)
* @return true if successful. * @return true if successful.
@ -201,7 +201,7 @@ public class UnitRepairApi {
// Test if value section exist // Test if value section exist
if (!section.isDouble(repairableKey)) continue; if (!section.isDouble(repairableKey)) continue;
// Test if repairable is valid a material // Test if repairable is valid a item type
ItemType repairable = ItemTypeUtil.INSTANCE.getItemType(repairableKey); ItemType repairable = ItemTypeUtil.INSTANCE.getItemType(repairableKey);
if (repairable == null) continue; if (repairable == null) continue;

View file

@ -3,6 +3,7 @@ package xyz.alexcrea.cuanvil.api.event;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.api.ItemGroupApi;
/** /**
* Called when the configuration of CustomAnvil is ready. * Called when the configuration of CustomAnvil is ready.
@ -17,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
* <p> * <p>
* use {@link xyz.alexcrea.cuanvil.api.ConflictAPI ConflictApi}, * use {@link xyz.alexcrea.cuanvil.api.ConflictAPI ConflictApi},
* {@link xyz.alexcrea.cuanvil.gui.config.global.CustomRecipeConfigGui CustomRecipeConfigGui}, * {@link xyz.alexcrea.cuanvil.gui.config.global.CustomRecipeConfigGui CustomRecipeConfigGui},
* {@link xyz.alexcrea.cuanvil.api.MaterialGroupApi MaterialGroupApi} * {@link ItemGroupApi MaterialGroupApi}
* and {@link xyz.alexcrea.cuanvil.api.UnitRepairApi UnitRepairApi} * and {@link xyz.alexcrea.cuanvil.api.UnitRepairApi UnitRepairApi}
* to add/remove/edit configurations * to add/remove/edit configurations
*/ */

View file

@ -11,17 +11,17 @@ import java.util.Set;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public interface SelectItemTypeContainer { public interface SelectItemTypeContainer {
Set<ItemType> getSelectedMaterials(); Set<ItemType> getSelectedItems();
boolean setSelectedItems(Set<ItemType> types); boolean setSelectedItems(Set<ItemType> types);
Set<ItemType> illegalMaterials(); Set<ItemType> illegalItems();
static List<String> getMaterialLore(SelectItemTypeContainer container, String containerType, String action) { static List<String> getItemLore(SelectItemTypeContainer container, String containerType, String action) {
// Prepare material lore // Prepare material lore
ArrayList<String> groupLore = new ArrayList<>(); ArrayList<String> groupLore = new ArrayList<>();
groupLore.add("§7Allow you to select a list of §ematerials §7that this " + containerType + " should " + action); groupLore.add("§7Allow you to select a list of §ematerials §7that this " + containerType + " should " + action);
Set<ItemType> typeSet = container.getSelectedMaterials(); Set<ItemType> typeSet = container.getSelectedItems();
if (typeSet.isEmpty()) { if (typeSet.isEmpty()) {
groupLore.add("§7There is no " + action + "d material for this " + containerType + "."); groupLore.add("§7There is no " + action + "d material for this " + containerType + ".");
} else { } else {

View file

@ -25,7 +25,7 @@ public class SelectItemTypeGui extends AbstractAskGui {
@NotNull String actionDescription, @NotNull String actionDescription,
@NotNull Gui backOnCancel, @NotNull Gui backOnCancel,
@NotNull BiConsumer<ItemStack, HumanEntity> onSave, @NotNull BiConsumer<ItemStack, HumanEntity> onSave,
boolean materialOnly) { boolean typeOnly) {
super(3, title, backOnCancel); super(3, title, backOnCancel);
this.selectedItem = null; this.selectedItem = null;
@ -56,7 +56,7 @@ public class SelectItemTypeGui extends AbstractAskGui {
if(cursor.getType().isAir()) return; if(cursor.getType().isAir()) return;
ItemStack finalItem; ItemStack finalItem;
if(materialOnly){ if(typeOnly){
finalItem = setDisplayMeta( finalItem = setDisplayMeta(
cursor.getType().asItemType().createItemStack(), cursor.getType().asItemType().createItemStack(),
actionDescription); actionDescription);

View file

@ -70,7 +70,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
@Override @Override
public ItemStack createItemForGeneric(EnchantConflictGroup conflict) { public ItemStack createItemForGeneric(EnchantConflictGroup conflict) {
ItemStack item = conflict.getRepresentativeMaterial().createItemStack(); ItemStack item = conflict.getRepresentativeItemType().createItemStack();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
assert meta != null; assert meta != null;

View file

@ -45,7 +45,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeItemTypeGroup,
@Override @Override
protected ItemStack createItemForGeneric(IncludeItemTypeGroup group) { protected ItemStack createItemForGeneric(IncludeItemTypeGroup group) {
ItemStack item = group.getRepresentativeMaterial().createItemStack(); ItemStack item = group.getRepresentativeItem().createItemStack();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
assert meta != null; assert meta != null;
@ -53,7 +53,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeItemTypeGroup,
meta.setDisplayName("§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §fGroup"); meta.setDisplayName("§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §fGroup");
meta.setLore(Arrays.asList( meta.setLore(Arrays.asList(
"§7Number of selected groups : " + group.getGroups().size(), "§7Number of selected groups : " + group.getGroups().size(),
"§7Number of included material : " + group.getNonGroupInheritedMaterials().size(), "§7Number of included material : " + group.getNonGroupInheritedItemTypes().size(),
"", "",
"§7Total number of included material " + group.getItemTypes().size())); "§7Total number of included material " + group.getItemTypes().size()));

View file

@ -31,7 +31,7 @@ public class UnitRepairElementListGui extends
private final ItemType parentType; private final ItemType parentType;
private final UnitRepairConfigGui parentGui; private final UnitRepairConfigGui parentGui;
private final String materialName; private final String typeName;
private boolean shouldWork = true; private boolean shouldWork = true;
@ -40,7 +40,7 @@ public class UnitRepairElementListGui extends
super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentType.getKey().getKey()) + " §rUnit repair"); super("§e" + CasedStringUtil.snakeToUpperSpacedCase(parentType.getKey().getKey()) + " §rUnit repair");
this.parentType = parentType; this.parentType = parentType;
this.parentGui = parentGui; this.parentGui = parentGui;
this.materialName = CasedStringUtil.snakeToUpperSpacedCase(parentType.getKey().getKey()); this.typeName = CasedStringUtil.snakeToUpperSpacedCase(parentType.getKey().getKey());
GuiGlobalItems.addBackItem(this.backgroundPane, parentGui); GuiGlobalItems.addBackItem(this.backgroundPane, parentGui);
} }
@ -66,7 +66,7 @@ public class UnitRepairElementListGui extends
new SelectItemTypeGui( new SelectItemTypeGui(
"Select item to be repaired.", "Select item to be repaired.",
"§7Click here with an item to set the item\n" + "§7Click here with an item to set the item\n" +
"§7You like to be repaired by " + this.materialName, "§7You like to be repaired by " + this.typeName,
this, this,
(itemStack, player) -> { (itemStack, player) -> {
ItemMeta meta = itemStack.getItemMeta(); ItemMeta meta = itemStack.getItemMeta();
@ -103,7 +103,7 @@ public class UnitRepairElementListGui extends
@Override @Override
protected String createItemName() { protected String createItemName() {
return "§aAdd a new item reparable by " + this.materialName; return "§aAdd a new item reparable by " + this.typeName;
} }
@Override @Override
@ -117,7 +117,7 @@ public class UnitRepairElementListGui extends
this.parentType.getKey() + "." + type.getKey(), this.parentType.getKey() + "." + type.getKey(),
Arrays.asList( Arrays.asList(
"§7Click here to change how many §e% §7of §a" + materialDisplayName, "§7Click here to change how many §e% §7of §a" + materialDisplayName,
"§7Should get repaired by §e" + this.materialName "§7Should get repaired by §e" + this.typeName
), ),
2, 2,
true, true, true, true,
@ -134,15 +134,15 @@ public class UnitRepairElementListGui extends
@Override @Override
protected GuiItem itemFromFactory(ItemType type, DoubleSettingGui.DoubleSettingFactory factory) { protected GuiItem itemFromFactory(ItemType type, DoubleSettingGui.DoubleSettingFactory factory) {
return factory.getItem(type, return factory.getItem(type,
"§7%§a" + CasedStringUtil.snakeToUpperSpacedCase(type.getKey().getKey()) + " §erepaired by §a" + this.materialName); "§7%§a" + CasedStringUtil.snakeToUpperSpacedCase(type.getKey().getKey()) + " §erepaired by §a" + this.typeName);
} }
private void fillSet(HashSet<ItemType> set, String path){ private void fillSet(HashSet<ItemType> set, String path){
ConfigurationSection materialSection = ConfigHolder.UNIT_REPAIR_HOLDER ConfigurationSection itemSection = ConfigHolder.UNIT_REPAIR_HOLDER
.getConfig() .getConfig()
.getConfigurationSection(path); .getConfigurationSection(path);
if (materialSection != null) { if (itemSection != null) {
for (String key : materialSection.getKeys(false)) { for (String key : itemSection.getKeys(false)) {
ItemType type = ItemTypeUtil.INSTANCE.getItemTypeExact(key); ItemType type = ItemTypeUtil.INSTANCE.getItemTypeExact(key);
if(type == null) continue; // maybe warn the user ? if(type == null) continue; // maybe warn the user ?

View file

@ -18,7 +18,7 @@ import xyz.alexcrea.cuanvil.gui.config.SelectItemTypeContainer;
import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui; import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui;
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui; import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.GroupSelectSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.GroupSelectSettingGui;
import xyz.alexcrea.cuanvil.gui.config.settings.MaterialSelectSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.ItemTypeSelectSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
@ -55,7 +55,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
prepareStaticValues(); prepareStaticValues();
} }
private GuiItem materialSelection; private GuiItem itemSelection;
private GuiItem groupSelection; private GuiItem groupSelection;
private void prepareStaticValues() { private void prepareStaticValues() {
@ -73,16 +73,16 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
this.pane.bindItem('D', new GuiItem(deleteItem, openGuiAndCheckAction(), CustomAnvil.instance)); this.pane.bindItem('D', new GuiItem(deleteItem, openGuiAndCheckAction(), CustomAnvil.instance));
// Displayed item will be updated later // Displayed item will be updated later
String materialSelectionName = "§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §rMaterials"; String selectionName = "§e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName()) + " §rItems";
ItemStack selectItem = ItemType.DIAMOND_SWORD.createItemStack(); ItemStack selectItem = ItemType.DIAMOND_SWORD.createItemStack();
ItemMeta selectItemMeta = selectItem.getItemMeta(); ItemMeta selectItemMeta = selectItem.getItemMeta();
selectItemMeta.setDisplayName(materialSelectionName); selectItemMeta.setDisplayName(selectionName);
selectItem.setItemMeta(selectItemMeta); selectItem.setItemMeta(selectItemMeta);
this.materialSelection = new GuiItem(selectItem, (event) -> { this.itemSelection = new GuiItem(selectItem, (event) -> {
event.setCancelled(true); event.setCancelled(true);
MaterialSelectSettingGui selectGui = new MaterialSelectSettingGui(this, ItemTypeSelectSettingGui selectGui = new ItemTypeSelectSettingGui(this,
materialSelectionName selectionName
, this); , this);
selectGui.show(event.getWhoClicked()); selectGui.show(event.getWhoClicked());
@ -102,7 +102,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
enchantGui.show(event.getWhoClicked()); enchantGui.show(event.getWhoClicked());
}, CustomAnvil.instance); }, CustomAnvil.instance);
this.pane.bindItem('1', this.materialSelection); this.pane.bindItem('1', this.itemSelection);
this.pane.bindItem('2', this.groupSelection); this.pane.bindItem('2', this.groupSelection);
} }
@ -217,13 +217,13 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
public void updateLocal() { public void updateLocal() {
if (!this.usable) return; if (!this.usable) return;
// Prepare material lore // Prepare material lore
List<String> matLore = SelectItemTypeContainer.getMaterialLore(this, "group", "include"); List<String> matLore = SelectItemTypeContainer.getItemLore(this, "group", "include");
// Prepare group lore // Prepare group lore
List<String> groupLore = SelectGroupContainer.getGroupLore(this, "group", "include"); List<String> groupLore = SelectGroupContainer.getGroupLore(this, "group", "include");
// Configure included material setting item // Configure included material setting item
ItemStack matSelectItem = this.materialSelection.getItem(); ItemStack matSelectItem = this.itemSelection.getItem();
ItemMeta matSelectMeta = matSelectItem.getItemMeta(); ItemMeta matSelectMeta = matSelectItem.getItemMeta();
matSelectMeta.setDisplayName("§aSelect included §eMaterials §aSettings"); matSelectMeta.setDisplayName("§aSelect included §eMaterials §aSettings");
@ -232,7 +232,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
matSelectItem.setItemMeta(matSelectMeta); matSelectItem.setItemMeta(matSelectMeta);
this.materialSelection.setItem(matSelectItem); // Just in case this.itemSelection.setItem(matSelectItem); // Just in case
// Configure enchant setting item // Configure enchant setting item
ItemStack groupSelectItem = this.groupSelection.getItem(); ItemStack groupSelectItem = this.groupSelection.getItem();
@ -327,13 +327,13 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// ---------------------------- // ----------------------------
@Override @Override
public Set<ItemType> getSelectedMaterials() { public Set<ItemType> getSelectedItems() {
return this.group.getNonGroupInheritedMaterials(); return this.group.getNonGroupInheritedItemTypes();
} }
@Override @Override
public boolean setSelectedItems(Set<ItemType> types) { public boolean setSelectedItems(Set<ItemType> types) {
this.group.setNonGroupInheritedMaterials(types); this.group.setNonGroupInheritedItemTypes(types);
// Write to file configuration // Write to file configuration
String[] groupNames = new String[types.size()]; String[] groupNames = new String[types.size()];
@ -342,7 +342,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
groupNames[index++] = otherGroup.key().value().toLowerCase(); groupNames[index++] = otherGroup.key().value().toLowerCase();
} }
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(this.group.getName() + "." + ItemGroupManager.MATERIAL_LIST_PATH, groupNames); ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(this.group.getName() + "." + ItemGroupManager.ITEMS_LIST_PATH, groupNames);
// update referencing groups // update referencing groups
updateDirectReferencingGroups(this.group); updateDirectReferencingGroups(this.group);
@ -363,7 +363,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
} }
@Override @Override
public Set<ItemType> illegalMaterials() { public Set<ItemType> illegalItems() {
return ONLY_AIR_ITEM_SET; return ONLY_AIR_ITEM_SET;
} }
@ -390,7 +390,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// Update other stored group // Update other stored group
for (AbstractItemTypeGroup otherGroup : everyStoredGroups) { for (AbstractItemTypeGroup otherGroup : everyStoredGroups) {
if (otherGroup.getGroups().contains(testGroup)) { if (otherGroup.getGroups().contains(testGroup)) {
otherGroup.updateMaterials(); otherGroup.update();
updateFuture.add(otherGroup); updateFuture.add(otherGroup);
} }
} }
@ -413,7 +413,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// Update conflict group // Update conflict group
for (AbstractItemTypeGroup conflictGroup : conflictGroupPlanned) { for (AbstractItemTypeGroup conflictGroup : conflictGroupPlanned) {
conflictGroup.updateMaterials(); conflictGroup.update();
} }
} }

View file

@ -86,7 +86,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
private GuiItem getGuiItemFromGroup(AbstractItemTypeGroup 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.getRepresentativeItem().createItemStack();
setGroupItemMeta(item, group.getName(), isIn); setGroupItemMeta(item, group.getName(), isIn);

View file

@ -23,7 +23,7 @@ import java.util.*;
import java.util.function.Consumer; import java.util.function.Consumer;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
public class MaterialSelectSettingGui extends MappedElementListConfigGui<ItemType, GuiItem> { public class ItemTypeSelectSettingGui extends MappedElementListConfigGui<ItemType, GuiItem> {
private final SelectItemTypeContainer selector; private final SelectItemTypeContainer selector;
private final Gui backGui; private final Gui backGui;
@ -34,7 +34,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<ItemTyp
private final int defaultMaterialHash; private final int defaultMaterialHash;
private int nowMaterialHash; private int nowMaterialHash;
public MaterialSelectSettingGui( public ItemTypeSelectSettingGui(
@NotNull SelectItemTypeContainer selector, @NotNull SelectItemTypeContainer selector,
@NotNull String title, @NotNull String title,
@NotNull Gui backGui) { @NotNull Gui backGui) {
@ -43,8 +43,8 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<ItemTyp
this.backGui = backGui; this.backGui = backGui;
this.instantRemove = false; this.instantRemove = false;
this.defaultMaterials = new ArrayList<>(this.selector.getSelectedMaterials()); this.defaultMaterials = new ArrayList<>(this.selector.getSelectedItems());
this.illegalMaterials = this.selector.illegalMaterials(); this.illegalMaterials = this.selector.illegalItems();
this.defaultMaterialHash = hashFromItemTypeList(this.defaultMaterials); this.defaultMaterialHash = hashFromItemTypeList(this.defaultMaterials);
this.nowMaterialHash = this.defaultMaterialHash; this.nowMaterialHash = this.defaultMaterialHash;

View file

@ -5,7 +5,7 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemType; import org.bukkit.inventory.ItemType;
import org.jetbrains.annotations.NotNull; 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.ItemGroupApi;
import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup; import xyz.alexcrea.cuanvil.group.AbstractItemTypeGroup;
import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup; import xyz.alexcrea.cuanvil.group.IncludeItemTypeGroup;
@ -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
AbstractItemTypeGroup tools = MaterialGroupApi.getGroup("tools"); AbstractItemTypeGroup tools = ItemGroupApi.getGroup("tools");
migrateTools(tools, "pickaxes", PICKAXES); migrateTools(tools, "pickaxes", PICKAXES);
migrateTools(tools, "shovels", SHOVELS); migrateTools(tools, "shovels", SHOVELS);
@ -72,19 +72,19 @@ public class PUpdate_1_11_0 {
IncludeItemTypeGroup group = new IncludeItemTypeGroup(toolset); IncludeItemTypeGroup group = new IncludeItemTypeGroup(toolset);
group.addAll(toolMats); group.addAll(toolMats);
MaterialGroupApi.addMaterialGroup(group, true); ItemGroupApi.addItemGroup(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 IncludeItemTypeGroup 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.getNonGroupInheritedItemTypes();
if (!typeSet.containsAll(types)) return; if (!typeSet.containsAll(types)) return;
types.forEach(typeSet::remove); types.forEach(typeSet::remove);
tools.addToPolicy(group); tools.addToPolicy(group);
MaterialGroupApi.writeMaterialGroup(tools); ItemGroupApi.writeItemGroup(tools);
} }
private static void handleMaceMigration(@Nonnull Set<ConfigHolder> toSave) { private static void handleMaceMigration(@Nonnull Set<ConfigHolder> toSave) {

View file

@ -344,7 +344,7 @@ object ConfigOptions {
} }
/** /**
* Get material enchantment count limit * Get item enchantment count limit
* *
* @return the current enchantment limit. -1 if none * @return the current enchantment limit. -1 if none
*/ */
@ -358,7 +358,7 @@ object ConfigOptions {
} }
/** /**
* Get the material enchantment count limit. * Get the item enchantment count limit.
* *
* @return The current enchantment limit. -1 if none * @return The current enchantment limit. -1 if none
*/ */

View file

@ -8,7 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.configuration.file.YamlConfiguration
import xyz.alexcrea.cuanvil.api.ConflictBuilder import xyz.alexcrea.cuanvil.api.ConflictBuilder
import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.api.MaterialGroupApi import xyz.alexcrea.cuanvil.api.ItemGroupApi
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.enchant.wrapped.CABukkitEnchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CABukkitEnchantment
@ -138,7 +138,7 @@ object DataPackDependency {
for (groupName in yml.getKeys(false)) { for (groupName in yml.getKeys(false)) {
val section = yml.getConfigurationSection(groupName) ?: continue val section = yml.getConfigurationSection(groupName) ?: continue
var group = MaterialGroupApi.getGroup(groupName) var group = ItemGroupApi.getGroup(groupName)
val exist = group != null val exist = group != null
if (group == null) group = IncludeItemTypeGroup(groupName) if (group == null) group = IncludeItemTypeGroup(groupName)
@ -154,7 +154,7 @@ object DataPackDependency {
group.addToPolicy(type) group.addToPolicy(type)
} }
for (name in section.getStringList("groups")) { for (name in section.getStringList("groups")) {
val otherGroup = MaterialGroupApi.getGroup(name) val otherGroup = ItemGroupApi.getGroup(name)
if (otherGroup == null) { if (otherGroup == null) {
CustomAnvil.instance.logger.warning("Could not find sub group $name for group $groupName") CustomAnvil.instance.logger.warning("Could not find sub group $name for group $groupName")
continue continue
@ -163,12 +163,12 @@ object DataPackDependency {
group.addToPolicy(otherGroup) group.addToPolicy(otherGroup)
} }
group.updateMaterials() group.update()
if (exist) { if (exist) {
MaterialGroupApi.writeMaterialGroup(group) ItemGroupApi.writeItemGroup(group)
} else { } else {
MaterialGroupApi.addMaterialGroup(group, true) ItemGroupApi.addItemGroup(group, true)
} }
} }
} }

View file

@ -12,7 +12,7 @@ import org.bukkit.inventory.ItemType
import org.bukkit.plugin.Plugin import org.bukkit.plugin.Plugin
import xyz.alexcrea.cuanvil.api.ConflictBuilder import xyz.alexcrea.cuanvil.api.ConflictBuilder
import xyz.alexcrea.cuanvil.api.EnchantmentApi import xyz.alexcrea.cuanvil.api.EnchantmentApi
import xyz.alexcrea.cuanvil.api.MaterialGroupApi import xyz.alexcrea.cuanvil.api.ItemGroupApi
import xyz.alexcrea.cuanvil.enchant.CAEnchantment 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
@ -106,15 +106,15 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
// Write group that do not exist on custom anvil. // Write group that do not exist on custom anvil.
val shield = IncludeItemTypeGroup("shield") val shield = IncludeItemTypeGroup("shield")
shield.addToPolicy(ItemType.SHIELD) shield.addToPolicy(ItemType.SHIELD)
MaterialGroupApi.addMaterialGroup(shield) ItemGroupApi.addItemGroup(shield)
val elytra = IncludeItemTypeGroup("elytra") val elytra = IncludeItemTypeGroup("elytra")
elytra.addToPolicy(ItemType.ELYTRA) elytra.addToPolicy(ItemType.ELYTRA)
MaterialGroupApi.addMaterialGroup(elytra) ItemGroupApi.addItemGroup(elytra)
val trinkets = IncludeItemTypeGroup("trinkets") val trinkets = IncludeItemTypeGroup("trinkets")
trinkets.addToPolicy(ItemType.ROTTEN_FLESH) trinkets.addToPolicy(ItemType.ROTTEN_FLESH)
MaterialGroupApi.addMaterialGroup(trinkets) ItemGroupApi.addItemGroup(trinkets)
} }
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>) { private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>) {

View file

@ -69,14 +69,14 @@ abstract class AbstractItemTypeGroup(private val name: String) {
/** /**
* Get the group non-inherited items as a set * Get the group non-inherited items as a set
*/ */
open fun getNonGroupInheritedMaterials(): MutableSet<ItemType> { open fun getNonGroupInheritedItemTypes(): MutableSet<ItemType> {
return includedItems return includedItems
} }
/** /**
* Set the group non-inherited items * Set the group non-inherited items
*/ */
open fun setNonGroupInheritedMaterials(types: Set<ItemType>) { open fun setNonGroupInheritedItemTypes(types: Set<ItemType>) {
this.includedItems.clear() this.includedItems.clear()
this.includedItems.addAll(types) this.includedItems.addAll(types)
} }
@ -102,7 +102,7 @@ abstract class AbstractItemTypeGroup(private val name: String) {
*/ */
abstract fun getGroups(): MutableSet<AbstractItemTypeGroup> abstract fun getGroups(): MutableSet<AbstractItemTypeGroup>
open fun getRepresentativeMaterial(): ItemType { open fun getRepresentativeItem(): ItemType {
// Test inner material // Test inner material
val itemIterator = includedItems.iterator() val itemIterator = includedItems.iterator()
while (itemIterator.hasNext()) { while (itemIterator.hasNext()) {
@ -113,13 +113,13 @@ abstract class AbstractItemTypeGroup(private val name: String) {
// Test included group representative material // Test included group representative material
val groupIterator = getGroups().iterator() val groupIterator = getGroups().iterator()
while (groupIterator.hasNext()) { while (groupIterator.hasNext()) {
val groupType = groupIterator.next().getRepresentativeMaterial() val groupType = groupIterator.next().getRepresentativeItem()
if (groupType == ItemType.AIR) continue if (groupType == ItemType.AIR) continue
return groupType return groupType
} }
return ItemType.PAPER return ItemType.PAPER
} }
abstract fun updateMaterials() abstract fun update()
} }

View file

@ -58,11 +58,11 @@ class EnchantConflictGroup(
enchantments.addAll(enchants) enchantments.addAll(enchants)
} }
fun getRepresentativeMaterial(): ItemType { fun getRepresentativeItemType(): ItemType {
val groups = getCantConflictGroup().getGroups() val groups = getCantConflictGroup().getGroups()
val groupIterator = groups.iterator() val groupIterator = groups.iterator()
while (groupIterator.hasNext()) { while (groupIterator.hasNext()) {
val itemType = groupIterator.next().getRepresentativeMaterial() val itemType = groupIterator.next().getRepresentativeItem()
if (itemType != ItemType.ENCHANTED_BOOK) return itemType if (itemType != ItemType.ENCHANTED_BOOK) return itemType
} }

View file

@ -18,8 +18,8 @@ class ExcludeItemTypeGroup(name: String) : AbstractItemTypeGroup(name) {
private val groupItems by lazy { createDefaultSet() } private val groupItems by lazy { createDefaultSet() }
override fun isReferencing(other: AbstractItemTypeGroup): Boolean { override fun isReferencing(other: AbstractItemTypeGroup): Boolean {
for (materialGroup in includedGroup.iterator()) { for (itemGroup in includedGroup.iterator()) {
if ((materialGroup == other) || (materialGroup.isReferencing(other))) { if ((itemGroup == other) || (itemGroup.isReferencing(other))) {
return true return true
} }
} }
@ -57,7 +57,7 @@ class ExcludeItemTypeGroup(name: String) : AbstractItemTypeGroup(name) {
return includedGroup return includedGroup
} }
override fun updateMaterials() { override fun update() {
groupItems.clear() groupItems.clear()
groupItems.addAll(includedItems) groupItems.addAll(includedItems)

View file

@ -12,8 +12,8 @@ class IncludeItemTypeGroup(name: String) : AbstractItemTypeGroup(name) {
private val groupItems by lazy { createDefaultSet() } private val groupItems by lazy { createDefaultSet() }
override fun isReferencing(other: AbstractItemTypeGroup): Boolean { override fun isReferencing(other: AbstractItemTypeGroup): Boolean {
for (materialGroup in includedGroup.iterator()) { for (subGroup in includedGroup.iterator()) {
if ((materialGroup == other) || (materialGroup.isReferencing(other))) { if ((subGroup == other) || (subGroup.isReferencing(other))) {
return true return true
} }
} }
@ -47,17 +47,17 @@ class IncludeItemTypeGroup(name: String) : AbstractItemTypeGroup(name) {
} }
} }
override fun setNonGroupInheritedMaterials(types: Set<ItemType>) { override fun setNonGroupInheritedItemTypes(types: Set<ItemType>) {
super.setNonGroupInheritedMaterials(types) super.setNonGroupInheritedItemTypes(types)
updateMaterials() update()
} }
override fun getGroups(): MutableSet<AbstractItemTypeGroup> { override fun getGroups(): MutableSet<AbstractItemTypeGroup> {
return includedGroup return includedGroup
} }
override fun updateMaterials() { override fun update() {
groupItems.clear() groupItems.clear()
groupItems.addAll(includedItems) groupItems.addAll(includedItems)

View file

@ -13,13 +13,10 @@ class ItemGroupManager {
const val GROUP_TYPE_PATH = "type" const val GROUP_TYPE_PATH = "type"
// Path for included items list // Path for included items list
const val MATERIAL_LIST_PATH = "items" const val ITEMS_LIST_PATH = "items"
// Path for included groups list // Path for included groups list
const val GROUP_LIST_PATH = "groups" const val GROUP_LIST_PATH = "groups"
// Temporary list of elements in default config that are use in future
private val FUTURE_MATERIAL = setOf("PIGLIN_HEAD", "BRUSH")
} }
lateinit var groupMap: LinkedHashMap<String, AbstractItemTypeGroup> lateinit var groupMap: LinkedHashMap<String, AbstractItemTypeGroup>
@ -78,17 +75,13 @@ class ItemGroupManager {
keys: Set<String> keys: Set<String>
) { ) {
// Read material to include in this group policy // Read material to include in this group policy
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH) val itemTypeNames = groupSection.getStringList(ITEMS_LIST_PATH)
for (typeName in materialList) { for (typeName in itemTypeNames) {
val type = ItemTypeUtil.getItemType(typeName) val type = ItemTypeUtil.getItemType(typeName)
if (type == null) { if (type == null) {
// Check if we should warn the user
if (typeName !in FUTURE_MATERIAL) {
CustomAnvil.instance.logger.warning( CustomAnvil.instance.logger.warning(
"Unknown item type $typeName on group ${group.getName()}" "Unknown item type $typeName on group ${group.getName()}"
) )
}
continue continue
} }

View file

@ -23,22 +23,22 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
assertFalse(doGroupCanBeFound(groupName)); assertFalse(doGroupCanBeFound(groupName));
// Add group // Add group
assertTrue(MaterialGroupApi.addMaterialGroup(group)); assertTrue(ItemGroupApi.addItemGroup(group));
assertFalse(MaterialGroupApi.addMaterialGroup(group, true)); assertFalse(ItemGroupApi.addItemGroup(group, true));
assertTrue(doGroupExist(groupName)); assertTrue(doGroupExist(groupName));
assertTrue(doGroupCanBeFound(groupName)); assertTrue(doGroupCanBeFound(groupName));
// Remove group // Remove group
assertTrue(MaterialGroupApi.removeGroup(group)); assertTrue(ItemGroupApi.removeGroup(group));
assertFalse(MaterialGroupApi.removeGroup(group)); assertFalse(ItemGroupApi.removeGroup(group));
assertFalse(doGroupExist(groupName)); assertFalse(doGroupExist(groupName));
assertFalse(doGroupCanBeFound(groupName)); assertFalse(doGroupCanBeFound(groupName));
// Re add // Re add
assertFalse(MaterialGroupApi.addMaterialGroup(group, false)); assertFalse(ItemGroupApi.addItemGroup(group, false));
assertTrue(MaterialGroupApi.addMaterialGroup(group, true)); assertTrue(ItemGroupApi.addItemGroup(group, true));
assertTrue(doGroupExist(groupName)); assertTrue(doGroupExist(groupName));
assertTrue(doGroupCanBeFound(groupName)); assertTrue(doGroupCanBeFound(groupName));
@ -56,7 +56,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
assertFalse(doGroupCanBeFound(groupName)); assertFalse(doGroupCanBeFound(groupName));
// Add group and reload // Add group and reload
assertTrue(MaterialGroupApi.writeMaterialGroup(group)); assertTrue(ItemGroupApi.writeItemGroup(group));
assertFalse(doGroupExist(groupName)); assertFalse(doGroupExist(groupName));
assertFalse(doGroupCanBeFound(groupName)); assertFalse(doGroupCanBeFound(groupName));
@ -73,7 +73,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName); IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName);
// Add group and reload // Add group and reload
assertFalse(MaterialGroupApi.writeMaterialGroup(group)); assertFalse(ItemGroupApi.writeItemGroup(group));
assertFalse(doGroupExist(groupName)); assertFalse(doGroupExist(groupName));
assertFalse(doGroupCanBeFound(groupName)); assertFalse(doGroupCanBeFound(groupName));
@ -90,11 +90,11 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName); IncludeItemTypeGroup group = new IncludeItemTypeGroup(groupName);
// Try write group // Try write group
assertFalse(MaterialGroupApi.writeMaterialGroup(group)); assertFalse(ItemGroupApi.writeItemGroup(group));
} }
boolean doGroupExist(String groupName) { boolean doGroupExist(String groupName) {
return MaterialGroupApi.getGroup(groupName) != null; return ItemGroupApi.getGroup(groupName) != null;
} }
boolean doGroupCanBeFound(String groupName) { boolean doGroupCanBeFound(String groupName) {