From bd48e85fcc500882dd87cd70e5ee1a45fd55c34a Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 22:38:45 +0200 Subject: [PATCH 1/4] Create method that allows to change ValueObject value. --- .../world/bentobox/challenges/panel/CommonGUI.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 9ff4c1e..5e08cbe 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -4,7 +4,6 @@ package world.bentobox.challenges.panel; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; - import java.util.Collections; import java.util.List; @@ -232,5 +231,15 @@ public abstract class CommonGUI return new PanelItem(icon, name, description, false, clickHandler, false); } + + + /** + * This method sets new value to ValueObject variable. + * @param value new Value of valueObject. + */ + public void setValue(Object value) + { + this.valueObject = value; + } } From dab5f2b331c8481929822810ab056497cbe1a3df Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 22:44:48 +0200 Subject: [PATCH 2/4] Remove commands from UtilGuis, instead use CommonGUI.valueObject to store new value. Proper ItemSwitchGUI implementation. --- .../panel/util/ConfirmationGUI.java | 31 +-- .../challenges/panel/util/ItemGUI.java | 129 ---------- .../challenges/panel/util/ItemSwitchGUI.java | 236 ++++++++++++++++++ .../challenges/panel/util/NumberGUI.java | 35 +-- .../challenges/panel/util/StringListGUI.java | 35 +-- 5 files changed, 249 insertions(+), 217 deletions(-) delete mode 100644 src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java create mode 100644 src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java index 1fa7178..f12edbd 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -1,10 +1,8 @@ package world.bentobox.challenges.panel.util; + import org.bukkit.Material; -import java.util.*; - -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; @@ -22,18 +20,11 @@ public class ConfirmationGUI * * @param user Gui Caller. * @param parentGUI Parent GUI. - * @param command Command . - * @param parameters Variables at the end of command. */ - public ConfirmationGUI(CommonGUI parentGUI, - User user, - CompositeCommand command, - String... parameters) + public ConfirmationGUI(CommonGUI parentGUI, User user) { this.user = user; this.parentGUI = parentGUI; - this.command = command; - this.parameters = parameters; this.build(); } @@ -50,11 +41,8 @@ public class ConfirmationGUI panelBuilder.item(3, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")). icon(Material.GREEN_STAINED_GLASS_PANE). - clickHandler((panel, user1, clickType, index) -> - { - this.command - .execute(this.user, "CONFIRMATION", Arrays.asList(this.parameters)); - + clickHandler((panel, user1, clickType, index) -> { + this.parentGUI.setValue(true); this.user.closeInventory(); this.parentGUI.build(); return true; @@ -66,6 +54,7 @@ public class ConfirmationGUI icon(Material.RED_STAINED_GLASS_PANE). clickHandler((panel, user1, clickType, i) -> { + this.parentGUI.setValue(null); this.parentGUI.build(); return true; }). @@ -88,14 +77,4 @@ public class ConfirmationGUI * Parent GUI where should return on cancel or proceed. */ private CommonGUI parentGUI; - - /** - * Command that must be run on confirmation. - */ - private CompositeCommand command; - - /** - * List of variables. - */ - private String[] parameters; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java deleted file mode 100644 index 552c77b..0000000 --- a/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java +++ /dev/null @@ -1,129 +0,0 @@ -package world.bentobox.challenges.panel.util; - - -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.ItemStack; -import java.util.Collections; -import java.util.List; - -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; - - -/** - * This class allows to change Input ItemStacks to different ItemStacks. - */ -public class ItemGUI -{ - public ItemGUI(User user, List itemStacks) - { - this.user = user; - this.itemStacks = itemStacks; - this.build(); - } - - - /** - * This method builds panel that allows to change given number value. - */ - private void build() - { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); - panelBuilder.listener(new CustomPanelListener()); - - for (ItemStack itemStack : this.itemStacks) - { - panelBuilder.item(new CustomPanelItem(itemStack)); - } - - panelBuilder.build().open(this.user); - } - - -// --------------------------------------------------------------------- -// Section: Private classes -// --------------------------------------------------------------------- - - - /** - * This CustomPanelItem does no lose Item original MetaData. After PanelItem has been - * created it restores original meta data. It also does not allow to change anything that - * could destroy meta data. - */ - private class CustomPanelItem extends PanelItem - { - CustomPanelItem(ItemStack item) - { - super(item.clone(), "", Collections.emptyList(), false, null, false); - this.getItem().setItemMeta(item.getItemMeta()); - } - - - @Override - public void setGlow(boolean glow) - { - } - - - @Override - public void setDescription(List description) - { - } - - - @Override - public void setName(String name) - { - } - - - @Override - public void setHead(ItemStack itemStack) - { - } - } - - - /** - * This CustomPanelListener allows to move items in current panel. - */ - private class CustomPanelListener implements PanelListener - { - @Override - public void setup() - { - } - - - @Override - public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) - { - } - - - @Override - public void onInventoryClick(User user, InventoryClickEvent event) - { - event.setCancelled(false); - } - } - - -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - - /** - * User who opens current gui. - */ - private User user; - - /** - * List with original items. - */ - private List itemStacks; -} diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java new file mode 100644 index 0000000..83e6992 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java @@ -0,0 +1,236 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +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; + + +/** + * This class allows to change Input ItemStacks to different ItemStacks. + */ +public class ItemSwitchGUI +{ + public ItemSwitchGUI(CommonGUI parentGUI, User user, List itemStacks) + { + this.parentGUI = parentGUI; + this.user = user; + this.itemStacks = itemStacks; + this.build(); + } + + + /** + * This method builds panel that allows to change given number value. + */ + private void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); + + // Size of inventory that user can set via GUI. + panelBuilder.size(45); + + panelBuilder.listener(new CustomPanelListener()); + + panelBuilder.item(0, this.getButton(Button.SAVE)); + + for (int i = 1; i < 8; i++) + { + panelBuilder.item(i, this.getButton(Button.EMPTY)); + } + + panelBuilder.item(8, this.getButton(Button.CANCEL)); + + for (ItemStack itemStack : this.itemStacks) + { + panelBuilder.item(new CustomPanelItem(itemStack)); + } + + panelBuilder.build().open(this.user); + } + + + /** + * This method create button that does some functionality in current gui. + * @param button Button functionality. + * @return PanelItem. + */ + private PanelItem getButton(Button button) + { + ItemStack icon; + String name; + List description; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case SAVE: + { + name = this.user.getTranslation("challenges.gui.buttons.save"); + description = Collections.emptyList(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + // Magic number 9 - second row. First row is for custom buttons. + // Magic number 45 - This GUI is initialed with 45 elements. + List returnItems = new ArrayList<>(36); + + for (int i = 9; i < 45; i++) + { + ItemStack itemStack = panel.getInventory().getItem(i); + + if (itemStack != null) + { + returnItems.add(itemStack); + } + } + + this.parentGUI.setValue(returnItems); + this.user.closeInventory(); + this.parentGUI.build(); + + return true; + }; + break; + } + case CANCEL: + { + name = this.user.getTranslation("challenges.gui.buttons.cancel"); + description = Collections.emptyList(); + icon = new ItemStack(Material.IRON_DOOR); + clickHandler = (panel, user, clickType, slot) -> { + this.parentGUI.build(); + return true; + }; + break; + } + case EMPTY: + { + name = ""; + description = Collections.emptyList(); + icon = new ItemStack(Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> true; + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, false, clickHandler, false); + } + + +// --------------------------------------------------------------------- +// Section: Private classes +// --------------------------------------------------------------------- + + + /** + * This CustomPanelItem does no lose Item original MetaData. After PanelItem has been + * created it restores original meta data. It also does not allow to change anything that + * could destroy meta data. + */ + private class CustomPanelItem extends PanelItem + { + CustomPanelItem(ItemStack item) + { + super(item.clone(), "", Collections.emptyList(), false, null, false); + this.getItem().setItemMeta(item.getItemMeta()); + } + + + @Override + public void setGlow(boolean glow) + { + } + + + @Override + public void setDescription(List description) + { + } + + + @Override + public void setName(String name) + { + } + + + @Override + public void setHead(ItemStack itemStack) + { + } + } + + + /** + * This CustomPanelListener allows to move items in current panel. + */ + private class CustomPanelListener implements PanelListener + { + @Override + public void setup() + { + } + + + @Override + public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) + { + } + + + @Override + public void onInventoryClick(User user, InventoryClickEvent event) + { + // First row of elements should be ignored, as it contains buttons and blocked slots. + event.setCancelled(event.getRawSlot() < 9); + } + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * This enum holds all button values in current gui. + */ + private enum Button + { + CANCEL, + SAVE, + EMPTY + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * ParentGUI from which current gui is called. + */ + private CommonGUI parentGUI; + + /** + * User who opens current gui. + */ + private User user; + + /** + * List with original items. + */ + private List itemStacks; +} 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 5844eb8..e16e81a 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -3,11 +3,9 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -20,17 +18,11 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class NumberGUI { - public NumberGUI(CommonGUI parentGUI, - User user, - int value, - CompositeCommand command, - String... parameters) + public NumberGUI(CommonGUI parentGUI, User user, int value) { this.parentGUI = parentGUI; this.user = user; this.value = value; - this.command = command; - this.parameters = parameters; this.currentOperation = Button.SET; @@ -101,18 +93,9 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - List values = Arrays.asList(this.parameters); - values.add(Integer.toString(this.value)); - - if (this.command.execute(this.user, "NUMBER_GUI", values)) - { - this.user.closeInventory(); - this.parentGUI.build(); - } - else - { - this.build(); - } + this.parentGUI.setValue(this.value); + this.user.closeInventory(); + this.parentGUI.build(); return true; }; @@ -321,16 +304,6 @@ public class NumberGUI */ private int value; - /** - * Command that must be processed on save. - */ - private CompositeCommand command; - - /** - * Command input parameters before number. - */ - private String[] parameters; - /** * This variable holds which operation now is processed. */ 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 3ba79a8..081e0ce 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -3,11 +3,9 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -21,17 +19,11 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class StringListGUI { - public StringListGUI(CommonGUI parentGUI, - User user, - List value, - CompositeCommand command, - String... parameters) + public StringListGUI(CommonGUI parentGUI, User user, List value) { this.parentGUI = parentGUI; this.user = user; this.value = value; - this.command = command; - this.parameters = parameters; if (this.value.size() > 18) { @@ -90,18 +82,9 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - List values = Arrays.asList(this.parameters); - values.addAll(this.value); - - if (this.command.execute(this.user, "STRING_LIST_GUI", values)) - { - this.user.closeInventory(); - this.parentGUI.build(); - } - else - { - this.build(); - } + this.parentGUI.setValue(this.value); + this.user.closeInventory(); + this.parentGUI.build(); return true; }; @@ -228,14 +211,4 @@ public class StringListGUI * Current value. */ private List value; - - /** - * Command that must be processed on save. - */ - private CompositeCommand command; - - /** - * Command input parameters before number. - */ - private String[] parameters; } From 29dadf38411f118ac09369c67ee274b87222cb2d Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 22:56:05 +0200 Subject: [PATCH 3/4] Implement existing GUIs in AdminGUI. Update TODO comments. --- .../challenges/panel/admin/AdminGUI.java | 70 ++++++++++++++++--- .../challenges/panel/admin/ListUsersGUI.java | 2 +- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 7f0f405..77334ac 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -4,7 +4,6 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; - import java.util.Collections; import java.util.List; @@ -29,6 +28,11 @@ public class AdminGUI extends CommonGUI */ private boolean overwriteMode; + /** + * This indicate if Reset Challenges must work as reset all. + */ + private boolean resetAllMode; + // --------------------------------------------------------------------- // Section: Enums @@ -135,7 +139,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Complete Challenge GUI + new ListUsersGUI(this.addon, + this.world, + this.user, + ListUsersGUI.Mode.COMPLETE, + this.topLabel, + this.permissionPrefix, + this).build(); return true; }; @@ -148,12 +158,28 @@ public class AdminGUI extends CommonGUI name = this.user.getTranslation("challenges.gui.admin.buttons.reset"); description = Collections.emptyList(); icon = new ItemStack(Material.WRITABLE_BOOK); + + glow = this.resetAllMode; + clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Reset Challenge GUI + if (clickType.isRightClick()) + { + this.resetAllMode = !this.resetAllMode; + this.build(); + } + else + { + new ListUsersGUI(this.addon, + this.world, + this.user, + this.resetAllMode ? ListUsersGUI.Mode.RESET_ALL : ListUsersGUI.Mode.RESET, + this.topLabel, + this.permissionPrefix, + this).build(); + } return true; }; - glow = false; break; case ADD_CHALLENGE: @@ -163,7 +189,7 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Add Challenge GUI + // TODO: Create AnvilGUI that force to create String for "unique_id" return true; }; @@ -177,7 +203,7 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Add Level GUI + // TODO: Create AnvilGUI that force to create String for "unique_id" return true; }; @@ -191,7 +217,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.ANVIL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Edit Challenge GUI + new ListChallengesGUI(this.addon, + this.world, + this.user, + ListChallengesGUI.Mode.EDIT, + this.topLabel, + this.permissionPrefix, + this); return true; }; @@ -206,7 +238,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.ANVIL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Edit Level GUI + new ListLevelsGUI(this.addon, + this.world, + this.user, + ListLevelsGUI.Mode.EDIT, + this.topLabel, + this.permissionPrefix, + this); return true; }; @@ -222,7 +260,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.LAVA_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Delete Challenge GUI + new ListChallengesGUI(this.addon, + this.world, + this.user, + ListChallengesGUI.Mode.DELETE, + this.topLabel, + this.permissionPrefix, + this); return true; }; @@ -238,7 +282,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.LAVA_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Delete Level GUI + new ListLevelsGUI(this.addon, + this.world, + this.user, + ListLevelsGUI.Mode.DELETE, + this.topLabel, + this.permissionPrefix, + this); return true; }; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index 3365ad6..c7304a6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -54,7 +54,7 @@ public class ListUsersGUI extends CommonGUI /** * This allows to decide what User Icon should do. */ - private enum Mode + public enum Mode { COMPLETE, RESET, From 13291b450cbc6a42cc1395f71de8f8d37c0c0cc1 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 23:09:32 +0200 Subject: [PATCH 4/4] Implement ConfirmationGUIs in Delete operation for ListLevelsGUI and ListChallengesGUI. --- .../challenges/ChallengesManager.java | 12 ++++++++++ .../panel/admin/ListChallengesGUI.java | 23 +++++++++++++++++- .../challenges/panel/admin/ListLevelsGUI.java | 24 +++++++++++++++++-- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 75081f2..e050e70 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -527,4 +527,16 @@ public class ChallengesManager { { return new ArrayList<>(); } + + + public void deleteChallenge(Challenges selectedChallenge) + { + + } + + + public void deleteChallengeLevel(ChallengeLevels valueObject) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 20464e3..69ad0d6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -11,6 +11,7 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ConfirmationGUI; /** @@ -140,7 +141,8 @@ public class ListChallengesGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - // TODO: Conformation GUI for DELETING. + new ConfirmationGUI(this, this.user); + this.valueObject = challenge; return true; }); } @@ -149,6 +151,25 @@ public class ListChallengesGUI extends CommonGUI } + /** + * Overwriting set value allows to catch if ConfirmationGui returns true. + * @param value new Value of valueObject. + */ + @Override + public void setValue(Object value) + { + if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null) + { + this.addon.getChallengesManager().deleteChallenge((Challenges) this.valueObject); + this.valueObject = null; + } + else + { + this.valueObject = null; + } + } + + // --------------------------------------------------------------------- // Section: Enums // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 5167706..511d6a3 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -2,7 +2,6 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.World; - import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; @@ -12,6 +11,7 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ConfirmationGUI; /** @@ -141,7 +141,8 @@ public class ListLevelsGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - // TODO: Conformation GUI for DELETING. + new ConfirmationGUI(this, this.user); + this.valueObject = challengeLevel; return true; }); } @@ -150,6 +151,25 @@ public class ListLevelsGUI extends CommonGUI } + /** + * Overwriting set value allows to catch if ConfirmationGui returns true. + * @param value new Value of valueObject. + */ + @Override + public void setValue(Object value) + { + if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null) + { + this.addon.getChallengesManager().deleteChallengeLevel((ChallengeLevels) this.valueObject); + this.valueObject = null; + } + else + { + this.valueObject = null; + } + } + + // --------------------------------------------------------------------- // Section: Enums // ---------------------------------------------------------------------