mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-24 00:26:16 +02:00
progress on using item type
# Conflicts: # src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CABukkitEnchantment.java
This commit is contained in:
parent
b011edd606
commit
b193ec7094
18 changed files with 331 additions and 251 deletions
|
|
@ -2,8 +2,8 @@ package xyz.alexcrea.cuanvil.api;
|
|||
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import io.delilaheve.util.ConfigOptions;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
|
|
@ -19,7 +19,7 @@ import java.util.*;
|
|||
/**
|
||||
* Custom Anvil api for material group registry.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({"unused", "UnstableApiUsage"})
|
||||
public class MaterialGroupApi {
|
||||
|
||||
private MaterialGroupApi() {
|
||||
|
|
@ -105,6 +105,7 @@ public class MaterialGroupApi {
|
|||
if (group instanceof IncludeGroup includeGroup) {
|
||||
changed = writeKnownGroup("include", includeGroup);
|
||||
} else if (group instanceof ExcludeGroup 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
|
||||
//changed = writeKnownGroup("exclude", excludeGroup);
|
||||
|
|
@ -123,12 +124,12 @@ public class MaterialGroupApi {
|
|||
FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||
|
||||
String basePath = group.getName() + ".";
|
||||
Set<Material> materialSet = group.getNonGroupInheritedMaterials();
|
||||
Set<ItemType> itemSets = group.getNonGroupInheritedMaterials();
|
||||
Set<AbstractMaterialGroup> groupSet = group.getGroups();
|
||||
|
||||
boolean empty = true;
|
||||
if (!materialSet.isEmpty()) {
|
||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materialSet));
|
||||
if (!itemSets.isEmpty()) {
|
||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, itemTypesSetToStringList(itemSets));
|
||||
empty = false;
|
||||
} else {
|
||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, null);
|
||||
|
|
@ -153,18 +154,18 @@ public class MaterialGroupApi {
|
|||
FileConfiguration config = ConfigHolder.ITEM_GROUP_HOLDER.getConfig();
|
||||
|
||||
String basePath = group.getName() + ".";
|
||||
EnumSet<Material> materials = group.getMaterials();
|
||||
Set<ItemType> itemTypes = group.getItemTypes();
|
||||
|
||||
if (materials.isEmpty()) return false;
|
||||
if (itemTypes.isEmpty()) return false;
|
||||
|
||||
config.set(basePath + ItemGroupManager.GROUP_TYPE_PATH, "include");
|
||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materials));
|
||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, itemTypesSetToStringList(itemTypes));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<String> materialSetToStringList(@NotNull Set<Material> materials) {
|
||||
return materials.stream().map(material -> material.getKey().getKey().toLowerCase()).toList();
|
||||
public static List<String> itemTypesSetToStringList(@NotNull Set<ItemType> types) {
|
||||
return types.stream().map(item -> item.getKey().getKey().toLowerCase()).toList();
|
||||
}
|
||||
|
||||
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config;
|
||||
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public interface SelectItemTypeContainer {
|
||||
|
||||
Set<ItemType> getSelectedMaterials();
|
||||
|
||||
boolean setSelectedItems(Set<ItemType> types);
|
||||
|
||||
Set<ItemType> illegalMaterials();
|
||||
|
||||
static List<String> getMaterialLore(SelectItemTypeContainer container, String containerType, String action) {
|
||||
// Prepare material lore
|
||||
ArrayList<String> groupLore = new ArrayList<>();
|
||||
groupLore.add("§7Allow you to select a list of §ematerials §7that this " + containerType + " should " + action);
|
||||
Set<ItemType> typeSet = container.getSelectedMaterials();
|
||||
if (typeSet.isEmpty()) {
|
||||
groupLore.add("§7There is no " + action + "d material for this " + containerType + ".");
|
||||
} else {
|
||||
groupLore.add("§7List of " + action + "d materials for this " + containerType + ":");
|
||||
Iterator<ItemType> typeIterator = typeSet.iterator();
|
||||
|
||||
boolean greaterThanMax = typeSet.size() > 5;
|
||||
int maxindex = (greaterThanMax ? 4 : typeSet.size());
|
||||
for (int i = 0; i < maxindex; i++) {
|
||||
// format string like "- Stone Sword"
|
||||
String formattedName = CasedStringUtil.snakeToUpperSpacedCase(typeIterator.next().key().value().toLowerCase());
|
||||
groupLore.add("§7- §e" + formattedName);
|
||||
|
||||
}
|
||||
if (greaterThanMax) {
|
||||
groupLore.add("§7And " + (typeSet.size() - 4) + " more...");
|
||||
}
|
||||
}
|
||||
return groupLore;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public interface SelectMaterialContainer {
|
||||
|
||||
EnumSet<Material> getSelectedMaterials();
|
||||
|
||||
boolean setSelectedMaterials(EnumSet<Material> materials);
|
||||
|
||||
EnumSet<Material> illegalMaterials();
|
||||
|
||||
static List<String> getMaterialLore(SelectMaterialContainer container, String containerType, String action){
|
||||
// Prepare material lore
|
||||
ArrayList<String> groupLore = new ArrayList<>();
|
||||
groupLore.add("§7Allow you to select a list of §ematerials §7that this " + containerType + " should " + action);
|
||||
Set<Material> materialSet = container.getSelectedMaterials();
|
||||
if (materialSet.isEmpty()) {
|
||||
groupLore.add("§7There is no "+action+"d material for this "+containerType+".");
|
||||
} else {
|
||||
groupLore.add("§7List of "+action+"d materials for this "+containerType+":");
|
||||
Iterator<Material> materialIterator = materialSet.iterator();
|
||||
|
||||
boolean greaterThanMax = materialSet.size() > 5;
|
||||
int maxindex = (greaterThanMax ? 4 : materialSet.size());
|
||||
for (int i = 0; i < maxindex; i++) {
|
||||
// format string like "- Stone Sword"
|
||||
String formattedName = CasedStringUtil.snakeToUpperSpacedCase(materialIterator.next().name().toLowerCase());
|
||||
groupLore.add("§7- §e" + formattedName);
|
||||
|
||||
}
|
||||
if (greaterThanMax) {
|
||||
groupLore.add("§7And " + (materialSet.size() - 4) + " more...");
|
||||
}
|
||||
}
|
||||
return groupLore;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup,
|
||||
MappedGuiListConfigGui.LazyElement<EnchantConflictSubSettingGui>> {
|
||||
|
||||
|
|
@ -69,7 +70,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
|
|||
|
||||
@Override
|
||||
public ItemStack createItemForGeneric(EnchantConflictGroup conflict) {
|
||||
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
|
||||
ItemStack item = conflict.getRepresentativeMaterial().createItemStack();
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
|
||||
|
||||
private static GroupConfigGui INSTANCE;
|
||||
|
|
@ -44,7 +45,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
|||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(IncludeGroup group) {
|
||||
ItemStack item = new ItemStack(group.getRepresentativeMaterial());
|
||||
ItemStack item = group.getRepresentativeMaterial().createItemStack();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
|
|
@ -54,7 +55,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
|||
"§7Number of selected groups : " + group.getGroups().size(),
|
||||
"§7Number of included material : " + group.getNonGroupInheritedMaterials().size(),
|
||||
"",
|
||||
"§7Total number of included material " + group.getMaterials().size()));
|
||||
"§7Total number of included material " + group.getItemTypes().size()));
|
||||
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
|
|
|
|||
|
|
@ -9,12 +9,13 @@ import org.bukkit.entity.HumanEntity;
|
|||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.group.*;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectItemTypeContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.GroupConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.GroupSelectSettingGui;
|
||||
|
|
@ -28,7 +29,8 @@ import java.util.*;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implements SelectGroupContainer, SelectMaterialContainer {
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implements SelectGroupContainer, SelectItemTypeContainer {
|
||||
|
||||
private final GroupConfigGui parent;
|
||||
private final IncludeGroup group;
|
||||
|
|
@ -56,6 +58,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
|
||||
private GuiItem materialSelection;
|
||||
private GuiItem groupSelection;
|
||||
|
||||
private void prepareStaticValues() {
|
||||
GuiGlobalItems.addBackItem(this.pane, this.parent);
|
||||
GuiGlobalItems.addBackgroundItem(this.pane);
|
||||
|
|
@ -215,7 +218,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
public void updateLocal() {
|
||||
if (!this.usable) return;
|
||||
// Prepare material lore
|
||||
List<String> matLore = SelectMaterialContainer.getMaterialLore(this, "group", "include");
|
||||
List<String> matLore = SelectItemTypeContainer.getMaterialLore(this, "group", "include");
|
||||
|
||||
// Prepare group lore
|
||||
List<String> groupLore = SelectGroupContainer.getGroupLore(this, "group", "include");
|
||||
|
|
@ -325,19 +328,19 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
// ----------------------------
|
||||
|
||||
@Override
|
||||
public EnumSet<Material> getSelectedMaterials() {
|
||||
public Set<ItemType> getSelectedMaterials() {
|
||||
return this.group.getNonGroupInheritedMaterials();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSelectedMaterials(EnumSet<Material> materials) {
|
||||
this.group.setNonGroupInheritedMaterials(materials);
|
||||
public boolean setSelectedItems(Set<ItemType> types) {
|
||||
this.group.setNonGroupInheritedMaterials(types);
|
||||
|
||||
// Write to file configuration
|
||||
String[] groupNames = new String[materials.size()];
|
||||
String[] groupNames = new String[types.size()];
|
||||
int index = 0;
|
||||
for (Material otherGroup : materials) {
|
||||
groupNames[index++] = otherGroup.name().toLowerCase();
|
||||
for (ItemType otherGroup : types) {
|
||||
groupNames[index++] = otherGroup.key().value().toLowerCase();
|
||||
}
|
||||
|
||||
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(this.group.getName() + "." + ItemGroupManager.MATERIAL_LIST_PATH, groupNames);
|
||||
|
|
@ -352,9 +355,17 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
return true;
|
||||
}
|
||||
|
||||
private static final Set<ItemType> ONLY_AIR_ITEM_SET;
|
||||
|
||||
static {
|
||||
Set<ItemType> onlyAir = new HashSet<>();
|
||||
onlyAir.add(ItemType.AIR);
|
||||
ONLY_AIR_ITEM_SET = Collections.unmodifiableSet(onlyAir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<Material> illegalMaterials() {
|
||||
return EnumSet.of(Material.AIR);
|
||||
public Set<ItemType> illegalMaterials() {
|
||||
return ONLY_AIR_ITEM_SET;
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
|
|
|
|||
|
|
@ -86,8 +86,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
|
|||
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group) {
|
||||
boolean isIn = this.selectedGroups.contains(group);
|
||||
|
||||
Material usedMaterial = group.getRepresentativeMaterial();
|
||||
ItemStack item = new ItemStack(usedMaterial);
|
||||
ItemStack item = group.getRepresentativeMaterial().createItemStack();
|
||||
|
||||
setGroupItemMeta(item, group.getName(), isIn);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,10 @@ import org.bukkit.entity.HumanEntity;
|
|||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectItemTypeContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.ask.ConfirmActionGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
|
|
@ -22,19 +23,20 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
|||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class MaterialSelectSettingGui extends MappedElementListConfigGui<Material, GuiItem> {
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class MaterialSelectSettingGui extends MappedElementListConfigGui<ItemType, GuiItem> {
|
||||
|
||||
private final SelectMaterialContainer selector;
|
||||
private final SelectItemTypeContainer selector;
|
||||
private final Gui backGui;
|
||||
private boolean instantRemove;
|
||||
|
||||
private final List<Material> defaultMaterials;
|
||||
private final EnumSet<Material> illegalMaterials;
|
||||
private final List<ItemType> defaultMaterials;
|
||||
private final Set<ItemType> illegalMaterials;
|
||||
private final int defaultMaterialHash;
|
||||
private int nowMaterialHash;
|
||||
|
||||
public MaterialSelectSettingGui(
|
||||
@NotNull SelectMaterialContainer selector,
|
||||
@NotNull SelectItemTypeContainer selector,
|
||||
@NotNull String title,
|
||||
@NotNull Gui backGui) {
|
||||
super(title);
|
||||
|
|
@ -45,7 +47,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
this.defaultMaterials = new ArrayList<>(this.selector.getSelectedMaterials());
|
||||
this.illegalMaterials = this.selector.illegalMaterials();
|
||||
|
||||
this.defaultMaterialHash = hashFromMaterialList(this.defaultMaterials);
|
||||
this.defaultMaterialHash = hashFromItemTypeList(this.defaultMaterials);
|
||||
this.nowMaterialHash = this.defaultMaterialHash;
|
||||
|
||||
init();
|
||||
|
|
@ -161,10 +163,9 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
|
||||
|
||||
// Save setting
|
||||
EnumSet<Material> result = EnumSet.noneOf(Material.class);
|
||||
result.addAll(this.elementGuiMap.keySet());
|
||||
Set<ItemType> result = new HashSet<>(this.elementGuiMap.keySet());
|
||||
|
||||
if(!this.selector.setSelectedMaterials(result)){
|
||||
if (!this.selector.setSelectedItems(result)) {
|
||||
player.sendMessage("§cSomething went wrong while saving the change of value.");
|
||||
}
|
||||
|
||||
|
|
@ -185,8 +186,8 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
ItemStack cursor = player.getItemOnCursor();
|
||||
|
||||
// Test if cursor material allowed
|
||||
Material cursorMat = cursor.getType();
|
||||
if(cursorMat.isAir()) return;
|
||||
ItemType cursorMat = cursor.getType().asItemType();
|
||||
if (cursorMat == ItemType.AIR) return;
|
||||
if (this.illegalMaterials.contains(cursorMat)) return;
|
||||
|
||||
// Update gui only if item did not exist before.
|
||||
|
|
@ -201,12 +202,12 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack createItemForGeneric(Material material) {
|
||||
ItemStack item = new ItemStack(material);
|
||||
protected ItemStack createItemForGeneric(ItemType type) {
|
||||
ItemStack item = type.createItemStack();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta == null) return item;
|
||||
meta.setDisplayName("§a" + CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase()));
|
||||
meta.setDisplayName("§a" + CasedStringUtil.snakeToUpperSpacedCase(type.key().value().toLowerCase()));
|
||||
meta.setLore(Collections.singletonList("§7Click here to remove this material from the list"));
|
||||
meta.addItemFlags(ItemFlag.values());
|
||||
|
||||
|
|
@ -216,22 +217,22 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Collection<Material> getEveryDisplayableInstanceOfGeneric() {
|
||||
protected Collection<ItemType> getEveryDisplayableInstanceOfGeneric() {
|
||||
return this.defaultMaterials;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateElement(Material material, GuiItem element) {
|
||||
protected void updateElement(ItemType type, GuiItem element) {
|
||||
// Nothing happen here I think
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem newElementRequested(Material material, GuiItem newItem) {
|
||||
protected GuiItem newElementRequested(ItemType type, GuiItem newItem) {
|
||||
newItem.setAction(event -> {
|
||||
if (this.instantRemove) {
|
||||
removeMaterial(material);
|
||||
removeItemType(type);
|
||||
} else {
|
||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
|
||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(type.key().value().toLowerCase());
|
||||
|
||||
// Create and show confirm remove gui.
|
||||
ConfirmActionGui confirmGui = new ConfirmActionGui(
|
||||
|
|
@ -239,7 +240,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
"§7Confirm Remove " + materialName.toLowerCase() + " from this list.",
|
||||
this, this,
|
||||
() -> {
|
||||
removeMaterial(material);
|
||||
removeItemType(type);
|
||||
return true;
|
||||
}, false
|
||||
);
|
||||
|
|
@ -250,29 +251,28 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
return newItem;
|
||||
}
|
||||
|
||||
private void removeMaterial(Material material) {
|
||||
if(this.elementGuiMap.containsKey(material)){
|
||||
this.nowMaterialHash ^= material.hashCode();
|
||||
private void removeItemType(ItemType type) {
|
||||
if (this.elementGuiMap.containsKey(type)) {
|
||||
this.nowMaterialHash ^= type.hashCode(); //TODO check would this be valid with item type
|
||||
setSaveItem();
|
||||
removeGeneric(material);
|
||||
removeGeneric(type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem findItemFromElement(Material generic, GuiItem element) {
|
||||
protected GuiItem findItemFromElement(ItemType type, GuiItem element) {
|
||||
return element;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiItem findGuiItemForRemoval(Material generic, GuiItem element) {
|
||||
protected GuiItem findGuiItemForRemoval(ItemType type, GuiItem element) {
|
||||
return element;
|
||||
}
|
||||
|
||||
private static int hashFromMaterialList(List<Material> materialList){
|
||||
private static int hashFromItemTypeList(List<ItemType> itemTypeList) {
|
||||
int defaultMaterialHash = 0;
|
||||
for (Material material : materialList) {
|
||||
defaultMaterialHash ^= material.hashCode();
|
||||
for (ItemType type : itemTypeList) {
|
||||
defaultMaterialHash ^= type.hashCode(); //TODO check would this be valid with item type
|
||||
}
|
||||
return defaultMaterialHash;
|
||||
}
|
||||
|
|
@ -296,6 +296,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
|||
protected GuiItem prepareCreateNewItem() {// Not used
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player) {// Not used
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package xyz.alexcrea.cuanvil.update.plugin;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.api.MaterialGroupApi;
|
||||
|
|
@ -16,6 +16,7 @@ import java.util.Set;
|
|||
|
||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class PUpdate_1_11_0 {
|
||||
|
||||
private static final List<String> mace_expected = List.of(
|
||||
|
|
@ -30,22 +31,22 @@ public class PUpdate_1_11_0 {
|
|||
"bane_of_arthropods"
|
||||
);
|
||||
|
||||
private static final Material[] PICKAXES = new Material[]{
|
||||
Material.WOODEN_PICKAXE, Material.STONE_PICKAXE,
|
||||
Material.IRON_PICKAXE, Material.DIAMOND_PICKAXE,
|
||||
Material.GOLDEN_PICKAXE, Material.NETHERITE_PICKAXE
|
||||
private static final ItemType[] PICKAXES = new ItemType[]{
|
||||
ItemType.WOODEN_PICKAXE, ItemType.STONE_PICKAXE,
|
||||
ItemType.IRON_PICKAXE, ItemType.DIAMOND_PICKAXE,
|
||||
ItemType.GOLDEN_PICKAXE, ItemType.NETHERITE_PICKAXE
|
||||
};
|
||||
|
||||
private static final Material[] SHOVELS = new Material[]{
|
||||
Material.WOODEN_SHOVEL, Material.STONE_SHOVEL,
|
||||
Material.IRON_SHOVEL, Material.DIAMOND_SHOVEL,
|
||||
Material.GOLDEN_SHOVEL, Material.NETHERITE_SHOVEL
|
||||
private static final ItemType[] SHOVELS = new ItemType[]{
|
||||
ItemType.WOODEN_SHOVEL, ItemType.STONE_SHOVEL,
|
||||
ItemType.IRON_SHOVEL, ItemType.DIAMOND_SHOVEL,
|
||||
ItemType.GOLDEN_SHOVEL, ItemType.NETHERITE_SHOVEL
|
||||
};
|
||||
|
||||
private static final Material[] HOES = new Material[]{
|
||||
Material.WOODEN_HOE, Material.STONE_HOE,
|
||||
Material.IRON_HOE, Material.DIAMOND_HOE,
|
||||
Material.GOLDEN_HOE, Material.NETHERITE_HOE
|
||||
private static final ItemType[] HOES = new ItemType[]{
|
||||
ItemType.WOODEN_HOE, ItemType.STONE_HOE,
|
||||
ItemType.IRON_HOE, ItemType.DIAMOND_HOE,
|
||||
ItemType.GOLDEN_HOE, ItemType.NETHERITE_HOE
|
||||
};
|
||||
|
||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||
|
|
@ -65,7 +66,7 @@ public class PUpdate_1_11_0 {
|
|||
private static void migrateTools(
|
||||
@Nullable AbstractMaterialGroup tools,
|
||||
@NotNull String toolset,
|
||||
@NotNull Material[] toolMats) {
|
||||
@NotNull ItemType[] toolMats) {
|
||||
|
||||
// Create new group
|
||||
IncludeGroup group = new IncludeGroup(toolset);
|
||||
|
|
@ -77,11 +78,11 @@ public class PUpdate_1_11_0 {
|
|||
if (tools == null) return;
|
||||
if (!(tools instanceof IncludeGroup include)) return;
|
||||
|
||||
List<Material> mats = List.of(toolMats);
|
||||
Set<Material> matSet = include.getNonGroupInheritedMaterials();
|
||||
if (!matSet.containsAll(mats)) return;
|
||||
List<ItemType> types = List.of(toolMats);
|
||||
Set<ItemType> typeSet = include.getNonGroupInheritedMaterials();
|
||||
if (!typeSet.containsAll(types)) return;
|
||||
|
||||
mats.forEach(matSet::remove);
|
||||
types.forEach(typeSet::remove);
|
||||
tools.addToPolicy(group);
|
||||
MaterialGroupApi.writeMaterialGroup(tools);
|
||||
}
|
||||
|
|
@ -108,6 +109,8 @@ public class PUpdate_1_11_0 {
|
|||
|
||||
// Test sword_enchant_conflict is default
|
||||
ConfigurationSection sword_conflict = config.getConfigurationSection("sword_enchant_conflict");
|
||||
if (sword_conflict == null) return;
|
||||
|
||||
if (sword_conflict.getInt("maxEnchantmentBeforeConflict", 0) != 1) return;
|
||||
|
||||
if (sword_conflict.isList("notAffectedGroups") && !sword_conflict.getList("notAffectedGroups").isEmpty())
|
||||
|
|
@ -124,6 +127,7 @@ public class PUpdate_1_11_0 {
|
|||
"minecraft:density", "minecraft:breach");
|
||||
|
||||
config.set("mace_enchant_conflict", null);
|
||||
|
||||
toSave.add(ConfigHolder.CONFLICT_HOLDER);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -135,6 +135,9 @@ object DataPackDependency {
|
|||
// Order matter for this file
|
||||
// Could rewrite to not matter but not really important, so I keep it like that
|
||||
private fun handleItemGroups(yml: YamlConfiguration) {
|
||||
//TODO see below todo
|
||||
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||
|
||||
for (groupName in yml.getKeys(false)) {
|
||||
val section = yml.getConfigurationSection(groupName) ?: continue
|
||||
|
||||
|
|
@ -144,12 +147,19 @@ object DataPackDependency {
|
|||
if (group == null) group = IncludeGroup(groupName)
|
||||
|
||||
for (name in section.getStringList("items")) {
|
||||
//TODO get item key from
|
||||
/*val key = NamespacedKey.fromString(name.lowercase())
|
||||
if (key == null) throw IllegalStateException("Invalid item type: " + name)
|
||||
val type = itemRegistry.get(key)*/
|
||||
|
||||
val mat = Material.getMaterial(name.uppercase())
|
||||
|
||||
|
||||
if (mat == null) {
|
||||
CustomAnvil.instance.logger.warning("Could not find material $name for item group $groupName")
|
||||
continue
|
||||
}
|
||||
group.addToPolicy(mat)
|
||||
group.addToPolicy(mat.asItemType()!!)
|
||||
}
|
||||
for (name in section.getStringList("groups")) {
|
||||
val otherGroup = MaterialGroupApi.getGroup(name)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ import io.delilaheve.CustomAnvil
|
|||
import me.athlaeos.enchantssquared.enchantments.CustomEnchant
|
||||
import me.athlaeos.enchantssquared.listeners.AnvilListener
|
||||
import me.athlaeos.enchantssquared.managers.CustomEnchantManager
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.ItemType
|
||||
import org.bukkit.plugin.Plugin
|
||||
import xyz.alexcrea.cuanvil.api.ConflictBuilder
|
||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||
|
|
@ -20,6 +20,7 @@ import xyz.alexcrea.cuanvil.enchant.wrapped.CAEnchantSquaredEnchantment
|
|||
import xyz.alexcrea.cuanvil.group.IncludeGroup
|
||||
import java.util.*
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) {
|
||||
|
||||
init {
|
||||
|
|
@ -30,7 +31,8 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
|||
"disable_anvil, " +
|
||||
"incompatible_vanilla_enchantments, " +
|
||||
"incompatible_custom_enchantments and max_level " +
|
||||
"configuration values.")
|
||||
"configuration values."
|
||||
)
|
||||
}
|
||||
|
||||
fun disableAnvilListener() {
|
||||
|
|
@ -69,8 +71,8 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
|||
fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap<CAEnchantment, Int>) {
|
||||
val customEnchants = CustomEnchantManager.getInstance().getItemsEnchantsFromPDC(item)
|
||||
|
||||
customEnchants.forEach{
|
||||
(enchantment, level ) -> enchantments[getWrappedEnchant(enchantment)] = level
|
||||
customEnchants.forEach { (enchantment, level) ->
|
||||
enchantments[getWrappedEnchant(enchantment)] = level
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -78,6 +80,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
|||
fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey {
|
||||
return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!!
|
||||
}
|
||||
|
||||
private fun getWrappedEnchant(enchant: CustomEnchant): CAEnchantment {
|
||||
return CAEnchantment.getByKey(getKeyFromEnchant(enchant))!!
|
||||
}
|
||||
|
|
@ -102,15 +105,15 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
|||
private fun writeMissingGroups() {
|
||||
// Write group that do not exist on custom anvil.
|
||||
val shield = IncludeGroup("shield")
|
||||
shield.addToPolicy(Material.SHIELD)
|
||||
shield.addToPolicy(ItemType.SHIELD)
|
||||
MaterialGroupApi.addMaterialGroup(shield)
|
||||
|
||||
val elytra = IncludeGroup("elytra")
|
||||
elytra.addToPolicy(Material.ELYTRA)
|
||||
elytra.addToPolicy(ItemType.ELYTRA)
|
||||
MaterialGroupApi.addMaterialGroup(elytra)
|
||||
|
||||
val trinkets = IncludeGroup("trinkets")
|
||||
trinkets.addToPolicy(Material.ROTTEN_FLESH)
|
||||
trinkets.addToPolicy(ItemType.ROTTEN_FLESH)
|
||||
MaterialGroupApi.addMaterialGroup(trinkets)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
package xyz.alexcrea.cuanvil.group
|
||||
|
||||
import org.bukkit.Material
|
||||
import java.util.*
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import org.bukkit.inventory.ItemType
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
abstract class AbstractMaterialGroup(private val name: String) {
|
||||
protected val includedMaterial by lazy { createDefaultSet() }
|
||||
protected val includedItems by lazy { createDefaultSet() }
|
||||
|
||||
/**
|
||||
* Get the group default set
|
||||
*/
|
||||
protected abstract fun createDefaultSet(): EnumSet<Material>
|
||||
protected abstract fun createDefaultSet(): MutableSet<ItemType>
|
||||
|
||||
/**
|
||||
* Get if a material is allowed following the group policy
|
||||
*/
|
||||
open fun contain(mat: Material): Boolean {
|
||||
return mat in getMaterials()
|
||||
open fun contain(mat: ItemType): Boolean {
|
||||
return mat in getItemTypes()
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -24,30 +25,34 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
abstract fun isReferencing(other: AbstractMaterialGroup): Boolean
|
||||
|
||||
/**
|
||||
* Push a material to this group to follow this group policy
|
||||
* Push an item to this group to follow this group policy
|
||||
*
|
||||
* @return this instance.
|
||||
*/
|
||||
abstract fun addToPolicy(mat: Material): AbstractMaterialGroup
|
||||
abstract fun addToPolicy(type: ItemType): AbstractMaterialGroup
|
||||
|
||||
/**
|
||||
* Push a list of material to this group to follow this group policy
|
||||
* Push a list of items to this group to follow this group policy
|
||||
*
|
||||
* @return this instance.
|
||||
*/
|
||||
fun addAll(vararg materials: Material): AbstractMaterialGroup {
|
||||
for (material in materials) {
|
||||
addToPolicy(material)
|
||||
fun addAll(vararg types: ItemType): AbstractMaterialGroup {
|
||||
for (type in types) {
|
||||
addToPolicy(type)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Push a group to this group to follow this group policy
|
||||
*
|
||||
* @return this instance.
|
||||
*/
|
||||
abstract fun addToPolicy(other: AbstractMaterialGroup): AbstractMaterialGroup
|
||||
|
||||
/**
|
||||
* Push a list of group to this group to follow this group policy
|
||||
*
|
||||
* @return this instance.
|
||||
*/
|
||||
fun addAll(vararg otherList: AbstractMaterialGroup): AbstractMaterialGroup {
|
||||
|
|
@ -58,23 +63,23 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the group contained material as a set
|
||||
* Get the group contained item as a set
|
||||
*/
|
||||
abstract fun getMaterials(): EnumSet<Material>
|
||||
abstract fun getItemTypes(): ImmutableSet<ItemType>
|
||||
|
||||
/**
|
||||
* Get the group non-inherited material as a set
|
||||
* Get the group non-inherited items as a set
|
||||
*/
|
||||
open fun getNonGroupInheritedMaterials(): EnumSet<Material> {
|
||||
return includedMaterial
|
||||
open fun getNonGroupInheritedMaterials(): MutableSet<ItemType> {
|
||||
return includedItems
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the group non-inherited material as a set
|
||||
* Set the group non-inherited items
|
||||
*/
|
||||
open fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
||||
this.includedMaterial.clear()
|
||||
this.includedMaterial.addAll(materials)
|
||||
open fun setNonGroupInheritedMaterials(types: Set<ItemType>) {
|
||||
this.includedItems.clear()
|
||||
this.includedItems.addAll(types)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -98,22 +103,22 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
|||
*/
|
||||
abstract fun getGroups(): MutableSet<AbstractMaterialGroup>
|
||||
|
||||
open fun getRepresentativeMaterial(): Material {
|
||||
open fun getRepresentativeMaterial(): ItemType {
|
||||
// Test inner material
|
||||
val matIterator = includedMaterial.iterator()
|
||||
while (matIterator.hasNext()) {
|
||||
val material = matIterator.next()
|
||||
if (material.isAir) continue
|
||||
return material
|
||||
val itemIterator = includedItems.iterator()
|
||||
while (itemIterator.hasNext()) {
|
||||
val type = itemIterator.next()
|
||||
if (type == ItemType.AIR) continue
|
||||
return type
|
||||
}
|
||||
// Test included group representative material
|
||||
val groupIterator = getGroups().iterator()
|
||||
while (groupIterator.hasNext()) {
|
||||
val groupMat = groupIterator.next().getRepresentativeMaterial()
|
||||
if (groupMat.isAir) continue
|
||||
return groupMat
|
||||
val groupType = groupIterator.next().getRepresentativeMaterial()
|
||||
if (groupType == ItemType.AIR) continue
|
||||
return groupType
|
||||
}
|
||||
return Material.PAPER
|
||||
return ItemType.PAPER
|
||||
}
|
||||
|
||||
abstract fun updateMaterials()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package xyz.alexcrea.cuanvil.group
|
||||
|
||||
import io.delilaheve.CustomAnvil
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.inventory.ItemType
|
||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
class EnchantConflictGroup(
|
||||
val name: String,
|
||||
private val cantConflict: AbstractMaterialGroup,
|
||||
|
|
@ -15,17 +16,18 @@ class EnchantConflictGroup(
|
|||
fun addEnchantment(enchant: CAEnchantment) {
|
||||
enchantments.add(enchant)
|
||||
}
|
||||
|
||||
fun addEnchantments(enchants: List<CAEnchantment>) {
|
||||
enchantments.addAll(enchants)
|
||||
}
|
||||
|
||||
fun allowed(enchants: Set<CAEnchantment>, mat: Material): Boolean {
|
||||
fun allowed(enchants: Set<CAEnchantment>, type: ItemType): Boolean {
|
||||
if (enchantments.size < minBeforeBlock) {
|
||||
CustomAnvil.verboseLog("Conflicting bc of to many enchantments")
|
||||
return true
|
||||
}
|
||||
|
||||
if (cantConflict.contain(mat)) {
|
||||
if (cantConflict.contain(type)) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
@ -56,15 +58,15 @@ class EnchantConflictGroup(
|
|||
enchantments.addAll(enchants)
|
||||
}
|
||||
|
||||
fun getRepresentativeMaterial(): Material {
|
||||
fun getRepresentativeMaterial(): ItemType {
|
||||
val groups = getCantConflictGroup().getGroups()
|
||||
val groupIterator = groups.iterator()
|
||||
while (groupIterator.hasNext()) {
|
||||
val mat = groupIterator.next().getRepresentativeMaterial()
|
||||
if (mat != Material.ENCHANTED_BOOK) return mat
|
||||
val itemType = groupIterator.next().getRepresentativeMaterial()
|
||||
if (itemType != ItemType.ENCHANTED_BOOK) return itemType
|
||||
|
||||
}
|
||||
return Material.ENCHANTED_BOOK
|
||||
return ItemType.ENCHANTED_BOOK
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
|||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||
import java.util.*
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
class EnchantConflictManager {
|
||||
|
||||
companion object {
|
||||
|
|
@ -176,7 +177,9 @@ class EnchantConflictManager {
|
|||
newEnchant: CAEnchantment
|
||||
): ConflictType {
|
||||
val mat = item.type
|
||||
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${mat.key}")
|
||||
val itemType = mat.asItemType()!!
|
||||
|
||||
CustomAnvil.verboseLog("Testing conflict for ${newEnchant.key} on ${itemType.key}")
|
||||
val conflictList = newEnchant.conflicts
|
||||
|
||||
var result = ConflictType.NO_CONFLICT
|
||||
|
|
@ -187,7 +190,7 @@ class EnchantConflictManager {
|
|||
continue
|
||||
}
|
||||
|
||||
val allowed = conflict.allowed(appliedEnchants.keys, mat)
|
||||
val allowed = conflict.allowed(appliedEnchants.keys, itemType)
|
||||
CustomAnvil.verboseLog("Was against $conflict and conflicting: ${!allowed} ")
|
||||
if (!allowed) {
|
||||
if (conflict.getEnchants().size <= 1) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,20 @@
|
|||
package xyz.alexcrea.cuanvil.group
|
||||
|
||||
import org.bukkit.Material
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import io.papermc.paper.registry.RegistryAccess
|
||||
import io.papermc.paper.registry.RegistryKey
|
||||
import org.bukkit.inventory.ItemType
|
||||
import java.util.*
|
||||
|
||||
@Deprecated("Need rework to reduce memory cost as not enum set")
|
||||
@Suppress("UnstableApiUsage")
|
||||
class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||
override fun createDefaultSet(): EnumSet<Material> {
|
||||
return EnumSet.allOf(Material::class.java)
|
||||
|
||||
override fun createDefaultSet(): MutableSet<ItemType> {
|
||||
val types: MutableSet<ItemType> = HashSet()
|
||||
|
||||
types.addAll(RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM))
|
||||
return types
|
||||
}
|
||||
|
||||
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
||||
|
|
@ -20,29 +29,29 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun addToPolicy(mat: Material): ExcludeGroup {
|
||||
includedMaterial.remove(mat)
|
||||
groupItems.remove(mat)
|
||||
override fun addToPolicy(type: ItemType): ExcludeGroup {
|
||||
includedItems.remove(type)
|
||||
groupItems.remove(type)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
override fun addToPolicy(other: AbstractMaterialGroup): ExcludeGroup {
|
||||
includedGroup.add(other)
|
||||
groupItems.removeAll(other.getMaterials())
|
||||
groupItems.removeAll(other.getItemTypes())
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
groupItems.addAll(includedItems)
|
||||
|
||||
includedGroup.clear()
|
||||
groups.forEach { group ->
|
||||
if (!group.isReferencing(this)) {
|
||||
includedGroup.add(group)
|
||||
groupItems.removeAll(group.getMaterials())
|
||||
groupItems.removeAll(group.getItemTypes())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,15 +62,15 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
|
||||
override fun updateMaterials() {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
groupItems.addAll(includedItems)
|
||||
|
||||
includedGroup.forEach { group ->
|
||||
groupItems.addAll(group.getMaterials())
|
||||
groupItems.addAll(group.getItemTypes())
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMaterials(): EnumSet<Material> {
|
||||
return groupItems
|
||||
override fun getItemTypes(): ImmutableSet<ItemType> {
|
||||
return Collections.unmodifiableSet(groupItems) as ImmutableSet<ItemType>
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
package xyz.alexcrea.cuanvil.group
|
||||
|
||||
import org.bukkit.Material
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import org.bukkit.inventory.ItemType
|
||||
import java.util.*
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||
override fun createDefaultSet(): EnumSet<Material> {
|
||||
return EnumSet.noneOf(Material::class.java)
|
||||
override fun createDefaultSet(): MutableSet<ItemType> {
|
||||
return HashSet()
|
||||
}
|
||||
|
||||
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
||||
|
|
@ -20,35 +22,35 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
return false
|
||||
}
|
||||
|
||||
override fun addToPolicy(mat: Material): IncludeGroup {
|
||||
includedMaterial.add(mat)
|
||||
groupItems.add(mat)
|
||||
override fun addToPolicy(type: ItemType): IncludeGroup {
|
||||
includedItems.add(type)
|
||||
groupItems.add(type)
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
override fun addToPolicy(other: AbstractMaterialGroup): IncludeGroup {
|
||||
includedGroup.add(other)
|
||||
groupItems.addAll(other.getMaterials())
|
||||
groupItems.addAll(other.getItemTypes())
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
groupItems.addAll(includedItems)
|
||||
|
||||
includedGroup.clear()
|
||||
groups.forEach { group ->
|
||||
if (!group.isReferencing(this)) {
|
||||
includedGroup.add(group)
|
||||
groupItems.addAll(group.getMaterials())
|
||||
groupItems.addAll(group.getItemTypes())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
||||
super.setNonGroupInheritedMaterials(materials)
|
||||
override fun setNonGroupInheritedMaterials(types: Set<ItemType>) {
|
||||
super.setNonGroupInheritedMaterials(types)
|
||||
|
||||
updateMaterials()
|
||||
}
|
||||
|
|
@ -59,15 +61,15 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
|||
|
||||
override fun updateMaterials() {
|
||||
groupItems.clear()
|
||||
groupItems.addAll(includedMaterial)
|
||||
groupItems.addAll(includedItems)
|
||||
|
||||
includedGroup.forEach { group ->
|
||||
groupItems.addAll(group.getMaterials())
|
||||
groupItems.addAll(group.getItemTypes())
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMaterials(): EnumSet<Material> {
|
||||
return groupItems
|
||||
override fun getItemTypes(): ImmutableSet<ItemType> {
|
||||
return Collections.unmodifiableSet(groupItems) as ImmutableSet<ItemType>
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -76,22 +76,48 @@ class ItemGroupManager {
|
|||
config: ConfigurationSection,
|
||||
keys: Set<String>
|
||||
) {
|
||||
//TODO see below todo
|
||||
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||
|
||||
// Read material to include in this group policy
|
||||
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH)
|
||||
for (materialTemp in materialList) {
|
||||
val materialName = materialTemp.uppercase(Locale.getDefault())
|
||||
for (typeName in materialList) {
|
||||
//TODO get item key from
|
||||
/*val key = NamespacedKey.fromString(typeName.lowercase())
|
||||
if (key == null) {
|
||||
CustomAnvil.instance.logger.warning(
|
||||
"Malformed item type $typeName on group ${group.getName()}"
|
||||
)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
val type = itemRegistry.get(key)
|
||||
if(type == null){
|
||||
// Check if we should warn the user
|
||||
if (typeName !in FUTURE_MATERIAL) {
|
||||
CustomAnvil.instance.logger.warning(
|
||||
"Unknown item type $typeName on group ${group.getName()}"
|
||||
)
|
||||
|
||||
}
|
||||
continue
|
||||
}*/
|
||||
|
||||
|
||||
val materialName = typeName.uppercase(Locale.getDefault())
|
||||
val material = Material.getMaterial(materialName)
|
||||
if (material == null) {
|
||||
// Check if we should warn the user
|
||||
if (materialName !in FUTURE_MATERIAL) {
|
||||
CustomAnvil.instance.logger.warning(
|
||||
"Unknown material $materialTemp on group ${group.getName()}"
|
||||
"Unknown material $materialName on group ${group.getName()}"
|
||||
)
|
||||
|
||||
}
|
||||
continue
|
||||
}
|
||||
group.addToPolicy(material)
|
||||
group.addToPolicy(material.asItemType()!!)
|
||||
}
|
||||
|
||||
// Read group to include in this group policy.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.alexcrea.cuanvil.api;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemType;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
||||
|
|
@ -9,13 +9,14 @@ import xyz.alexcrea.cuanvil.tests.ConfigResetCustomAnvilTest;
|
|||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
||||
|
||||
@Test
|
||||
void groupAddAndRemove() {
|
||||
String groupName = "group";
|
||||
IncludeGroup group = new IncludeGroup(groupName);
|
||||
group.addToPolicy(Material.DIAMOND_PICKAXE); // We do not want it to be empty
|
||||
group.addToPolicy(ItemType.DIAMOND_PICKAXE); // We do not want it to be empty
|
||||
|
||||
// Group not being set should not exist
|
||||
assertFalse(doGroupExist(groupName));
|
||||
|
|
@ -48,7 +49,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
|||
void writeGroup_Reload() {
|
||||
String groupName = "group";
|
||||
IncludeGroup group = new IncludeGroup(groupName);
|
||||
group.addToPolicy(Material.DIAMOND_PICKAXE); // We do not want it to be empty
|
||||
group.addToPolicy(ItemType.DIAMOND_PICKAXE); // We do not want it to be empty
|
||||
|
||||
// Group not being set should not exist
|
||||
assertFalse(doGroupExist(groupName));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue