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 8ee26ce..5e66bf2 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 @@ -57,7 +57,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu protected ArrayList pages; protected HashMap pageMap; - public void init() { // Why I'm using an init function ? + public void init() { // Why I'm using an init function ? //TODO determine why is it using a init function and not used on constructor. 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/SettingGuiListConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java index f9aafd1..808b40d 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/SettingGuiListConfigGui.java @@ -38,16 +38,16 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu @Override public void updateValueForGeneric(T generic, boolean shouldUpdate) { - S factory = this.factoryMap.get(generic); - if(factory == null){ + if(!this.factoryMap.containsKey(generic)){ // Create new item & factory - factory = createFactory(generic); + S factory = createFactory(generic); GuiItem newItem = itemFromFactory(generic, factory); addToPage(newItem); this.guiItemMap.put(generic, newItem); this.factoryMap.put(generic, factory); }else{ + S factory = this.factoryMap.get(generic); // Update old item GuiItem oldItem = this.guiItemMap.get(generic); @@ -73,6 +73,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu oldITem.setProperties(newItem.getProperties()); oldITem.setVisible(newItem.isVisible()); } + @Override protected GuiItem findGuiItemForRemoval(T generic) { return this.guiItemMap.get(generic); diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java index f8b550e..a3d95b4 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java @@ -79,15 +79,15 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance)); // Displayed item will be updated later - this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), (event) -> { + this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), event -> { event.setCancelled(true); EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui( - "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " \u00A75Enchantments", - this, this, 0); + "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + "\u00A75", + this, this); enchantGui.show(event.getWhoClicked()); }, CustomAnvil.instance); - this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), (event) -> { + this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), event -> { event.setCancelled(true); GroupSelectSettingGui enchantGui = new GroupSelectSettingGui( "\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + " \u00A73Groups", diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/AbstractSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/AbstractSettingGui.java index cd99905..c9ce78e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/AbstractSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/AbstractSettingGui.java @@ -45,7 +45,6 @@ public abstract class AbstractSettingGui extends ChestGui implements SettingGui } protected GuiItem saveItem; - protected GuiItem noChangeItem; /** * Initialise and prepare value for this gui. @@ -61,15 +60,14 @@ public abstract class AbstractSettingGui extends ChestGui implements SettingGui GuiGlobalItems.addBackgroundItem(pane); saveItem = GuiGlobalItems.saveItem(this, parent); - noChangeItem = GuiGlobalItems.noChangeItem(); - pane.bindItem('S', noChangeItem); + pane.bindItem('S', GuiGlobalItems.noChangeItem()); } @Override public void update() { - pane.bindItem('S', hadChange() ? saveItem : noChangeItem); + pane.bindItem('S', hadChange() ? saveItem : GuiGlobalItems.noChangeItem()); super.update(); } @@ -95,6 +93,7 @@ public abstract class AbstractSettingGui extends ChestGui implements SettingGui */ protected abstract Pattern getGuiPattern(); + /** * Most of the time a setting gui will be called from a global gui. *

diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java index 6eeef37..88a2b2e 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/settings/EnchantSelectSettingGui.java @@ -1,9 +1,7 @@ package xyz.alexcrea.cuanvil.gui.config.settings; import com.github.stefvanschie.inventoryframework.gui.GuiItem; -import com.github.stefvanschie.inventoryframework.pane.Orientable; -import com.github.stefvanschie.inventoryframework.pane.OutlinePane; -import com.github.stefvanschie.inventoryframework.pane.Pane; +import com.github.stefvanschie.inventoryframework.gui.type.util.Gui; import com.github.stefvanschie.inventoryframework.pane.util.Pattern; import io.delilaheve.CustomAnvil; import org.bukkit.Material; @@ -13,71 +11,67 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.jetbrains.annotations.NotNull; +import xyz.alexcrea.cuanvil.config.ConfigHolder; import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer; +import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui; +import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.util.CasedStringUtil; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.function.Consumer; +import java.util.stream.Collectors; -public class EnchantSelectSettingGui extends AbstractSettingGui { +public class EnchantSelectSettingGui extends SettingGuiListConfigGui implements SettingGui { - SelectEnchantmentContainer enchantContainer; - int page; + private final SelectEnchantmentContainer enchantContainer; - Set selectedEnchant; + private final Set selectedEnchant; + private final GuiItem saveItem; - public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer, int page) { - super(6, title, parent); + public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer) { + super(title); this.enchantContainer = enchantContainer; - // Not used and not planned rn - this.page = page; this.selectedEnchant = new HashSet<>(enchantContainer.getSelectedEnchantments()); - // Add secondary background item - this.getPane().bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM); + this.saveItem = GuiGlobalItems.saveItem(this, parent); + this.backgroundPane.bindItem('S', GuiGlobalItems.noChangeItem()); - initGroups(); + init(); } @Override - protected Pattern getGuiPattern() { + protected Pattern getBackgroundPattern() { return new Pattern( GuiSharedConstant.EMPTY_GUI_FULL_LINE, GuiSharedConstant.EMPTY_GUI_FULL_LINE, GuiSharedConstant.EMPTY_GUI_FULL_LINE, GuiSharedConstant.EMPTY_GUI_FULL_LINE, GuiSharedConstant.EMPTY_GUI_FULL_LINE, - "B1111111S" + "B11L1R11S" ); } - protected void initGroups() { - // Add enchantment gui item - OutlinePane filledEnchant = new OutlinePane(0, 0, 9, 5); - filledEnchant.setPriority(Pane.Priority.HIGH); - filledEnchant.align(OutlinePane.Alignment.BEGIN); - filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL); - - Set illegalEnchant = this.enchantContainer.illegalEnchantments(); - for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) { - if (illegalEnchant.contains(enchant)) { - return; - } - filledEnchant.addItem(getGuiItemFromEnchant(enchant)); - } - - addPane(filledEnchant); + @Override + protected List getEveryDisplayableInstanceOfGeneric() { + Set illegalEnchantments = this.enchantContainer.illegalEnchantments(); + return Arrays.stream(WrappedEnchantment.values()) + .filter(enchantment -> !illegalEnchantments.contains(enchantment)) + .collect(Collectors.toList()); } - private GuiItem getGuiItemFromEnchant(WrappedEnchantment enchantment) { + @Override + public void update() { + this.backgroundPane.bindItem('S', hadChange() ? saveItem : GuiGlobalItems.noChangeItem()); + super.update(); + } + + @Override + protected GuiItem itemFromFactory(WrappedEnchantment enchantment, DummyFactory factory) { boolean isIn = this.selectedEnchant.contains(enchantment); Material usedMaterial; @@ -95,7 +89,6 @@ public class EnchantSelectSettingGui extends AbstractSettingGui { return guiItem; } - private static final List TRUE_LORE = Collections.singletonList("\u00A77Value: \u00A7aSelected"); private static final List FALSE_LORE = Collections.singletonList("\u00A77Value: \u00A7cNot Selected"); @@ -157,4 +150,32 @@ public class EnchantSelectSettingGui extends AbstractSettingGui { !baseGroup.containsAll(this.selectedEnchant); } + + // Unused methods and class + public static class DummyFactory extends AbstractSettingGui.SettingGuiFactory{ + protected DummyFactory(@NotNull String configPath, @NotNull ConfigHolder config) { + super(configPath, config); + } + @Override + public Gui create() { + return null; + } + } + @Override + protected List getCreateItemLore() { + return Collections.emptyList(); + } + @Override + protected Consumer getCreateClickConsumer() { + return null; + } + @Override + protected String createItemName() { + return null; + } + @Override + protected DummyFactory createFactory(WrappedEnchantment generic) { + return null; + } + }