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 69ad0d6..0dd0cfc 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -141,8 +141,12 @@ public class ListChallengesGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new ConfirmationGUI(this, this.user); - this.valueObject = challenge; + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager().deleteChallenge(challenge); + } + }); return true; }); } @@ -151,25 +155,6 @@ 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 511d6a3..e89ff2f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -141,8 +141,13 @@ public class ListLevelsGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new ConfirmationGUI(this, this.user); - this.valueObject = challengeLevel; + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager(). + deleteChallengeLevel(challengeLevel); + } + }); return true; }); } @@ -151,25 +156,6 @@ 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 // --------------------------------------------------------------------- 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 f12edbd..921c32f 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -3,10 +3,11 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; +import java.util.function.Consumer; + 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,12 +20,11 @@ public class ConfirmationGUI * This constructor inits and opens ConfirmationGUI. * * @param user Gui Caller. - * @param parentGUI Parent GUI. */ - public ConfirmationGUI(CommonGUI parentGUI, User user) + public ConfirmationGUI(User user, Consumer consumer) { this.user = user; - this.parentGUI = parentGUI; + this.consumer = consumer; this.build(); } @@ -35,16 +35,13 @@ public class ConfirmationGUI */ public void build() { - PanelBuilder panelBuilder = new PanelBuilder() - .name(this.user.getTranslation("challenges.gui.admin.confirm-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.admin.confirm-title")); 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.parentGUI.setValue(true); - this.user.closeInventory(); - this.parentGUI.build(); + this.consumer.accept(true); return true; }). build()); @@ -52,10 +49,8 @@ public class ConfirmationGUI panelBuilder.item(5, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.cancel")). icon(Material.RED_STAINED_GLASS_PANE). - clickHandler((panel, user1, clickType, i) -> - { - this.parentGUI.setValue(null); - this.parentGUI.build(); + clickHandler((panel, user1, clickType, i) -> { + this.consumer.accept(false); return true; }). build()); @@ -74,7 +69,7 @@ public class ConfirmationGUI private User user; /** - * Parent GUI where should return on cancel or proceed. + * Stores current Consumer */ - private CommonGUI parentGUI; + private Consumer consumer; }