diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java index 83e6992..1188ec5 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java @@ -8,12 +8,12 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelListener; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -21,9 +21,9 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class ItemSwitchGUI { - public ItemSwitchGUI(CommonGUI parentGUI, User user, List itemStacks) + public ItemSwitchGUI(User user, List itemStacks, BiConsumer> consumer) { - this.parentGUI = parentGUI; + this.consumer = consumer; this.user = user; this.itemStacks = itemStacks; this.build(); @@ -35,7 +35,7 @@ public class ItemSwitchGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.change-items")); // Size of inventory that user can set via GUI. panelBuilder.size(45); @@ -94,9 +94,7 @@ public class ItemSwitchGUI } } - this.parentGUI.setValue(returnItems); - this.user.closeInventory(); - this.parentGUI.build(); + this.consumer.accept(true, returnItems); return true; }; @@ -108,7 +106,7 @@ public class ItemSwitchGUI description = Collections.emptyList(); icon = new ItemStack(Material.IRON_DOOR); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.build(); + this.consumer.accept(false, Collections.emptyList()); return true; }; break; @@ -219,10 +217,6 @@ public class ItemSwitchGUI // Section: Variables // --------------------------------------------------------------------- - /** - * ParentGUI from which current gui is called. - */ - private CommonGUI parentGUI; /** * User who opens current gui. @@ -233,4 +227,9 @@ public class ItemSwitchGUI * List with original items. */ private List itemStacks; + + /** + * Consumer that returns item stacks on save action. + */ + private BiConsumer> consumer; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index e16e81a..d625547 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -5,12 +5,12 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -18,11 +18,11 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class NumberGUI { - public NumberGUI(CommonGUI parentGUI, User user, int value) + public NumberGUI(User user, int value, BiConsumer consumer) { - this.parentGUI = parentGUI; this.user = user; this.value = value; + this.consumer = consumer; this.currentOperation = Button.SET; @@ -35,7 +35,7 @@ public class NumberGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.edit-number-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.edit-number-title")); // Others panelBuilder.item(0, this.getButton(Button.SAVE)); @@ -93,10 +93,7 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.setValue(this.value); - this.user.closeInventory(); - this.parentGUI.build(); - + this.consumer.accept(true, this.value); return true; }; glow = false; @@ -108,7 +105,7 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.IRON_DOOR); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.build(); + this.consumer.accept(false, this.value); return true; }; glow = false; @@ -290,9 +287,9 @@ public class NumberGUI // --------------------------------------------------------------------- /** - * This variable stores return GUI. + * This variable stores current GUI consumer. */ - private CommonGUI parentGUI; + private BiConsumer consumer; /** * User who runs GUI. diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index 081e0ce..452c2d9 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -5,12 +5,12 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -19,16 +19,16 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class StringListGUI { - public StringListGUI(CommonGUI parentGUI, User user, List value) + public StringListGUI(User user, List value, BiConsumer> consumer) { - this.parentGUI = parentGUI; + this.consumer = consumer; this.user = user; this.value = value; if (this.value.size() > 18) { // TODO: throw error that so large list cannot be edited. - this.parentGUI.build(); + this.consumer.accept(false, this.value); } else { @@ -42,7 +42,7 @@ public class StringListGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.text-edit-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.text-edit-title")); panelBuilder.item(0, this.getButton(Button.SAVE)); panelBuilder.item(1, this.getButton(Button.VALUE)); @@ -82,9 +82,7 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.setValue(this.value); - this.user.closeInventory(); - this.parentGUI.build(); + this.consumer.accept(true, this.value); return true; }; @@ -96,7 +94,8 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.IRON_DOOR); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.build(); + this.consumer.accept(false, this.value); + return true; }; break; @@ -198,9 +197,9 @@ public class StringListGUI /** - * This variable stores return GUI. + * This variable stores consumer. */ - private CommonGUI parentGUI; + private BiConsumer> consumer; /** * User who runs GUI.