From 25f676f7f3388d9154de83109c3c1a38b3a16436 Mon Sep 17 00:00:00 2001 From: alexcrea Date: Tue, 30 Jun 2026 19:26:52 +0200 Subject: [PATCH] enchant conflict working --- .../gui/config/global/EnchantConflictGui.java | 15 ++- .../gui/config/global/ItemConfigGui.java | 106 ++++++++++++++++++ .../gui/config/list/ElementListConfigGui.java | 2 +- .../list/MappedElementListConfigGui.java | 26 +++-- .../config/list/MappedGuiListConfigGui.java | 23 ++-- .../cuanvil/command/EditConfigExecutor.kt | 11 +- 6 files changed, 157 insertions(+), 26 deletions(-) create mode 100644 src/main/java/xyz/alexcrea/cuanvil/gui/config/global/ItemConfigGui.java diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java index 79f52923..3c28e7c5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/EnchantConflictGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.global; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; @@ -24,26 +25,30 @@ public class EnchantConflictGui extends MappedGuiListConfigGui + group.getCantConflictGroup().contain(material) + ); + enchantConflictGui.init(); + } + + return enchantConflictGui; + } +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java index a9e499b0..1386b31d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/ElementListConfigGui.java @@ -68,7 +68,7 @@ public abstract class ElementListConfigGui extends ChestGui implements ValueU protected ArrayList pages; protected HashMap pageMap; - public void init() { // Why I'm using an init function ? //TODO determine why is it using a init function and not used on constructor. + public void init() { GuiGlobalItems.addBackgroundItem(this.backgroundPane); this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM); addPane(this.backgroundPane); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java index 31ab7184..9b6c6100 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedElementListConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.list; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.CustomAnvil; import org.bukkit.Material; import org.bukkit.entity.HumanEntity; @@ -14,27 +15,32 @@ import java.util.Arrays; import java.util.HashMap; import java.util.function.Consumer; -public abstract class MappedElementListConfigGui< T, S > extends ElementListConfigGui< T > { +public abstract class MappedElementListConfigGui extends ElementListConfigGui { protected final HashMap elementGuiMap; - protected MappedElementListConfigGui(@NotNull String title) { - super(title, MainConfigGui.getInstance()); + + protected MappedElementListConfigGui(@NotNull String title, @NotNull Gui parent) { + super(title, parent); this.elementGuiMap = new HashMap<>(); } + protected MappedElementListConfigGui(@NotNull String title) { + this(title, MainConfigGui.getInstance()); + } + @Override - protected GuiItem prepareCreateNewItem(){ + protected GuiItem prepareCreateNewItem() { // Create new conflict item ItemStack createItem = new ItemStack(Material.PAPER); ItemMeta createMeta = createItem.getItemMeta(); assert createMeta != null; - createMeta.setDisplayName("§aCreate new "+genericDisplayedName()); + createMeta.setDisplayName("§aCreate new " + genericDisplayedName()); createMeta.setLore(Arrays.asList( - "§7Create a new "+genericDisplayedName()+".", - "§7You will be asked to name the "+genericDisplayedName()+" in chat.", - "§7Then, you should edit the "+genericDisplayedName()+" config as you need" + "§7Create a new " + genericDisplayedName() + ".", + "§7You will be asked to name the " + genericDisplayedName() + " in chat.", + "§7Then, you should edit the " + genericDisplayedName() + " config as you need" )); createItem.setItemMeta(createMeta); @@ -51,8 +57,8 @@ public abstract class MappedElementListConfigGui< T, S > extends ElementListConf } player.closeInventory(); - player.sendMessage("§eWrite the "+genericDisplayedName()+" name you want to create in the chat.\n" + - "§eOr write §ccancel §eto go back to "+genericDisplayedName()+" config menu"); + player.sendMessage("§eWrite the " + genericDisplayedName() + " name you want to create in the chat.\n" + + "§eOr write §ccancel §eto go back to " + genericDisplayedName() + " config menu"); CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player)); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java index 18a5f864..8180694e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/MappedGuiListConfigGui.java @@ -1,6 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.list; import com.github.stefvanschie.inventoryframework.gui.GuiItem; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import io.delilaheve.CustomAnvil; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryClickEvent; @@ -14,19 +15,22 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import java.util.function.Supplier; -public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGui.LazyElement> - extends MappedElementListConfigGui< T, S > { +public abstract class MappedGuiListConfigGui> + extends MappedElementListConfigGui { protected MappedGuiListConfigGui(@NotNull String title) { super(title); + } + protected MappedGuiListConfigGui(@NotNull String title, @NotNull Gui parent) { + super(title, parent); } @Override public void reloadValues() { this.elementGuiMap.forEach((conflict, element) -> { ElementMappedToListGui gui = element.getStored(); - if(gui != null) gui.cleanAndBeUnusable(); + if (gui != null) gui.cleanAndBeUnusable(); }); this.elementGuiMap.clear(); @@ -49,7 +53,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu @Override protected void updateElement(T generic, S element) { ElementMappedToListGui gui = element.getStored(); - if(gui != null) gui.updateLocal(); + if (gui != null) gui.updateLocal(); } @Override @@ -58,7 +62,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu } @Override - protected Consumer prepareCreateItemConsumer(HumanEntity player){ + protected Consumer prepareCreateItemConsumer(HumanEntity player) { AtomicReference> selfRef = new AtomicReference<>(); Consumer selfCallback = (message) -> { if (message == null) return; @@ -71,7 +75,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu message = message.toLowerCase(Locale.ROOT); if ("cancel".equalsIgnoreCase(message)) { - player.sendMessage(genericDisplayedName()+" creation cancelled..."); + player.sendMessage(genericDisplayedName() + " creation cancelled..."); show(player); return; } @@ -82,7 +86,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu // Not the most efficient on large number of conflict, but it should not run often. for (T generic : getDisplayableInstanceOfGeneric()) { if (generic.toString().equalsIgnoreCase(message)) { - player.sendMessage("§cPlease enter a "+genericDisplayedName()+" name that do not already exist..."); + player.sendMessage("§cPlease enter a " + genericDisplayedName() + " name that do not already exist..."); // wait next message. CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get()); return; @@ -90,7 +94,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu } T generic = createAndSaveNewEmptyGeneric(message); - if(generic == null) {// we don't know what to do. so we back up by opening this gui. + if (generic == null) {// we don't know what to do. so we back up by opening this gui. this.show(player); return; } @@ -117,6 +121,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu private final GuiItem parentItem; private final LazyValue> lazyOpenConsumer; + public LazyElement(GuiItem parentItem, Supplier valueSupplier) { super(valueSupplier); this.parentItem = parentItem; @@ -131,7 +136,7 @@ public abstract class MappedGuiListConfigGui< T, S extends MappedGuiListConfigGu } @NotNull - public Consumer openAction(){ + public Consumer openAction() { return event -> lazyOpenConsumer.get().accept(event); } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 4be32bc3..8aa54a96 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -9,7 +9,10 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.enchant.CAEnchantment import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry import xyz.alexcrea.cuanvil.gui.config.MainConfigGui +import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions +import xyz.alexcrea.cuanvil.util.MaterialUtil.customType +import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir class EditConfigExecutor : CASubCommand() { @@ -82,7 +85,13 @@ class EditConfigExecutor : CASubCommand() { } private fun processItem(sender: HumanEntity) { - // TODO open item edit gui + val item = sender.inventory.itemInMainHand + if(item.isAir) { + sender.sendMessage("Cannot configure the item in hand") + return + } + + ItemConfigGui(item.type, item.customType).show(sender) } private fun processOpen(sender: HumanEntity) {