From 96cb4488c384dd5e6b1fa066c70048f77d17a82a Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 21:44:33 +0200 Subject: [PATCH] Disable Money and Level buttons in admin panel, if EconomyPlugin or Level addon is missing. --- .../panel/admin/EditChallengeGUI.java | 162 ++++++++++++------ .../challenges/panel/admin/EditLevelGUI.java | 33 ++-- 2 files changed, 127 insertions(+), 68 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 61cbb74..523a652 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -11,7 +11,6 @@ import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; @@ -25,9 +24,6 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary methods that creates GUI and allow to edit challenges * properties. - * - * TODO: In current class set that MONEY are availabe only if ECONOMY exist. - * TODO: In current class set that ISLAND LEVEL are availabe only if LEVEL ADDON exist. */ public class EditChallengeGUI extends CommonGUI { @@ -762,19 +758,29 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.required-level", "[value]", Long.toString(this.challenge.getRequiredIslandLevel()))); - icon = new ItemStack(Material.BEACON); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> { - if (status) - { - this.challenge.setRequiredIslandLevel(value); - } - this.build(); - }); + if (this.addon.isLevelProvided()) + { + icon = new ItemStack(Material.BEACON); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> { + if (status) + { + this.challenge.setRequiredIslandLevel(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } @@ -785,18 +791,28 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.required-money", "[value]", Integer.toString(this.challenge.getRequiredMoney()))); - icon = new ItemStack(Material.GOLD_INGOT); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> { - if (status) - { - this.challenge.setRequiredMoney(value); - } - this.build(); - }); - return true; - }; + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> { + if (status) + { + this.challenge.setRequiredMoney(value); + } + + this.build(); + }); + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } + glow = false; break; } @@ -806,20 +822,31 @@ public class EditChallengeGUI extends CommonGUI if (this.challenge.isTakeMoney()) { - description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + description = Collections.singletonList(this.user + .getTranslation("challenges.gui.admin.descriptions.enabled")); } else { - description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + description = Collections.singletonList(this.user + .getTranslation("challenges.gui.admin.descriptions.disabled")); } - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); + + this.build(); + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - this.build(); - return true; - }; glow = this.challenge.isTakeMoney(); break; } @@ -901,19 +928,29 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", "[value]", Integer.toString(this.challenge.getRewardMoney()))); - icon = new ItemStack(Material.GOLD_INGOT); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> { - if (status) - { - this.challenge.setRewardMoney(value); - } - this.build(); - }); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> { + if (status) + { + this.challenge.setRewardMoney(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } @@ -1062,19 +1099,32 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-money", "[value]", Integer.toString(this.challenge.getRepeatMoneyReward()))); - icon = new ItemStack(Material.GOLD_NUGGET); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRepeatMoneyReward(), 0, (status, value) -> { - if (status) - { - this.challenge.setRepeatMoneyReward(value); - } - this.build(); - }); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_NUGGET); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, + this.challenge.getRepeatMoneyReward(), + 0, + (status, value) -> { + if (status) + { + this.challenge.setRepeatMoneyReward(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 23deeb5..e3113a5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -28,7 +28,6 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary elements to create Levels Edit GUI. - * TODO: In current class set that MONEY are availabe only if ECONOMY exist. */ public class EditLevelGUI extends CommonGUI { @@ -493,19 +492,29 @@ public class EditLevelGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", "[value]", Integer.toString(this.challengeLevel.getRewardMoney()))); - icon = new ItemStack(Material.GOLD_INGOT); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardMoney(value); - } - this.build(); - }); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardMoney(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; }