mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +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.CustomAnvil;
|
||||||
import io.delilaheve.util.ConfigOptions;
|
import io.delilaheve.util.ConfigOptions;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
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.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
|
|
@ -19,7 +19,7 @@ import java.util.*;
|
||||||
/**
|
/**
|
||||||
* Custom Anvil api for material group registry.
|
* Custom Anvil api for material group registry.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings({"unused", "UnstableApiUsage"})
|
||||||
public class MaterialGroupApi {
|
public class MaterialGroupApi {
|
||||||
|
|
||||||
private MaterialGroupApi() {
|
private MaterialGroupApi() {
|
||||||
|
|
@ -105,6 +105,7 @@ public class MaterialGroupApi {
|
||||||
if (group instanceof IncludeGroup includeGroup) {
|
if (group instanceof IncludeGroup includeGroup) {
|
||||||
changed = writeKnownGroup("include", includeGroup);
|
changed = writeKnownGroup("include", includeGroup);
|
||||||
} else if (group instanceof ExcludeGroup excludeGroup) {
|
} 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");
|
throw new UnsupportedOperationException("exclude group is temporarily disable for the time being. sorry");
|
||||||
// This code do not do what is intended ? idk why do it exist
|
// This code do not do what is intended ? idk why do it exist
|
||||||
//changed = writeKnownGroup("exclude", excludeGroup);
|
//changed = writeKnownGroup("exclude", excludeGroup);
|
||||||
|
|
@ -123,12 +124,12 @@ 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<Material> materialSet = group.getNonGroupInheritedMaterials();
|
Set<ItemType> itemSets = group.getNonGroupInheritedMaterials();
|
||||||
Set<AbstractMaterialGroup> groupSet = group.getGroups();
|
Set<AbstractMaterialGroup> groupSet = group.getGroups();
|
||||||
|
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
if (!materialSet.isEmpty()) {
|
if (!itemSets.isEmpty()) {
|
||||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materialSet));
|
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, itemTypesSetToStringList(itemSets));
|
||||||
empty = false;
|
empty = false;
|
||||||
} else {
|
} else {
|
||||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, null);
|
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, null);
|
||||||
|
|
@ -153,18 +154,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() + ".";
|
||||||
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.GROUP_TYPE_PATH, "include");
|
||||||
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, materialSetToStringList(materials));
|
config.set(basePath + ItemGroupManager.MATERIAL_LIST_PATH, itemTypesSetToStringList(itemTypes));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> materialSetToStringList(@NotNull Set<Material> materials) {
|
public static List<String> itemTypesSetToStringList(@NotNull Set<ItemType> types) {
|
||||||
return materials.stream().map(material -> material.getKey().getKey().toLowerCase()).toList();
|
return types.stream().map(item -> item.getKey().getKey().toLowerCase()).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> materialGroupSetToStringList(@NotNull Set<AbstractMaterialGroup> groups) {
|
public static List<String> materialGroupSetToStringList(@NotNull Set<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,32 +18,33 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup,
|
public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGroup,
|
||||||
MappedGuiListConfigGui.LazyElement<EnchantConflictSubSettingGui>> {
|
MappedGuiListConfigGui.LazyElement<EnchantConflictSubSettingGui>> {
|
||||||
|
|
||||||
private static EnchantConflictGui INSTANCE;
|
private static EnchantConflictGui INSTANCE;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static EnchantConflictGui getCurrentInstance(){
|
public static EnchantConflictGui getCurrentInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static EnchantConflictGui getInstance(){
|
public static EnchantConflictGui getInstance() {
|
||||||
if(INSTANCE == null) INSTANCE = new EnchantConflictGui();
|
if (INSTANCE == null) INSTANCE = new EnchantConflictGui();
|
||||||
|
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private EnchantConflictGui() {
|
private EnchantConflictGui() {
|
||||||
super( "Conflict Config");
|
super("Conflict Config");
|
||||||
|
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EnchantConflictGroup createAndSaveNewEmptyGeneric(String name){
|
protected EnchantConflictGroup createAndSaveNewEmptyGeneric(String name) {
|
||||||
// Create new empty conflict and display it to the admin
|
// Create new empty conflict and display it to the admin
|
||||||
EnchantConflictGroup conflict = new EnchantConflictGroup(
|
EnchantConflictGroup conflict = new EnchantConflictGroup(
|
||||||
name,
|
name,
|
||||||
|
|
@ -69,7 +70,7 @@ public class EnchantConflictGui extends MappedGuiListConfigGui<EnchantConflictGr
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack createItemForGeneric(EnchantConflictGroup conflict) {
|
public ItemStack createItemForGeneric(EnchantConflictGroup conflict) {
|
||||||
ItemStack item = new ItemStack(conflict.getRepresentativeMaterial());
|
ItemStack item = conflict.getRepresentativeMaterial().createItemStack();
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
assert meta != null;
|
assert meta != null;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
|
public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedGuiListConfigGui.LazyElement<GroupConfigSubSettingGui>> {
|
||||||
|
|
||||||
private static GroupConfigGui INSTANCE;
|
private static GroupConfigGui INSTANCE;
|
||||||
|
|
@ -44,7 +45,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ItemStack createItemForGeneric(IncludeGroup group) {
|
protected ItemStack createItemForGeneric(IncludeGroup group) {
|
||||||
ItemStack item = new ItemStack(group.getRepresentativeMaterial());
|
ItemStack item = group.getRepresentativeMaterial().createItemStack();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
assert meta != null;
|
assert meta != null;
|
||||||
|
|
||||||
|
|
@ -54,7 +55,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, MappedG
|
||||||
"§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.getNonGroupInheritedMaterials().size(),
|
||||||
"",
|
"",
|
||||||
"§7Total number of included material " + group.getMaterials().size()));
|
"§7Total number of included material " + group.getItemTypes().size()));
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
return item;
|
return item;
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,13 @@ import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
import xyz.alexcrea.cuanvil.group.*;
|
import xyz.alexcrea.cuanvil.group.*;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
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.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;
|
||||||
|
|
@ -28,7 +29,8 @@ import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
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 GroupConfigGui parent;
|
||||||
private final IncludeGroup group;
|
private final IncludeGroup group;
|
||||||
|
|
@ -56,6 +58,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
|
|
||||||
private GuiItem materialSelection;
|
private GuiItem materialSelection;
|
||||||
private GuiItem groupSelection;
|
private GuiItem groupSelection;
|
||||||
|
|
||||||
private void prepareStaticValues() {
|
private void prepareStaticValues() {
|
||||||
GuiGlobalItems.addBackItem(this.pane, this.parent);
|
GuiGlobalItems.addBackItem(this.pane, this.parent);
|
||||||
GuiGlobalItems.addBackgroundItem(this.pane);
|
GuiGlobalItems.addBackgroundItem(this.pane);
|
||||||
|
|
@ -116,7 +119,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// test if group is used & cancel & warn user if so
|
// test if group is used & cancel & warn user if so
|
||||||
if(testAndWarnIfUsed(player)) return;
|
if (testAndWarnIfUsed(player)) return;
|
||||||
|
|
||||||
deleteGui.show(player);
|
deleteGui.show(player);
|
||||||
};
|
};
|
||||||
|
|
@ -125,7 +128,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
private @NotNull ConfirmActionGui createDeleteGui() {
|
private @NotNull ConfirmActionGui createDeleteGui() {
|
||||||
Supplier<Boolean> deleteSupplier = () -> {
|
Supplier<Boolean> deleteSupplier = () -> {
|
||||||
// test if group is used & cancel if so
|
// test if group is used & cancel if so
|
||||||
if(!getUsedLocations(this.group).isEmpty()) return false;
|
if (!getUsedLocations(this.group).isEmpty()) return false;
|
||||||
|
|
||||||
ItemGroupManager manager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
ItemGroupManager manager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
||||||
|
|
||||||
|
|
@ -156,23 +159,23 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean testAndWarnIfUsed(HumanEntity player){
|
public boolean testAndWarnIfUsed(HumanEntity player) {
|
||||||
List<String> usedLoc = getUsedLocations(this.group);
|
List<String> usedLoc = getUsedLocations(this.group);
|
||||||
if(usedLoc.isEmpty()){
|
if (usedLoc.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
StringBuilder stb = new StringBuilder("§cCan't delete group " +this.group.getName()+
|
StringBuilder stb = new StringBuilder("§cCan't delete group " + this.group.getName() +
|
||||||
"\n§eUsed by:");
|
"\n§eUsed by:");
|
||||||
int maxIndex = usedLoc.size();
|
int maxIndex = usedLoc.size();
|
||||||
int nbMore = 0;
|
int nbMore = 0;
|
||||||
if(maxIndex > 10){
|
if (maxIndex > 10) {
|
||||||
nbMore = maxIndex - 9;
|
nbMore = maxIndex - 9;
|
||||||
maxIndex = 9;
|
maxIndex = 9;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < maxIndex; i++) {
|
for (int i = 0; i < maxIndex; i++) {
|
||||||
stb.append("\n§r-§e ").append(usedLoc.get(i));
|
stb.append("\n§r-§e ").append(usedLoc.get(i));
|
||||||
}
|
}
|
||||||
if(nbMore > 0){
|
if (nbMore > 0) {
|
||||||
stb.append("§cAnd ").append(nbMore).append(" More...");
|
stb.append("§cAnd ").append(nbMore).append(" More...");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,13 +184,13 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a string containing every instance of where this group is used
|
// return a string containing every instance of where this group is used
|
||||||
public static List<String> getUsedLocations(AbstractMaterialGroup group){
|
public static List<String> getUsedLocations(AbstractMaterialGroup group) {
|
||||||
ArrayList<String> usageList = new ArrayList<>();
|
ArrayList<String> usageList = new ArrayList<>();
|
||||||
|
|
||||||
// Test used by another group
|
// Test used by another group
|
||||||
ItemGroupManager groupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
ItemGroupManager groupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
|
||||||
for (AbstractMaterialGroup otherGroup : groupManager.getGroupMap().values()) {
|
for (AbstractMaterialGroup otherGroup : groupManager.getGroupMap().values()) {
|
||||||
if(otherGroup.getGroups().contains(group)) {
|
if (otherGroup.getGroups().contains(group)) {
|
||||||
usageList.add("group " + otherGroup.getName());
|
usageList.add("group " + otherGroup.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -195,7 +198,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
// Test if used for conflict
|
// Test if used for conflict
|
||||||
EnchantConflictManager conflictManager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
|
EnchantConflictManager conflictManager = ConfigHolder.CONFLICT_HOLDER.getConflictManager();
|
||||||
for (EnchantConflictGroup conflict : conflictManager.getConflictList()) {
|
for (EnchantConflictGroup conflict : conflictManager.getConflictList()) {
|
||||||
if(conflict.getCantConflictGroup().getGroups().contains(group)) {
|
if (conflict.getCantConflictGroup().getGroups().contains(group)) {
|
||||||
usageList.add("conflict " + conflict);
|
usageList.add("conflict " + conflict);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +208,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGuiValues() {
|
public void updateGuiValues() {
|
||||||
if(!this.usable) return;
|
if (!this.usable) return;
|
||||||
// Parent should call updateLocal with this call
|
// Parent should call updateLocal with this call
|
||||||
this.parent.updateValueForGeneric(this.group, true);
|
this.parent.updateValueForGeneric(this.group, true);
|
||||||
|
|
||||||
|
|
@ -213,9 +216,9 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateLocal() {
|
public void updateLocal() {
|
||||||
if(!this.usable) return;
|
if (!this.usable) return;
|
||||||
// Prepare material lore
|
// Prepare material lore
|
||||||
List<String> matLore = SelectMaterialContainer.getMaterialLore(this, "group", "include");
|
List<String> matLore = SelectItemTypeContainer.getMaterialLore(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");
|
||||||
|
|
@ -255,7 +258,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(@NotNull HumanEntity player) {
|
public void show(@NotNull HumanEntity player) {
|
||||||
if(!this.usable) {
|
if (!this.usable) {
|
||||||
this.parent.show(player);
|
this.parent.show(player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -284,7 +287,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGroup(@NotNull AbstractMaterialGroup group, Set<AbstractMaterialGroup> groups){
|
private void updateGroup(@NotNull AbstractMaterialGroup group, Set<AbstractMaterialGroup> groups) {
|
||||||
// Set live configuration
|
// Set live configuration
|
||||||
group.setGroups(groups);
|
group.setGroups(groups);
|
||||||
|
|
||||||
|
|
@ -296,7 +299,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
groupNames[index++] = otherGroup.getName();
|
groupNames[index++] = otherGroup.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName()+"."+ItemGroupManager.GROUP_LIST_PATH, groupNames);
|
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName() + "." + ItemGroupManager.GROUP_LIST_PATH, groupNames);
|
||||||
|
|
||||||
// Try to update referencing group. kind of expensive operation in some case.
|
// Try to update referencing group. kind of expensive operation in some case.
|
||||||
updateDirectReferencingGroups(group);
|
updateDirectReferencingGroups(group);
|
||||||
|
|
@ -309,7 +312,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
Set<AbstractMaterialGroup> illegal = new HashSet<>();
|
Set<AbstractMaterialGroup> illegal = new HashSet<>();
|
||||||
|
|
||||||
for (AbstractMaterialGroup otherGroup : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
for (AbstractMaterialGroup otherGroup : ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values()) {
|
||||||
if(otherGroup.isReferencing(this.group)){
|
if (otherGroup.isReferencing(this.group)) {
|
||||||
illegal.add(otherGroup);
|
illegal.add(otherGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -325,22 +328,22 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<Material> getSelectedMaterials() {
|
public Set<ItemType> getSelectedMaterials() {
|
||||||
return this.group.getNonGroupInheritedMaterials();
|
return this.group.getNonGroupInheritedMaterials();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSelectedMaterials(EnumSet<Material> materials) {
|
public boolean setSelectedItems(Set<ItemType> types) {
|
||||||
this.group.setNonGroupInheritedMaterials(materials);
|
this.group.setNonGroupInheritedMaterials(types);
|
||||||
|
|
||||||
// Write to file configuration
|
// Write to file configuration
|
||||||
String[] groupNames = new String[materials.size()];
|
String[] groupNames = new String[types.size()];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Material otherGroup : materials) {
|
for (ItemType otherGroup : types) {
|
||||||
groupNames[index++] = otherGroup.name().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.MATERIAL_LIST_PATH, groupNames);
|
||||||
|
|
||||||
// update referencing groups
|
// update referencing groups
|
||||||
updateDirectReferencingGroups(this.group);
|
updateDirectReferencingGroups(this.group);
|
||||||
|
|
@ -352,16 +355,24 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
return true;
|
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
|
@Override
|
||||||
public EnumSet<Material> illegalMaterials() {
|
public Set<ItemType> illegalMaterials() {
|
||||||
return EnumSet.of(Material.AIR);
|
return ONLY_AIR_ITEM_SET;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
// End of SelectMaterialContainer related methods
|
// End of SelectMaterialContainer related methods
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
|
|
||||||
private void updateDirectReferencingGroups(AbstractMaterialGroup referenceTo){
|
private void updateDirectReferencingGroups(AbstractMaterialGroup referenceTo) {
|
||||||
Collection<AbstractMaterialGroup> everyStoredGroups = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values();
|
Collection<AbstractMaterialGroup> everyStoredGroups = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().getGroupMap().values();
|
||||||
List<EnchantConflictGroup> everyConflicts = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
|
List<EnchantConflictGroup> everyConflicts = ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList();
|
||||||
|
|
||||||
|
|
@ -370,7 +381,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
HashSet<AbstractMaterialGroup> conflictGroupPlanned = new HashSet<>();
|
HashSet<AbstractMaterialGroup> conflictGroupPlanned = new HashSet<>();
|
||||||
|
|
||||||
updateFuture.add(referenceTo);
|
updateFuture.add(referenceTo);
|
||||||
while (!updateFuture.isEmpty()){
|
while (!updateFuture.isEmpty()) {
|
||||||
HashSet<AbstractMaterialGroup> temp = updateFuture;
|
HashSet<AbstractMaterialGroup> temp = updateFuture;
|
||||||
updateFuture = toUpdate;
|
updateFuture = toUpdate;
|
||||||
updateFuture.clear();
|
updateFuture.clear();
|
||||||
|
|
@ -379,7 +390,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
for (AbstractMaterialGroup testGroup : toUpdate) {
|
for (AbstractMaterialGroup testGroup : toUpdate) {
|
||||||
// Update other stored group
|
// Update other stored group
|
||||||
for (AbstractMaterialGroup otherGroup : everyStoredGroups) {
|
for (AbstractMaterialGroup otherGroup : everyStoredGroups) {
|
||||||
if(otherGroup.getGroups().contains(testGroup)){
|
if (otherGroup.getGroups().contains(testGroup)) {
|
||||||
otherGroup.updateMaterials();
|
otherGroup.updateMaterials();
|
||||||
updateFuture.add(otherGroup);
|
updateFuture.add(otherGroup);
|
||||||
}
|
}
|
||||||
|
|
@ -388,13 +399,13 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
||||||
// plan update for conflict groups
|
// plan update for conflict groups
|
||||||
for (EnchantConflictGroup everyConflict : everyConflicts) {
|
for (EnchantConflictGroup everyConflict : everyConflicts) {
|
||||||
AbstractMaterialGroup conflictGroup = everyConflict.getCantConflictGroup();
|
AbstractMaterialGroup conflictGroup = everyConflict.getCantConflictGroup();
|
||||||
if(conflictGroup.getGroups().contains(testGroup)){
|
if (conflictGroup.getGroups().contains(testGroup)) {
|
||||||
conflictGroupPlanned.add(conflictGroup);
|
conflictGroupPlanned.add(conflictGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update parent & local by extension
|
// Update parent & local by extension
|
||||||
if(testGroup instanceof IncludeGroup){
|
if (testGroup instanceof IncludeGroup) {
|
||||||
this.parent.updateValueForGeneric((IncludeGroup) testGroup, false);
|
this.parent.updateValueForGeneric((IncludeGroup) testGroup, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,8 +86,7 @@ public class GroupSelectSettingGui extends AbstractSettingGui {
|
||||||
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group) {
|
private GuiItem getGuiItemFromGroup(AbstractMaterialGroup group) {
|
||||||
boolean isIn = this.selectedGroups.contains(group);
|
boolean isIn = this.selectedGroups.contains(group);
|
||||||
|
|
||||||
Material usedMaterial = group.getRepresentativeMaterial();
|
ItemStack item = group.getRepresentativeMaterial().createItemStack();
|
||||||
ItemStack item = new ItemStack(usedMaterial);
|
|
||||||
|
|
||||||
setGroupItemMeta(item, group.getName(), isIn);
|
setGroupItemMeta(item, group.getName(), isIn);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ import org.bukkit.entity.HumanEntity;
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer;
|
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.list.MappedElementListConfigGui;
|
import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||||
|
|
@ -22,19 +23,20 @@ import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
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 final Gui backGui;
|
||||||
private boolean instantRemove;
|
private boolean instantRemove;
|
||||||
|
|
||||||
private final List<Material> defaultMaterials;
|
private final List<ItemType> defaultMaterials;
|
||||||
private final EnumSet<Material> illegalMaterials;
|
private final Set<ItemType> illegalMaterials;
|
||||||
private final int defaultMaterialHash;
|
private final int defaultMaterialHash;
|
||||||
private int nowMaterialHash;
|
private int nowMaterialHash;
|
||||||
|
|
||||||
public MaterialSelectSettingGui(
|
public MaterialSelectSettingGui(
|
||||||
@NotNull SelectMaterialContainer selector,
|
@NotNull SelectItemTypeContainer selector,
|
||||||
@NotNull String title,
|
@NotNull String title,
|
||||||
@NotNull Gui backGui) {
|
@NotNull Gui backGui) {
|
||||||
super(title);
|
super(title);
|
||||||
|
|
@ -45,7 +47,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
this.defaultMaterials = new ArrayList<>(this.selector.getSelectedMaterials());
|
this.defaultMaterials = new ArrayList<>(this.selector.getSelectedMaterials());
|
||||||
this.illegalMaterials = this.selector.illegalMaterials();
|
this.illegalMaterials = this.selector.illegalMaterials();
|
||||||
|
|
||||||
this.defaultMaterialHash = hashFromMaterialList(this.defaultMaterials);
|
this.defaultMaterialHash = hashFromItemTypeList(this.defaultMaterials);
|
||||||
this.nowMaterialHash = this.defaultMaterialHash;
|
this.nowMaterialHash = this.defaultMaterialHash;
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
@ -55,7 +57,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pattern getBackgroundPattern(){
|
protected Pattern getBackgroundPattern() {
|
||||||
return new Pattern(
|
return new Pattern(
|
||||||
GuiSharedConstant.UPPER_FILLER_FULL_PLANE,
|
GuiSharedConstant.UPPER_FILLER_FULL_PLANE,
|
||||||
GuiSharedConstant.EMPTY_FILLER_FULL_LINE,
|
GuiSharedConstant.EMPTY_FILLER_FULL_LINE,
|
||||||
|
|
@ -157,14 +159,13 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(testCantSave()) return;
|
if (testCantSave()) return;
|
||||||
|
|
||||||
|
|
||||||
// Save setting
|
// Save setting
|
||||||
EnumSet<Material> result = EnumSet.noneOf(Material.class);
|
Set<ItemType> result = new HashSet<>(this.elementGuiMap.keySet());
|
||||||
result.addAll(this.elementGuiMap.keySet());
|
|
||||||
|
|
||||||
if(!this.selector.setSelectedMaterials(result)){
|
if (!this.selector.setSelectedItems(result)) {
|
||||||
player.sendMessage("§cSomething went wrong while saving the change of value.");
|
player.sendMessage("§cSomething went wrong while saving the change of value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,12 +186,12 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
ItemStack cursor = player.getItemOnCursor();
|
ItemStack cursor = player.getItemOnCursor();
|
||||||
|
|
||||||
// Test if cursor material allowed
|
// Test if cursor material allowed
|
||||||
Material cursorMat = cursor.getType();
|
ItemType cursorMat = cursor.getType().asItemType();
|
||||||
if(cursorMat.isAir()) return;
|
if (cursorMat == ItemType.AIR) return;
|
||||||
if(this.illegalMaterials.contains(cursorMat)) return;
|
if (this.illegalMaterials.contains(cursorMat)) return;
|
||||||
|
|
||||||
// Update gui only if item did not exist before.
|
// Update gui only if item did not exist before.
|
||||||
if(!this.elementGuiMap.containsKey(cursorMat)){
|
if (!this.elementGuiMap.containsKey(cursorMat)) {
|
||||||
updateValueForGeneric(cursorMat, true);
|
updateValueForGeneric(cursorMat, true);
|
||||||
this.nowMaterialHash ^= cursorMat.hashCode();
|
this.nowMaterialHash ^= cursorMat.hashCode();
|
||||||
|
|
||||||
|
|
@ -201,12 +202,12 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ItemStack createItemForGeneric(Material material) {
|
protected ItemStack createItemForGeneric(ItemType type) {
|
||||||
ItemStack item = new ItemStack(material);
|
ItemStack item = type.createItemStack();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
if(meta == null) return item;
|
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.setLore(Collections.singletonList("§7Click here to remove this material from the list"));
|
||||||
meta.addItemFlags(ItemFlag.values());
|
meta.addItemFlags(ItemFlag.values());
|
||||||
|
|
||||||
|
|
@ -216,22 +217,22 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Collection<Material> getEveryDisplayableInstanceOfGeneric() {
|
protected Collection<ItemType> getEveryDisplayableInstanceOfGeneric() {
|
||||||
return this.defaultMaterials;
|
return this.defaultMaterials;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateElement(Material material, GuiItem element) {
|
protected void updateElement(ItemType type, GuiItem element) {
|
||||||
// Nothing happen here I think
|
// Nothing happen here I think
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem newElementRequested(Material material, GuiItem newItem) {
|
protected GuiItem newElementRequested(ItemType type, GuiItem newItem) {
|
||||||
newItem.setAction(event -> {
|
newItem.setAction(event -> {
|
||||||
if(this.instantRemove){
|
if (this.instantRemove) {
|
||||||
removeMaterial(material);
|
removeItemType(type);
|
||||||
}else {
|
} else {
|
||||||
String materialName = CasedStringUtil.snakeToUpperSpacedCase(material.name().toLowerCase());
|
String materialName = CasedStringUtil.snakeToUpperSpacedCase(type.key().value().toLowerCase());
|
||||||
|
|
||||||
// Create and show confirm remove gui.
|
// Create and show confirm remove gui.
|
||||||
ConfirmActionGui confirmGui = new ConfirmActionGui(
|
ConfirmActionGui confirmGui = new ConfirmActionGui(
|
||||||
|
|
@ -239,7 +240,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
"§7Confirm Remove " + materialName.toLowerCase() + " from this list.",
|
"§7Confirm Remove " + materialName.toLowerCase() + " from this list.",
|
||||||
this, this,
|
this, this,
|
||||||
() -> {
|
() -> {
|
||||||
removeMaterial(material);
|
removeItemType(type);
|
||||||
return true;
|
return true;
|
||||||
}, false
|
}, false
|
||||||
);
|
);
|
||||||
|
|
@ -250,37 +251,36 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
return newItem;
|
return newItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeMaterial(Material material) {
|
private void removeItemType(ItemType type) {
|
||||||
if(this.elementGuiMap.containsKey(material)){
|
if (this.elementGuiMap.containsKey(type)) {
|
||||||
this.nowMaterialHash ^= material.hashCode();
|
this.nowMaterialHash ^= type.hashCode(); //TODO check would this be valid with item type
|
||||||
setSaveItem();
|
setSaveItem();
|
||||||
removeGeneric(material);
|
removeGeneric(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findItemFromElement(Material generic, GuiItem element) {
|
protected GuiItem findItemFromElement(ItemType type, GuiItem element) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findGuiItemForRemoval(Material generic, GuiItem element) {
|
protected GuiItem findGuiItemForRemoval(ItemType type, GuiItem element) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int hashFromMaterialList(List<Material> materialList){
|
private static int hashFromItemTypeList(List<ItemType> itemTypeList) {
|
||||||
int defaultMaterialHash = 0;
|
int defaultMaterialHash = 0;
|
||||||
for (Material material : materialList) {
|
for (ItemType type : itemTypeList) {
|
||||||
defaultMaterialHash ^= material.hashCode();
|
defaultMaterialHash ^= type.hashCode(); //TODO check would this be valid with item type
|
||||||
}
|
}
|
||||||
return defaultMaterialHash;
|
return defaultMaterialHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSaveItem() {
|
private void setSaveItem() {
|
||||||
if(testCantSave()){
|
if (testCantSave()) {
|
||||||
this.backgroundPane.bindItem('S', this.noChangeItem);
|
this.backgroundPane.bindItem('S', this.noChangeItem);
|
||||||
}else{
|
} else {
|
||||||
this.backgroundPane.bindItem('S', this.saveItem);
|
this.backgroundPane.bindItem('S', this.saveItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -296,6 +296,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Materia
|
||||||
protected GuiItem prepareCreateNewItem() {// Not used
|
protected GuiItem prepareCreateNewItem() {// Not used
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player) {// Not used
|
protected Consumer<String> prepareCreateItemConsumer(HumanEntity player) {// Not used
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
package xyz.alexcrea.cuanvil.update.plugin;
|
package xyz.alexcrea.cuanvil.update.plugin;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
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.MaterialGroupApi;
|
||||||
|
|
@ -16,6 +16,7 @@ import java.util.Set;
|
||||||
|
|
||||||
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
import static xyz.alexcrea.cuanvil.update.UpdateUtils.addAbsentToList;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class PUpdate_1_11_0 {
|
public class PUpdate_1_11_0 {
|
||||||
|
|
||||||
private static final List<String> mace_expected = List.of(
|
private static final List<String> mace_expected = List.of(
|
||||||
|
|
@ -30,22 +31,22 @@ public class PUpdate_1_11_0 {
|
||||||
"bane_of_arthropods"
|
"bane_of_arthropods"
|
||||||
);
|
);
|
||||||
|
|
||||||
private static final Material[] PICKAXES = new Material[]{
|
private static final ItemType[] PICKAXES = new ItemType[]{
|
||||||
Material.WOODEN_PICKAXE, Material.STONE_PICKAXE,
|
ItemType.WOODEN_PICKAXE, ItemType.STONE_PICKAXE,
|
||||||
Material.IRON_PICKAXE, Material.DIAMOND_PICKAXE,
|
ItemType.IRON_PICKAXE, ItemType.DIAMOND_PICKAXE,
|
||||||
Material.GOLDEN_PICKAXE, Material.NETHERITE_PICKAXE
|
ItemType.GOLDEN_PICKAXE, ItemType.NETHERITE_PICKAXE
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final Material[] SHOVELS = new Material[]{
|
private static final ItemType[] SHOVELS = new ItemType[]{
|
||||||
Material.WOODEN_SHOVEL, Material.STONE_SHOVEL,
|
ItemType.WOODEN_SHOVEL, ItemType.STONE_SHOVEL,
|
||||||
Material.IRON_SHOVEL, Material.DIAMOND_SHOVEL,
|
ItemType.IRON_SHOVEL, ItemType.DIAMOND_SHOVEL,
|
||||||
Material.GOLDEN_SHOVEL, Material.NETHERITE_SHOVEL
|
ItemType.GOLDEN_SHOVEL, ItemType.NETHERITE_SHOVEL
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final Material[] HOES = new Material[]{
|
private static final ItemType[] HOES = new ItemType[]{
|
||||||
Material.WOODEN_HOE, Material.STONE_HOE,
|
ItemType.WOODEN_HOE, ItemType.STONE_HOE,
|
||||||
Material.IRON_HOE, Material.DIAMOND_HOE,
|
ItemType.IRON_HOE, ItemType.DIAMOND_HOE,
|
||||||
Material.GOLDEN_HOE, Material.NETHERITE_HOE
|
ItemType.GOLDEN_HOE, ItemType.NETHERITE_HOE
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
public static void handleUpdate(@Nonnull Set<ConfigHolder> toSave) {
|
||||||
|
|
@ -65,7 +66,7 @@ public class PUpdate_1_11_0 {
|
||||||
private static void migrateTools(
|
private static void migrateTools(
|
||||||
@Nullable AbstractMaterialGroup tools,
|
@Nullable AbstractMaterialGroup tools,
|
||||||
@NotNull String toolset,
|
@NotNull String toolset,
|
||||||
@NotNull Material[] toolMats) {
|
@NotNull ItemType[] toolMats) {
|
||||||
|
|
||||||
// Create new group
|
// Create new group
|
||||||
IncludeGroup group = new IncludeGroup(toolset);
|
IncludeGroup group = new IncludeGroup(toolset);
|
||||||
|
|
@ -77,11 +78,11 @@ public class PUpdate_1_11_0 {
|
||||||
if (tools == null) return;
|
if (tools == null) return;
|
||||||
if (!(tools instanceof IncludeGroup include)) return;
|
if (!(tools instanceof IncludeGroup include)) return;
|
||||||
|
|
||||||
List<Material> mats = List.of(toolMats);
|
List<ItemType> types = List.of(toolMats);
|
||||||
Set<Material> matSet = include.getNonGroupInheritedMaterials();
|
Set<ItemType> typeSet = include.getNonGroupInheritedMaterials();
|
||||||
if (!matSet.containsAll(mats)) return;
|
if (!typeSet.containsAll(types)) return;
|
||||||
|
|
||||||
mats.forEach(matSet::remove);
|
types.forEach(typeSet::remove);
|
||||||
tools.addToPolicy(group);
|
tools.addToPolicy(group);
|
||||||
MaterialGroupApi.writeMaterialGroup(tools);
|
MaterialGroupApi.writeMaterialGroup(tools);
|
||||||
}
|
}
|
||||||
|
|
@ -108,6 +109,8 @@ public class PUpdate_1_11_0 {
|
||||||
|
|
||||||
// Test sword_enchant_conflict is default
|
// Test sword_enchant_conflict is default
|
||||||
ConfigurationSection sword_conflict = config.getConfigurationSection("sword_enchant_conflict");
|
ConfigurationSection sword_conflict = config.getConfigurationSection("sword_enchant_conflict");
|
||||||
|
if (sword_conflict == null) return;
|
||||||
|
|
||||||
if (sword_conflict.getInt("maxEnchantmentBeforeConflict", 0) != 1) return;
|
if (sword_conflict.getInt("maxEnchantmentBeforeConflict", 0) != 1) return;
|
||||||
|
|
||||||
if (sword_conflict.isList("notAffectedGroups") && !sword_conflict.getList("notAffectedGroups").isEmpty())
|
if (sword_conflict.isList("notAffectedGroups") && !sword_conflict.getList("notAffectedGroups").isEmpty())
|
||||||
|
|
@ -124,6 +127,7 @@ public class PUpdate_1_11_0 {
|
||||||
"minecraft:density", "minecraft:breach");
|
"minecraft:density", "minecraft:breach");
|
||||||
|
|
||||||
config.set("mace_enchant_conflict", null);
|
config.set("mace_enchant_conflict", null);
|
||||||
|
|
||||||
toSave.add(ConfigHolder.CONFLICT_HOLDER);
|
toSave.add(ConfigHolder.CONFLICT_HOLDER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,9 @@ object DataPackDependency {
|
||||||
// Order matter for this file
|
// Order matter for this file
|
||||||
// Could rewrite to not matter but not really important, so I keep it like that
|
// Could rewrite to not matter but not really important, so I keep it like that
|
||||||
private fun handleItemGroups(yml: YamlConfiguration) {
|
private fun handleItemGroups(yml: YamlConfiguration) {
|
||||||
|
//TODO see below todo
|
||||||
|
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||||
|
|
||||||
for (groupName in yml.getKeys(false)) {
|
for (groupName in yml.getKeys(false)) {
|
||||||
val section = yml.getConfigurationSection(groupName) ?: continue
|
val section = yml.getConfigurationSection(groupName) ?: continue
|
||||||
|
|
||||||
|
|
@ -144,12 +147,19 @@ object DataPackDependency {
|
||||||
if (group == null) group = IncludeGroup(groupName)
|
if (group == null) group = IncludeGroup(groupName)
|
||||||
|
|
||||||
for (name in section.getStringList("items")) {
|
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())
|
val mat = Material.getMaterial(name.uppercase())
|
||||||
|
|
||||||
|
|
||||||
if (mat == null) {
|
if (mat == null) {
|
||||||
CustomAnvil.instance.logger.warning("Could not find material $name for item group $groupName")
|
CustomAnvil.instance.logger.warning("Could not find material $name for item group $groupName")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
group.addToPolicy(mat)
|
group.addToPolicy(mat.asItemType()!!)
|
||||||
}
|
}
|
||||||
for (name in section.getStringList("groups")) {
|
for (name in section.getStringList("groups")) {
|
||||||
val otherGroup = MaterialGroupApi.getGroup(name)
|
val otherGroup = MaterialGroupApi.getGroup(name)
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,11 @@ import io.delilaheve.CustomAnvil
|
||||||
import me.athlaeos.enchantssquared.enchantments.CustomEnchant
|
import me.athlaeos.enchantssquared.enchantments.CustomEnchant
|
||||||
import me.athlaeos.enchantssquared.listeners.AnvilListener
|
import me.athlaeos.enchantssquared.listeners.AnvilListener
|
||||||
import me.athlaeos.enchantssquared.managers.CustomEnchantManager
|
import me.athlaeos.enchantssquared.managers.CustomEnchantManager
|
||||||
import org.bukkit.Material
|
|
||||||
import org.bukkit.NamespacedKey
|
import org.bukkit.NamespacedKey
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent
|
import org.bukkit.event.inventory.InventoryClickEvent
|
||||||
import org.bukkit.event.inventory.PrepareAnvilEvent
|
import org.bukkit.event.inventory.PrepareAnvilEvent
|
||||||
import org.bukkit.inventory.ItemStack
|
import org.bukkit.inventory.ItemStack
|
||||||
|
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
|
||||||
|
|
@ -20,6 +20,7 @@ import xyz.alexcrea.cuanvil.enchant.wrapped.CAEnchantSquaredEnchantment
|
||||||
import xyz.alexcrea.cuanvil.group.IncludeGroup
|
import xyz.alexcrea.cuanvil.group.IncludeGroup
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) {
|
class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
@ -30,28 +31,29 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
"disable_anvil, " +
|
"disable_anvil, " +
|
||||||
"incompatible_vanilla_enchantments, " +
|
"incompatible_vanilla_enchantments, " +
|
||||||
"incompatible_custom_enchantments and max_level " +
|
"incompatible_custom_enchantments and max_level " +
|
||||||
"configuration values.")
|
"configuration values."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disableAnvilListener(){
|
fun disableAnvilListener() {
|
||||||
PrepareAnvilEvent.getHandlerList().unregister(this.enchantmentSquaredPlugin)
|
PrepareAnvilEvent.getHandlerList().unregister(this.enchantmentSquaredPlugin)
|
||||||
|
|
||||||
// Find the anvil click event
|
// Find the anvil click event
|
||||||
var toRemove: AnvilListener? = null
|
var toRemove: AnvilListener? = null
|
||||||
for (registered in InventoryClickEvent.getHandlerList().registeredListeners) {
|
for (registered in InventoryClickEvent.getHandlerList().registeredListeners) {
|
||||||
val listener = registered.listener
|
val listener = registered.listener
|
||||||
if(listener is AnvilListener) {
|
if (listener is AnvilListener) {
|
||||||
toRemove = listener
|
toRemove = listener
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(toRemove != null)
|
if (toRemove != null)
|
||||||
InventoryClickEvent.getHandlerList().unregister(toRemove)
|
InventoryClickEvent.getHandlerList().unregister(toRemove)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerEnchantments(){
|
fun registerEnchantments() {
|
||||||
CustomAnvil.instance.logger.info("Preparing Enchantment Squared compatibility...")
|
CustomAnvil.instance.logger.info("Preparing Enchantment Squared compatibility...")
|
||||||
|
|
||||||
// Register enchantments
|
// Register enchantments
|
||||||
|
|
@ -69,20 +71,21 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap<CAEnchantment, Int>) {
|
fun getEnchantmentsSquared(item: ItemStack, enchantments: MutableMap<CAEnchantment, Int>) {
|
||||||
val customEnchants = CustomEnchantManager.getInstance().getItemsEnchantsFromPDC(item)
|
val customEnchants = CustomEnchantManager.getInstance().getItemsEnchantsFromPDC(item)
|
||||||
|
|
||||||
customEnchants.forEach{
|
customEnchants.forEach { (enchantment, level) ->
|
||||||
(enchantment, level ) -> enchantments[getWrappedEnchant(enchantment)] = level
|
enchantments[getWrappedEnchant(enchantment)] = level
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey{
|
fun getKeyFromEnchant(enchant: CustomEnchant): NamespacedKey {
|
||||||
return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!!
|
return NamespacedKey.fromString(enchant.type.lowercase(Locale.getDefault()), this.enchantmentSquaredPlugin)!!
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getWrappedEnchant(enchant: CustomEnchant): CAEnchantment {
|
private fun getWrappedEnchant(enchant: CustomEnchant): CAEnchantment {
|
||||||
return CAEnchantment.getByKey(getKeyFromEnchant(enchant))!!
|
return CAEnchantment.getByKey(getKeyFromEnchant(enchant))!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun registerPluginConfiguration(){
|
fun registerPluginConfiguration() {
|
||||||
CustomAnvil.instance.logger.info("Preparing Enchantment Squared config...")
|
CustomAnvil.instance.logger.info("Preparing Enchantment Squared config...")
|
||||||
|
|
||||||
// Prepare enchantments
|
// Prepare enchantments
|
||||||
|
|
@ -99,22 +102,22 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
CustomAnvil.instance.logger.info("Enchantment Squared should now work as expected !")
|
CustomAnvil.instance.logger.info("Enchantment Squared should now work as expected !")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeMissingGroups(){
|
private fun writeMissingGroups() {
|
||||||
// Write group that do not exist on custom anvil.
|
// Write group that do not exist on custom anvil.
|
||||||
val shield = IncludeGroup("shield")
|
val shield = IncludeGroup("shield")
|
||||||
shield.addToPolicy(Material.SHIELD)
|
shield.addToPolicy(ItemType.SHIELD)
|
||||||
MaterialGroupApi.addMaterialGroup(shield)
|
MaterialGroupApi.addMaterialGroup(shield)
|
||||||
|
|
||||||
val elytra = IncludeGroup("elytra")
|
val elytra = IncludeGroup("elytra")
|
||||||
elytra.addToPolicy(Material.ELYTRA)
|
elytra.addToPolicy(ItemType.ELYTRA)
|
||||||
MaterialGroupApi.addMaterialGroup(elytra)
|
MaterialGroupApi.addMaterialGroup(elytra)
|
||||||
|
|
||||||
val trinkets = IncludeGroup("trinkets")
|
val trinkets = IncludeGroup("trinkets")
|
||||||
trinkets.addToPolicy(Material.ROTTEN_FLESH)
|
trinkets.addToPolicy(ItemType.ROTTEN_FLESH)
|
||||||
MaterialGroupApi.addMaterialGroup(trinkets)
|
MaterialGroupApi.addMaterialGroup(trinkets)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>){
|
private fun writeMaterialRestriction(esEnchantments: List<CAEnchantSquaredEnchantment>) {
|
||||||
for (enchantment in esEnchantments) {
|
for (enchantment in esEnchantments) {
|
||||||
val conflict = ConflictBuilder("restriction_${enchantment.key.key}", CustomAnvil.instance)
|
val conflict = ConflictBuilder("restriction_${enchantment.key.key}", CustomAnvil.instance)
|
||||||
conflict.addEnchantment(enchantment)
|
conflict.addEnchantment(enchantment)
|
||||||
|
|
@ -125,7 +128,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
// Get allowed groups
|
// Get allowed groups
|
||||||
for (esGroup in enchantment.enchant.compatibleItems) {
|
for (esGroup in enchantment.enchant.compatibleItems) {
|
||||||
val caGroup = esGroupToCAGroup(esGroup)
|
val caGroup = esGroupToCAGroup(esGroup)
|
||||||
if(caGroup == null){
|
if (caGroup == null) {
|
||||||
CustomAnvil.instance.logger.info("Could not find equivalent custom anvil group for $esGroup")
|
CustomAnvil.instance.logger.info("Could not find equivalent custom anvil group for $esGroup")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +139,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeEnchantmentConflicts(esEnchantments: List<CAEnchantSquaredEnchantment>){
|
private fun writeEnchantmentConflicts(esEnchantments: List<CAEnchantSquaredEnchantment>) {
|
||||||
val otherEnchants = ArrayList<CAEnchantment>()
|
val otherEnchants = ArrayList<CAEnchantment>()
|
||||||
otherEnchants.addAll(CAEnchantmentRegistry.getInstance().values())
|
otherEnchants.addAll(CAEnchantmentRegistry.getInstance().values())
|
||||||
|
|
||||||
|
|
@ -145,14 +148,14 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
|
|
||||||
// find conflicting enchantment.
|
// find conflicting enchantment.
|
||||||
for (otherEnchant in otherEnchants) {
|
for (otherEnchant in otherEnchants) {
|
||||||
if(enchantment.enchant.conflictsWithEnchantment(otherEnchant.name)){
|
if (enchantment.enchant.conflictsWithEnchantment(otherEnchant.name)) {
|
||||||
writeConflict(enchantment, otherEnchant)
|
writeConflict(enchantment, otherEnchant)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment){
|
private fun writeConflict(enchantment1: CAEnchantment, enchantment2: CAEnchantment) {
|
||||||
val conflict = ConflictBuilder("${enchantment1.name}_with_${enchantment2.name}_conflict", CustomAnvil.instance)
|
val conflict = ConflictBuilder("${enchantment1.name}_with_${enchantment2.name}_conflict", CustomAnvil.instance)
|
||||||
|
|
||||||
conflict.addEnchantment(enchantment1).addEnchantment(enchantment2)
|
conflict.addEnchantment(enchantment1).addEnchantment(enchantment2)
|
||||||
|
|
@ -165,7 +168,7 @@ class EnchantmentSquaredDependency(private val enchantmentSquaredPlugin: Plugin)
|
||||||
* Transform an Enchantment Squared group to a Custom Anvil group
|
* Transform an Enchantment Squared group to a Custom Anvil group
|
||||||
*/
|
*/
|
||||||
private fun esGroupToCAGroup(esGroup: String): String? {
|
private fun esGroupToCAGroup(esGroup: String): String? {
|
||||||
return when(esGroup){
|
return when (esGroup) {
|
||||||
"SWORDS" -> "swords"
|
"SWORDS" -> "swords"
|
||||||
"BOWS" -> "bow"
|
"BOWS" -> "bow"
|
||||||
"CROSSBOWS" -> "crossbow"
|
"CROSSBOWS" -> "crossbow"
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
package xyz.alexcrea.cuanvil.group
|
package xyz.alexcrea.cuanvil.group
|
||||||
|
|
||||||
import org.bukkit.Material
|
import com.google.common.collect.ImmutableSet
|
||||||
import java.util.*
|
import org.bukkit.inventory.ItemType
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
abstract class AbstractMaterialGroup(private val name: String) {
|
abstract class AbstractMaterialGroup(private val name: String) {
|
||||||
protected val includedMaterial by lazy { createDefaultSet() }
|
protected val includedItems by lazy { createDefaultSet() }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the group default set
|
* 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
|
* Get if a material is allowed following the group policy
|
||||||
*/
|
*/
|
||||||
open fun contain(mat: Material): Boolean {
|
open fun contain(mat: ItemType): Boolean {
|
||||||
return mat in getMaterials()
|
return mat in getItemTypes()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -24,30 +25,34 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
||||||
abstract fun isReferencing(other: AbstractMaterialGroup): Boolean
|
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.
|
* @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.
|
* @return this instance.
|
||||||
*/
|
*/
|
||||||
fun addAll(vararg materials: Material): AbstractMaterialGroup {
|
fun addAll(vararg types: ItemType): AbstractMaterialGroup {
|
||||||
for (material in materials) {
|
for (type in types) {
|
||||||
addToPolicy(material)
|
addToPolicy(type)
|
||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a group to this group to follow this group policy
|
* Push a group to this group to follow this group policy
|
||||||
|
*
|
||||||
* @return this instance.
|
* @return this instance.
|
||||||
*/
|
*/
|
||||||
abstract fun addToPolicy(other: AbstractMaterialGroup): AbstractMaterialGroup
|
abstract fun addToPolicy(other: AbstractMaterialGroup): AbstractMaterialGroup
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push a list of group to this group to follow this group policy
|
* Push a list of group to this group to follow this group policy
|
||||||
|
*
|
||||||
* @return this instance.
|
* @return this instance.
|
||||||
*/
|
*/
|
||||||
fun addAll(vararg otherList: AbstractMaterialGroup): AbstractMaterialGroup {
|
fun addAll(vararg otherList: 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> {
|
open fun getNonGroupInheritedMaterials(): MutableSet<ItemType> {
|
||||||
return includedMaterial
|
return includedItems
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the group non-inherited material as a set
|
* Set the group non-inherited items
|
||||||
*/
|
*/
|
||||||
open fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
open fun setNonGroupInheritedMaterials(types: Set<ItemType>) {
|
||||||
this.includedMaterial.clear()
|
this.includedItems.clear()
|
||||||
this.includedMaterial.addAll(materials)
|
this.includedItems.addAll(types)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -98,22 +103,22 @@ abstract class AbstractMaterialGroup(private val name: String) {
|
||||||
*/
|
*/
|
||||||
abstract fun getGroups(): MutableSet<AbstractMaterialGroup>
|
abstract fun getGroups(): MutableSet<AbstractMaterialGroup>
|
||||||
|
|
||||||
open fun getRepresentativeMaterial(): Material {
|
open fun getRepresentativeMaterial(): ItemType {
|
||||||
// Test inner material
|
// Test inner material
|
||||||
val matIterator = includedMaterial.iterator()
|
val itemIterator = includedItems.iterator()
|
||||||
while (matIterator.hasNext()) {
|
while (itemIterator.hasNext()) {
|
||||||
val material = matIterator.next()
|
val type = itemIterator.next()
|
||||||
if (material.isAir) continue
|
if (type == ItemType.AIR) continue
|
||||||
return material
|
return type
|
||||||
}
|
}
|
||||||
// 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 groupMat = groupIterator.next().getRepresentativeMaterial()
|
val groupType = groupIterator.next().getRepresentativeMaterial()
|
||||||
if (groupMat.isAir) continue
|
if (groupType == ItemType.AIR) continue
|
||||||
return groupMat
|
return groupType
|
||||||
}
|
}
|
||||||
return Material.PAPER
|
return ItemType.PAPER
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun updateMaterials()
|
abstract fun updateMaterials()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
package xyz.alexcrea.cuanvil.group
|
package xyz.alexcrea.cuanvil.group
|
||||||
|
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import org.bukkit.Material
|
import org.bukkit.inventory.ItemType
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
class EnchantConflictGroup(
|
class EnchantConflictGroup(
|
||||||
val name: String,
|
val name: String,
|
||||||
private val cantConflict: AbstractMaterialGroup,
|
private val cantConflict: AbstractMaterialGroup,
|
||||||
|
|
@ -15,17 +16,18 @@ class EnchantConflictGroup(
|
||||||
fun addEnchantment(enchant: CAEnchantment) {
|
fun addEnchantment(enchant: CAEnchantment) {
|
||||||
enchantments.add(enchant)
|
enchantments.add(enchant)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addEnchantments(enchants: List<CAEnchantment>) {
|
fun addEnchantments(enchants: List<CAEnchantment>) {
|
||||||
enchantments.addAll(enchants)
|
enchantments.addAll(enchants)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun allowed(enchants: Set<CAEnchantment>, mat: Material): Boolean {
|
fun allowed(enchants: Set<CAEnchantment>, type: ItemType): Boolean {
|
||||||
if (enchantments.size < minBeforeBlock) {
|
if (enchantments.size < minBeforeBlock) {
|
||||||
CustomAnvil.verboseLog("Conflicting bc of to many enchantments")
|
CustomAnvil.verboseLog("Conflicting bc of to many enchantments")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cantConflict.contain(mat)) {
|
if (cantConflict.contain(type)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,15 +58,15 @@ class EnchantConflictGroup(
|
||||||
enchantments.addAll(enchants)
|
enchantments.addAll(enchants)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRepresentativeMaterial(): Material {
|
fun getRepresentativeMaterial(): ItemType {
|
||||||
val groups = getCantConflictGroup().getGroups()
|
val groups = getCantConflictGroup().getGroups()
|
||||||
val groupIterator = groups.iterator()
|
val groupIterator = groups.iterator()
|
||||||
while (groupIterator.hasNext()) {
|
while (groupIterator.hasNext()) {
|
||||||
val mat = groupIterator.next().getRepresentativeMaterial()
|
val itemType = groupIterator.next().getRepresentativeMaterial()
|
||||||
if (mat != Material.ENCHANTED_BOOK) return mat
|
if (itemType != ItemType.ENCHANTED_BOOK) return itemType
|
||||||
|
|
||||||
}
|
}
|
||||||
return Material.ENCHANTED_BOOK
|
return ItemType.ENCHANTED_BOOK
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
class EnchantConflictManager {
|
class EnchantConflictManager {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -176,7 +177,9 @@ class EnchantConflictManager {
|
||||||
newEnchant: CAEnchantment
|
newEnchant: CAEnchantment
|
||||||
): ConflictType {
|
): ConflictType {
|
||||||
val mat = item.type
|
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
|
val conflictList = newEnchant.conflicts
|
||||||
|
|
||||||
var result = ConflictType.NO_CONFLICT
|
var result = ConflictType.NO_CONFLICT
|
||||||
|
|
@ -187,7 +190,7 @@ class EnchantConflictManager {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val allowed = conflict.allowed(appliedEnchants.keys, mat)
|
val allowed = conflict.allowed(appliedEnchants.keys, itemType)
|
||||||
CustomAnvil.verboseLog("Was against $conflict and conflicting: ${!allowed} ")
|
CustomAnvil.verboseLog("Was against $conflict and conflicting: ${!allowed} ")
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
if (conflict.getEnchants().size <= 1) {
|
if (conflict.getEnchants().size <= 1) {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,20 @@
|
||||||
package xyz.alexcrea.cuanvil.group
|
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.*
|
import java.util.*
|
||||||
|
|
||||||
|
@Deprecated("Need rework to reduce memory cost as not enum set")
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
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()
|
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
||||||
|
|
@ -20,29 +29,29 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addToPolicy(mat: Material): ExcludeGroup {
|
override fun addToPolicy(type: ItemType): ExcludeGroup {
|
||||||
includedMaterial.remove(mat)
|
includedItems.remove(type)
|
||||||
groupItems.remove(mat)
|
groupItems.remove(type)
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addToPolicy(other: AbstractMaterialGroup): ExcludeGroup {
|
override fun addToPolicy(other: AbstractMaterialGroup): ExcludeGroup {
|
||||||
includedGroup.add(other)
|
includedGroup.add(other)
|
||||||
groupItems.removeAll(other.getMaterials())
|
groupItems.removeAll(other.getItemTypes())
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
||||||
groupItems.clear()
|
groupItems.clear()
|
||||||
groupItems.addAll(includedMaterial)
|
groupItems.addAll(includedItems)
|
||||||
|
|
||||||
includedGroup.clear()
|
includedGroup.clear()
|
||||||
groups.forEach { group ->
|
groups.forEach { group ->
|
||||||
if (!group.isReferencing(this)) {
|
if (!group.isReferencing(this)) {
|
||||||
includedGroup.add(group)
|
includedGroup.add(group)
|
||||||
groupItems.removeAll(group.getMaterials())
|
groupItems.removeAll(group.getItemTypes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -53,15 +62,15 @@ class ExcludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||||
|
|
||||||
override fun updateMaterials() {
|
override fun updateMaterials() {
|
||||||
groupItems.clear()
|
groupItems.clear()
|
||||||
groupItems.addAll(includedMaterial)
|
groupItems.addAll(includedItems)
|
||||||
|
|
||||||
includedGroup.forEach { group ->
|
includedGroup.forEach { group ->
|
||||||
groupItems.addAll(group.getMaterials())
|
groupItems.addAll(group.getItemTypes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMaterials(): EnumSet<Material> {
|
override fun getItemTypes(): ImmutableSet<ItemType> {
|
||||||
return groupItems
|
return Collections.unmodifiableSet(groupItems) as ImmutableSet<ItemType>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
package xyz.alexcrea.cuanvil.group
|
package xyz.alexcrea.cuanvil.group
|
||||||
|
|
||||||
import org.bukkit.Material
|
import com.google.common.collect.ImmutableSet
|
||||||
|
import org.bukkit.inventory.ItemType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||||
override fun createDefaultSet(): EnumSet<Material> {
|
override fun createDefaultSet(): MutableSet<ItemType> {
|
||||||
return EnumSet.noneOf(Material::class.java)
|
return HashSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
private var includedGroup: MutableSet<AbstractMaterialGroup> = HashSet()
|
||||||
|
|
@ -20,35 +22,35 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addToPolicy(mat: Material): IncludeGroup {
|
override fun addToPolicy(type: ItemType): IncludeGroup {
|
||||||
includedMaterial.add(mat)
|
includedItems.add(type)
|
||||||
groupItems.add(mat)
|
groupItems.add(type)
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addToPolicy(other: AbstractMaterialGroup): IncludeGroup {
|
override fun addToPolicy(other: AbstractMaterialGroup): IncludeGroup {
|
||||||
includedGroup.add(other)
|
includedGroup.add(other)
|
||||||
groupItems.addAll(other.getMaterials())
|
groupItems.addAll(other.getItemTypes())
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
override fun setGroups(groups: MutableSet<AbstractMaterialGroup>) {
|
||||||
groupItems.clear()
|
groupItems.clear()
|
||||||
groupItems.addAll(includedMaterial)
|
groupItems.addAll(includedItems)
|
||||||
|
|
||||||
includedGroup.clear()
|
includedGroup.clear()
|
||||||
groups.forEach { group ->
|
groups.forEach { group ->
|
||||||
if (!group.isReferencing(this)) {
|
if (!group.isReferencing(this)) {
|
||||||
includedGroup.add(group)
|
includedGroup.add(group)
|
||||||
groupItems.addAll(group.getMaterials())
|
groupItems.addAll(group.getItemTypes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setNonGroupInheritedMaterials(materials: EnumSet<Material>) {
|
override fun setNonGroupInheritedMaterials(types: Set<ItemType>) {
|
||||||
super.setNonGroupInheritedMaterials(materials)
|
super.setNonGroupInheritedMaterials(types)
|
||||||
|
|
||||||
updateMaterials()
|
updateMaterials()
|
||||||
}
|
}
|
||||||
|
|
@ -59,15 +61,15 @@ class IncludeGroup(name: String) : AbstractMaterialGroup(name) {
|
||||||
|
|
||||||
override fun updateMaterials() {
|
override fun updateMaterials() {
|
||||||
groupItems.clear()
|
groupItems.clear()
|
||||||
groupItems.addAll(includedMaterial)
|
groupItems.addAll(includedItems)
|
||||||
|
|
||||||
includedGroup.forEach { group ->
|
includedGroup.forEach { group ->
|
||||||
groupItems.addAll(group.getMaterials())
|
groupItems.addAll(group.getItemTypes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMaterials(): EnumSet<Material> {
|
override fun getItemTypes(): ImmutableSet<ItemType> {
|
||||||
return groupItems
|
return Collections.unmodifiableSet(groupItems) as ImmutableSet<ItemType>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class ItemGroupManager {
|
||||||
fun createGroup(
|
fun createGroup(
|
||||||
config: ConfigurationSection,
|
config: ConfigurationSection,
|
||||||
name: String
|
name: String
|
||||||
): AbstractMaterialGroup{
|
): AbstractMaterialGroup {
|
||||||
return createGroup(config, groupMap.keys, name)
|
return createGroup(config, groupMap.keys, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,22 +76,48 @@ class ItemGroupManager {
|
||||||
config: ConfigurationSection,
|
config: ConfigurationSection,
|
||||||
keys: Set<String>
|
keys: Set<String>
|
||||||
) {
|
) {
|
||||||
|
//TODO see below todo
|
||||||
|
//val itemRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.ITEM)
|
||||||
|
|
||||||
// Read material to include in this group policy
|
// Read material to include in this group policy
|
||||||
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH)
|
val materialList = groupSection.getStringList(MATERIAL_LIST_PATH)
|
||||||
for (materialTemp in materialList) {
|
for (typeName in materialList) {
|
||||||
val materialName = materialTemp.uppercase(Locale.getDefault())
|
//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)
|
val material = Material.getMaterial(materialName)
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
// Check if we should warn the user
|
// Check if we should warn the user
|
||||||
if (materialName !in FUTURE_MATERIAL) {
|
if (materialName !in FUTURE_MATERIAL) {
|
||||||
CustomAnvil.instance.logger.warning(
|
CustomAnvil.instance.logger.warning(
|
||||||
"Unknown material $materialTemp on group ${group.getName()}"
|
"Unknown material $materialName on group ${group.getName()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
group.addToPolicy(material)
|
group.addToPolicy(material.asItemType()!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read group to include in this group policy.
|
// Read group to include in this group policy.
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package xyz.alexcrea.cuanvil.api;
|
package xyz.alexcrea.cuanvil.api;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.inventory.ItemType;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
import xyz.alexcrea.cuanvil.group.EnchantConflictGroup;
|
||||||
import xyz.alexcrea.cuanvil.group.IncludeGroup;
|
import xyz.alexcrea.cuanvil.group.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.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void groupAddAndRemove() {
|
void groupAddAndRemove() {
|
||||||
String groupName = "group";
|
String groupName = "group";
|
||||||
IncludeGroup group = new IncludeGroup(groupName);
|
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
|
// Group not being set should not exist
|
||||||
assertFalse(doGroupExist(groupName));
|
assertFalse(doGroupExist(groupName));
|
||||||
|
|
@ -48,7 +49,7 @@ public class MaterialGroupApiTests extends ConfigResetCustomAnvilTest {
|
||||||
void writeGroup_Reload() {
|
void writeGroup_Reload() {
|
||||||
String groupName = "group";
|
String groupName = "group";
|
||||||
IncludeGroup group = new IncludeGroup(groupName);
|
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
|
// Group not being set should not exist
|
||||||
assertFalse(doGroupExist(groupName));
|
assertFalse(doGroupExist(groupName));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue