From a50d00b2e79e8d7a508d4bcdabe5fc04c51bc131 Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 5 Aug 2019 03:00:03 -0700 Subject: [PATCH] Fixes JavaDoc warnings. (#164) @inheritDoc cannot be used on Constructors. Fixed some other warnings. --- .../handlers/ChallengeDataRequestHandler.java | 110 +- .../handlers/ChallengeListRequestHandler.java | 72 +- .../CompletedChallengesRequestHandler.java | 86 +- .../handlers/LevelDataRequestHandler.java | 106 +- .../handlers/LevelListRequestHandler.java | 72 +- .../bentobox/challenges/panel/CommonGUI.java | 1738 +++++------ .../challenges/panel/GameModesGUI.java | 197 +- .../challenges/panel/admin/AdminGUI.java | 948 +++--- .../panel/admin/EditChallengeGUI.java | 2590 +++++++++-------- .../challenges/panel/admin/EditLevelGUI.java | 1458 +++++----- .../panel/admin/EditSettingsGUI.java | 957 +++--- .../panel/admin/ListChallengesGUI.java | 290 +- .../challenges/panel/admin/ListLevelsGUI.java | 294 +- .../challenges/panel/admin/ListUsersGUI.java | 498 ++-- 14 files changed, 4738 insertions(+), 4678 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/handlers/ChallengeDataRequestHandler.java b/src/main/java/world/bentobox/challenges/handlers/ChallengeDataRequestHandler.java index 50d5a80..303b4de 100644 --- a/src/main/java/world/bentobox/challenges/handlers/ChallengeDataRequestHandler.java +++ b/src/main/java/world/bentobox/challenges/handlers/ChallengeDataRequestHandler.java @@ -17,27 +17,27 @@ import world.bentobox.challenges.database.object.Challenge; public class ChallengeDataRequestHandler extends AddonRequestHandler { - /** - * Constructor creates a new ChallengesDataRequestHandler instance. - * - * @param addon of type ChallengesAddon - */ - public ChallengeDataRequestHandler(ChallengesAddon addon) - { - super("challenge-data"); - this.addon = addon; - } + /** + * Constructor creates a new ChallengesDataRequestHandler instance. + * + * @param addon of type ChallengesAddon + */ + public ChallengeDataRequestHandler(ChallengesAddon addon) + { + super("challenge-data"); + this.addon = addon; + } - /** - * @param metaData Required meta data. - * @return Map that returns information about challenges - * @see AddonRequestHandler#handle(Map) - */ - @Override - public Object handle(Map metaData) - { - /* + /* (non-Javadoc) + * @param metaData Required meta data. + * @return Map that returns information about challenges + * @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map) + */ + @Override + public Object handle(Map metaData) + { + /* What we need in the metaData: 0. "challenge-name" -> String What we will return: @@ -56,51 +56,51 @@ public class ChallengeDataRequestHandler extends AddonRequestHandler - maxTimes: Integer object that represents how many times challenge can be completed. */ - if (metaData == null || - metaData.isEmpty() || - metaData.get("challenge-name") == null || - !(metaData.get("challenge-name") instanceof String)) - { - return Collections.emptyMap(); - } + if (metaData == null || + metaData.isEmpty() || + metaData.get("challenge-name") == null || + !(metaData.get("challenge-name") instanceof String)) + { + return Collections.emptyMap(); + } - Challenge challenge = this.addon.getChallengesManager().getChallenge((String) metaData.get("challenge-name")); + Challenge challenge = this.addon.getChallengesManager().getChallenge((String) metaData.get("challenge-name")); - Map challengeDataMap; + Map challengeDataMap; - if (challenge == null) - { - challengeDataMap = Collections.emptyMap(); - } - else - { - challengeDataMap = new HashMap<>(); + if (challenge == null) + { + challengeDataMap = Collections.emptyMap(); + } + else + { + challengeDataMap = new HashMap<>(); - challengeDataMap.put("uniqueId", challenge.getUniqueId()); - challengeDataMap.put("name", challenge.getFriendlyName()); - challengeDataMap.put("icon", challenge.getIcon()); - challengeDataMap.put("levelId", challenge.getLevel()); - challengeDataMap.put("order", challenge.getOrder()); - challengeDataMap.put("deployed", challenge.isDeployed()); - challengeDataMap.put("description", challenge.getDescription()); - challengeDataMap.put("type", challenge.getChallengeType().toString()); + challengeDataMap.put("uniqueId", challenge.getUniqueId()); + challengeDataMap.put("name", challenge.getFriendlyName()); + challengeDataMap.put("icon", challenge.getIcon()); + challengeDataMap.put("levelId", challenge.getLevel()); + challengeDataMap.put("order", challenge.getOrder()); + challengeDataMap.put("deployed", challenge.isDeployed()); + challengeDataMap.put("description", challenge.getDescription()); + challengeDataMap.put("type", challenge.getChallengeType().toString()); - challengeDataMap.put("repeatable", challenge.isRepeatable()); - challengeDataMap.put("maxTimes", challenge.isRepeatable() ? challenge.getMaxTimes() : 1); + challengeDataMap.put("repeatable", challenge.isRepeatable()); + challengeDataMap.put("maxTimes", challenge.isRepeatable() ? challenge.getMaxTimes() : 1); - } + } - return challengeDataMap; - } + return challengeDataMap; + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Variable stores challenges addon. - */ - private ChallengesAddon addon; + /** + * Variable stores challenges addon. + */ + private ChallengesAddon addon; } diff --git a/src/main/java/world/bentobox/challenges/handlers/ChallengeListRequestHandler.java b/src/main/java/world/bentobox/challenges/handlers/ChallengeListRequestHandler.java index 7cd8003..c270bb3 100644 --- a/src/main/java/world/bentobox/challenges/handlers/ChallengeListRequestHandler.java +++ b/src/main/java/world/bentobox/challenges/handlers/ChallengeListRequestHandler.java @@ -14,53 +14,53 @@ import world.bentobox.challenges.ChallengesAddon; */ public class ChallengeListRequestHandler extends AddonRequestHandler { - /** - * Constructor creates a new CompletedChallengesRequestHandler instance. - * - * @param addon of type ChallengesAddon - */ - public ChallengeListRequestHandler(ChallengesAddon addon) - { - super("challenge-list"); - this.addon = addon; - } + /** + * Constructor creates a new CompletedChallengesRequestHandler instance. + * + * @param addon of type ChallengesAddon + */ + public ChallengeListRequestHandler(ChallengesAddon addon) + { + super("challenge-list"); + this.addon = addon; + } - /** - * @param metaData Required meta data. - * @return Set of strings that contains completed challenges. - * @see AddonRequestHandler#handle(Map ) - */ - @Override - public Object handle(Map metaData) - { - /* + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map) + * @param metaData Required meta data. + * @return Set of strings that contains completed challenges. + */ + @Override + public Object handle(Map metaData) + { + /* What we need in the metaData: 0. "world-name" -> String What we will return: - List of challenges in given world. */ - if (metaData == null || - metaData.isEmpty() || - metaData.get("world-name") == null || - !(metaData.get("world-name") instanceof String) || - Bukkit.getWorld((String) metaData.get("world-name")) == null) - { - return Collections.emptyList(); - } + if (metaData == null || + metaData.isEmpty() || + metaData.get("world-name") == null || + !(metaData.get("world-name") instanceof String) || + Bukkit.getWorld((String) metaData.get("world-name")) == null) + { + return Collections.emptyList(); + } - return this.addon.getChallengesManager().getAllChallengesNames(Bukkit.getWorld((String) metaData.get("world-name"))); - } + return this.addon.getChallengesManager().getAllChallengesNames(Bukkit.getWorld((String) metaData.get("world-name"))); + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Variable stores challenges addon. - */ - private ChallengesAddon addon; + /** + * Variable stores challenges addon. + */ + private ChallengesAddon addon; } diff --git a/src/main/java/world/bentobox/challenges/handlers/CompletedChallengesRequestHandler.java b/src/main/java/world/bentobox/challenges/handlers/CompletedChallengesRequestHandler.java index 2293708..3452a34 100644 --- a/src/main/java/world/bentobox/challenges/handlers/CompletedChallengesRequestHandler.java +++ b/src/main/java/world/bentobox/challenges/handlers/CompletedChallengesRequestHandler.java @@ -17,27 +17,27 @@ import world.bentobox.challenges.ChallengesManager; public class CompletedChallengesRequestHandler extends AddonRequestHandler { - /** - * Constructor creates a new CompletedChallengesRequestHandler instance. - * - * @param addon of type ChallengesAddon - */ - public CompletedChallengesRequestHandler(ChallengesAddon addon) - { - super("completed-challenges"); - this.addon = addon; - } + /** + * Constructor creates a new CompletedChallengesRequestHandler instance. + * + * @param addon of type ChallengesAddon + */ + public CompletedChallengesRequestHandler(ChallengesAddon addon) + { + super("completed-challenges"); + this.addon = addon; + } - /** - * @param metaData Required meta data. - * @return Set of strings that contains completed challenges. - * @see AddonRequestHandler#handle(Map) - */ - @Override - public Object handle(Map metaData) - { - /* + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map) + * @param metaData Required meta data. + * @return Set of strings that contains completed challenges. + */ + @Override + public Object handle(Map metaData) + { + /* What we need in the metaData: 0. "player" -> UUID 1. "world-name" -> String @@ -46,35 +46,35 @@ public class CompletedChallengesRequestHandler extends AddonRequestHandler - Set of completed challenges in given world (or empty list if user haven't completed any challenge) */ - if (metaData == null || - metaData.isEmpty() || - metaData.get("world-name") == null || - !(metaData.get("world-name") instanceof String) || - metaData.get("player") == null || - !(metaData.get("player") instanceof UUID) || - Bukkit.getWorld((String) metaData.get("world-name")) == null) - { - return Collections.emptySet(); - } + if (metaData == null || + metaData.isEmpty() || + metaData.get("world-name") == null || + !(metaData.get("world-name") instanceof String) || + metaData.get("player") == null || + !(metaData.get("player") instanceof UUID) || + Bukkit.getWorld((String) metaData.get("world-name")) == null) + { + return Collections.emptySet(); + } - World world = Bukkit.getWorld((String) metaData.get("world-name")); - UUID player = (UUID) metaData.get("player"); + World world = Bukkit.getWorld((String) metaData.get("world-name")); + UUID player = (UUID) metaData.get("player"); - ChallengesManager manager = this.addon.getChallengesManager(); + ChallengesManager manager = this.addon.getChallengesManager(); - return manager.getAllChallengesNames(world).stream(). - filter(challenge -> manager.isChallengeComplete(player, world, challenge)). - collect(Collectors.toSet()); - } + return manager.getAllChallengesNames(world).stream(). + filter(challenge -> manager.isChallengeComplete(player, world, challenge)). + collect(Collectors.toSet()); + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Variable stores challenges addon. - */ - private ChallengesAddon addon; + /** + * Variable stores challenges addon. + */ + private ChallengesAddon addon; } diff --git a/src/main/java/world/bentobox/challenges/handlers/LevelDataRequestHandler.java b/src/main/java/world/bentobox/challenges/handlers/LevelDataRequestHandler.java index 6ae183a..10bf01d 100644 --- a/src/main/java/world/bentobox/challenges/handlers/LevelDataRequestHandler.java +++ b/src/main/java/world/bentobox/challenges/handlers/LevelDataRequestHandler.java @@ -15,27 +15,27 @@ import world.bentobox.challenges.database.object.ChallengeLevel; */ public class LevelDataRequestHandler extends AddonRequestHandler { - /** - * Constructor creates a new LevelDataRequestHandler instance. - * - * @param addon of type ChallengesAddon - */ - public LevelDataRequestHandler(ChallengesAddon addon) - { - super("level-data"); - this.addon = addon; - } + /** + * Constructor creates a new LevelDataRequestHandler instance. + * + * @param addon of type ChallengesAddon + */ + public LevelDataRequestHandler(ChallengesAddon addon) + { + super("level-data"); + this.addon = addon; + } - /** - * @param metaData Required meta data. - * @return Map that returns information about level - * @see AddonRequestHandler#handle(Map ) - */ - @Override - public Object handle(Map metaData) - { - /* + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map) + * @param metaData Required meta data. + * @return Map that returns information about level + */ + @Override + public Object handle(Map metaData) + { + /* What we need in the metaData: 0. "level-name" -> String What we will return: @@ -52,47 +52,47 @@ public class LevelDataRequestHandler extends AddonRequestHandler - challenges: List of strings that represents challenges that is owned by given level. */ - if (metaData == null || - metaData.isEmpty() || - metaData.get("level-name") == null || - !(metaData.get("level-name") instanceof String)) - { - return Collections.emptyMap(); - } + if (metaData == null || + metaData.isEmpty() || + metaData.get("level-name") == null || + !(metaData.get("level-name") instanceof String)) + { + return Collections.emptyMap(); + } - ChallengeLevel level = this.addon.getChallengesManager().getLevel((String) metaData.get("level-name")); + ChallengeLevel level = this.addon.getChallengesManager().getLevel((String) metaData.get("level-name")); - Map levelDataMap; + Map levelDataMap; - if (level == null) - { - levelDataMap = Collections.emptyMap(); - } - else - { - levelDataMap = new HashMap<>(); + if (level == null) + { + levelDataMap = Collections.emptyMap(); + } + else + { + levelDataMap = new HashMap<>(); - levelDataMap.put("uniqueId", level.getUniqueId()); - levelDataMap.put("name", level.getFriendlyName()); - levelDataMap.put("icon", level.getIcon()); - levelDataMap.put("order", level.getOrder()); - levelDataMap.put("message", level.getUnlockMessage()); - levelDataMap.put("world", level.getWorld()); - levelDataMap.put("challenges", level.getChallenges()); - levelDataMap.put("waiveramount", level.getWaiverAmount()); - } + levelDataMap.put("uniqueId", level.getUniqueId()); + levelDataMap.put("name", level.getFriendlyName()); + levelDataMap.put("icon", level.getIcon()); + levelDataMap.put("order", level.getOrder()); + levelDataMap.put("message", level.getUnlockMessage()); + levelDataMap.put("world", level.getWorld()); + levelDataMap.put("challenges", level.getChallenges()); + levelDataMap.put("waiveramount", level.getWaiverAmount()); + } - return levelDataMap; - } + return levelDataMap; + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Variable stores challenges addon. - */ - private ChallengesAddon addon; + /** + * Variable stores challenges addon. + */ + private ChallengesAddon addon; } diff --git a/src/main/java/world/bentobox/challenges/handlers/LevelListRequestHandler.java b/src/main/java/world/bentobox/challenges/handlers/LevelListRequestHandler.java index 66b46e3..8d8f809 100644 --- a/src/main/java/world/bentobox/challenges/handlers/LevelListRequestHandler.java +++ b/src/main/java/world/bentobox/challenges/handlers/LevelListRequestHandler.java @@ -15,53 +15,53 @@ import world.bentobox.challenges.ChallengesAddon; public class LevelListRequestHandler extends AddonRequestHandler { - /** - * Constructor creates a new CompletedChallengesRequestHandler instance. - * - * @param addon of type ChallengesAddon - */ - public LevelListRequestHandler(ChallengesAddon addon) - { - super("level-list"); - this.addon = addon; - } + /** + * Constructor creates a new CompletedChallengesRequestHandler instance. + * + * @param addon of type ChallengesAddon + */ + public LevelListRequestHandler(ChallengesAddon addon) + { + super("level-list"); + this.addon = addon; + } - /** - * @param metaData Required meta data. - * @return List of strings that contains levels in given world - * @see AddonRequestHandler#handle(Map ) - */ - @Override - public Object handle(Map metaData) - { - /* + /* (non-Javadoc) + * @see world.bentobox.bentobox.api.addons.request.AddonRequestHandler#handle(java.util.Map) + * @param metaData Required meta data. + * @return List of strings that contains levels in given world + */ + @Override + public Object handle(Map metaData) + { + /* What we need in the metaData: 0. "world-name" -> String What we will return: - List of levels in given world. */ - if (metaData == null || - metaData.isEmpty() || - metaData.get("world-name") == null || - !(metaData.get("world-name") instanceof String) || - Bukkit.getWorld((String) metaData.get("world-name")) == null) - { - return Collections.emptyList(); - } + if (metaData == null || + metaData.isEmpty() || + metaData.get("world-name") == null || + !(metaData.get("world-name") instanceof String) || + Bukkit.getWorld((String) metaData.get("world-name")) == null) + { + return Collections.emptyList(); + } - return this.addon.getChallengesManager().getLevels(Bukkit.getWorld((String) metaData.get("world-name"))); - } + return this.addon.getChallengesManager().getLevels(Bukkit.getWorld((String) metaData.get("world-name"))); + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Variable stores challenges addon. - */ - private ChallengesAddon addon; + /** + * Variable stores challenges addon. + */ + private ChallengesAddon addon; } diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 4722e3e..d52253b 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -1,6 +1,11 @@ package world.bentobox.challenges.panel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -16,10 +21,6 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SpawnEggMeta; import org.bukkit.inventory.meta.TropicalFishBucketMeta; import org.bukkit.potion.PotionData; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -38,882 +39,883 @@ import world.bentobox.challenges.utils.Utils; */ public abstract class CommonGUI { -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * This variable stores parent gui. - */ - private CommonGUI parentGUI; + /** + * This variable stores parent gui. + */ + private CommonGUI parentGUI; - /** - * Variable stores Challenges addon. - */ - protected ChallengesAddon addon; + /** + * Variable stores Challenges addon. + */ + protected ChallengesAddon addon; - /** - * Variable stores world in which panel is referred to. - */ - protected World world; + /** + * Variable stores world in which panel is referred to. + */ + protected World world; - /** - * Variable stores user who created this panel. - */ - protected User user; + /** + * Variable stores user who created this panel. + */ + protected User user; - /** - * Variable stores top label of command from which panel was called. - */ - protected String topLabel; + /** + * Variable stores top label of command from which panel was called. + */ + protected String topLabel; - /** - * Variable stores permission prefix of command from which panel was called. - */ - protected String permissionPrefix; - - /** - * Variable stores any value. - */ - protected Object valueObject; + /** + * Variable stores permission prefix of command from which panel was called. + */ + protected String permissionPrefix; + + /** + * Variable stores any value. + */ + protected Object valueObject; - /** - * This object holds current page index. - */ - protected int pageIndex; + /** + * This object holds current page index. + */ + protected int pageIndex; - /** - * This object holds PanelItem that allows to return to previous panel. - */ - protected PanelItem returnButton; - - - /** - * This enum contains buttons that is offten used in multiple GUIs. - */ - protected enum CommonButtons - { - NEXT, - PREVIOUS, - RETURN - } - - -// --------------------------------------------------------------------- -// Section: Constants -// --------------------------------------------------------------------- + /** + * This object holds PanelItem that allows to return to previous panel. + */ + protected PanelItem returnButton; + + + /** + * This enum contains buttons that is offten used in multiple GUIs. + */ + protected enum CommonButtons + { + NEXT, + PREVIOUS, + RETURN + } + + + // --------------------------------------------------------------------- + // Section: Constants + // --------------------------------------------------------------------- - protected static final String ADMIN = "admin"; - - protected static final String CHALLENGES = "challenges"; + protected static final String ADMIN = "admin"; + + protected static final String CHALLENGES = "challenges"; - protected static final String IMPORT = "import"; + protected static final String IMPORT = "import"; - protected static final String DEFAULT = "defaults"; + protected static final String DEFAULT = "defaults"; - protected static final String GENERATE = "generate"; - - protected static final String SETTINGS = "settings"; - - protected static final String DELETE = "delete"; - - protected static final String WIPE = "wipe"; - - protected static final String EDIT = "edit"; - - protected static final String ADD = "add"; - - protected static final String RESET = "reset"; - - protected static final String COMPLETE = "complete"; - - -// --------------------------------------------------------------------- -// Section: Constructors -// --------------------------------------------------------------------- - - - /** - * Default constructor that inits panels with minimal requirements, without parent panel. - * - * @param addon Addon where panel operates. - * @param world World from which panel was created. - * @param user User who created panel. - * @param topLabel Command top label which creates panel (f.e. island or ai) - * @param permissionPrefix Command permission prefix (f.e. bskyblock.) - */ - public CommonGUI(ChallengesAddon addon, - World world, - User user, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, topLabel, permissionPrefix, null); - } - - - /** - * Default constructor that inits panels with minimal requirements. - * - * @param addon Addon where panel operates. - * @param world World from which panel was created. - * @param user User who created panel. - * @param topLabel Command top label which creates panel (f.e. island or ai) - * @param permissionPrefix Command permission prefix (f.e. bskyblock.) - * @param parentGUI Parent panel for current panel. - */ - public CommonGUI(ChallengesAddon addon, - World world, - User user, - String topLabel, - String permissionPrefix, - CommonGUI parentGUI) - { - this.addon = addon; - this.world = world; - this.user = user; - - this.topLabel = topLabel; - this.permissionPrefix = permissionPrefix; - - this.parentGUI = parentGUI; - - this.pageIndex = 0; - - this.returnButton = new PanelItemBuilder(). - name(this.user.getTranslation("challenges.gui.buttons.return")). - icon(Material.OAK_DOOR). - clickHandler((panel, user1, clickType, i) -> { - if (this.parentGUI == null) - { - this.user.closeInventory(); - return true; - } - - this.parentGUI.build(); - return true; - }).build(); - } - - -// --------------------------------------------------------------------- -// Section: Common methods -// --------------------------------------------------------------------- - - - /** - * This method builds all necessary elements in GUI panel. - */ - public abstract void build(); - - - /** - * This method returns PanelItem that represents given Button. - * @param button Button that must be returned. - * @return PanelItem with requested functionality. - */ - protected PanelItem getButton(CommonButtons button) - { - ItemStack icon; - String name; - List description; - PanelItem.ClickHandler clickHandler; - - switch (button) - { - case NEXT: - { - name = this.user.getTranslation("challenges.gui.buttons.next"); - description = Collections.emptyList(); - icon = new ItemStack(ChallengesAddon.SIGN_MATERIAL); - clickHandler = (panel, user, clickType, slot) -> { - this.pageIndex++; - this.build(); - return true; - }; - - break; - } - case PREVIOUS: - { - name = this.user.getTranslation("challenges.gui.buttons.previous"); - description = Collections.emptyList(); - icon = new ItemStack(ChallengesAddon.SIGN_MATERIAL); - clickHandler = (panel, user, clickType, slot) -> { - this.pageIndex--; - this.build(); - return true; - }; - - break; - } - case RETURN: - return this.returnButton; - default: - return null; - } - - return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(false). - clickHandler(clickHandler). - build(); - } - - - /** - * This method sets new value to ValueObject variable. - * @param value new Value of valueObject. - */ - public void setValue(Object value) - { - this.valueObject = value; - } - - -// --------------------------------------------------------------------- -// Section: Generate Challenge Description -// --------------------------------------------------------------------- - - - /** - * This method generates and returns given challenge description. It is used here to avoid multiple - * duplicates, as it would be nice to have single place where challenge could be generated. - * @param challenge Challenge which description must be generated. - * @return List of strings that will be used in challenges description. - */ - protected List generateChallengeDescription(Challenge challenge, Player user) - { - List result = new ArrayList<>(); - - // Some values to avoid overchecking. - ChallengesManager manager = this.addon.getChallengesManager(); - - final boolean isCompletedOnce = manager.isChallengeComplete(user.getUniqueId(), world, challenge); - final long doneTimes = challenge.isRepeatable() ? - manager.getChallengeTimes(this.user, this.world, challenge) : - isCompletedOnce ? 0 : 1; - boolean isCompletedAll = isCompletedOnce && challenge.isRepeatable() && - challenge.getMaxTimes() > 0 && doneTimes >= challenge.getMaxTimes(); - - // Used to know if blocks, entities, items should be added after requirements and rewards. - char prevChar = ' '; - - for (char c : this.addon.getChallengesSettings().getChallengeLoreMessage().toLowerCase().toCharArray()) - { - switch (c) - { - case 'l': - { - ChallengeLevel level = manager.getLevel(challenge); - - if (level == null) - { - result.add(this.user.getTranslation("challenges.errors.missing-level", - "[level]", challenge.getLevel())); - } - else - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.level", - "[level]", level.getFriendlyName())); - } - - break; - } - case 's': - { - if (isCompletedOnce) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.completed")); - } - break; - } - case 't': - { - if (challenge.isRepeatable()) - { - if (challenge.getMaxTimes() > 0) - { - if (isCompletedAll) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.maxed-reached", - "[donetimes]", String.valueOf(doneTimes), - "[maxtimes]", String.valueOf(challenge.getMaxTimes()))); - } - else - { - result.add(this.user.getTranslation( - "challenges.gui.challenge-description.completed-times-of", - "[donetimes]", String.valueOf(doneTimes), - "[maxtimes]", String.valueOf(challenge.getMaxTimes()))); - } - } - else - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.completed-times", - "[donetimes]", String.valueOf(doneTimes))); - } - } - break; - } - case 'd': - { - if (!isCompletedAll) - { - result.addAll(challenge.getDescription()); - } - break; - } - case 'w': - { - if (!isCompletedAll) - { - if (challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) - { - if (challenge.isTakeItems()) - { - result.add(this.user.getTranslation( - "challenges.gui.challenge-description.warning-items-take")); - } - } - else if (challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.objects-close-by")); - - if (challenge.isRemoveEntities() && !challenge.getRequiredEntities().isEmpty()) - { - result.add(this.user.getTranslation( - "challenges.gui.challenge-description.warning-entities-kill")); - } - - if (challenge.isRemoveBlocks() && !challenge.getRequiredBlocks().isEmpty()) - { - result.add(this.user.getTranslation( - "challenges.gui.challenge-description.warning-blocks-remove")); - } - } - } - break; - } - case 'e': - { - // Display only if there are limited environments - - if (!isCompletedAll && - !challenge.getEnvironment().isEmpty() && - challenge.getEnvironment().size() != 3) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.environment")); - - if (challenge.getEnvironment().contains(World.Environment.NORMAL)) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.normal")); - } - - if (challenge.getEnvironment().contains(World.Environment.NETHER)) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.nether")); - } - - if (challenge.getEnvironment().contains(World.Environment.THE_END)) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.the-end")); - } - } - break; - } - case 'q': - { - if (!isCompletedAll && challenge.getChallengeType() == Challenge.ChallengeType.OTHER) - { - result.addAll(this.getChallengeRequirements(challenge)); - } - break; - } - case 'r': - { - if (isCompletedAll) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.not-repeatable")); - } - else - { - result.addAll(this.getChallengeRewards(challenge, isCompletedOnce)); - } - break; - } - case 'i': - { - if (!isCompletedAll) - { - if (prevChar == 'q' && challenge.getChallengeType() != Challenge.ChallengeType.OTHER) - { - result.addAll(this.getChallengeRequiredItems(challenge)); - } - else if (prevChar == 'r') - { - result.addAll(this.getChallengeRewardItems(challenge, isCompletedOnce, user)); - } - } - break; - } - default: - { - break; - } - } - - prevChar = c; - } - - result.replaceAll(x -> x.replace("[label]", this.topLabel)); - - return result; - } - - - /** - * This method returns list of strings that contains basic information about challenge rewards. - * @param challenge which reward message must be created. - * @param isCompletedOnce indicate if must use repeat rewards - * @return list of strings that contains rewards message. - */ - private List getChallengeRewards(Challenge challenge, boolean isCompletedOnce) - { - String rewardText; - double rewardMoney; - int rewardExperience; - - - if (!isCompletedOnce) - { - rewardText = challenge.getRewardText(); - rewardMoney = challenge.getRewardMoney(); - rewardExperience = challenge.getRewardExperience(); - } - else - { - rewardText = challenge.getRepeatRewardText(); - rewardMoney = challenge.getRepeatMoneyReward(); - rewardExperience = challenge.getRepeatExperienceReward(); - } - - List result = new ArrayList<>(); - - // Add reward text - result.add(rewardText); - - // Add message about reward XP - if (rewardExperience > 0) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.experience-reward", - "[value]", Integer.toString(rewardExperience))); - } - - // Add message about reward money - if (this.addon.getPlugin().getSettings().isUseEconomy() && rewardMoney > 0) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.money-reward", - "[value]", Double.toString(rewardMoney))); - } - - return result; - } - - - /** - * This method returns list of strings that contains reward items and commands from given challenge. - * @param challenge Challenge which reward items and commands must be returned. - * @param isCompletedOnce Boolean that indicate if must use repeat rewards. - * @param user Target user for command string. - * @return List of strings that contains message from challenges. - */ - private List getChallengeRewardItems(Challenge challenge, boolean isCompletedOnce, Player user) - { - List result = new ArrayList<>(); - - List rewardItems; - List rewardCommands; - - if (!isCompletedOnce) - { - rewardItems = challenge.getRewardItems(); - rewardCommands = challenge.getRewardCommands(); - } - else - { - rewardItems = challenge.getRepeatItemReward(); - rewardCommands = challenge.getRepeatRewardCommands(); - } - - // Add message about reward items - if (!rewardItems.isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.reward-items")); - - Utils.groupEqualItems(rewardItems).forEach(itemStack -> - result.addAll(this.generateItemStackDescription(itemStack))); - } - - // Add message about reward commands - if (!rewardCommands.isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.reward-commands")); - - for (String command : rewardCommands) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.command", - "[command]", command.replace("[player]", user.getName()).replace("[SELF]", ""))); - } - } - - return result; - } - - - /** - * This method returns list of strings that contains basic information about challenge requirements. - * @param challenge which requirements message must be created. - * @return list of strings that contains requirements message. - */ - private List getChallengeRequirements(Challenge challenge) - { - List result = new ArrayList<>(); - - // Add message about required exp - if (challenge.getRequiredExperience() > 0) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.required-experience", - "[value]", Integer.toString(challenge.getRequiredExperience()))); - } - - // Add message about required money - if (this.addon.isEconomyProvided() && challenge.getRequiredMoney() > 0) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.required-money", - "[value]", Integer.toString(challenge.getRequiredMoney()))); - } - - // Add message about required island level - if (this.addon.isLevelProvided() && challenge.getRequiredIslandLevel() > 0) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.required-island-level", - "[value]", Long.toString(challenge.getRequiredIslandLevel()))); - } - - return result; - } - - - /** - * This method returns list of strings that contains required items, entities and blocks from given challenge. - * @param challenge Challenge which requirement items, entities and blocks must be returned. - * @return List of strings that contains message from challenges. - */ - private List getChallengeRequiredItems(Challenge challenge) - { - List result = new ArrayList<>(); - - // Add message about required items - if (challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY) && - !challenge.getRequiredItems().isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.required-items")); - - Utils.groupEqualItems(challenge.getRequiredItems()).forEach(itemStack -> - result.addAll(this.generateItemStackDescription(itemStack))); - } - - if (challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND) && - (!challenge.getRequiredBlocks().isEmpty() || !challenge.getRequiredEntities().isEmpty())) - { - // Add required blocks - if (!challenge.getRequiredBlocks().isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.required-blocks")); - - for (Map.Entry entry : challenge.getRequiredBlocks().entrySet()) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.block", - "[block]", entry.getKey().name(), - "[count]", Integer.toString(entry.getValue()))); - } - } - - // Add required entities - if (!challenge.getRequiredEntities().isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.challenge-description.required-entities")); - - for (Map.Entry entry : challenge.getRequiredEntities().entrySet()) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.entity", - "[entity]", entry.getKey().name(), - "[count]", Integer.toString(entry.getValue()))); - } - } - } - - return result; - } - - -// --------------------------------------------------------------------- -// Section: Generate Level Description -// --------------------------------------------------------------------- - - - /** - * This method generates level description string. - * @param level Level which string must be generated. - * @param user User who calls generation. - * @return List with generated description. - */ - protected List generateLevelDescription(ChallengeLevel level, Player user) - { - List result = new ArrayList<>(); - - ChallengesManager manager = this.addon.getChallengesManager(); - LevelStatus status = manager.getChallengeLevelStatus(user.getUniqueId(), this.world, level); - - // Used to know if blocks, entities, items should be added after requirements and rewards. - char prevChar = ' '; - - for (char c : this.addon.getChallengesSettings().getLevelLoreMessage().toLowerCase().toCharArray()) - { - switch (c) - { - case 's': - { - if (status.isComplete()) - { - result.add(this.user.getTranslation("challenges.gui.level-description.completed")); - } - break; - } - case 't': - { - if (!status.isComplete()) - { - int doneChallengeCount = (int) level.getChallenges().stream(). - filter(challenge -> this.addon.getChallengesManager().isChallengeComplete(user.getUniqueId(), world, challenge)). - count(); - - result.add(this.user.getTranslation("challenges.gui.level-description.completed-challenges-of", - "[number]", Integer.toString(doneChallengeCount), - "[max]", Integer.toString(level.getChallenges().size()))); - } - break; - } - case 'd': - { - if (!status.isUnlocked()) - { - result.add(level.getUnlockMessage()); - } - break; - } - case 'a': - { - if (!status.isUnlocked() && !status.isComplete()) - { - result.add(this.user.getTranslation("challenges.gui.level-description.waver-amount", - "[value]", Integer.toString(level.getWaiverAmount()))); - } - break; - } - case 'r': - { - if (status.isUnlocked() && !status.isComplete()) - { - if (level.getRewardExperience() > 0) - { - result.add(this.user - .getTranslation("challenges.gui.level-description.experience-reward", - "[value]", Integer.toString(level.getWaiverAmount()))); - } - - if (this.addon.isEconomyProvided() && level.getRewardMoney() > 0) - { - result.add(this.user.getTranslation("challenges.gui.level-description.money-reward", - "[value]", Integer.toString(level.getRewardMoney()))); - } - } - break; - } - case 'i': - { - if (status.isUnlocked() && !status.isComplete() && prevChar == 'r') - { - // Add message about reward items - if (!level.getRewardItems().isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.level-description.reward-items")); - - Utils.groupEqualItems(level.getRewardItems()).forEach(itemStack -> - result.addAll(this.generateItemStackDescription(itemStack))); - } - - // Add message about reward commands - if (!level.getRewardCommands().isEmpty()) - { - result.add(this.user.getTranslation("challenges.gui.level-description.reward-commands")); - - for (String command : level.getRewardCommands()) - { - result.add(this.user.getTranslation("challenges.gui.descriptions.command", - "[command]", command.replace("[player]", user.getName()).replace("[SELF]", ""))); - } - } - } - break; - } - default: - { - break; - } - } - - prevChar = c; - } - - result.replaceAll(x -> x.replace("[label]", this.topLabel)); - - return result; - } - - -// --------------------------------------------------------------------- -// Section: ItemStack Description -// --------------------------------------------------------------------- - - - /** - * This method generates decsription for given item stack object. - * @param itemStack Object which lore must be generated - * @return List with generated description - */ - protected List generateItemStackDescription(ItemStack itemStack) - { - List result = new ArrayList<>(); - - result.add(this.user.getTranslation("challenges.gui.item-description.item", - "[item]", itemStack.getType().name(), - "[count]", Integer.toString(itemStack.getAmount()))); - - if (itemStack.hasItemMeta()) - { - ItemMeta meta = itemStack.getItemMeta(); - - if (meta.hasDisplayName()) - { - result.add(this.user.getTranslation("challenges.gui.item-description.item-name", - "[name]", meta.getDisplayName())); - } - - if (meta.hasLore()) - { - result.add(this.user.getTranslation("challenges.gui.item-description.item-lore")); - result.addAll(meta.getLore()); - } - - if (meta instanceof BookMeta) - { - result.add(this.user.getTranslation("challenges.gui.item-description.book-meta", - "[author]", ((BookMeta) meta).getAuthor(), - "[title]", ((BookMeta) meta).getTitle())); - } - else if (meta instanceof EnchantmentStorageMeta) - { - ((EnchantmentStorageMeta) meta).getStoredEnchants().forEach(((enchantment, level) -> { - result.add(this.user.getTranslation("challenges.gui.item-description.item-enchant", - "[enchant]", enchantment.getKey().getKey(), "[level]", Integer.toString(level))); - })); - } - else if (meta instanceof KnowledgeBookMeta) - { - result.add(this.user.getTranslation("challenges.gui.item-description.recipe-count", - "[count]", Integer.toString(((KnowledgeBookMeta) meta).getRecipes().size()))); - } - else if (meta instanceof LeatherArmorMeta) - { - result.add(this.user.getTranslation("challenges.gui.item-description.armor-color", - "[color]", ((LeatherArmorMeta) meta).getColor().toString())); - } - else if (meta instanceof PotionMeta) - { - PotionData data = ((PotionMeta) meta).getBasePotionData(); - - if (data.isExtended() && data.isUpgraded()) - { - result.add(this.user.getTranslation("challenges.gui.item-description.potion-type-extended-upgraded", - "[name]", data.getType().name())); - } - else if (data.isUpgraded()) - { - result.add(this.user.getTranslation("challenges.gui.item-description.potion-type-upgraded", - "[name]", data.getType().name())); - } - else if (data.isExtended()) - { - result.add(this.user.getTranslation("challenges.gui.item-description.potion-type-extended", - "[name]", data.getType().name())); - } - else - { - result.add(this.user.getTranslation("challenges.gui.item-description.potion-type", - "[name]", data.getType().name())); - } - - if (((PotionMeta) meta).hasCustomEffects()) - { - result.add(this.user.getTranslation("challenges.gui.item-description.custom-effects")); - - ((PotionMeta) meta).getCustomEffects().forEach(potionEffect -> - result.add(this.user.getTranslation("challenges.gui.item-description.potion-effect", - "[effect]", potionEffect.getType().getName(), - "[duration]", Integer.toString(potionEffect.getDuration()), - "[amplifier]", Integer.toString(potionEffect.getAmplifier())))); - } - } - else if (meta instanceof SkullMeta) - { - if (((SkullMeta) meta).getOwningPlayer() != null) - { - result.add(this.user.getTranslation("challenges.gui.item-description.skull-owner", - "[owner]", ((SkullMeta) meta).getOwningPlayer().getName())); - } - } - else if (meta instanceof SpawnEggMeta) - { - result.add(this.user.getTranslation("challenges.gui.item-description.egg-meta", - "[mob]", ((SpawnEggMeta) meta).getSpawnedType().name())); - } - else if (meta instanceof TropicalFishBucketMeta) - { - result.add(this.user.getTranslation("challenges.gui.item-description.fish-meta", - "[pattern]", ((TropicalFishBucketMeta) meta).getPattern().name(), - "[pattern-color]", ((TropicalFishBucketMeta) meta).getPatternColor().name(), - "[body-color]", ((TropicalFishBucketMeta) meta).getBodyColor().name())); - // parse ne - } - - if (meta.hasEnchants()) - { - itemStack.getEnchantments().forEach((enchantment, level) -> { - result.add(this.user.getTranslation("challenges.gui.item-description.item-enchant", - "[enchant]", - enchantment.getKey().getKey(), - "[level]", - Integer.toString(level))); - }); - } - } - - return result; - } + protected static final String GENERATE = "generate"; + + protected static final String SETTINGS = "settings"; + + protected static final String DELETE = "delete"; + + protected static final String WIPE = "wipe"; + + protected static final String EDIT = "edit"; + + protected static final String ADD = "add"; + + protected static final String RESET = "reset"; + + protected static final String COMPLETE = "complete"; + + + // --------------------------------------------------------------------- + // Section: Constructors + // --------------------------------------------------------------------- + + + /** + * Default constructor that inits panels with minimal requirements, without parent panel. + * + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + */ + public CommonGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, topLabel, permissionPrefix, null); + } + + + /** + * Default constructor that inits panels with minimal requirements. + * + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param parentGUI Parent panel for current panel. + */ + public CommonGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + this.addon = addon; + this.world = world; + this.user = user; + + this.topLabel = topLabel; + this.permissionPrefix = permissionPrefix; + + this.parentGUI = parentGUI; + + this.pageIndex = 0; + + this.returnButton = new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.buttons.return")). + icon(Material.OAK_DOOR). + clickHandler((panel, user1, clickType, i) -> { + if (this.parentGUI == null) + { + this.user.closeInventory(); + return true; + } + + this.parentGUI.build(); + return true; + }).build(); + } + + + // --------------------------------------------------------------------- + // Section: Common methods + // --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + public abstract void build(); + + + /** + * This method returns PanelItem that represents given Button. + * @param button Button that must be returned. + * @return PanelItem with requested functionality. + */ + @SuppressWarnings("deprecation") + protected PanelItem getButton(CommonButtons button) + { + ItemStack icon; + String name; + List description; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case NEXT: + { + name = this.user.getTranslation("challenges.gui.buttons.next"); + description = Collections.emptyList(); + icon = new ItemStack(ChallengesAddon.SIGN_MATERIAL); + clickHandler = (panel, user, clickType, slot) -> { + this.pageIndex++; + this.build(); + return true; + }; + + break; + } + case PREVIOUS: + { + name = this.user.getTranslation("challenges.gui.buttons.previous"); + description = Collections.emptyList(); + icon = new ItemStack(ChallengesAddon.SIGN_MATERIAL); + clickHandler = (panel, user, clickType, slot) -> { + this.pageIndex--; + this.build(); + return true; + }; + + break; + } + case RETURN: + return this.returnButton; + default: + return null; + } + + return new PanelItemBuilder(). + icon(icon). + name(name). + description(description). + glow(false). + clickHandler(clickHandler). + build(); + } + + + /** + * This method sets new value to ValueObject variable. + * @param value new Value of valueObject. + */ + public void setValue(Object value) + { + this.valueObject = value; + } + + + // --------------------------------------------------------------------- + // Section: Generate Challenge Description + // --------------------------------------------------------------------- + + + /** + * This method generates and returns given challenge description. It is used here to avoid multiple + * duplicates, as it would be nice to have single place where challenge could be generated. + * @param challenge Challenge which description must be generated. + * @return List of strings that will be used in challenges description. + */ + protected List generateChallengeDescription(Challenge challenge, Player user) + { + List result = new ArrayList<>(); + + // Some values to avoid overchecking. + ChallengesManager manager = this.addon.getChallengesManager(); + + final boolean isCompletedOnce = manager.isChallengeComplete(user.getUniqueId(), world, challenge); + final long doneTimes = challenge.isRepeatable() ? + manager.getChallengeTimes(this.user, this.world, challenge) : + isCompletedOnce ? 0 : 1; + boolean isCompletedAll = isCompletedOnce && challenge.isRepeatable() && + challenge.getMaxTimes() > 0 && doneTimes >= challenge.getMaxTimes(); + + // Used to know if blocks, entities, items should be added after requirements and rewards. + char prevChar = ' '; + + for (char c : this.addon.getChallengesSettings().getChallengeLoreMessage().toLowerCase().toCharArray()) + { + switch (c) + { + case 'l': + { + ChallengeLevel level = manager.getLevel(challenge); + + if (level == null) + { + result.add(this.user.getTranslation("challenges.errors.missing-level", + "[level]", challenge.getLevel())); + } + else + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.level", + "[level]", level.getFriendlyName())); + } + + break; + } + case 's': + { + if (isCompletedOnce) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.completed")); + } + break; + } + case 't': + { + if (challenge.isRepeatable()) + { + if (challenge.getMaxTimes() > 0) + { + if (isCompletedAll) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.maxed-reached", + "[donetimes]", String.valueOf(doneTimes), + "[maxtimes]", String.valueOf(challenge.getMaxTimes()))); + } + else + { + result.add(this.user.getTranslation( + "challenges.gui.challenge-description.completed-times-of", + "[donetimes]", String.valueOf(doneTimes), + "[maxtimes]", String.valueOf(challenge.getMaxTimes()))); + } + } + else + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.completed-times", + "[donetimes]", String.valueOf(doneTimes))); + } + } + break; + } + case 'd': + { + if (!isCompletedAll) + { + result.addAll(challenge.getDescription()); + } + break; + } + case 'w': + { + if (!isCompletedAll) + { + if (challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) + { + if (challenge.isTakeItems()) + { + result.add(this.user.getTranslation( + "challenges.gui.challenge-description.warning-items-take")); + } + } + else if (challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.objects-close-by")); + + if (challenge.isRemoveEntities() && !challenge.getRequiredEntities().isEmpty()) + { + result.add(this.user.getTranslation( + "challenges.gui.challenge-description.warning-entities-kill")); + } + + if (challenge.isRemoveBlocks() && !challenge.getRequiredBlocks().isEmpty()) + { + result.add(this.user.getTranslation( + "challenges.gui.challenge-description.warning-blocks-remove")); + } + } + } + break; + } + case 'e': + { + // Display only if there are limited environments + + if (!isCompletedAll && + !challenge.getEnvironment().isEmpty() && + challenge.getEnvironment().size() != 3) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.environment")); + + if (challenge.getEnvironment().contains(World.Environment.NORMAL)) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.normal")); + } + + if (challenge.getEnvironment().contains(World.Environment.NETHER)) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.nether")); + } + + if (challenge.getEnvironment().contains(World.Environment.THE_END)) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.the-end")); + } + } + break; + } + case 'q': + { + if (!isCompletedAll && challenge.getChallengeType() == Challenge.ChallengeType.OTHER) + { + result.addAll(this.getChallengeRequirements(challenge)); + } + break; + } + case 'r': + { + if (isCompletedAll) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.not-repeatable")); + } + else + { + result.addAll(this.getChallengeRewards(challenge, isCompletedOnce)); + } + break; + } + case 'i': + { + if (!isCompletedAll) + { + if (prevChar == 'q' && challenge.getChallengeType() != Challenge.ChallengeType.OTHER) + { + result.addAll(this.getChallengeRequiredItems(challenge)); + } + else if (prevChar == 'r') + { + result.addAll(this.getChallengeRewardItems(challenge, isCompletedOnce, user)); + } + } + break; + } + default: + { + break; + } + } + + prevChar = c; + } + + result.replaceAll(x -> x.replace("[label]", this.topLabel)); + + return result; + } + + + /** + * This method returns list of strings that contains basic information about challenge rewards. + * @param challenge which reward message must be created. + * @param isCompletedOnce indicate if must use repeat rewards + * @return list of strings that contains rewards message. + */ + private List getChallengeRewards(Challenge challenge, boolean isCompletedOnce) + { + String rewardText; + double rewardMoney; + int rewardExperience; + + + if (!isCompletedOnce) + { + rewardText = challenge.getRewardText(); + rewardMoney = challenge.getRewardMoney(); + rewardExperience = challenge.getRewardExperience(); + } + else + { + rewardText = challenge.getRepeatRewardText(); + rewardMoney = challenge.getRepeatMoneyReward(); + rewardExperience = challenge.getRepeatExperienceReward(); + } + + List result = new ArrayList<>(); + + // Add reward text + result.add(rewardText); + + // Add message about reward XP + if (rewardExperience > 0) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.experience-reward", + "[value]", Integer.toString(rewardExperience))); + } + + // Add message about reward money + if (this.addon.getPlugin().getSettings().isUseEconomy() && rewardMoney > 0) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.money-reward", + "[value]", Double.toString(rewardMoney))); + } + + return result; + } + + + /** + * This method returns list of strings that contains reward items and commands from given challenge. + * @param challenge Challenge which reward items and commands must be returned. + * @param isCompletedOnce Boolean that indicate if must use repeat rewards. + * @param user Target user for command string. + * @return List of strings that contains message from challenges. + */ + private List getChallengeRewardItems(Challenge challenge, boolean isCompletedOnce, Player user) + { + List result = new ArrayList<>(); + + List rewardItems; + List rewardCommands; + + if (!isCompletedOnce) + { + rewardItems = challenge.getRewardItems(); + rewardCommands = challenge.getRewardCommands(); + } + else + { + rewardItems = challenge.getRepeatItemReward(); + rewardCommands = challenge.getRepeatRewardCommands(); + } + + // Add message about reward items + if (!rewardItems.isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.reward-items")); + + Utils.groupEqualItems(rewardItems).forEach(itemStack -> + result.addAll(this.generateItemStackDescription(itemStack))); + } + + // Add message about reward commands + if (!rewardCommands.isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.reward-commands")); + + for (String command : rewardCommands) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.command", + "[command]", command.replace("[player]", user.getName()).replace("[SELF]", ""))); + } + } + + return result; + } + + + /** + * This method returns list of strings that contains basic information about challenge requirements. + * @param challenge which requirements message must be created. + * @return list of strings that contains requirements message. + */ + private List getChallengeRequirements(Challenge challenge) + { + List result = new ArrayList<>(); + + // Add message about required exp + if (challenge.getRequiredExperience() > 0) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.required-experience", + "[value]", Integer.toString(challenge.getRequiredExperience()))); + } + + // Add message about required money + if (this.addon.isEconomyProvided() && challenge.getRequiredMoney() > 0) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.required-money", + "[value]", Integer.toString(challenge.getRequiredMoney()))); + } + + // Add message about required island level + if (this.addon.isLevelProvided() && challenge.getRequiredIslandLevel() > 0) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.required-island-level", + "[value]", Long.toString(challenge.getRequiredIslandLevel()))); + } + + return result; + } + + + /** + * This method returns list of strings that contains required items, entities and blocks from given challenge. + * @param challenge Challenge which requirement items, entities and blocks must be returned. + * @return List of strings that contains message from challenges. + */ + private List getChallengeRequiredItems(Challenge challenge) + { + List result = new ArrayList<>(); + + // Add message about required items + if (challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY) && + !challenge.getRequiredItems().isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.required-items")); + + Utils.groupEqualItems(challenge.getRequiredItems()).forEach(itemStack -> + result.addAll(this.generateItemStackDescription(itemStack))); + } + + if (challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND) && + (!challenge.getRequiredBlocks().isEmpty() || !challenge.getRequiredEntities().isEmpty())) + { + // Add required blocks + if (!challenge.getRequiredBlocks().isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.required-blocks")); + + for (Map.Entry entry : challenge.getRequiredBlocks().entrySet()) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.block", + "[block]", entry.getKey().name(), + "[count]", Integer.toString(entry.getValue()))); + } + } + + // Add required entities + if (!challenge.getRequiredEntities().isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.challenge-description.required-entities")); + + for (Map.Entry entry : challenge.getRequiredEntities().entrySet()) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.entity", + "[entity]", entry.getKey().name(), + "[count]", Integer.toString(entry.getValue()))); + } + } + } + + return result; + } + + + // --------------------------------------------------------------------- + // Section: Generate Level Description + // --------------------------------------------------------------------- + + + /** + * This method generates level description string. + * @param level Level which string must be generated. + * @param user User who calls generation. + * @return List with generated description. + */ + protected List generateLevelDescription(ChallengeLevel level, Player user) + { + List result = new ArrayList<>(); + + ChallengesManager manager = this.addon.getChallengesManager(); + LevelStatus status = manager.getChallengeLevelStatus(user.getUniqueId(), this.world, level); + + // Used to know if blocks, entities, items should be added after requirements and rewards. + char prevChar = ' '; + + for (char c : this.addon.getChallengesSettings().getLevelLoreMessage().toLowerCase().toCharArray()) + { + switch (c) + { + case 's': + { + if (status.isComplete()) + { + result.add(this.user.getTranslation("challenges.gui.level-description.completed")); + } + break; + } + case 't': + { + if (!status.isComplete()) + { + int doneChallengeCount = (int) level.getChallenges().stream(). + filter(challenge -> this.addon.getChallengesManager().isChallengeComplete(user.getUniqueId(), world, challenge)). + count(); + + result.add(this.user.getTranslation("challenges.gui.level-description.completed-challenges-of", + "[number]", Integer.toString(doneChallengeCount), + "[max]", Integer.toString(level.getChallenges().size()))); + } + break; + } + case 'd': + { + if (!status.isUnlocked()) + { + result.add(level.getUnlockMessage()); + } + break; + } + case 'a': + { + if (!status.isUnlocked() && !status.isComplete()) + { + result.add(this.user.getTranslation("challenges.gui.level-description.waver-amount", + "[value]", Integer.toString(level.getWaiverAmount()))); + } + break; + } + case 'r': + { + if (status.isUnlocked() && !status.isComplete()) + { + if (level.getRewardExperience() > 0) + { + result.add(this.user + .getTranslation("challenges.gui.level-description.experience-reward", + "[value]", Integer.toString(level.getWaiverAmount()))); + } + + if (this.addon.isEconomyProvided() && level.getRewardMoney() > 0) + { + result.add(this.user.getTranslation("challenges.gui.level-description.money-reward", + "[value]", Integer.toString(level.getRewardMoney()))); + } + } + break; + } + case 'i': + { + if (status.isUnlocked() && !status.isComplete() && prevChar == 'r') + { + // Add message about reward items + if (!level.getRewardItems().isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.level-description.reward-items")); + + Utils.groupEqualItems(level.getRewardItems()).forEach(itemStack -> + result.addAll(this.generateItemStackDescription(itemStack))); + } + + // Add message about reward commands + if (!level.getRewardCommands().isEmpty()) + { + result.add(this.user.getTranslation("challenges.gui.level-description.reward-commands")); + + for (String command : level.getRewardCommands()) + { + result.add(this.user.getTranslation("challenges.gui.descriptions.command", + "[command]", command.replace("[player]", user.getName()).replace("[SELF]", ""))); + } + } + } + break; + } + default: + { + break; + } + } + + prevChar = c; + } + + result.replaceAll(x -> x.replace("[label]", this.topLabel)); + + return result; + } + + + // --------------------------------------------------------------------- + // Section: ItemStack Description + // --------------------------------------------------------------------- + + + /** + * This method generates decsription for given item stack object. + * @param itemStack Object which lore must be generated + * @return List with generated description + */ + protected List generateItemStackDescription(ItemStack itemStack) + { + List result = new ArrayList<>(); + + result.add(this.user.getTranslation("challenges.gui.item-description.item", + "[item]", itemStack.getType().name(), + "[count]", Integer.toString(itemStack.getAmount()))); + + if (itemStack.hasItemMeta()) + { + ItemMeta meta = itemStack.getItemMeta(); + + if (meta.hasDisplayName()) + { + result.add(this.user.getTranslation("challenges.gui.item-description.item-name", + "[name]", meta.getDisplayName())); + } + + if (meta.hasLore()) + { + result.add(this.user.getTranslation("challenges.gui.item-description.item-lore")); + result.addAll(meta.getLore()); + } + + if (meta instanceof BookMeta) + { + result.add(this.user.getTranslation("challenges.gui.item-description.book-meta", + "[author]", ((BookMeta) meta).getAuthor(), + "[title]", ((BookMeta) meta).getTitle())); + } + else if (meta instanceof EnchantmentStorageMeta) + { + ((EnchantmentStorageMeta) meta).getStoredEnchants().forEach(((enchantment, level) -> { + result.add(this.user.getTranslation("challenges.gui.item-description.item-enchant", + "[enchant]", enchantment.getKey().getKey(), "[level]", Integer.toString(level))); + })); + } + else if (meta instanceof KnowledgeBookMeta) + { + result.add(this.user.getTranslation("challenges.gui.item-description.recipe-count", + "[count]", Integer.toString(((KnowledgeBookMeta) meta).getRecipes().size()))); + } + else if (meta instanceof LeatherArmorMeta) + { + result.add(this.user.getTranslation("challenges.gui.item-description.armor-color", + "[color]", ((LeatherArmorMeta) meta).getColor().toString())); + } + else if (meta instanceof PotionMeta) + { + PotionData data = ((PotionMeta) meta).getBasePotionData(); + + if (data.isExtended() && data.isUpgraded()) + { + result.add(this.user.getTranslation("challenges.gui.item-description.potion-type-extended-upgraded", + "[name]", data.getType().name())); + } + else if (data.isUpgraded()) + { + result.add(this.user.getTranslation("challenges.gui.item-description.potion-type-upgraded", + "[name]", data.getType().name())); + } + else if (data.isExtended()) + { + result.add(this.user.getTranslation("challenges.gui.item-description.potion-type-extended", + "[name]", data.getType().name())); + } + else + { + result.add(this.user.getTranslation("challenges.gui.item-description.potion-type", + "[name]", data.getType().name())); + } + + if (((PotionMeta) meta).hasCustomEffects()) + { + result.add(this.user.getTranslation("challenges.gui.item-description.custom-effects")); + + ((PotionMeta) meta).getCustomEffects().forEach(potionEffect -> + result.add(this.user.getTranslation("challenges.gui.item-description.potion-effect", + "[effect]", potionEffect.getType().getName(), + "[duration]", Integer.toString(potionEffect.getDuration()), + "[amplifier]", Integer.toString(potionEffect.getAmplifier())))); + } + } + else if (meta instanceof SkullMeta) + { + if (((SkullMeta) meta).getOwningPlayer() != null) + { + result.add(this.user.getTranslation("challenges.gui.item-description.skull-owner", + "[owner]", ((SkullMeta) meta).getOwningPlayer().getName())); + } + } + else if (meta instanceof SpawnEggMeta) + { + result.add(this.user.getTranslation("challenges.gui.item-description.egg-meta", + "[mob]", ((SpawnEggMeta) meta).getSpawnedType().name())); + } + else if (meta instanceof TropicalFishBucketMeta) + { + result.add(this.user.getTranslation("challenges.gui.item-description.fish-meta", + "[pattern]", ((TropicalFishBucketMeta) meta).getPattern().name(), + "[pattern-color]", ((TropicalFishBucketMeta) meta).getPatternColor().name(), + "[body-color]", ((TropicalFishBucketMeta) meta).getBodyColor().name())); + // parse ne + } + + if (meta.hasEnchants()) + { + itemStack.getEnchantments().forEach((enchantment, level) -> { + result.add(this.user.getTranslation("challenges.gui.item-description.item-enchant", + "[enchant]", + enchantment.getKey().getKey(), + "[level]", + Integer.toString(level))); + }); + } + } + + return result; + } } diff --git a/src/main/java/world/bentobox/challenges/panel/GameModesGUI.java b/src/main/java/world/bentobox/challenges/panel/GameModesGUI.java index d9acb52..bbc26c8 100644 --- a/src/main/java/world/bentobox/challenges/panel/GameModesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/GameModesGUI.java @@ -22,117 +22,122 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class GameModesGUI extends CommonGUI { - /** - * {@inheritDoc} - * @param adminMode - boolean that indicate if Gui is in admin mode. - * @param gameModeAddons - List with GameModes where Challenges addon is integrated. - */ - public GameModesGUI(ChallengesAddon addon, - World world, - User user, - String topLabel, - String permissionPrefix, - boolean adminMode, - List gameModeAddons) - { - super(addon, world, user, topLabel, permissionPrefix); - this.adminMode = adminMode; - this.gameModeAddons = gameModeAddons; - } + /** + * @param adminMode - boolean that indicate if Gui is in admin mode. + * @param gameModeAddons - List with GameModes where Challenges addon is integrated. + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + + */ + public GameModesGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix, + boolean adminMode, + List gameModeAddons) + { + super(addon, world, user, topLabel, permissionPrefix); + this.adminMode = adminMode; + this.gameModeAddons = gameModeAddons; + } - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user). - name("challenges.gui.title.game-modes"); + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user). + name("challenges.gui.title.game-modes"); - GuiUtils.fillBorder(panelBuilder, this.adminMode ? - Material.BLACK_STAINED_GLASS_PANE : - Material.BLUE_STAINED_GLASS_PANE); + GuiUtils.fillBorder(panelBuilder, this.adminMode ? + Material.BLACK_STAINED_GLASS_PANE : + Material.BLUE_STAINED_GLASS_PANE); - int elementIndex; + int elementIndex; - if (this.gameModeAddons.size() < 8) - { - if (this.gameModeAddons.size() == 7) - { - elementIndex = 19; - } - else - { - elementIndex = 22 - this.gameModeAddons.size() / 2; - } - } - else - { - elementIndex = 10; - } + if (this.gameModeAddons.size() < 8) + { + if (this.gameModeAddons.size() == 7) + { + elementIndex = 19; + } + else + { + elementIndex = 22 - this.gameModeAddons.size() / 2; + } + } + else + { + elementIndex = 10; + } - for (GameModeAddon gameModeAddon : this.gameModeAddons) - { - if (!panelBuilder.slotOccupied(elementIndex)) - { - panelBuilder.item(elementIndex++, this.createGameModeIcon(gameModeAddon)); - } - else - { - // Find first open slot - while (panelBuilder.slotOccupied(elementIndex)) - { - elementIndex++; - } - } - } + for (GameModeAddon gameModeAddon : this.gameModeAddons) + { + if (!panelBuilder.slotOccupied(elementIndex)) + { + panelBuilder.item(elementIndex++, this.createGameModeIcon(gameModeAddon)); + } + else + { + // Find first open slot + while (panelBuilder.slotOccupied(elementIndex)) + { + elementIndex++; + } + } + } - panelBuilder.build(); - } + panelBuilder.build(); + } - /** - * This method creates icon that will display given GameMode addon. - * @param gameModeAddon GameMode addon. - * @return PanelItem that acts as icon for given GameMode. - */ - private PanelItem createGameModeIcon(GameModeAddon gameModeAddon) - { - return new PanelItemBuilder(). - name(gameModeAddon.getDescription().getName()). - description(gameModeAddon.getDescription().getDescription()). - icon(Material.PAPER). - clickHandler((panel, user, clickType, slot) -> { - Optional command; + /** + * This method creates icon that will display given GameMode addon. + * @param gameModeAddon GameMode addon. + * @return PanelItem that acts as icon for given GameMode. + */ + private PanelItem createGameModeIcon(GameModeAddon gameModeAddon) + { + return new PanelItemBuilder(). + name(gameModeAddon.getDescription().getName()). + description(gameModeAddon.getDescription().getDescription()). + icon(Material.PAPER). + clickHandler((panel, user, clickType, slot) -> { + Optional command; - if (this.adminMode) - { - command = gameModeAddon.getAdminCommand(); - } - else - { - command = gameModeAddon.getPlayerCommand(); - } + if (this.adminMode) + { + command = gameModeAddon.getAdminCommand(); + } + else + { + command = gameModeAddon.getPlayerCommand(); + } - command.ifPresent(compositeCommand -> - user.performCommand(compositeCommand.getTopLabel() + " challenges")); + command.ifPresent(compositeCommand -> + user.performCommand(compositeCommand.getTopLabel() + " challenges")); - return true; - }). - build(); - } + return true; + }). + build(); + } - // --------------------------------------------------------------------- - // Section: Variables - // --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * List with game mode addons which must be showed in current GUI. - */ - private List gameModeAddons; + /** + * List with game mode addons which must be showed in current GUI. + */ + private List gameModeAddons; - /** - * Stores if current GUI is in Admin Mode or not. - */ - private boolean adminMode; + /** + * Stores if current GUI is in Admin Mode or not. + */ + private boolean adminMode; } 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 8e148a9..52b3ef5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -5,15 +5,11 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; -import java.util.Optional; - import net.wesjd.anvilgui.AnvilGUI; -import world.bentobox.bentobox.api.addons.GameModeAddon; 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.bentobox.util.Util; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; @@ -26,474 +22,478 @@ import world.bentobox.challenges.utils.Utils; */ public class AdminGUI extends CommonGUI { -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - /** - * This boolean holds if import should overwrite existing challenges. - */ - private boolean overwriteMode; - - /** - * This indicate if Reset Challenges must work as reset all. - */ - private boolean resetAllMode; - - -// --------------------------------------------------------------------- -// Section: Enums -// --------------------------------------------------------------------- - - - /** - * This enum contains all button variations. Just for cleaner code. - */ - private enum Button - { - COMPLETE_USER_CHALLENGES, - RESET_USER_CHALLENGES, - ADD_CHALLENGE, - ADD_LEVEL, - EDIT_CHALLENGE, - EDIT_LEVEL, - DELETE_CHALLENGE, - DELETE_LEVEL, - IMPORT_CHALLENGES, - EDIT_SETTINGS, - DEFAULT_IMPORT_CHALLENGES, - DEFAULT_EXPORT_CHALLENGES, - COMPLETE_WIPE - } - - -// --------------------------------------------------------------------- -// Section: Constructor -// --------------------------------------------------------------------- - - - /** - * {@inheritDoc} - */ - public AdminGUI(ChallengesAddon addon, - World world, - User user, - String topLabel, - String permissionPrefix) - { - super(addon, world, user, topLabel, permissionPrefix); - } - - -// --------------------------------------------------------------------- -// Section: Methods -// --------------------------------------------------------------------- - - - /** - * {@inheritDoc} - */ - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.gui-title")); - - GuiUtils.fillBorder(panelBuilder); - - panelBuilder.item(10, this.createButton(Button.COMPLETE_USER_CHALLENGES)); - panelBuilder.item(19, this.createButton(Button.RESET_USER_CHALLENGES)); - - // Add Challenges - panelBuilder.item(12, this.createButton(Button.ADD_CHALLENGE)); - panelBuilder.item(13, this.createButton(Button.ADD_LEVEL)); - - // Edit Challenges - panelBuilder.item(21, this.createButton(Button.EDIT_CHALLENGE)); - panelBuilder.item(22, this.createButton(Button.EDIT_LEVEL)); - - // Remove Challenges - panelBuilder.item(30, this.createButton(Button.DELETE_CHALLENGE)); - panelBuilder.item(31, this.createButton(Button.DELETE_LEVEL)); - - - // Import Challenges - panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES)); - panelBuilder.item(24, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES)); - // Not added as I do not think admins should use it. It still will be able via command. -// panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES)); - - // Edit Addon Settings - panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS)); - - // Button that deletes everything from challenges addon - panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE)); - - panelBuilder.item(44, this.returnButton); - - panelBuilder.build(); - } - - - /** - * This method is used to create PanelItem for each button type. - * @param button Button which must be created. - * @return PanelItem with necessary functionality. - */ - private PanelItem createButton(Button button) - { - ItemStack icon; - String name; - String description; - boolean glow; - PanelItem.ClickHandler clickHandler; - - String permissionSuffix; - - switch (button) - { - case COMPLETE_USER_CHALLENGES: - permissionSuffix = COMPLETE; - - name = this.user.getTranslation("challenges.gui.buttons.admin.complete"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.complete"); - icon = new ItemStack(Material.WRITTEN_BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new ListUsersGUI(this.addon, - this.world, - this.user, - ListUsersGUI.Mode.COMPLETE, - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - - break; - case RESET_USER_CHALLENGES: - permissionSuffix = RESET; - - name = this.user.getTranslation("challenges.gui.buttons.admin.reset"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.reset"); - icon = new ItemStack(Material.WRITABLE_BOOK); - - glow = this.resetAllMode; - - clickHandler = (panel, user, clickType, slot) -> { - 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; - }; - - break; - case ADD_CHALLENGE: - permissionSuffix = ADD; - - name = this.user.getTranslation("challenges.gui.buttons.admin.create-challenge"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.create-challenge"); - icon = new ItemStack(Material.BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - "unique_id", - (player, reply) -> { - String newName = Utils.getGameMode(this.world) + "_" + reply; - - if (!this.addon.getChallengesManager().containsChallenge(newName)) - { - new EditChallengeGUI(this.addon, - this.world, - this.user, - this.addon.getChallengesManager().createChallenge(newName), - this.topLabel, - this.permissionPrefix, - this).build(); - } - else - { - this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); - } - - return reply; - }); - - return true; - }; - glow = false; - - break; - case ADD_LEVEL: - permissionSuffix = ADD; - - name = this.user.getTranslation("challenges.gui.buttons.admin.create-level"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.create-level"); - icon = new ItemStack(Material.BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - "unique_id", - (player, reply) -> { - String newName = Utils.getGameMode(this.world) + "_" + reply; - - if (!this.addon.getChallengesManager().containsLevel(newName)) - { - new EditLevelGUI(this.addon, - this.world, - this.user, - this.addon.getChallengesManager().createLevel(newName, this.world), - this.topLabel, - this.permissionPrefix, - this).build(); - } - else - { - this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); - } - - return reply; - }); - - return true; - }; - glow = false; - - break; - case EDIT_CHALLENGE: - permissionSuffix = EDIT; - - name = this.user.getTranslation("challenges.gui.buttons.admin.edit-challenge"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-challenge"); - icon = new ItemStack(Material.ANVIL); - clickHandler = (panel, user, clickType, slot) -> { - new ListChallengesGUI(this.addon, - this.world, - this.user, - ListChallengesGUI.Mode.EDIT, - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - - break; - case EDIT_LEVEL: - { - permissionSuffix = EDIT; - - name = this.user.getTranslation("challenges.gui.buttons.admin.edit-level"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-level"); - icon = new ItemStack(Material.ANVIL); - clickHandler = (panel, user, clickType, slot) -> { - new ListLevelsGUI(this.addon, - this.world, - this.user, - ListLevelsGUI.Mode.EDIT, - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - - break; - } - case DELETE_CHALLENGE: - { - permissionSuffix = DELETE; - - name = this.user.getTranslation("challenges.gui.buttons.admin.delete-challenge"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-challenge"); - icon = new ItemStack(Material.LAVA_BUCKET); - clickHandler = (panel, user, clickType, slot) -> { - new ListChallengesGUI(this.addon, - this.world, - this.user, - ListChallengesGUI.Mode.DELETE, - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - - break; - } - case DELETE_LEVEL: - { - permissionSuffix = DELETE; - - name = this.user.getTranslation("challenges.gui.buttons.admin.delete-level"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-level"); - icon = new ItemStack(Material.LAVA_BUCKET); - clickHandler = (panel, user, clickType, slot) -> { - new ListLevelsGUI(this.addon, - this.world, - this.user, - ListLevelsGUI.Mode.DELETE, - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - - break; - } - case IMPORT_CHALLENGES: - { - permissionSuffix = IMPORT; - - name = this.user.getTranslation("challenges.gui.buttons.admin.import"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.import"); - icon = new ItemStack(Material.HOPPER); - clickHandler = (panel, user, clickType, slot) -> { - if (clickType.isRightClick()) - { - this.overwriteMode = !this.overwriteMode; - this.build(); - } - else - { - // Run import command. - this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + IMPORT + - (this.overwriteMode ? " overwrite" : "")); - } - return true; - }; - glow = this.overwriteMode; - - break; - } - case DEFAULT_IMPORT_CHALLENGES: - { - permissionSuffix = DEFAULT; - - name = this.user.getTranslation("challenges.gui.buttons.admin.default-import"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.default-import"); - icon = new ItemStack(Material.HOPPER); - clickHandler = (panel, user, clickType, slot) -> { - // Run import command. - this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + IMPORT); - - return true; - }; - glow = false; - - break; - } - case DEFAULT_EXPORT_CHALLENGES: - { - permissionSuffix = DEFAULT; - - name = this.user.getTranslation("challenges.gui.buttons.admin.default-export"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.default-export"); - icon = new ItemStack(Material.HOPPER); - clickHandler = (panel, user, clickType, slot) -> { - if (clickType.isRightClick()) - { - this.overwriteMode = !this.overwriteMode; - this.build(); - } - else - { - // Run import command. - this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + GENERATE + - (this.overwriteMode ? " overwrite" : "")); - } - return true; - }; - glow = this.overwriteMode; - - break; - } - case EDIT_SETTINGS: - { - permissionSuffix = SETTINGS; - - name = this.user.getTranslation("challenges.gui.buttons.admin.settings"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.settings"); - icon = new ItemStack(Material.CRAFTING_TABLE); - clickHandler = (panel, user, clickType, slot) -> { - new EditSettingsGUI(this.addon, - this.world, - this.user, - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - - break; - } - case COMPLETE_WIPE: - { - permissionSuffix = WIPE; - - name = this.user.getTranslation("challenges.gui.buttons.admin.complete-wipe"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.complete-wipe"); - icon = new ItemStack(Material.TNT); - clickHandler = (panel, user, clickType, slot) -> { - new ConfirmationGUI(this.user, value -> { - if (value) - { - this.addon.getChallengesManager().wipeDatabase(); - this.user.sendMessage("challenges.messages.admin.complete-wipe"); - } - - this.build(); - }); - - return true; - }; - glow = false; - - break; - } - default: - // This should never happen. - return null; - } - - // If user does not have permission to run command, then change icon and clickHandler. - final String actionPermission = this.permissionPrefix + ADMIN + "." + CHALLENGES + "." + permissionSuffix; - - if (!this.user.hasPermission(actionPermission)) - { - icon = new ItemStack(Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - this.user.sendMessage("general.errors.no-permission", "[permission]", actionPermission); - return true; - }; - } - - return new PanelItemBuilder(). - icon(icon). - name(name). - description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). - glow(glow). - clickHandler(clickHandler). - build(); - } + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + /** + * This boolean holds if import should overwrite existing challenges. + */ + private boolean overwriteMode; + + /** + * This indicate if Reset Challenges must work as reset all. + */ + private boolean resetAllMode; + + + // --------------------------------------------------------------------- + // Section: Enums + // --------------------------------------------------------------------- + + + /** + * This enum contains all button variations. Just for cleaner code. + */ + private enum Button + { + COMPLETE_USER_CHALLENGES, + RESET_USER_CHALLENGES, + ADD_CHALLENGE, + ADD_LEVEL, + EDIT_CHALLENGE, + EDIT_LEVEL, + DELETE_CHALLENGE, + DELETE_LEVEL, + IMPORT_CHALLENGES, + EDIT_SETTINGS, + DEFAULT_IMPORT_CHALLENGES, + DEFAULT_EXPORT_CHALLENGES, + COMPLETE_WIPE + } + + + // --------------------------------------------------------------------- + // Section: Constructor + // --------------------------------------------------------------------- + + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + */ + public AdminGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + super(addon, world, user, topLabel, permissionPrefix); + } + + + // --------------------------------------------------------------------- + // Section: Methods + // --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.gui-title")); + + GuiUtils.fillBorder(panelBuilder); + + panelBuilder.item(10, this.createButton(Button.COMPLETE_USER_CHALLENGES)); + panelBuilder.item(19, this.createButton(Button.RESET_USER_CHALLENGES)); + + // Add Challenges + panelBuilder.item(12, this.createButton(Button.ADD_CHALLENGE)); + panelBuilder.item(13, this.createButton(Button.ADD_LEVEL)); + + // Edit Challenges + panelBuilder.item(21, this.createButton(Button.EDIT_CHALLENGE)); + panelBuilder.item(22, this.createButton(Button.EDIT_LEVEL)); + + // Remove Challenges + panelBuilder.item(30, this.createButton(Button.DELETE_CHALLENGE)); + panelBuilder.item(31, this.createButton(Button.DELETE_LEVEL)); + + + // Import Challenges + panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES)); + panelBuilder.item(24, this.createButton(Button.DEFAULT_IMPORT_CHALLENGES)); + // Not added as I do not think admins should use it. It still will be able via command. + // panelBuilder.item(33, this.createButton(Button.DEFAULT_EXPORT_CHALLENGES)); + + // Edit Addon Settings + panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS)); + + // Button that deletes everything from challenges addon + panelBuilder.item(34, this.createButton(Button.COMPLETE_WIPE)); + + panelBuilder.item(44, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This method is used to create PanelItem for each button type. + * @param button Button which must be created. + * @return PanelItem with necessary functionality. + */ + private PanelItem createButton(Button button) + { + ItemStack icon; + String name; + String description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + String permissionSuffix; + + switch (button) + { + case COMPLETE_USER_CHALLENGES: + permissionSuffix = COMPLETE; + + name = this.user.getTranslation("challenges.gui.buttons.admin.complete"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.complete"); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new ListUsersGUI(this.addon, + this.world, + this.user, + ListUsersGUI.Mode.COMPLETE, + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + + break; + case RESET_USER_CHALLENGES: + permissionSuffix = RESET; + + name = this.user.getTranslation("challenges.gui.buttons.admin.reset"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.reset"); + icon = new ItemStack(Material.WRITABLE_BOOK); + + glow = this.resetAllMode; + + clickHandler = (panel, user, clickType, slot) -> { + 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; + }; + + break; + case ADD_CHALLENGE: + permissionSuffix = ADD; + + name = this.user.getTranslation("challenges.gui.buttons.admin.create-challenge"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.create-challenge"); + icon = new ItemStack(Material.BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + "unique_id", + (player, reply) -> { + String newName = Utils.getGameMode(this.world) + "_" + reply; + + if (!this.addon.getChallengesManager().containsChallenge(newName)) + { + new EditChallengeGUI(this.addon, + this.world, + this.user, + this.addon.getChallengesManager().createChallenge(newName), + this.topLabel, + this.permissionPrefix, + this).build(); + } + else + { + this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); + } + + return reply; + }); + + return true; + }; + glow = false; + + break; + case ADD_LEVEL: + permissionSuffix = ADD; + + name = this.user.getTranslation("challenges.gui.buttons.admin.create-level"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.create-level"); + icon = new ItemStack(Material.BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + "unique_id", + (player, reply) -> { + String newName = Utils.getGameMode(this.world) + "_" + reply; + + if (!this.addon.getChallengesManager().containsLevel(newName)) + { + new EditLevelGUI(this.addon, + this.world, + this.user, + this.addon.getChallengesManager().createLevel(newName, this.world), + this.topLabel, + this.permissionPrefix, + this).build(); + } + else + { + this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); + } + + return reply; + }); + + return true; + }; + glow = false; + + break; + case EDIT_CHALLENGE: + permissionSuffix = EDIT; + + name = this.user.getTranslation("challenges.gui.buttons.admin.edit-challenge"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-challenge"); + icon = new ItemStack(Material.ANVIL); + clickHandler = (panel, user, clickType, slot) -> { + new ListChallengesGUI(this.addon, + this.world, + this.user, + ListChallengesGUI.Mode.EDIT, + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + + break; + case EDIT_LEVEL: + { + permissionSuffix = EDIT; + + name = this.user.getTranslation("challenges.gui.buttons.admin.edit-level"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.edit-level"); + icon = new ItemStack(Material.ANVIL); + clickHandler = (panel, user, clickType, slot) -> { + new ListLevelsGUI(this.addon, + this.world, + this.user, + ListLevelsGUI.Mode.EDIT, + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + + break; + } + case DELETE_CHALLENGE: + { + permissionSuffix = DELETE; + + name = this.user.getTranslation("challenges.gui.buttons.admin.delete-challenge"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-challenge"); + icon = new ItemStack(Material.LAVA_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + new ListChallengesGUI(this.addon, + this.world, + this.user, + ListChallengesGUI.Mode.DELETE, + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + + break; + } + case DELETE_LEVEL: + { + permissionSuffix = DELETE; + + name = this.user.getTranslation("challenges.gui.buttons.admin.delete-level"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.delete-level"); + icon = new ItemStack(Material.LAVA_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + new ListLevelsGUI(this.addon, + this.world, + this.user, + ListLevelsGUI.Mode.DELETE, + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + + break; + } + case IMPORT_CHALLENGES: + { + permissionSuffix = IMPORT; + + name = this.user.getTranslation("challenges.gui.buttons.admin.import"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.import"); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.overwriteMode = !this.overwriteMode; + this.build(); + } + else + { + // Run import command. + this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + IMPORT + + (this.overwriteMode ? " overwrite" : "")); + } + return true; + }; + glow = this.overwriteMode; + + break; + } + case DEFAULT_IMPORT_CHALLENGES: + { + permissionSuffix = DEFAULT; + + name = this.user.getTranslation("challenges.gui.buttons.admin.default-import"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.default-import"); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + // Run import command. + this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + IMPORT); + + return true; + }; + glow = false; + + break; + } + case DEFAULT_EXPORT_CHALLENGES: + { + permissionSuffix = DEFAULT; + + name = this.user.getTranslation("challenges.gui.buttons.admin.default-export"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.default-export"); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.overwriteMode = !this.overwriteMode; + this.build(); + } + else + { + // Run import command. + this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + DEFAULT + " " + GENERATE + + (this.overwriteMode ? " overwrite" : "")); + } + return true; + }; + glow = this.overwriteMode; + + break; + } + case EDIT_SETTINGS: + { + permissionSuffix = SETTINGS; + + name = this.user.getTranslation("challenges.gui.buttons.admin.settings"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.settings"); + icon = new ItemStack(Material.CRAFTING_TABLE); + clickHandler = (panel, user, clickType, slot) -> { + new EditSettingsGUI(this.addon, + this.world, + this.user, + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + + break; + } + case COMPLETE_WIPE: + { + permissionSuffix = WIPE; + + name = this.user.getTranslation("challenges.gui.buttons.admin.complete-wipe"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.complete-wipe"); + icon = new ItemStack(Material.TNT); + clickHandler = (panel, user, clickType, slot) -> { + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager().wipeDatabase(); + this.user.sendMessage("challenges.messages.admin.complete-wipe"); + } + + this.build(); + }); + + return true; + }; + glow = false; + + break; + } + default: + // This should never happen. + return null; + } + + // If user does not have permission to run command, then change icon and clickHandler. + final String actionPermission = this.permissionPrefix + ADMIN + "." + CHALLENGES + "." + permissionSuffix; + + if (!this.user.hasPermission(actionPermission)) + { + icon = new ItemStack(Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + this.user.sendMessage("general.errors.no-permission", "[permission]", actionPermission); + return true; + }; + } + + return new PanelItemBuilder(). + icon(icon). + name(name). + description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). + glow(glow). + clickHandler(clickHandler). + build(); + } } \ No newline at end of file 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 d76609a..72dac51 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -31,1295 +31,1303 @@ import world.bentobox.challenges.utils.Utils; */ public class EditChallengeGUI extends CommonGUI { -// --------------------------------------------------------------------- -// Section: Constructors -// --------------------------------------------------------------------- - - - /** - * {@inheritDoc} - * @param challenge challenge that needs editing. - */ - public EditChallengeGUI(ChallengesAddon addon, - World world, - User user, - Challenge challenge, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, challenge, topLabel, permissionPrefix, null); - } - - - /** - * {@inheritDoc} - * @param challenge challenge that needs editing. - */ - public EditChallengeGUI(ChallengesAddon addon, - World world, - User user, - Challenge challenge, - String topLabel, - String permissionPrefix, - CommonGUI parentGUI) - { - super(addon, world, user, topLabel, permissionPrefix, parentGUI); - this.challenge = challenge; - - // Default panel should be Properties. - this.currentMenuType = MenuType.PROPERTIES; - } - - -// --------------------------------------------------------------------- -// Section: Panel Creation related methods -// --------------------------------------------------------------------- - - - /** - * {@inheritDoc} - */ - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.edit-challenge-title")); - - GuiUtils.fillBorder(panelBuilder); - - panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); - panelBuilder.item(4, this.createMenuButton(MenuType.REQUIREMENTS)); - panelBuilder.item(6, this.createMenuButton(MenuType.REWARDS)); - - if (this.currentMenuType.equals(MenuType.PROPERTIES)) - { - this.buildMainPropertiesPanel(panelBuilder); - } - else if (this.currentMenuType.equals(MenuType.REQUIREMENTS)) - { - switch (this.challenge.getChallengeType()) - { - case INVENTORY: - this.buildInventoryRequirementsPanel(panelBuilder); - break; - case ISLAND: - this.buildIslandRequirementsPanel(panelBuilder); - break; - case OTHER: - this.buildOtherRequirementsPanel(panelBuilder); - break; - } - } - else if (this.currentMenuType.equals(MenuType.REWARDS)) - { - this.buildRewardsPanel(panelBuilder); - } - - panelBuilder.item(44, this.returnButton); - - // Every time when this GUI is build, save challenge - // This will ensure that all main things will be always stored - this.addon.getChallengesManager().saveChallenge(this.challenge); - - panelBuilder.build(); - } - - - /** - * This class populate ChallengesEditGUI with main challenge settings. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildMainPropertiesPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(10, this.createButton(Button.NAME)); - panelBuilder.item(13, this.createButton(Button.TYPE)); - panelBuilder.item(16, this.createButton(Button.DEPLOYED)); - - panelBuilder.item(19, this.createButton(Button.ICON)); - panelBuilder.item(22, this.createButton(Button.DESCRIPTION)); - panelBuilder.item(25, this.createButton(Button.ORDER)); - - panelBuilder.item(28, this.createButton(Button.ENVIRONMENT)); - panelBuilder.item(31, this.createButton(Button.REMOVE_ON_COMPLETE)); - } - - - /** - * This class populates ChallengesEditGUI with island challenges requirement elements. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildIslandRequirementsPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(19, this.createButton(Button.REQUIRED_ENTITIES)); - panelBuilder.item(28, this.createButton(Button.REMOVE_ENTITIES)); - - panelBuilder.item(21, this.createButton(Button.REQUIRED_BLOCKS)); - panelBuilder.item(30, this.createButton(Button.REMOVE_BLOCKS)); - - panelBuilder.item(23, this.createButton(Button.SEARCH_RADIUS)); - panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); - } - - - /** - * This class populates ChallengesEditGUI with inventory challenges requirement elements. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildInventoryRequirementsPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(10, this.createButton(Button.REQUIRED_ITEMS)); - panelBuilder.item(19, this.createButton(Button.REMOVE_ITEMS)); - - panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); - } - - - /** - * This class populates ChallengesEditGUI with other challenges requirement elements. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildOtherRequirementsPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(10, this.createButton(Button.REQUIRED_EXPERIENCE)); - panelBuilder.item(19, this.createButton(Button.REMOVE_EXPERIENCE)); - - panelBuilder.item(12, this.createButton(Button.REQUIRED_MONEY)); - panelBuilder.item(21, this.createButton(Button.REMOVE_MONEY)); - - panelBuilder.item(23, this.createButton(Button.REQUIRED_LEVEL)); - - panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); - } - - - /** - * This class populates ChallengesEditGUI with challenges reward elements. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildRewardsPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(10, this.createButton(Button.REWARD_TEXT)); - panelBuilder.item(19, this.createButton(Button.REWARD_COMMANDS)); - - panelBuilder.item(11, this.createButton(Button.REWARD_ITEM)); - panelBuilder.item(20, this.createButton(Button.REWARD_EXPERIENCE)); - panelBuilder.item(29, this.createButton(Button.REWARD_MONEY)); - - panelBuilder.item(22, this.createButton(Button.REPEATABLE)); - - if (this.challenge.isRepeatable()) - { - panelBuilder.item(31, this.createButton(Button.REPEAT_COUNT)); - - panelBuilder.item(15, this.createButton(Button.REPEAT_REWARD_TEXT)); - panelBuilder.item(24, this.createButton(Button.REPEAT_REWARD_COMMANDS)); - - panelBuilder.item(16, this.createButton(Button.REPEAT_REWARD_ITEM)); - panelBuilder.item(25, this.createButton(Button.REPEAT_REWARD_EXPERIENCE)); - panelBuilder.item(34, this.createButton(Button.REPEAT_REWARD_MONEY)); - } - } - - -// --------------------------------------------------------------------- -// Section: Other methods -// --------------------------------------------------------------------- - - - /** - * This method creates top menu buttons, that allows to switch "tabs". - * @param menuType Menu Type which button must be constructed. - * @return PanelItem that represents given menu type. - */ - private PanelItem createMenuButton(MenuType menuType) - { - ItemStack icon; - String name; - String description; - boolean glow; - PanelItem.ClickHandler clickHandler; - - switch (menuType) - { - case PROPERTIES: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.properties"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.properties"); - icon = new ItemStack(Material.CRAFTING_TABLE); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.PROPERTIES; - this.build(); - - return true; - }; - glow = this.currentMenuType.equals(MenuType.PROPERTIES); - break; - } - case REQUIREMENTS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.requirements"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.requirements"); - icon = new ItemStack(Material.HOPPER); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.REQUIREMENTS; - this.build(); - - return true; - }; - glow = this.currentMenuType.equals(MenuType.REQUIREMENTS); - break; - } - case REWARDS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.rewards"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.rewards"); - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.REWARDS; - this.build(); - - return true; - }; - glow = this.currentMenuType.equals(MenuType.REWARDS); - break; - } - default: - return null; - } - - return new PanelItemBuilder(). - icon(icon). - name(name). - description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). - glow(glow). - clickHandler(clickHandler). - build(); - } - - - /** - * This method creates buttons for default main menu. - * @param button Button which panel item must be created. - * @return PanelItem that represetns given button. - */ - private PanelItem createButton(Button button) - { - ItemStack icon; - String name; - List description; - boolean glow; - PanelItem.ClickHandler clickHandler; - - final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); - - switch (button) - { - case TYPE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.type"); - - List values = new ArrayList<>(5); - values.add(this.user.getTranslation("challenges.gui.descriptions.admin.type")); - - values.add((this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND) ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.type.island")); - values.add((this.challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY) ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.type.inventory")); - values.add((this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER) ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.type.other")); - - values.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", this.challenge.getChallengeType().name())); - - description = values; - - if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) - { - icon = new ItemStack(Material.GRASS_BLOCK); - } - else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) - { - icon = new ItemStack(Material.CHEST); - } - else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)) - { - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - } - else - { - icon = this.challenge.getIcon(); - } - - clickHandler = (panel, user, clickType, slot) -> { - if (clickType.isRightClick()) - { - this.challenge.setChallengeType( - this.getPreviousType(this.challenge.getChallengeType())); - } - else - { - this.challenge.setChallengeType( - this.getNextType(this.challenge.getChallengeType())); - } - - this.build(); - - return true; - }; - glow = false; - break; - } - case DEPLOYED: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.deployment"); - - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.deployment")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isDeployed() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setDeployed(!this.challenge.isDeployed()); - - this.build(); - return true; - }; - glow = this.challenge.isDeployed(); - break; - } - case ICON: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.icon"); - description = Collections.singletonList(this.user.getTranslation( - "challenges.gui.descriptions.admin.icon-challenge")); - icon = this.challenge.getIcon(); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.challenge.getIcon().getType().name(), - (player, reply) -> { - Material material = Material.getMaterial(reply); - - if (material != null) - { - this.challenge.setIcon(new ItemStack(material)); - this.build(); - } - else - { - this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); - } - - return reply; - }); - - return true; - }; - glow = false; - break; - } - case DESCRIPTION: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.description"); - description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.description")); - icon = new ItemStack(Material.WRITTEN_BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getDescription(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setDescription(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case ORDER: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.order"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.order")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getOrder()))); - - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getOrder(), -1, 9999, lineLength, (status, value) -> { - if (status) - { - this.challenge.setOrder(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case ENVIRONMENT: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.environment"); - - description = new ArrayList<>(4); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.environment")); - - description.add((this.challenge.getEnvironment().contains(World.Environment.NORMAL) ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.normal")); - description.add((this.challenge.getEnvironment().contains(World.Environment.NETHER) ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.nether")); - description.add((this.challenge.getEnvironment().contains(World.Environment.THE_END) ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.the-end")); - - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - new SelectEnvironmentGUI(this.user, this.challenge.getEnvironment(), (status, value) -> { - if (status) - { - this.challenge.setEnvironment(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REMOVE_ON_COMPLETE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-on-complete"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-on-complete")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isRemoveWhenCompleted() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - if (this.challenge.isRemoveWhenCompleted()) - { - icon = new ItemStack(Material.LAVA_BUCKET); - } - else - { - icon = new ItemStack(Material.BUCKET); - } - - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setRemoveWhenCompleted(!this.challenge.isRemoveWhenCompleted()); - this.build(); - - return true; - }; - glow = this.challenge.isRemoveWhenCompleted(); - break; - } - case NAME: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.name"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.name-challenge")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", this.challenge.getFriendlyName())); - - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.challenge.getFriendlyName(), - (player, reply) -> { - this.challenge.setFriendlyName(reply); - this.build(); - return reply; - }); - - return true; - }; - glow = false; - break; - } - - case REQUIRED_ENTITIES: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-entities"); - - description = new ArrayList<>(this.challenge.getRequiredEntities().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-entities")); - - for (Map.Entry entry : this.challenge.getRequiredEntities().entrySet()) - { - description.add(this.user.getTranslation("challenges.gui.descriptions.entity", - "[entity]", entry.getKey().name(), - "[count]", Integer.toString(entry.getValue()))); - } - - icon = new ItemStack(Material.CREEPER_HEAD); - clickHandler = (panel, user, clickType, slot) -> { - new ManageEntitiesGUI(this.addon, - this.world, - this.user, - this.challenge.getRequiredEntities(), - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - break; - } - case REMOVE_ENTITIES: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-entities"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-entities")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isRemoveEntities() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setRemoveEntities(!this.challenge.isRemoveEntities()); - - this.build(); - return true; - }; - glow = this.challenge.isRemoveEntities(); - break; - } - case REQUIRED_BLOCKS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-blocks"); - - description = new ArrayList<>(this.challenge.getRequiredBlocks().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-blocks")); - - for (Map.Entry entry : this.challenge.getRequiredBlocks().entrySet()) - { - description.add(this.user.getTranslation("challenges.gui.descriptions.block", - "[block]", entry.getKey().name(), - "[count]", Integer.toString(entry.getValue()))); - } - - icon = new ItemStack(Material.STONE); - clickHandler = (panel, user, clickType, slot) -> { - new ManageBlocksGUI(this.addon, - this.world, - this.user, - this.challenge.getRequiredBlocks(), - this.topLabel, - this.permissionPrefix, - this).build(); - - return true; - }; - glow = false; - break; - } - case REMOVE_BLOCKS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-blocks"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-blocks")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isRemoveBlocks() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setRemoveBlocks(!this.challenge.isRemoveBlocks()); - - this.build(); - return true; - }; - glow = this.challenge.isRemoveBlocks(); - break; - } - case SEARCH_RADIUS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.search-radius"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.search-radius")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getSearchRadius()))); - - icon = new ItemStack(Material.COBBLESTONE_WALL); - - // Search radius should not be larger then island radius. - int maxSearchDistance = - this.addon.getPlugin().getIWM().getAddon(this.world).map(gameModeAddon -> - gameModeAddon.getWorldSettings().getIslandDistance()).orElse(100); - - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getSearchRadius(), 0, maxSearchDistance, lineLength, (status, value) -> { - if (status) - { - this.challenge.setSearchRadius(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REQUIRED_PERMISSIONS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-permissions"); - description = new ArrayList<>(this.challenge.getRequiredPermissions().size() + 1); - description.add(this.user.getTranslation( - "challenges.gui.descriptions.admin.required-permissions")); - - for (String permission : this.challenge.getRequiredPermissions()) - { - description.add(this.user.getTranslation("challenges.gui.descriptions.permission", - "[permission]", permission)); - } - - icon = new ItemStack(Material.REDSTONE_LAMP); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getRequiredPermissions(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRequiredPermissions(new HashSet<>(value)); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REQUIRED_ITEMS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-items"); - - description = new ArrayList<>(this.challenge.getRequiredItems().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-items")); - - Utils.groupEqualItems(this.challenge.getRequiredItems()).forEach(itemStack -> - description.addAll(this.generateItemStackDescription(itemStack))); - - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, slot) -> { - new ItemSwitchGUI(this.user, this.challenge.getRequiredItems(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRequiredItems(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REMOVE_ITEMS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-items"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-items")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isTakeItems() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setTakeItems(!this.challenge.isTakeItems()); - - this.build(); - return true; - }; - glow = this.challenge.isTakeItems(); - break; - } - case REQUIRED_EXPERIENCE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-experience"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-experience")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getRequiredExperience()))); - - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRequiredExperience(), 0, lineLength, (status, value) -> { - if (status) - { - this.challenge.setRequiredExperience(value); - } - - this.build(); - }); - return true; - }; - glow = false; - break; - } - case REMOVE_EXPERIENCE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-experience"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-experience")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isTakeExperience() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setTakeExperience(!this.challenge.isTakeExperience()); - - this.build(); - return true; - }; - glow = this.challenge.isTakeExperience(); - break; - } - case REQUIRED_LEVEL: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-level"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-level")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Long.toString(this.challenge.getRequiredIslandLevel()))); - - icon = new ItemStack(this.addon.isLevelProvided() ? Material.BEACON : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRequiredIslandLevel(value); - } - - this.build(); - }); - - return true; - }; - - glow = false; - break; - } - case REQUIRED_MONEY: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.required-money"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-money")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Long.toString(this.challenge.getRequiredMoney()))); - - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, lineLength, (status, value) -> { - if (status) - { - this.challenge.setRequiredMoney(value); - } - - this.build(); - }); - return true; - }; - - glow = false; - break; - } - case REMOVE_MONEY: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-money"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-money")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isTakeMoney() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.LEVER : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); - - this.build(); - return true; - }; - - glow = this.challenge.isTakeMoney(); - break; - } - - case REWARD_TEXT: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-text"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-text")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", "|" + this.challenge.getRewardText())); - - icon = new ItemStack(Material.WRITTEN_BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getRewardText(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining())); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REWARD_ITEM: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-items"); - - description = new ArrayList<>(this.challenge.getRewardItems().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-items")); - - Utils.groupEqualItems(this.challenge.getRewardItems()).forEach(itemStack -> - description.addAll(this.generateItemStackDescription(itemStack))); - - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, slot) -> { - new ItemSwitchGUI(this.user, this.challenge.getRewardItems(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRewardItems(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REWARD_EXPERIENCE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-experience"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-experience")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getRewardExperience()))); - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRewardExperience(), 0, lineLength, (status, value) -> { - if (status) - { - this.challenge.setRewardExperience(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REWARD_MONEY: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-money"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-money")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getRewardMoney()))); - - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, lineLength, (status, value) -> { - if (status) - { - this.challenge.setRewardMoney(value); - } - - this.build(); - }); - - return true; - }; - - - glow = false; - break; - } - case REWARD_COMMANDS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-commands"); - description = new ArrayList<>(this.challenge.getRewardCommands().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-commands")); - - for (String command : this.challenge.getRewardCommands()) - { - description.add(this.user.getTranslation("challenges.gui.descriptions.command", - "[command]", command)); - } - - icon = new ItemStack(Material.COMMAND_BLOCK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getRewardCommands(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRewardCommands(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - - case REPEATABLE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeatable"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeatable")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.challenge.isRepeatable() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setRepeatable(!this.challenge.isRepeatable()); - - this.build(); - return true; - }; - glow = this.challenge.isRepeatable(); - break; - } - case REPEAT_COUNT: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-count"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-count")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getMaxTimes()))); - - icon = new ItemStack(Material.COBBLESTONE_WALL); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getMaxTimes(), 0, lineLength, (status, value) -> { - if (status) - { - this.challenge.setMaxTimes(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - - case REPEAT_REWARD_TEXT: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-text"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-text")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", "|" + this.challenge.getRepeatRewardText())); - - icon = new ItemStack(Material.WRITTEN_BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getRepeatRewardText(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRepeatRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining())); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REPEAT_REWARD_ITEM: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-items"); - - description = new ArrayList<>(this.challenge.getRepeatItemReward().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-items")); - - Utils.groupEqualItems(this.challenge.getRepeatItemReward()).forEach(itemStack -> - description.addAll(this.generateItemStackDescription(itemStack))); - - icon = new ItemStack(Material.TRAPPED_CHEST); - clickHandler = (panel, user, clickType, slot) -> { - new ItemSwitchGUI(this.user, this.challenge.getRepeatItemReward(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRepeatItemReward(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REPEAT_REWARD_EXPERIENCE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-experience"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-experience")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getRepeatExperienceReward()))); - - icon = new ItemStack(Material.GLASS_BOTTLE); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRepeatExperienceReward(), 0, lineLength, (status, value) -> { - if (status) - { - this.challenge.setRepeatExperienceReward(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REPEAT_REWARD_MONEY: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-money"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-money")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challenge.getRepeatMoneyReward()))); - - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_NUGGET : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, - this.challenge.getRepeatMoneyReward(), - 0, - lineLength, - (status, value) -> { - if (status) - { - this.challenge.setRepeatMoneyReward(value); - } - - this.build(); - }); - - return true; - }; - - glow = false; - break; - } - case REPEAT_REWARD_COMMANDS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-commands"); - description = new ArrayList<>(this.challenge.getRepeatRewardCommands().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-commands")); - - for (String command : this.challenge.getRepeatRewardCommands()) - { - description.add(this.user.getTranslation("challenges.gui.descriptions.command", - "[command]", command)); - } - - icon = new ItemStack(Material.COMMAND_BLOCK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getRepeatRewardCommands(), lineLength, (status, value) -> { - if (status) - { - this.challenge.setRepeatRewardCommands(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - default: - return null; - } - - return new PanelItemBuilder(). - icon(icon). - name(name). - description(GuiUtils.stringSplit(description, lineLength)). - glow(glow). - clickHandler(clickHandler). - build(); - } - - - /** - * This method returns next challenge type from given. - * @param type Given challenge type. - * @return Next Challenge Type. - */ - private Challenge.ChallengeType getNextType(Challenge.ChallengeType type) - { - Challenge.ChallengeType[] values = Challenge.ChallengeType.values(); - - for (int i = 0; i < values.length; i++) - { - if (values[i].equals(type)) - { - if (i + 1 == values.length) - { - return values[0]; - } - else - { - return values[i + 1]; - } - } - } - - return type; - } - - - /** - * This method returns previous challenge type from given. - * @param type Given challenge type. - * @return Previous Challenge Type. - */ - private Challenge.ChallengeType getPreviousType(Challenge.ChallengeType type) - { - Challenge.ChallengeType[] values = Challenge.ChallengeType.values(); - - for (int i = 0; i < values.length; i++) - { - if (values[i].equals(type)) - { - if (i > 0) - { - return values[i - 1]; - } - else - { - return values[values.length - 1]; - } - } - } - - return type; - } - - -// --------------------------------------------------------------------- -// Section: Enums -// --------------------------------------------------------------------- - - - /** - * Represents different types of menus - */ - private enum MenuType - { - PROPERTIES, - REQUIREMENTS, - REWARDS - } - - - /** - * Represents different buttons that could be in menus. - */ - private enum Button - { - NAME, - TYPE, - DEPLOYED, - ICON, - DESCRIPTION, - ORDER, - ENVIRONMENT, - REMOVE_ON_COMPLETE, - - REQUIRED_ENTITIES, - REMOVE_ENTITIES, - REQUIRED_BLOCKS, - REMOVE_BLOCKS, - SEARCH_RADIUS, - REQUIRED_PERMISSIONS, - REQUIRED_ITEMS, - REMOVE_ITEMS, - REQUIRED_EXPERIENCE, - REMOVE_EXPERIENCE, - REQUIRED_LEVEL, - REQUIRED_MONEY, - REMOVE_MONEY, - - REWARD_TEXT, - REWARD_ITEM, - REWARD_EXPERIENCE, - REWARD_MONEY, - REWARD_COMMANDS, - - REPEATABLE, - REPEAT_COUNT, - - REPEAT_REWARD_TEXT, - REPEAT_REWARD_ITEM, - REPEAT_REWARD_EXPERIENCE, - REPEAT_REWARD_MONEY, - REPEAT_REWARD_COMMANDS, - } - - -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - - /** - * Variable holds challenge thats needs editing. - */ - private Challenge challenge; - - /** - * Variable holds current active menu. - */ - private MenuType currentMenuType; + // --------------------------------------------------------------------- + // Section: Constructors + // --------------------------------------------------------------------- + + + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param challenge - challenge that needs editing + */ + public EditChallengeGUI(ChallengesAddon addon, + World world, + User user, + Challenge challenge, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, challenge, topLabel, permissionPrefix, null); + } + + + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param challenge challenge that needs editing. + */ + public EditChallengeGUI(ChallengesAddon addon, + World world, + User user, + Challenge challenge, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.challenge = challenge; + + // Default panel should be Properties. + this.currentMenuType = MenuType.PROPERTIES; + } + + + // --------------------------------------------------------------------- + // Section: Panel Creation related methods + // --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.edit-challenge-title")); + + GuiUtils.fillBorder(panelBuilder); + + panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); + panelBuilder.item(4, this.createMenuButton(MenuType.REQUIREMENTS)); + panelBuilder.item(6, this.createMenuButton(MenuType.REWARDS)); + + if (this.currentMenuType.equals(MenuType.PROPERTIES)) + { + this.buildMainPropertiesPanel(panelBuilder); + } + else if (this.currentMenuType.equals(MenuType.REQUIREMENTS)) + { + switch (this.challenge.getChallengeType()) + { + case INVENTORY: + this.buildInventoryRequirementsPanel(panelBuilder); + break; + case ISLAND: + this.buildIslandRequirementsPanel(panelBuilder); + break; + case OTHER: + this.buildOtherRequirementsPanel(panelBuilder); + break; + } + } + else if (this.currentMenuType.equals(MenuType.REWARDS)) + { + this.buildRewardsPanel(panelBuilder); + } + + panelBuilder.item(44, this.returnButton); + + // Every time when this GUI is build, save challenge + // This will ensure that all main things will be always stored + this.addon.getChallengesManager().saveChallenge(this.challenge); + + panelBuilder.build(); + } + + + /** + * This class populate ChallengesEditGUI with main challenge settings. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildMainPropertiesPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.NAME)); + panelBuilder.item(13, this.createButton(Button.TYPE)); + panelBuilder.item(16, this.createButton(Button.DEPLOYED)); + + panelBuilder.item(19, this.createButton(Button.ICON)); + panelBuilder.item(22, this.createButton(Button.DESCRIPTION)); + panelBuilder.item(25, this.createButton(Button.ORDER)); + + panelBuilder.item(28, this.createButton(Button.ENVIRONMENT)); + panelBuilder.item(31, this.createButton(Button.REMOVE_ON_COMPLETE)); + } + + + /** + * This class populates ChallengesEditGUI with island challenges requirement elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildIslandRequirementsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(19, this.createButton(Button.REQUIRED_ENTITIES)); + panelBuilder.item(28, this.createButton(Button.REMOVE_ENTITIES)); + + panelBuilder.item(21, this.createButton(Button.REQUIRED_BLOCKS)); + panelBuilder.item(30, this.createButton(Button.REMOVE_BLOCKS)); + + panelBuilder.item(23, this.createButton(Button.SEARCH_RADIUS)); + panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); + } + + + /** + * This class populates ChallengesEditGUI with inventory challenges requirement elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildInventoryRequirementsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.REQUIRED_ITEMS)); + panelBuilder.item(19, this.createButton(Button.REMOVE_ITEMS)); + + panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); + } + + + /** + * This class populates ChallengesEditGUI with other challenges requirement elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildOtherRequirementsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.REQUIRED_EXPERIENCE)); + panelBuilder.item(19, this.createButton(Button.REMOVE_EXPERIENCE)); + + panelBuilder.item(12, this.createButton(Button.REQUIRED_MONEY)); + panelBuilder.item(21, this.createButton(Button.REMOVE_MONEY)); + + panelBuilder.item(23, this.createButton(Button.REQUIRED_LEVEL)); + + panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); + } + + + /** + * This class populates ChallengesEditGUI with challenges reward elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildRewardsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.REWARD_TEXT)); + panelBuilder.item(19, this.createButton(Button.REWARD_COMMANDS)); + + panelBuilder.item(11, this.createButton(Button.REWARD_ITEM)); + panelBuilder.item(20, this.createButton(Button.REWARD_EXPERIENCE)); + panelBuilder.item(29, this.createButton(Button.REWARD_MONEY)); + + panelBuilder.item(22, this.createButton(Button.REPEATABLE)); + + if (this.challenge.isRepeatable()) + { + panelBuilder.item(31, this.createButton(Button.REPEAT_COUNT)); + + panelBuilder.item(15, this.createButton(Button.REPEAT_REWARD_TEXT)); + panelBuilder.item(24, this.createButton(Button.REPEAT_REWARD_COMMANDS)); + + panelBuilder.item(16, this.createButton(Button.REPEAT_REWARD_ITEM)); + panelBuilder.item(25, this.createButton(Button.REPEAT_REWARD_EXPERIENCE)); + panelBuilder.item(34, this.createButton(Button.REPEAT_REWARD_MONEY)); + } + } + + + // --------------------------------------------------------------------- + // Section: Other methods + // --------------------------------------------------------------------- + + + /** + * This method creates top menu buttons, that allows to switch "tabs". + * @param menuType Menu Type which button must be constructed. + * @return PanelItem that represents given menu type. + */ + private PanelItem createMenuButton(MenuType menuType) + { + ItemStack icon; + String name; + String description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + switch (menuType) + { + case PROPERTIES: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.properties"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.properties"); + icon = new ItemStack(Material.CRAFTING_TABLE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.PROPERTIES; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.PROPERTIES); + break; + } + case REQUIREMENTS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.requirements"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.requirements"); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.REQUIREMENTS; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.REQUIREMENTS); + break; + } + case REWARDS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.rewards"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.rewards"); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.REWARDS; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.REWARDS); + break; + } + default: + return null; + } + + return new PanelItemBuilder(). + icon(icon). + name(name). + description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). + glow(glow). + clickHandler(clickHandler). + build(); + } + + + /** + * This method creates buttons for default main menu. + * @param button Button which panel item must be created. + * @return PanelItem that represetns given button. + */ + private PanelItem createButton(Button button) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); + + switch (button) + { + case TYPE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.type"); + + List values = new ArrayList<>(5); + values.add(this.user.getTranslation("challenges.gui.descriptions.admin.type")); + + values.add((this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND) ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.type.island")); + values.add((this.challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY) ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.type.inventory")); + values.add((this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER) ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.type.other")); + + values.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", this.challenge.getChallengeType().name())); + + description = values; + + if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) + { + icon = new ItemStack(Material.GRASS_BLOCK); + } + else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) + { + icon = new ItemStack(Material.CHEST); + } + else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)) + { + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + } + else + { + icon = this.challenge.getIcon(); + } + + clickHandler = (panel, user, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.challenge.setChallengeType( + this.getPreviousType(this.challenge.getChallengeType())); + } + else + { + this.challenge.setChallengeType( + this.getNextType(this.challenge.getChallengeType())); + } + + this.build(); + + return true; + }; + glow = false; + break; + } + case DEPLOYED: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.deployment"); + + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.deployment")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isDeployed() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setDeployed(!this.challenge.isDeployed()); + + this.build(); + return true; + }; + glow = this.challenge.isDeployed(); + break; + } + case ICON: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.icon"); + description = Collections.singletonList(this.user.getTranslation( + "challenges.gui.descriptions.admin.icon-challenge")); + icon = this.challenge.getIcon(); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challenge.getIcon().getType().name(), + (player, reply) -> { + Material material = Material.getMaterial(reply); + + if (material != null) + { + this.challenge.setIcon(new ItemStack(material)); + this.build(); + } + else + { + this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); + } + + return reply; + }); + + return true; + }; + glow = false; + break; + } + case DESCRIPTION: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.description"); + description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.description")); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challenge.getDescription(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setDescription(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case ORDER: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.order"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.order")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getOrder()))); + + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getOrder(), -1, 9999, lineLength, (status, value) -> { + if (status) + { + this.challenge.setOrder(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case ENVIRONMENT: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.environment"); + + description = new ArrayList<>(4); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.environment")); + + description.add((this.challenge.getEnvironment().contains(World.Environment.NORMAL) ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.normal")); + description.add((this.challenge.getEnvironment().contains(World.Environment.NETHER) ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.nether")); + description.add((this.challenge.getEnvironment().contains(World.Environment.THE_END) ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.the-end")); + + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + new SelectEnvironmentGUI(this.user, this.challenge.getEnvironment(), (status, value) -> { + if (status) + { + this.challenge.setEnvironment(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REMOVE_ON_COMPLETE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-on-complete"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-on-complete")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isRemoveWhenCompleted() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + if (this.challenge.isRemoveWhenCompleted()) + { + icon = new ItemStack(Material.LAVA_BUCKET); + } + else + { + icon = new ItemStack(Material.BUCKET); + } + + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRemoveWhenCompleted(!this.challenge.isRemoveWhenCompleted()); + this.build(); + + return true; + }; + glow = this.challenge.isRemoveWhenCompleted(); + break; + } + case NAME: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.name"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.name-challenge")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", this.challenge.getFriendlyName())); + + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challenge.getFriendlyName(), + (player, reply) -> { + this.challenge.setFriendlyName(reply); + this.build(); + return reply; + }); + + return true; + }; + glow = false; + break; + } + + case REQUIRED_ENTITIES: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-entities"); + + description = new ArrayList<>(this.challenge.getRequiredEntities().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-entities")); + + for (Map.Entry entry : this.challenge.getRequiredEntities().entrySet()) + { + description.add(this.user.getTranslation("challenges.gui.descriptions.entity", + "[entity]", entry.getKey().name(), + "[count]", Integer.toString(entry.getValue()))); + } + + icon = new ItemStack(Material.CREEPER_HEAD); + clickHandler = (panel, user, clickType, slot) -> { + new ManageEntitiesGUI(this.addon, + this.world, + this.user, + this.challenge.getRequiredEntities(), + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_ENTITIES: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-entities"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-entities")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isRemoveEntities() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRemoveEntities(!this.challenge.isRemoveEntities()); + + this.build(); + return true; + }; + glow = this.challenge.isRemoveEntities(); + break; + } + case REQUIRED_BLOCKS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-blocks"); + + description = new ArrayList<>(this.challenge.getRequiredBlocks().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-blocks")); + + for (Map.Entry entry : this.challenge.getRequiredBlocks().entrySet()) + { + description.add(this.user.getTranslation("challenges.gui.descriptions.block", + "[block]", entry.getKey().name(), + "[count]", Integer.toString(entry.getValue()))); + } + + icon = new ItemStack(Material.STONE); + clickHandler = (panel, user, clickType, slot) -> { + new ManageBlocksGUI(this.addon, + this.world, + this.user, + this.challenge.getRequiredBlocks(), + this.topLabel, + this.permissionPrefix, + this).build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_BLOCKS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-blocks"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-blocks")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isRemoveBlocks() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRemoveBlocks(!this.challenge.isRemoveBlocks()); + + this.build(); + return true; + }; + glow = this.challenge.isRemoveBlocks(); + break; + } + case SEARCH_RADIUS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.search-radius"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.search-radius")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getSearchRadius()))); + + icon = new ItemStack(Material.COBBLESTONE_WALL); + + // Search radius should not be larger then island radius. + int maxSearchDistance = + this.addon.getPlugin().getIWM().getAddon(this.world).map(gameModeAddon -> + gameModeAddon.getWorldSettings().getIslandDistance()).orElse(100); + + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getSearchRadius(), 0, maxSearchDistance, lineLength, (status, value) -> { + if (status) + { + this.challenge.setSearchRadius(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REQUIRED_PERMISSIONS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-permissions"); + description = new ArrayList<>(this.challenge.getRequiredPermissions().size() + 1); + description.add(this.user.getTranslation( + "challenges.gui.descriptions.admin.required-permissions")); + + for (String permission : this.challenge.getRequiredPermissions()) + { + description.add(this.user.getTranslation("challenges.gui.descriptions.permission", + "[permission]", permission)); + } + + icon = new ItemStack(Material.REDSTONE_LAMP); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challenge.getRequiredPermissions(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRequiredPermissions(new HashSet<>(value)); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REQUIRED_ITEMS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-items"); + + description = new ArrayList<>(this.challenge.getRequiredItems().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-items")); + + Utils.groupEqualItems(this.challenge.getRequiredItems()).forEach(itemStack -> + description.addAll(this.generateItemStackDescription(itemStack))); + + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + new ItemSwitchGUI(this.user, this.challenge.getRequiredItems(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRequiredItems(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REMOVE_ITEMS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-items"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-items")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isTakeItems() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeItems(!this.challenge.isTakeItems()); + + this.build(); + return true; + }; + glow = this.challenge.isTakeItems(); + break; + } + case REQUIRED_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-experience"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-experience")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getRequiredExperience()))); + + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRequiredExperience(), 0, lineLength, (status, value) -> { + if (status) + { + this.challenge.setRequiredExperience(value); + } + + this.build(); + }); + return true; + }; + glow = false; + break; + } + case REMOVE_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-experience"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-experience")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isTakeExperience() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeExperience(!this.challenge.isTakeExperience()); + + this.build(); + return true; + }; + glow = this.challenge.isTakeExperience(); + break; + } + case REQUIRED_LEVEL: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-level"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-level")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Long.toString(this.challenge.getRequiredIslandLevel()))); + + icon = new ItemStack(this.addon.isLevelProvided() ? Material.BEACON : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRequiredIslandLevel(value); + } + + this.build(); + }); + + return true; + }; + + glow = false; + break; + } + case REQUIRED_MONEY: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.required-money"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.required-money")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Long.toString(this.challenge.getRequiredMoney()))); + + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, lineLength, (status, value) -> { + if (status) + { + this.challenge.setRequiredMoney(value); + } + + this.build(); + }); + return true; + }; + + glow = false; + break; + } + case REMOVE_MONEY: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-money"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-money")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isTakeMoney() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.LEVER : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); + + this.build(); + return true; + }; + + glow = this.challenge.isTakeMoney(); + break; + } + + case REWARD_TEXT: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-text"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-text")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", "|" + this.challenge.getRewardText())); + + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challenge.getRewardText(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining())); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REWARD_ITEM: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-items"); + + description = new ArrayList<>(this.challenge.getRewardItems().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-items")); + + Utils.groupEqualItems(this.challenge.getRewardItems()).forEach(itemStack -> + description.addAll(this.generateItemStackDescription(itemStack))); + + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + new ItemSwitchGUI(this.user, this.challenge.getRewardItems(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRewardItems(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REWARD_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-experience"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-experience")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getRewardExperience()))); + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRewardExperience(), 0, lineLength, (status, value) -> { + if (status) + { + this.challenge.setRewardExperience(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REWARD_MONEY: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-money"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-money")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getRewardMoney()))); + + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, lineLength, (status, value) -> { + if (status) + { + this.challenge.setRewardMoney(value); + } + + this.build(); + }); + + return true; + }; + + + glow = false; + break; + } + case REWARD_COMMANDS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-commands"); + description = new ArrayList<>(this.challenge.getRewardCommands().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-commands")); + + for (String command : this.challenge.getRewardCommands()) + { + description.add(this.user.getTranslation("challenges.gui.descriptions.command", + "[command]", command)); + } + + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challenge.getRewardCommands(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRewardCommands(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + + case REPEATABLE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeatable"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeatable")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.challenge.isRepeatable() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRepeatable(!this.challenge.isRepeatable()); + + this.build(); + return true; + }; + glow = this.challenge.isRepeatable(); + break; + } + case REPEAT_COUNT: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-count"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-count")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getMaxTimes()))); + + icon = new ItemStack(Material.COBBLESTONE_WALL); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getMaxTimes(), 0, lineLength, (status, value) -> { + if (status) + { + this.challenge.setMaxTimes(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + + case REPEAT_REWARD_TEXT: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-text"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-text")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", "|" + this.challenge.getRepeatRewardText())); + + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challenge.getRepeatRewardText(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRepeatRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining())); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_ITEM: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-items"); + + description = new ArrayList<>(this.challenge.getRepeatItemReward().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-items")); + + Utils.groupEqualItems(this.challenge.getRepeatItemReward()).forEach(itemStack -> + description.addAll(this.generateItemStackDescription(itemStack))); + + icon = new ItemStack(Material.TRAPPED_CHEST); + clickHandler = (panel, user, clickType, slot) -> { + new ItemSwitchGUI(this.user, this.challenge.getRepeatItemReward(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRepeatItemReward(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-experience"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-experience")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getRepeatExperienceReward()))); + + icon = new ItemStack(Material.GLASS_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRepeatExperienceReward(), 0, lineLength, (status, value) -> { + if (status) + { + this.challenge.setRepeatExperienceReward(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_MONEY: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-money"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-money")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challenge.getRepeatMoneyReward()))); + + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_NUGGET : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, + this.challenge.getRepeatMoneyReward(), + 0, + lineLength, + (status, value) -> { + if (status) + { + this.challenge.setRepeatMoneyReward(value); + } + + this.build(); + }); + + return true; + }; + + glow = false; + break; + } + case REPEAT_REWARD_COMMANDS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.repeat-reward-commands"); + description = new ArrayList<>(this.challenge.getRepeatRewardCommands().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.repeat-reward-commands")); + + for (String command : this.challenge.getRepeatRewardCommands()) + { + description.add(this.user.getTranslation("challenges.gui.descriptions.command", + "[command]", command)); + } + + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challenge.getRepeatRewardCommands(), lineLength, (status, value) -> { + if (status) + { + this.challenge.setRepeatRewardCommands(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + default: + return null; + } + + return new PanelItemBuilder(). + icon(icon). + name(name). + description(GuiUtils.stringSplit(description, lineLength)). + glow(glow). + clickHandler(clickHandler). + build(); + } + + + /** + * This method returns next challenge type from given. + * @param type Given challenge type. + * @return Next Challenge Type. + */ + private Challenge.ChallengeType getNextType(Challenge.ChallengeType type) + { + Challenge.ChallengeType[] values = Challenge.ChallengeType.values(); + + for (int i = 0; i < values.length; i++) + { + if (values[i].equals(type)) + { + if (i + 1 == values.length) + { + return values[0]; + } + else + { + return values[i + 1]; + } + } + } + + return type; + } + + + /** + * This method returns previous challenge type from given. + * @param type Given challenge type. + * @return Previous Challenge Type. + */ + private Challenge.ChallengeType getPreviousType(Challenge.ChallengeType type) + { + Challenge.ChallengeType[] values = Challenge.ChallengeType.values(); + + for (int i = 0; i < values.length; i++) + { + if (values[i].equals(type)) + { + if (i > 0) + { + return values[i - 1]; + } + else + { + return values[values.length - 1]; + } + } + } + + return type; + } + + + // --------------------------------------------------------------------- + // Section: Enums + // --------------------------------------------------------------------- + + + /** + * Represents different types of menus + */ + private enum MenuType + { + PROPERTIES, + REQUIREMENTS, + REWARDS + } + + + /** + * Represents different buttons that could be in menus. + */ + private enum Button + { + NAME, + TYPE, + DEPLOYED, + ICON, + DESCRIPTION, + ORDER, + ENVIRONMENT, + REMOVE_ON_COMPLETE, + + REQUIRED_ENTITIES, + REMOVE_ENTITIES, + REQUIRED_BLOCKS, + REMOVE_BLOCKS, + SEARCH_RADIUS, + REQUIRED_PERMISSIONS, + REQUIRED_ITEMS, + REMOVE_ITEMS, + REQUIRED_EXPERIENCE, + REMOVE_EXPERIENCE, + REQUIRED_LEVEL, + REQUIRED_MONEY, + REMOVE_MONEY, + + REWARD_TEXT, + REWARD_ITEM, + REWARD_EXPERIENCE, + REWARD_MONEY, + REWARD_COMMANDS, + + REPEATABLE, + REPEAT_COUNT, + + REPEAT_REWARD_TEXT, + REPEAT_REWARD_ITEM, + REPEAT_REWARD_EXPERIENCE, + REPEAT_REWARD_MONEY, + REPEAT_REWARD_COMMANDS, + } + + + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + + /** + * Variable holds challenge thats needs editing. + */ + private Challenge challenge; + + /** + * Variable holds current active menu. + */ + private MenuType currentMenuType; } 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 ac0b71d..2c8df01 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -1,13 +1,17 @@ package world.bentobox.challenges.panel.admin; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemStack; -import java.util.*; -import java.util.stream.Collectors; import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; @@ -29,726 +33,734 @@ import world.bentobox.challenges.utils.Utils; /** * This class contains all necessary elements to create Levels Edit GUI. -*/ + */ public class EditLevelGUI extends CommonGUI { -// --------------------------------------------------------------------- -// Section: Constructors -// --------------------------------------------------------------------- - - - /** - * {@inheritDoc} - * @param challengeLevel ChallengeLevel that must be edited. - */ - public EditLevelGUI(ChallengesAddon addon, - World world, - User user, - ChallengeLevel challengeLevel, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, challengeLevel, topLabel, permissionPrefix, null); - } - - - /** - * {@inheritDoc} - * @param challengeLevel ChallengeLevel that must be edited. - */ - public EditLevelGUI(ChallengesAddon addon, - World world, - User user, - ChallengeLevel challengeLevel, - String topLabel, - String permissionPrefix, - CommonGUI parentGUI) - { - super(addon, world, user, topLabel, permissionPrefix, parentGUI); - this.challengeLevel = challengeLevel; - this.currentMenuType = MenuType.PROPERTIES; - } - - -// --------------------------------------------------------------------- -// Section: Methods -// --------------------------------------------------------------------- - - - /** - * This method builds all necessary elements in GUI panel. - */ - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.edit-level-title")); - - GuiUtils.fillBorder(panelBuilder); - - panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); - panelBuilder.item(4, this.createMenuButton(MenuType.REWARDS)); - panelBuilder.item(6, this.createMenuButton(MenuType.CHALLENGES)); - - if (this.currentMenuType.equals(MenuType.PROPERTIES)) - { - this.buildMainPropertiesPanel(panelBuilder); - } - else if (this.currentMenuType.equals(MenuType.CHALLENGES)) - { - this.buildChallengesPanel(panelBuilder); - } - else if (this.currentMenuType.equals(MenuType.REWARDS)) - { - this.buildRewardsPanel(panelBuilder); - } - - panelBuilder.item(44, this.returnButton); - - // Save challenge level every time this gui is build. - // It will ensure that changes are stored in database. - this.addon.getChallengesManager().saveLevel(this.challengeLevel); - - panelBuilder.build(); - } - - - /** - * This class populate LevelsEditGUI with main level settings. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildMainPropertiesPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(10, this.createButton(Button.NAME)); - - panelBuilder.item(19, this.createButton(Button.ICON)); - panelBuilder.item(28, this.createButton(Button.CLOSED_ICON)); - panelBuilder.item(22, this.createButton(Button.UNLOCK_MESSAGE)); - panelBuilder.item(25, this.createButton(Button.ORDER)); - - panelBuilder.item(31, this.createButton(Button.WAIVER_AMOUNT)); - } - - - /** - * This class populate LevelsEditGUI with level rewards. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildRewardsPanel(PanelBuilder panelBuilder) - { - panelBuilder.item(12, this.createButton(Button.REWARD_DESCRIPTION)); - panelBuilder.item(21, this.createButton(Button.REWARD_COMMANDS)); - - panelBuilder.item(13, this.createButton(Button.REWARD_ITEM)); - panelBuilder.item(22, this.createButton(Button.REWARD_EXPERIENCE)); - panelBuilder.item(31, this.createButton(Button.REWARD_MONEY)); - } - - - /** - * This class populate LevelsEditGUI with level challenges. - * @param panelBuilder PanelBuilder where icons must be added. - */ - private void buildChallengesPanel(PanelBuilder panelBuilder) - { - List challengeList = this.addon.getChallengesManager().getLevelChallenges(this.challengeLevel); - - final int MAX_ELEMENTS = 21; - - if (this.pageIndex < 0) - { - this.pageIndex = challengeList.size() / MAX_ELEMENTS; - } - else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) - { - this.pageIndex = 0; - } - - int challengeIndex = MAX_ELEMENTS * this.pageIndex; - - // I want first row to be only for navigation and return button. - int index = 10; - - while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - challengeIndex < challengeList.size() && - index < 36) - { - if (!panelBuilder.slotOccupied(index)) - { - panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++))); - } - - index++; - } - - // Navigation buttons only if necessary - if (challengeList.size() > MAX_ELEMENTS) - { - panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); - panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); - } - - panelBuilder.item(39, this.createButton(Button.ADD_CHALLENGE)); - panelBuilder.item(41, this.createButton(Button.REMOVE_CHALLENGE)); - } - - -// --------------------------------------------------------------------- -// Section: Other methods -// --------------------------------------------------------------------- - - - /** - * This method creates top menu buttons, that allows to switch "tabs". - * @param menuType Menu Type which button must be constructed. - * @return PanelItem that represents given menu type. - */ - private PanelItem createMenuButton(MenuType menuType) - { - ItemStack icon; - String name; - String description; - boolean glow; - PanelItem.ClickHandler clickHandler; - - switch (menuType) - { - case PROPERTIES: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.properties"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.properties"); - icon = new ItemStack(Material.CRAFTING_TABLE); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.PROPERTIES; - this.build(); - - return true; - }; - glow = this.currentMenuType.equals(MenuType.PROPERTIES); - break; - } - case CHALLENGES: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.challenges"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.challenges"); - icon = new ItemStack(Material.RAIL); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.CHALLENGES; - this.build(); - - return true; - }; - glow = this.currentMenuType.equals(MenuType.CHALLENGES); - break; - } - case REWARDS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.rewards"); - description = this.user.getTranslation("challenges.gui.descriptions.admin.rewards"); - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.REWARDS; - this.build(); - - return true; - }; - glow = this.currentMenuType.equals(MenuType.REWARDS); - break; - } - default: - return null; - } - - return new PanelItemBuilder(). - icon(icon). - name(name). - description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). - glow(glow). - clickHandler(clickHandler). - build(); - } - - - /** - * This method creates given challenge icon. On click it should open Edit Challenge GUI. - * @param challenge Challenge which icon must be created. - * @return PanelItem that represents given challenge. - */ - private PanelItem createChallengeIcon(Challenge challenge) - { - return new PanelItemBuilder(). - name(ChatColor.translateAlternateColorCodes('&', challenge.getFriendlyName())). - description(GuiUtils.stringSplit( - challenge.getDescription(), - this.addon.getChallengesSettings().getLoreLineLength())). - icon(challenge.getIcon()). - clickHandler((panel, user1, clickType, slot) -> { - // Open challenges edit screen. - new EditChallengeGUI(this.addon, - this.world, - this.user, - challenge, - this.topLabel, - this.permissionPrefix, - this).build(); - return true; - }). - glow(!challenge.isDeployed()). - build(); - - } - - - /** - * This method creates buttons for default main menu. - * @param button Button which panel item must be created. - * @return PanelItem that represents given button. - */ - private PanelItem createButton(Button button) - { - ItemStack icon; - String name; - List description; - boolean glow; - PanelItem.ClickHandler clickHandler; - - final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); - - switch (button) - { - case NAME: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.name"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.name-level")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", this.challengeLevel.getFriendlyName())); - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.challengeLevel.getFriendlyName(), - (player, reply) -> { - this.challengeLevel.setFriendlyName(reply); - this.build(); - return reply; - }); - - return true; - }; - glow = false; - break; - } - case ICON: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.icon"); - description = Collections.singletonList(this.user.getTranslation( - "challenges.gui.descriptions.admin.icon-level")); - icon = this.challengeLevel.getIcon(); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.challengeLevel.getIcon().getType().name(), - (player, reply) -> { - Material material = Material.getMaterial(reply); - - if (material != null) - { - this.challengeLevel.setIcon(new ItemStack(material)); - this.build(); - } - else - { - this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); - } - - return reply; - }); - - return true; - }; - glow = false; - break; - } - case CLOSED_ICON: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.locked-icon"); - description = Collections.singletonList(this.user.getTranslation( - "challenges.gui.descriptions.admin.locked-icon")); - - boolean isNull = this.challengeLevel.getLockedIcon() == null; - - if (isNull) - { - icon = new ItemStack(Material.BARRIER); - } - else - { - icon = this.challengeLevel.getLockedIcon().clone(); - } - - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - isNull ? "NULL" : icon.getType().name(), - (player, reply) -> { - if (reply.equals("NULL")) - { - this.challengeLevel.setLockedIcon(null); - this.build(); - return reply; - } - - Material material = Material.getMaterial(reply); - - if (material != null) - { - this.challengeLevel.setLockedIcon(new ItemStack(material)); - this.build(); - } - else - { - this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); - } - - return reply; - }); - - return true; - }; - glow = false; - break; - } - case UNLOCK_MESSAGE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.description"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.description")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", "|" + this.challengeLevel.getUnlockMessage())); - icon = new ItemStack(Material.WRITABLE_BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challengeLevel.getUnlockMessage(), lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setUnlockMessage(value.stream().map(s -> s + "|").collect(Collectors.joining())); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case ORDER: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.order"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.order")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challengeLevel.getOrder()))); - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getOrder(), -1, 54, lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setOrder(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case WAIVER_AMOUNT: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.waiver-amount"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.waiver-amount")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challengeLevel.getWaiverAmount()))); - - icon = new ItemStack(Material.REDSTONE_TORCH); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getWaiverAmount(), 0, lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setWaiverAmount(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - - case REWARD_DESCRIPTION: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-text"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-text-level")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", "|" + this.challengeLevel.getRewardText())); - icon = new ItemStack(Material.WRITTEN_BOOK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challengeLevel.getRewardText(), lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining())); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REWARD_ITEM: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-items"); - - description = new ArrayList<>(this.challengeLevel.getRewardItems().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-items")); - - Utils.groupEqualItems(this.challengeLevel.getRewardItems()).forEach(itemStack -> - description.addAll(this.generateItemStackDescription(itemStack))); - - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, slot) -> { - new ItemSwitchGUI(this.user, this.challengeLevel.getRewardItems(), lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardItems(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REWARD_EXPERIENCE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-experience"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-experience")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challengeLevel.getRewardExperience()))); - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getRewardExperience(), 0, lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardExperience(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REWARD_MONEY: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-money"); - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-money")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.challengeLevel.getRewardMoney()))); - - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardMoney(value); - } - - this.build(); - }); - - return true; - }; - - glow = false; - break; - } - case REWARD_COMMANDS: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.reward-commands"); - description = new ArrayList<>(this.challengeLevel.getRewardCommands().size() + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-commands")); - - for (String command : this.challengeLevel.getRewardCommands()) - { - description.add(this.user.getTranslation("challenges.gui.descriptions.command", - "[command]", command)); - } - - icon = new ItemStack(Material.COMMAND_BLOCK); - clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challengeLevel.getRewardCommands(), lineLength, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardCommands(value); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - - case ADD_CHALLENGE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.add-challenge"); - description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.add-challenge")); - icon = new ItemStack(Material.WATER_BUCKET); - clickHandler = (panel, user, clickType, slot) -> { - ChallengesManager manager = this.addon.getChallengesManager(); - - // Get all challenge that is not in current level. - List challengeList = manager.getAllChallenges(this.world); - challengeList.removeAll(manager.getLevelChallenges(this.challengeLevel)); - - // Generate descriptions for these challenges - Map> challengeDescriptionMap = challengeList.stream(). - collect(Collectors.toMap(challenge -> challenge, - challenge -> this.generateChallengeDescription(challenge, this.user.getPlayer()), - (a, b) -> b, - () -> new LinkedHashMap<>(challengeList.size()))); - - // Open select gui - new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { - if (status) - { - valueSet.forEach(challenge -> manager.addChallengeToLevel(challenge, this.challengeLevel)); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - case REMOVE_CHALLENGE: - { - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-challenge"); - description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.remove-challenge")); - icon = new ItemStack(Material.LAVA_BUCKET); - clickHandler = (panel, user, clickType, slot) -> { - ChallengesManager manager = this.addon.getChallengesManager(); - - // Get all challenge that is in current level. - List challengeList = manager.getLevelChallenges(this.challengeLevel); - - // Generate descriptions for these challenges - Map> challengeDescriptionMap = challengeList.stream(). - collect(Collectors.toMap(challenge -> challenge, - challenge -> this.generateChallengeDescription(challenge, this.user.getPlayer()), - (a, b) -> b, - () -> new LinkedHashMap<>(challengeList.size()))); - - // Open select gui - new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { - if (status) - { - valueSet.forEach(challenge -> manager.removeChallengeFromLevel(challenge, this.challengeLevel)); - } - - this.build(); - }); - - return true; - }; - glow = false; - break; - } - default: - return null; - } - - - - return new PanelItemBuilder(). - icon(icon). - name(name). - description(GuiUtils.stringSplit(description, lineLength)). - glow(glow). - clickHandler(clickHandler). - build(); - } - - -// --------------------------------------------------------------------- -// Section: Enums -// --------------------------------------------------------------------- - - - /** - * Represents different buttons that could be in menus. - */ - private enum Button - { - NAME, - ICON, - CLOSED_ICON, - UNLOCK_MESSAGE, - ORDER, - WAIVER_AMOUNT, - - REWARD_DESCRIPTION, - REWARD_ITEM, - REWARD_EXPERIENCE, - REWARD_MONEY, - REWARD_COMMANDS, - - ADD_CHALLENGE, - REMOVE_CHALLENGE - } - - - /** - * Represents different types of menus - */ - private enum MenuType - { - PROPERTIES, - CHALLENGES, - REWARDS - } - - -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - /** - * This variable holds current challenge level that is in editing GUI. - */ - private ChallengeLevel challengeLevel; - - /** - * Variable holds current active menu. - */ - private MenuType currentMenuType; + // --------------------------------------------------------------------- + // Section: Constructors + // --------------------------------------------------------------------- + + + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param challengeLevel ChallengeLevel that must be edited. + */ + public EditLevelGUI(ChallengesAddon addon, + World world, + User user, + ChallengeLevel challengeLevel, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, challengeLevel, topLabel, permissionPrefix, null); + } + + + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param challengeLevel ChallengeLevel that must be edited. + */ + public EditLevelGUI(ChallengesAddon addon, + World world, + User user, + ChallengeLevel challengeLevel, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.challengeLevel = challengeLevel; + this.currentMenuType = MenuType.PROPERTIES; + } + + + // --------------------------------------------------------------------- + // Section: Methods + // --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.edit-level-title")); + + GuiUtils.fillBorder(panelBuilder); + + panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); + panelBuilder.item(4, this.createMenuButton(MenuType.REWARDS)); + panelBuilder.item(6, this.createMenuButton(MenuType.CHALLENGES)); + + if (this.currentMenuType.equals(MenuType.PROPERTIES)) + { + this.buildMainPropertiesPanel(panelBuilder); + } + else if (this.currentMenuType.equals(MenuType.CHALLENGES)) + { + this.buildChallengesPanel(panelBuilder); + } + else if (this.currentMenuType.equals(MenuType.REWARDS)) + { + this.buildRewardsPanel(panelBuilder); + } + + panelBuilder.item(44, this.returnButton); + + // Save challenge level every time this gui is build. + // It will ensure that changes are stored in database. + this.addon.getChallengesManager().saveLevel(this.challengeLevel); + + panelBuilder.build(); + } + + + /** + * This class populate LevelsEditGUI with main level settings. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildMainPropertiesPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.NAME)); + + panelBuilder.item(19, this.createButton(Button.ICON)); + panelBuilder.item(28, this.createButton(Button.CLOSED_ICON)); + panelBuilder.item(22, this.createButton(Button.UNLOCK_MESSAGE)); + panelBuilder.item(25, this.createButton(Button.ORDER)); + + panelBuilder.item(31, this.createButton(Button.WAIVER_AMOUNT)); + } + + + /** + * This class populate LevelsEditGUI with level rewards. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildRewardsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(12, this.createButton(Button.REWARD_DESCRIPTION)); + panelBuilder.item(21, this.createButton(Button.REWARD_COMMANDS)); + + panelBuilder.item(13, this.createButton(Button.REWARD_ITEM)); + panelBuilder.item(22, this.createButton(Button.REWARD_EXPERIENCE)); + panelBuilder.item(31, this.createButton(Button.REWARD_MONEY)); + } + + + /** + * This class populate LevelsEditGUI with level challenges. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildChallengesPanel(PanelBuilder panelBuilder) + { + List challengeList = this.addon.getChallengesManager().getLevelChallenges(this.challengeLevel); + + final int MAX_ELEMENTS = 21; + + if (this.pageIndex < 0) + { + this.pageIndex = challengeList.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) + { + this.pageIndex = 0; + } + + int challengeIndex = MAX_ELEMENTS * this.pageIndex; + + // I want first row to be only for navigation and return button. + int index = 10; + + while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + challengeIndex < challengeList.size() && + index < 36) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++))); + } + + index++; + } + + // Navigation buttons only if necessary + if (challengeList.size() > MAX_ELEMENTS) + { + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); + } + + panelBuilder.item(39, this.createButton(Button.ADD_CHALLENGE)); + panelBuilder.item(41, this.createButton(Button.REMOVE_CHALLENGE)); + } + + + // --------------------------------------------------------------------- + // Section: Other methods + // --------------------------------------------------------------------- + + + /** + * This method creates top menu buttons, that allows to switch "tabs". + * @param menuType Menu Type which button must be constructed. + * @return PanelItem that represents given menu type. + */ + private PanelItem createMenuButton(MenuType menuType) + { + ItemStack icon; + String name; + String description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + switch (menuType) + { + case PROPERTIES: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.properties"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.properties"); + icon = new ItemStack(Material.CRAFTING_TABLE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.PROPERTIES; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.PROPERTIES); + break; + } + case CHALLENGES: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.challenges"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.challenges"); + icon = new ItemStack(Material.RAIL); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.CHALLENGES; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.CHALLENGES); + break; + } + case REWARDS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.rewards"); + description = this.user.getTranslation("challenges.gui.descriptions.admin.rewards"); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.REWARDS; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.REWARDS); + break; + } + default: + return null; + } + + return new PanelItemBuilder(). + icon(icon). + name(name). + description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). + glow(glow). + clickHandler(clickHandler). + build(); + } + + + /** + * This method creates given challenge icon. On click it should open Edit Challenge GUI. + * @param challenge Challenge which icon must be created. + * @return PanelItem that represents given challenge. + */ + private PanelItem createChallengeIcon(Challenge challenge) + { + return new PanelItemBuilder(). + name(ChatColor.translateAlternateColorCodes('&', challenge.getFriendlyName())). + description(GuiUtils.stringSplit( + challenge.getDescription(), + this.addon.getChallengesSettings().getLoreLineLength())). + icon(challenge.getIcon()). + clickHandler((panel, user1, clickType, slot) -> { + // Open challenges edit screen. + new EditChallengeGUI(this.addon, + this.world, + this.user, + challenge, + this.topLabel, + this.permissionPrefix, + this).build(); + return true; + }). + glow(!challenge.isDeployed()). + build(); + + } + + + /** + * This method creates buttons for default main menu. + * @param button Button which panel item must be created. + * @return PanelItem that represents given button. + */ + private PanelItem createButton(Button button) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + final int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); + + switch (button) + { + case NAME: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.name"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.name-level")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", this.challengeLevel.getFriendlyName())); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challengeLevel.getFriendlyName(), + (player, reply) -> { + this.challengeLevel.setFriendlyName(reply); + this.build(); + return reply; + }); + + return true; + }; + glow = false; + break; + } + case ICON: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.icon"); + description = Collections.singletonList(this.user.getTranslation( + "challenges.gui.descriptions.admin.icon-level")); + icon = this.challengeLevel.getIcon(); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challengeLevel.getIcon().getType().name(), + (player, reply) -> { + Material material = Material.getMaterial(reply); + + if (material != null) + { + this.challengeLevel.setIcon(new ItemStack(material)); + this.build(); + } + else + { + this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); + } + + return reply; + }); + + return true; + }; + glow = false; + break; + } + case CLOSED_ICON: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.locked-icon"); + description = Collections.singletonList(this.user.getTranslation( + "challenges.gui.descriptions.admin.locked-icon")); + + boolean isNull = this.challengeLevel.getLockedIcon() == null; + + if (isNull) + { + icon = new ItemStack(Material.BARRIER); + } + else + { + icon = this.challengeLevel.getLockedIcon().clone(); + } + + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + isNull ? "NULL" : icon.getType().name(), + (player, reply) -> { + if (reply.equals("NULL")) + { + this.challengeLevel.setLockedIcon(null); + this.build(); + return reply; + } + + Material material = Material.getMaterial(reply); + + if (material != null) + { + this.challengeLevel.setLockedIcon(new ItemStack(material)); + this.build(); + } + else + { + this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); + } + + return reply; + }); + + return true; + }; + glow = false; + break; + } + case UNLOCK_MESSAGE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.description"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.description")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", "|" + this.challengeLevel.getUnlockMessage())); + icon = new ItemStack(Material.WRITABLE_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challengeLevel.getUnlockMessage(), lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setUnlockMessage(value.stream().map(s -> s + "|").collect(Collectors.joining())); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case ORDER: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.order"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.order")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challengeLevel.getOrder()))); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challengeLevel.getOrder(), -1, 54, lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setOrder(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case WAIVER_AMOUNT: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.waiver-amount"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.waiver-amount")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challengeLevel.getWaiverAmount()))); + + icon = new ItemStack(Material.REDSTONE_TORCH); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challengeLevel.getWaiverAmount(), 0, lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setWaiverAmount(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + + case REWARD_DESCRIPTION: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-text"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-text-level")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", "|" + this.challengeLevel.getRewardText())); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challengeLevel.getRewardText(), lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardText(value.stream().map(s -> s + "|").collect(Collectors.joining())); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REWARD_ITEM: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-items"); + + description = new ArrayList<>(this.challengeLevel.getRewardItems().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-items")); + + Utils.groupEqualItems(this.challengeLevel.getRewardItems()).forEach(itemStack -> + description.addAll(this.generateItemStackDescription(itemStack))); + + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + new ItemSwitchGUI(this.user, this.challengeLevel.getRewardItems(), lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardItems(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REWARD_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-experience"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-experience")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challengeLevel.getRewardExperience()))); + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challengeLevel.getRewardExperience(), 0, lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardExperience(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REWARD_MONEY: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-money"); + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-money")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.challengeLevel.getRewardMoney()))); + + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardMoney(value); + } + + this.build(); + }); + + return true; + }; + + glow = false; + break; + } + case REWARD_COMMANDS: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.reward-commands"); + description = new ArrayList<>(this.challengeLevel.getRewardCommands().size() + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reward-commands")); + + for (String command : this.challengeLevel.getRewardCommands()) + { + description.add(this.user.getTranslation("challenges.gui.descriptions.command", + "[command]", command)); + } + + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + new StringListGUI(this.user, this.challengeLevel.getRewardCommands(), lineLength, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardCommands(value); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + + case ADD_CHALLENGE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.add-challenge"); + description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.add-challenge")); + icon = new ItemStack(Material.WATER_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + ChallengesManager manager = this.addon.getChallengesManager(); + + // Get all challenge that is not in current level. + List challengeList = manager.getAllChallenges(this.world); + challengeList.removeAll(manager.getLevelChallenges(this.challengeLevel)); + + // Generate descriptions for these challenges + Map> challengeDescriptionMap = challengeList.stream(). + collect(Collectors.toMap(challenge -> challenge, + challenge -> this.generateChallengeDescription(challenge, this.user.getPlayer()), + (a, b) -> b, + () -> new LinkedHashMap<>(challengeList.size()))); + + // Open select gui + new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { + if (status) + { + valueSet.forEach(challenge -> manager.addChallengeToLevel(challenge, this.challengeLevel)); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + case REMOVE_CHALLENGE: + { + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-challenge"); + description = Collections.singletonList(this.user.getTranslation("challenges.gui.descriptions.admin.remove-challenge")); + icon = new ItemStack(Material.LAVA_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + ChallengesManager manager = this.addon.getChallengesManager(); + + // Get all challenge that is in current level. + List challengeList = manager.getLevelChallenges(this.challengeLevel); + + // Generate descriptions for these challenges + Map> challengeDescriptionMap = challengeList.stream(). + collect(Collectors.toMap(challenge -> challenge, + challenge -> this.generateChallengeDescription(challenge, this.user.getPlayer()), + (a, b) -> b, + () -> new LinkedHashMap<>(challengeList.size()))); + + // Open select gui + new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { + if (status) + { + valueSet.forEach(challenge -> manager.removeChallengeFromLevel(challenge, this.challengeLevel)); + } + + this.build(); + }); + + return true; + }; + glow = false; + break; + } + default: + return null; + } + + + + return new PanelItemBuilder(). + icon(icon). + name(name). + description(GuiUtils.stringSplit(description, lineLength)). + glow(glow). + clickHandler(clickHandler). + build(); + } + + + // --------------------------------------------------------------------- + // Section: Enums + // --------------------------------------------------------------------- + + + /** + * Represents different buttons that could be in menus. + */ + private enum Button + { + NAME, + ICON, + CLOSED_ICON, + UNLOCK_MESSAGE, + ORDER, + WAIVER_AMOUNT, + + REWARD_DESCRIPTION, + REWARD_ITEM, + REWARD_EXPERIENCE, + REWARD_MONEY, + REWARD_COMMANDS, + + ADD_CHALLENGE, + REMOVE_CHALLENGE + } + + + /** + * Represents different types of menus + */ + private enum MenuType + { + PROPERTIES, + CHALLENGES, + REWARDS + } + + + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + /** + * This variable holds current challenge level that is in editing GUI. + */ + private ChallengeLevel challengeLevel; + + /** + * Variable holds current active menu. + */ + private MenuType currentMenuType; } \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java index e4c46a7..7ddbd3f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java @@ -1,13 +1,13 @@ package world.bentobox.challenges.panel.admin; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.List; - import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -26,529 +26,538 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class EditSettingsGUI extends CommonGUI { -// --------------------------------------------------------------------- -// Section: Constructors -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Constructors + // --------------------------------------------------------------------- - /** - * {@inheritDoc} - */ - public EditSettingsGUI(ChallengesAddon addon, - World world, - User user, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, topLabel, permissionPrefix, null); - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + */ + public EditSettingsGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, topLabel, permissionPrefix, null); + } - /** - * {@inheritDoc} - */ - public EditSettingsGUI(ChallengesAddon addon, - World world, - User user, - String topLabel, - String permissionPrefix, - CommonGUI parentGUI) - { - super(addon, world, user, topLabel, permissionPrefix, parentGUI); - this.settings = this.addon.getChallengesSettings(); - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + */ + public EditSettingsGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.settings = this.addon.getChallengesSettings(); + } -// --------------------------------------------------------------------- -// Section: Methods -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Methods + // --------------------------------------------------------------------- - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.settings-title")); + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.settings-title")); - GuiUtils.fillBorder(panelBuilder); + GuiUtils.fillBorder(panelBuilder); - panelBuilder.item(10, this.getSettingsButton(Button.ENABLE_TITLE)); + panelBuilder.item(10, this.getSettingsButton(Button.ENABLE_TITLE)); - if (this.settings.isShowCompletionTitle()) - { - panelBuilder.item(19, this.getSettingsButton(Button.TITLE_SHOWTIME)); - } + if (this.settings.isShowCompletionTitle()) + { + panelBuilder.item(19, this.getSettingsButton(Button.TITLE_SHOWTIME)); + } - panelBuilder.item(28, this.getSettingsButton(Button.BROADCAST)); + panelBuilder.item(28, this.getSettingsButton(Button.BROADCAST)); - panelBuilder.item(20, this.getSettingsButton(Button.GLOW_COMPLETED)); - panelBuilder.item(29, this.getSettingsButton(Button.REMOVE_COMPLETED)); + panelBuilder.item(20, this.getSettingsButton(Button.GLOW_COMPLETED)); + panelBuilder.item(29, this.getSettingsButton(Button.REMOVE_COMPLETED)); - panelBuilder.item(21, this.getSettingsButton(Button.LOCKED_LEVEL_ICON)); - panelBuilder.item(30, this.getSettingsButton(Button.FREE_AT_TOP)); + panelBuilder.item(21, this.getSettingsButton(Button.LOCKED_LEVEL_ICON)); + panelBuilder.item(30, this.getSettingsButton(Button.FREE_AT_TOP)); - panelBuilder.item(22, this.getSettingsButton(Button.GAMEMODE_GUI)); + panelBuilder.item(22, this.getSettingsButton(Button.GAMEMODE_GUI)); - if (this.settings.isUseCommonGUI()) - { - // This should be active only when single gui is enabled. - panelBuilder.item(31, this.getSettingsButton(Button.GAMEMODE_GUI_VIEW_MODE)); - } + if (this.settings.isUseCommonGUI()) + { + // This should be active only when single gui is enabled. + panelBuilder.item(31, this.getSettingsButton(Button.GAMEMODE_GUI_VIEW_MODE)); + } - panelBuilder.item(14, this.getSettingsButton(Button.LORE_LENGTH)); - panelBuilder.item(23, this.getSettingsButton(Button.CHALLENGE_LORE)); - panelBuilder.item(32, this.getSettingsButton(Button.LEVEL_LORE)); + panelBuilder.item(14, this.getSettingsButton(Button.LORE_LENGTH)); + panelBuilder.item(23, this.getSettingsButton(Button.CHALLENGE_LORE)); + panelBuilder.item(32, this.getSettingsButton(Button.LEVEL_LORE)); - panelBuilder.item(24, this.getSettingsButton(Button.HISTORY)); + panelBuilder.item(24, this.getSettingsButton(Button.HISTORY)); - if (this.settings.isStoreHistory()) - { - panelBuilder.item(33, this.getSettingsButton(Button.PURGE_HISTORY)); - } + if (this.settings.isStoreHistory()) + { + panelBuilder.item(33, this.getSettingsButton(Button.PURGE_HISTORY)); + } - panelBuilder.item(25, this.getSettingsButton(Button.RESET_CHALLENGES)); - panelBuilder.item(34, this.getSettingsButton(Button.STORE_MODE)); + panelBuilder.item(25, this.getSettingsButton(Button.RESET_CHALLENGES)); + panelBuilder.item(34, this.getSettingsButton(Button.STORE_MODE)); - // Return Button - panelBuilder.item(44, this.returnButton); + // Return Button + panelBuilder.item(44, this.returnButton); - panelBuilder.build(); - } + panelBuilder.build(); + } - private PanelItem getSettingsButton(Button button) - { - ItemStack icon; - String name; - List description; - boolean glow; - PanelItem.ClickHandler clickHandler; + @SuppressWarnings("deprecation") + private PanelItem getSettingsButton(Button button) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; - switch (button) - { - case RESET_CHALLENGES: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reset-on-new")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isResetChallenges() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.reset-on-new"); - icon = new ItemStack(Material.LAVA_BUCKET); + switch (button) + { + case RESET_CHALLENGES: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.reset-on-new")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isResetChallenges() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.reset-on-new"); + icon = new ItemStack(Material.LAVA_BUCKET); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setResetChallenges( - !this.settings.isResetChallenges()); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setResetChallenges( + !this.settings.isResetChallenges()); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; - glow = this.settings.isResetChallenges(); - break; - } - case BROADCAST: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.broadcast")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isBroadcastMessages() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - description = new ArrayList<>(2); + glow = this.settings.isResetChallenges(); + break; + } + case BROADCAST: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.broadcast")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isBroadcastMessages() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.broadcast"); - icon = new ItemStack(Material.JUKEBOX); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setBroadcastMessages( - !this.settings.isBroadcastMessages()); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; - glow = this.settings.isBroadcastMessages(); - - break; - } - case REMOVE_COMPLETED: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-completed")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isRemoveCompleteOneTimeChallenges() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - - name = this.user.getTranslation("challenges.gui.buttons.admin.remove-completed"); - icon = new ItemStack(Material.MAGMA_BLOCK); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setRemoveCompleteOneTimeChallenges( - !this.settings.isRemoveCompleteOneTimeChallenges()); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; - glow = this.settings.isRemoveCompleteOneTimeChallenges(); + description = new ArrayList<>(2); - break; - } - case LORE_LENGTH: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.line-length")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.settings.getLoreLineLength()))); - name = this.user.getTranslation("challenges.gui.buttons.admin.line-length"); - icon = new ItemStack(Material.ANVIL); - clickHandler = (panel, user1, clickType, i) -> { - new NumberGUI(this.user, - this.settings.getLoreLineLength(), - 0, - this.settings.getLoreLineLength(), - (status, value) -> { - if (status) - { - this.settings.setLoreLineLength(value); - } + name = this.user.getTranslation("challenges.gui.buttons.admin.broadcast"); + icon = new ItemStack(Material.JUKEBOX); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setBroadcastMessages( + !this.settings.isBroadcastMessages()); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; + glow = this.settings.isBroadcastMessages(); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - }); + break; + } + case REMOVE_COMPLETED: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.remove-completed")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isRemoveCompleteOneTimeChallenges() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); - return true; - }; - glow = false; - break; - } - case LEVEL_LORE: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.level-lore")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", this.settings.getLevelLoreMessage())); - name = this.user.getTranslation("challenges.gui.buttons.admin.level-lore"); - icon = new ItemStack(Material.MAP); - clickHandler = (panel, user1, clickType, i) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.settings.getLevelLoreMessage(), - (player, reply) -> { - this.settings.setLevelLoreMessage(reply); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return reply; - }); + name = this.user.getTranslation("challenges.gui.buttons.admin.remove-completed"); + icon = new ItemStack(Material.MAGMA_BLOCK); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setRemoveCompleteOneTimeChallenges( + !this.settings.isRemoveCompleteOneTimeChallenges()); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; + glow = this.settings.isRemoveCompleteOneTimeChallenges(); - return true; - }; - glow = false; - break; - } - case CHALLENGE_LORE: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.challenge-lore")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", this.settings.getChallengeLoreMessage())); - name = this.user.getTranslation("challenges.gui.buttons.admin.challenge-lore"); - icon = new ItemStack(Material.PAPER); - clickHandler = (panel, user1, clickType, i) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.settings.getChallengeLoreMessage(), - (player, reply) -> { - this.settings.setChallengeLoreMessage(reply); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return reply; - }); + break; + } + case LORE_LENGTH: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.line-length")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.settings.getLoreLineLength()))); + name = this.user.getTranslation("challenges.gui.buttons.admin.line-length"); + icon = new ItemStack(Material.ANVIL); + clickHandler = (panel, user1, clickType, i) -> { + new NumberGUI(this.user, + this.settings.getLoreLineLength(), + 0, + this.settings.getLoreLineLength(), + (status, value) -> { + if (status) + { + this.settings.setLoreLineLength(value); + } - return true; - }; - glow = false; - break; - } - case FREE_AT_TOP: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.free-at-top")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isAddCompletedGlow() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.free-at-top"); - icon = new ItemStack(Material.FILLED_MAP); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setFreeChallengesFirst(!this.settings.isFreeChallengesFirst()); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; - glow = this.settings.isFreeChallengesFirst(); - break; - } - case GLOW_COMPLETED: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.glow")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isAddCompletedGlow() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + }); + + return true; + }; + glow = false; + break; + } + case LEVEL_LORE: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.level-lore")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", this.settings.getLevelLoreMessage())); + name = this.user.getTranslation("challenges.gui.buttons.admin.level-lore"); + icon = new ItemStack(Material.MAP); + clickHandler = (panel, user1, clickType, i) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.settings.getLevelLoreMessage(), + (player, reply) -> { + this.settings.setLevelLoreMessage(reply); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return reply; + }); + + return true; + }; + glow = false; + break; + } + case CHALLENGE_LORE: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.challenge-lore")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", this.settings.getChallengeLoreMessage())); + name = this.user.getTranslation("challenges.gui.buttons.admin.challenge-lore"); + icon = new ItemStack(Material.PAPER); + clickHandler = (panel, user1, clickType, i) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.settings.getChallengeLoreMessage(), + (player, reply) -> { + this.settings.setChallengeLoreMessage(reply); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return reply; + }); + + return true; + }; + glow = false; + break; + } + case FREE_AT_TOP: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.free-at-top")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isAddCompletedGlow() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.free-at-top"); + icon = new ItemStack(Material.FILLED_MAP); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setFreeChallengesFirst(!this.settings.isFreeChallengesFirst()); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; + glow = this.settings.isFreeChallengesFirst(); + break; + } + case GLOW_COMPLETED: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.glow")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isAddCompletedGlow() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.glow"); - icon = new ItemStack(Material.GLOWSTONE); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setAddCompletedGlow(!this.settings.isAddCompletedGlow()); - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; - glow = this.settings.isAddCompletedGlow(); - break; - } - case GAMEMODE_GUI_VIEW_MODE: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.gui-view-mode")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.getUserGuiMode().equals(Settings.GuiMode.GAMEMODE_LIST) ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.gui-view-mode"); - icon = new ItemStack(Material.STONE_BUTTON); - clickHandler = (panel, user1, clickType, i) -> { + name = this.user.getTranslation("challenges.gui.buttons.admin.glow"); + icon = new ItemStack(Material.GLOWSTONE); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setAddCompletedGlow(!this.settings.isAddCompletedGlow()); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; + glow = this.settings.isAddCompletedGlow(); + break; + } + case GAMEMODE_GUI_VIEW_MODE: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.gui-view-mode")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.getUserGuiMode().equals(Settings.GuiMode.GAMEMODE_LIST) ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.gui-view-mode"); + icon = new ItemStack(Material.STONE_BUTTON); + clickHandler = (panel, user1, clickType, i) -> { - if (this.settings.getUserGuiMode().equals(Settings.GuiMode.GAMEMODE_LIST)) - { - this.settings.setUserGuiMode(Settings.GuiMode.CURRENT_WORLD); - } - else - { - this.settings.setUserGuiMode(Settings.GuiMode.GAMEMODE_LIST); - } + if (this.settings.getUserGuiMode().equals(Settings.GuiMode.GAMEMODE_LIST)) + { + this.settings.setUserGuiMode(Settings.GuiMode.CURRENT_WORLD); + } + else + { + this.settings.setUserGuiMode(Settings.GuiMode.GAMEMODE_LIST); + } - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; - glow = this.settings.getUserGuiMode().equals(Settings.GuiMode.GAMEMODE_LIST); - break; - } - case GAMEMODE_GUI: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.gui-mode")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isUseCommonGUI() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.gui-mode"); - icon = new ItemStack(Material.BLACK_STAINED_GLASS_PANE); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setUseCommonGUI(!this.settings.isUseCommonGUI()); - // We cannot use single item changing as this option enabling/disabling will change other - // option visibility. - this.build(); - return true; - }; - glow = this.settings.isUseCommonGUI(); - break; - } - case HISTORY: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.history-store")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isStoreHistory() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.history-store"); - icon = new ItemStack(Material.WRITTEN_BOOK); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setStoreHistory(!this.settings.isStoreHistory()); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; + glow = this.settings.getUserGuiMode().equals(Settings.GuiMode.GAMEMODE_LIST); + break; + } + case GAMEMODE_GUI: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.gui-mode")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isUseCommonGUI() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.gui-mode"); + icon = new ItemStack(Material.BLACK_STAINED_GLASS_PANE); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setUseCommonGUI(!this.settings.isUseCommonGUI()); + // We cannot use single item changing as this option enabling/disabling will change other + // option visibility. + this.build(); + return true; + }; + glow = this.settings.isUseCommonGUI(); + break; + } + case HISTORY: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.history-store")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isStoreHistory() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.history-store"); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setStoreHistory(!this.settings.isStoreHistory()); - // Need to rebuild all as new buttons will show up. - this.build(); - return true; - }; - glow = this.settings.isStoreHistory(); - break; - } - case PURGE_HISTORY: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.history-lifespan")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.settings.getLifeSpan()))); - name = this.user.getTranslation("challenges.gui.buttons.admin.history-lifespan"); - icon = new ItemStack(Material.FLINT_AND_STEEL); - clickHandler = (panel, user1, clickType, i) -> { - new NumberGUI(this.user, - this.settings.getLifeSpan(), - 0, - this.settings.getLoreLineLength(), - (status, value) -> { - if (status) - { - this.settings.setLifeSpan(value); - } + // Need to rebuild all as new buttons will show up. + this.build(); + return true; + }; + glow = this.settings.isStoreHistory(); + break; + } + case PURGE_HISTORY: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.history-lifespan")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.settings.getLifeSpan()))); + name = this.user.getTranslation("challenges.gui.buttons.admin.history-lifespan"); + icon = new ItemStack(Material.FLINT_AND_STEEL); + clickHandler = (panel, user1, clickType, i) -> { + new NumberGUI(this.user, + this.settings.getLifeSpan(), + 0, + this.settings.getLoreLineLength(), + (status, value) -> { + if (status) + { + this.settings.setLifeSpan(value); + } - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - }); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + }); - return true; - }; - glow = false; - break; - } - case STORE_MODE: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.island-store")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isStoreAsIslandData() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.island-store"); - icon = new ItemStack(Material.GRASS_BLOCK); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setStoreAsIslandData(!this.settings.isStoreAsIslandData()); - // TODO: Data Migration must be added here. - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - return true; - }; - glow = this.settings.isStoreAsIslandData(); - break; - } - case LOCKED_LEVEL_ICON: - { - description = new ArrayList<>(1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.default-locked-icon")); - name = this.user.getTranslation("challenges.gui.buttons.admin.default-locked-icon"); - icon = this.settings.getLockedLevelIcon(); - clickHandler = (panel, user, clickType, slot) -> { - new AnvilGUI(this.addon.getPlugin(), - this.user.getPlayer(), - this.settings.getLockedLevelIcon().getType().name(), - (player, reply) -> { - Material material = Material.getMaterial(reply); + return true; + }; + glow = false; + break; + } + case STORE_MODE: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.island-store")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isStoreAsIslandData() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.island-store"); + icon = new ItemStack(Material.GRASS_BLOCK); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setStoreAsIslandData(!this.settings.isStoreAsIslandData()); + // TODO: Data Migration must be added here. + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + return true; + }; + glow = this.settings.isStoreAsIslandData(); + break; + } + case LOCKED_LEVEL_ICON: + { + description = new ArrayList<>(1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.default-locked-icon")); + name = this.user.getTranslation("challenges.gui.buttons.admin.default-locked-icon"); + icon = this.settings.getLockedLevelIcon(); + clickHandler = (panel, user, clickType, slot) -> { + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.settings.getLockedLevelIcon().getType().name(), + (player, reply) -> { + Material material = Material.getMaterial(reply); - if (material != null) - { - this.settings.setLockedLevelIcon(new ItemStack(material)); - this.build(); - } - else - { - this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); - } + if (material != null) + { + this.settings.setLockedLevelIcon(new ItemStack(material)); + this.build(); + } + else + { + this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); + } - return reply; - }); + return reply; + }); - return true; - }; - glow = false; - break; - } - case ENABLE_TITLE: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.title-enable")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", - this.settings.isShowCompletionTitle() ? - this.user.getTranslation("challenges.gui.descriptions.enabled") : - this.user.getTranslation("challenges.gui.descriptions.disabled"))); - name = this.user.getTranslation("challenges.gui.buttons.admin.title-enable"); - icon = new ItemStack(ChallengesAddon.SIGN_MATERIAL); - clickHandler = (panel, user1, clickType, i) -> { - this.settings.setShowCompletionTitle(!this.settings.isShowCompletionTitle()); + return true; + }; + glow = false; + break; + } + case ENABLE_TITLE: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.title-enable")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", + this.settings.isShowCompletionTitle() ? + this.user.getTranslation("challenges.gui.descriptions.enabled") : + this.user.getTranslation("challenges.gui.descriptions.disabled"))); + name = this.user.getTranslation("challenges.gui.buttons.admin.title-enable"); + icon = new ItemStack(ChallengesAddon.SIGN_MATERIAL); + clickHandler = (panel, user1, clickType, i) -> { + this.settings.setShowCompletionTitle(!this.settings.isShowCompletionTitle()); - // Need to rebuild all as new buttons will show up. - this.build(); - return true; - }; - glow = this.settings.isShowCompletionTitle(); - break; - } - case TITLE_SHOWTIME: - { - description = new ArrayList<>(2); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.title-showtime")); - description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", - "[value]", Integer.toString(this.settings.getTitleShowtime()))); - name = this.user.getTranslation("challenges.gui.buttons.admin.title-showtime"); - icon = new ItemStack(Material.CLOCK); - clickHandler = (panel, user1, clickType, i) -> { - new NumberGUI(this.user, - this.settings.getTitleShowtime(), - 0, - this.settings.getLoreLineLength(), - (status, value) -> { - if (status) - { - this.settings.setTitleShowtime(value); - } + // Need to rebuild all as new buttons will show up. + this.build(); + return true; + }; + glow = this.settings.isShowCompletionTitle(); + break; + } + case TITLE_SHOWTIME: + { + description = new ArrayList<>(2); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.title-showtime")); + description.add(this.user.getTranslation("challenges.gui.descriptions.current-value", + "[value]", Integer.toString(this.settings.getTitleShowtime()))); + name = this.user.getTranslation("challenges.gui.buttons.admin.title-showtime"); + icon = new ItemStack(Material.CLOCK); + clickHandler = (panel, user1, clickType, i) -> { + new NumberGUI(this.user, + this.settings.getTitleShowtime(), + 0, + this.settings.getLoreLineLength(), + (status, value) -> { + if (status) + { + this.settings.setTitleShowtime(value); + } - panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); - }); + panel.getInventory().setItem(i, this.getSettingsButton(button).getItem()); + }); - return true; - }; - glow = false; - break; - } - default: - return new PanelItemBuilder().build(); - } + return true; + }; + glow = false; + break; + } + default: + return new PanelItemBuilder().build(); + } - return new PanelItemBuilder(). - icon(icon). - name(name). - description(GuiUtils.stringSplit(description, this.settings.getLoreLineLength())). - glow(glow). - clickHandler(clickHandler). - build(); - } + return new PanelItemBuilder(). + icon(icon). + name(name). + description(GuiUtils.stringSplit(description, this.settings.getLoreLineLength())). + glow(glow). + clickHandler(clickHandler). + build(); + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * This enum holds all settings buttons that must have been displayed in this panel. - */ - private enum Button - { - RESET_CHALLENGES, - BROADCAST, - REMOVE_COMPLETED, - LORE_LENGTH, - LEVEL_LORE, - CHALLENGE_LORE, - FREE_AT_TOP, - GAMEMODE_GUI_VIEW_MODE, - GAMEMODE_GUI, - HISTORY, - PURGE_HISTORY, - STORE_MODE, - GLOW_COMPLETED, - LOCKED_LEVEL_ICON, - ENABLE_TITLE, - TITLE_SHOWTIME - } + /** + * This enum holds all settings buttons that must have been displayed in this panel. + */ + private enum Button + { + RESET_CHALLENGES, + BROADCAST, + REMOVE_COMPLETED, + LORE_LENGTH, + LEVEL_LORE, + CHALLENGE_LORE, + FREE_AT_TOP, + GAMEMODE_GUI_VIEW_MODE, + GAMEMODE_GUI, + HISTORY, + PURGE_HISTORY, + STORE_MODE, + GLOW_COMPLETED, + LOCKED_LEVEL_ICON, + ENABLE_TITLE, + TITLE_SHOWTIME + } - /** - * This allows faster access to challenges settings object. - */ - private Settings settings; + /** + * This allows faster access to challenges settings object. + */ + private Settings settings; } 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 1c21908..3894efe 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -23,176 +23,184 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class ListChallengesGUI extends CommonGUI { - // --------------------------------------------------------------------- -// Section: Constructor -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Constructor + // --------------------------------------------------------------------- - /** - * {@inheritDoc} - * @param mode - mode that indicate what should do icon clicking. - */ - public ListChallengesGUI(ChallengesAddon addon, - World world, - User user, - Mode mode, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, mode, topLabel, permissionPrefix, null); - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param mode - mode that indicate what should do icon clicking. + */ + public ListChallengesGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, mode, topLabel, permissionPrefix, null); + } - /** - * {@inheritDoc} - * @param mode - mode that indicate what should do icon clicking. - */ - public ListChallengesGUI(ChallengesAddon addon, - World world, - User user, - Mode mode, - String topLabel, - String permissionPrefix, - CommonGUI parentGUI) - { - super(addon, world, user, topLabel, permissionPrefix, parentGUI); - this.currentMode = mode; - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param mode - mode that indicate what should do icon clicking. + */ + public ListChallengesGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.currentMode = mode; + } -// --------------------------------------------------------------------- -// Section: Methods -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Methods + // --------------------------------------------------------------------- - /** - * {@inheritDoc} - */ - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.choose-challenge-title")); + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.choose-challenge-title")); - if (this.currentMode.equals(Mode.DELETE)) - { - GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE); - } - else - { - GuiUtils.fillBorder(panelBuilder); - } + if (this.currentMode.equals(Mode.DELETE)) + { + GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE); + } + else + { + GuiUtils.fillBorder(panelBuilder); + } - List challengeList = this.addon.getChallengesManager().getAllChallenges(this.world); + List challengeList = this.addon.getChallengesManager().getAllChallenges(this.world); - final int MAX_ELEMENTS = 21; + final int MAX_ELEMENTS = 21; - if (this.pageIndex < 0) - { - this.pageIndex = challengeList.size() / MAX_ELEMENTS; - } - else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) - { - this.pageIndex = 0; - } + if (this.pageIndex < 0) + { + this.pageIndex = challengeList.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) + { + this.pageIndex = 0; + } - int challengeIndex = MAX_ELEMENTS * this.pageIndex; + int challengeIndex = MAX_ELEMENTS * this.pageIndex; - // I want first row to be only for navigation and return button. - int index = 10; + // I want first row to be only for navigation and return button. + int index = 10; - while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - challengeIndex < challengeList.size() && - index < 36) - { - if (!panelBuilder.slotOccupied(index)) - { - panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++))); - } + while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + challengeIndex < challengeList.size() && + index < 36) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++))); + } - index++; - } + index++; + } - // Navigation buttons only if necessary - if (challengeList.size() > MAX_ELEMENTS) - { - panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); - panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); - } + // Navigation buttons only if necessary + if (challengeList.size() > MAX_ELEMENTS) + { + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); + } - panelBuilder.item(44, this.returnButton); + panelBuilder.item(44, this.returnButton); - panelBuilder.build(); - } + panelBuilder.build(); + } - /** - * This method creates button for given challenge. - * @param challenge Challenge which button must be created. - * @return Challenge button. - */ - private PanelItem createChallengeIcon(Challenge challenge) - { - PanelItemBuilder itemBuilder = new PanelItemBuilder(). - name(ChatColor.translateAlternateColorCodes('&', challenge.getFriendlyName())). - description(GuiUtils.stringSplit(this.generateChallengeDescription(challenge, this.user.getPlayer()), - this.addon.getChallengesSettings().getLoreLineLength())). - icon(challenge.getIcon()). - glow(challenge.isDeployed()); + /** + * This method creates button for given challenge. + * @param challenge Challenge which button must be created. + * @return Challenge button. + */ + private PanelItem createChallengeIcon(Challenge challenge) + { + PanelItemBuilder itemBuilder = new PanelItemBuilder(). + name(ChatColor.translateAlternateColorCodes('&', challenge.getFriendlyName())). + description(GuiUtils.stringSplit(this.generateChallengeDescription(challenge, this.user.getPlayer()), + this.addon.getChallengesSettings().getLoreLineLength())). + icon(challenge.getIcon()). + glow(challenge.isDeployed()); - if (this.currentMode.equals(Mode.EDIT)) - { - itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new EditChallengeGUI(this.addon, - this.world, - this.user, - challenge, - this.topLabel, - this.permissionPrefix, - this).build(); - return true; - }); - } - else if (this.currentMode.equals(Mode.DELETE)) - { - itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new ConfirmationGUI(this.user, value -> { - if (value) - { - this.addon.getChallengesManager().deleteChallenge(challenge); - } + if (this.currentMode.equals(Mode.EDIT)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + new EditChallengeGUI(this.addon, + this.world, + this.user, + challenge, + this.topLabel, + this.permissionPrefix, + this).build(); + return true; + }); + } + else if (this.currentMode.equals(Mode.DELETE)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager().deleteChallenge(challenge); + } - this.build(); - }); - return true; - }); - } + this.build(); + }); + return true; + }); + } - return itemBuilder.build(); - } + return itemBuilder.build(); + } -// --------------------------------------------------------------------- -// Section: Enums -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Enums + // --------------------------------------------------------------------- - /** - * Mode in which gui icons should processed. - */ - public enum Mode - { - EDIT, - DELETE - } + /** + * Mode in which gui icons should processed. + */ + public enum Mode + { + EDIT, + DELETE + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Current mode in which icons will act. - */ - private Mode currentMode; + /** + * Current mode in which icons will act. + */ + private Mode currentMode; } 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 b7fbc94..d51ffdf 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -23,178 +23,186 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class ListLevelsGUI extends CommonGUI { -// --------------------------------------------------------------------- -// Section: Constructor -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Constructor + // --------------------------------------------------------------------- - /** - * {@inheritDoc} - * @param mode - mode that indicate what should do icon clicking. - */ - public ListLevelsGUI(ChallengesAddon addon, - World world, - User user, - Mode mode, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, mode, topLabel, permissionPrefix, null); - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param mode - mode that indicate what should do icon clicking. + */ + public ListLevelsGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, mode, topLabel, permissionPrefix, null); + } - /** - * {@inheritDoc} - * @param mode - mode that indicate what should do icon clicking. - */ - public ListLevelsGUI(ChallengesAddon addon, - World world, - User user, - Mode mode, - String topLabel, - String permissionPrefix, - CommonGUI parentGUI) - { - super(addon, world, user, topLabel, permissionPrefix, parentGUI); - this.currentMode = mode; - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param mode - mode that indicate what should do icon clicking. + */ + public ListLevelsGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.currentMode = mode; + } -// --------------------------------------------------------------------- -// Section: Methods -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Methods + // --------------------------------------------------------------------- - /** - * {@inheritDoc} - */ - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.choose-level-title")); + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.choose-level-title")); - if (this.currentMode.equals(Mode.DELETE)) - { - GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE); - } - else - { - GuiUtils.fillBorder(panelBuilder); - } + if (this.currentMode.equals(Mode.DELETE)) + { + GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE); + } + else + { + GuiUtils.fillBorder(panelBuilder); + } - List levelList = this.addon.getChallengesManager().getLevels(this.world); + List levelList = this.addon.getChallengesManager().getLevels(this.world); - final int MAX_ELEMENTS = 21; + final int MAX_ELEMENTS = 21; - if (this.pageIndex < 0) - { - this.pageIndex = levelList.size() / MAX_ELEMENTS; - } - else if (this.pageIndex > (levelList.size() / MAX_ELEMENTS)) - { - this.pageIndex = 0; - } + if (this.pageIndex < 0) + { + this.pageIndex = levelList.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (levelList.size() / MAX_ELEMENTS)) + { + this.pageIndex = 0; + } - int levelIndex = MAX_ELEMENTS * this.pageIndex; + int levelIndex = MAX_ELEMENTS * this.pageIndex; - // I want first row to be only for navigation and return button. - int index = 10; + // I want first row to be only for navigation and return button. + int index = 10; - while (levelIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - levelIndex < levelList.size() && - index < 36) - { - if (!panelBuilder.slotOccupied(index)) - { - panelBuilder.item(index, this.createLevelIcon(levelList.get(levelIndex++))); - } + while (levelIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + levelIndex < levelList.size() && + index < 36) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createLevelIcon(levelList.get(levelIndex++))); + } - index++; - } + index++; + } - // Navigation buttons only if necessary - if (levelList.size() > MAX_ELEMENTS) - { - panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); - panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); - } + // Navigation buttons only if necessary + if (levelList.size() > MAX_ELEMENTS) + { + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); + } - panelBuilder.item(44, this.returnButton); + panelBuilder.item(44, this.returnButton); - panelBuilder.build(); - } + panelBuilder.build(); + } - /** - * This method creates button for given level - * @param challengeLevel Level which button must be created. - * @return Level button. - */ - private PanelItem createLevelIcon(ChallengeLevel challengeLevel) - { - PanelItemBuilder itemBuilder = new PanelItemBuilder(). - name(ChatColor.translateAlternateColorCodes('&', challengeLevel.getFriendlyName())). - description(GuiUtils.stringSplit( - this.generateLevelDescription(challengeLevel, this.user.getPlayer()), - this.addon.getChallengesSettings().getLoreLineLength())). - icon(challengeLevel.getIcon()). - glow(false); + /** + * This method creates button for given level + * @param challengeLevel Level which button must be created. + * @return Level button. + */ + private PanelItem createLevelIcon(ChallengeLevel challengeLevel) + { + PanelItemBuilder itemBuilder = new PanelItemBuilder(). + name(ChatColor.translateAlternateColorCodes('&', challengeLevel.getFriendlyName())). + description(GuiUtils.stringSplit( + this.generateLevelDescription(challengeLevel, this.user.getPlayer()), + this.addon.getChallengesSettings().getLoreLineLength())). + icon(challengeLevel.getIcon()). + glow(false); - if (this.currentMode.equals(Mode.EDIT)) - { - itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new EditLevelGUI(this.addon, - this.world, - this.user, - challengeLevel, - this.topLabel, - this.permissionPrefix, - this).build(); - return true; - }); - } - else if (this.currentMode.equals(Mode.DELETE)) - { - itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new ConfirmationGUI(this.user, value -> { - if (value) - { - this.addon.getChallengesManager(). - deleteChallengeLevel(challengeLevel); - } + if (this.currentMode.equals(Mode.EDIT)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + new EditLevelGUI(this.addon, + this.world, + this.user, + challengeLevel, + this.topLabel, + this.permissionPrefix, + this).build(); + return true; + }); + } + else if (this.currentMode.equals(Mode.DELETE)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager(). + deleteChallengeLevel(challengeLevel); + } - this.build(); - }); - return true; - }); - } + this.build(); + }); + return true; + }); + } - return itemBuilder.build(); - } + return itemBuilder.build(); + } -// --------------------------------------------------------------------- -// Section: Enums -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Enums + // --------------------------------------------------------------------- - /** - * Mode in which gui icons should processed. - */ - public enum Mode - { - EDIT, - DELETE - } + /** + * Mode in which gui icons should processed. + */ + public enum Mode + { + EDIT, + DELETE + } -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * Current mode in which icons will act. - */ - private Mode currentMode; + /** + * Current mode in which icons will act. + */ + private Mode currentMode; } 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 3d3b77b..c8e8332 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -30,296 +30,304 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class ListUsersGUI extends CommonGUI { -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- - /** - * List with players that should be in GUI. - */ - private List onlineUsers; + /** + * List with players that should be in GUI. + */ + private List onlineUsers; - /** - * Current operation mode. - */ - private Mode operationMode; + /** + * Current operation mode. + */ + private Mode operationMode; - /** - * Current index of view mode - */ - private int modeIndex = 2; + /** + * Current index of view mode + */ + private int modeIndex = 2; - /** - * This allows to switch which users should be in the list. - */ - private enum ViewMode - { - ONLINE, - WITH_ISLAND, - IN_WORLD - } + /** + * This allows to switch which users should be in the list. + */ + private enum ViewMode + { + ONLINE, + WITH_ISLAND, + IN_WORLD + } - /** - * This allows to decide what User Icon should do. - */ - public enum Mode - { - COMPLETE, - RESET, - RESET_ALL - } + /** + * This allows to decide what User Icon should do. + */ + public enum Mode + { + COMPLETE, + RESET, + RESET_ALL + } -// --------------------------------------------------------------------- -// Section: Constructors -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Constructors + // --------------------------------------------------------------------- - /** - * {@inheritDoc} - * @param operationMode Indicate what should happen on player icon click. - */ - public ListUsersGUI(ChallengesAddon addon, - World world, - User user, - Mode operationMode, - String topLabel, - String permissionPrefix) - { - this(addon, world, user, operationMode, topLabel, permissionPrefix, null); - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param operationMode Indicate what should happen on player icon click. + */ + public ListUsersGUI(ChallengesAddon addon, + World world, + User user, + Mode operationMode, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, operationMode, topLabel, permissionPrefix, null); + } - /** - * {@inheritDoc} - * @param operationMode Indicate what should happen on player icon click. - */ - public ListUsersGUI(ChallengesAddon addon, - World world, - User user, - Mode operationMode, - String topLabel, - String permissionPrefix, - CommonGUI parentPanel) - { - super(addon, world, user, topLabel, permissionPrefix, parentPanel); - this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD); - this.operationMode = operationMode; - } + /** + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param operationMode Indicate what should happen on player icon click. + */ + public ListUsersGUI(ChallengesAddon addon, + World world, + User user, + Mode operationMode, + String topLabel, + String permissionPrefix, + CommonGUI parentPanel) + { + super(addon, world, user, topLabel, permissionPrefix, parentPanel); + this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD); + this.operationMode = operationMode; + } -// --------------------------------------------------------------------- -// Section: Methods -// --------------------------------------------------------------------- + // --------------------------------------------------------------------- + // Section: Methods + // --------------------------------------------------------------------- - @Override - public void build() - { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation("challenges.gui.title.admin.choose-user-title")); + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.title.admin.choose-user-title")); - GuiUtils.fillBorder(panelBuilder); + GuiUtils.fillBorder(panelBuilder); - final int MAX_ELEMENTS = 21; + final int MAX_ELEMENTS = 21; - if (this.pageIndex < 0) - { - this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS; - } - else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS)) - { - this.pageIndex = 0; - } + if (this.pageIndex < 0) + { + this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS)) + { + this.pageIndex = 0; + } - int playerIndex = MAX_ELEMENTS * this.pageIndex; + int playerIndex = MAX_ELEMENTS * this.pageIndex; - // I want first row to be only for navigation and return button. - int index = 10; + // I want first row to be only for navigation and return button. + int index = 10; - while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - playerIndex < this.onlineUsers.size() && - index < 36) - { - if (!panelBuilder.slotOccupied(index)) - { - panelBuilder.item(index, this.createPlayerIcon(this.onlineUsers.get(playerIndex++))); - } + while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + playerIndex < this.onlineUsers.size() && + index < 36) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createPlayerIcon(this.onlineUsers.get(playerIndex++))); + } - index++; - } + index++; + } - // Add button that allows to toogle different player lists. - panelBuilder.item( 4, this.createToggleButton()); + // Add button that allows to toogle different player lists. + panelBuilder.item( 4, this.createToggleButton()); - // Navigation buttons only if necessary - if (this.onlineUsers.size() > MAX_ELEMENTS) - { - panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); - panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); - } + // Navigation buttons only if necessary + if (this.onlineUsers.size() > MAX_ELEMENTS) + { + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); + } - panelBuilder.item(44, this.returnButton); + panelBuilder.item(44, this.returnButton); - panelBuilder.build(); - } + panelBuilder.build(); + } - /** - * This method creates button for given user. If user has island it will add valid click handler. - * @param player Player which button must be created. - * @return Player button. - */ - private PanelItem createPlayerIcon(Player player) - { - int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); + /** + * This method creates button for given user. If user has island it will add valid click handler. + * @param player Player which button must be created. + * @return Player button. + */ + private PanelItem createPlayerIcon(Player player) + { + int lineLength = this.addon.getChallengesSettings().getLoreLineLength(); - if (this.addon.getIslands().getIsland(this.world, player.getUniqueId()) != null) - { - return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler( - (panel, user1, clickType, slot) -> { - ChallengesManager manager = this.addon.getChallengesManager(); - Map> challengeDescriptionMap; + if (this.addon.getIslands().getIsland(this.world, player.getUniqueId()) != null) + { + return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler( + (panel, user1, clickType, slot) -> { + ChallengesManager manager = this.addon.getChallengesManager(); + Map> challengeDescriptionMap; - switch (this.operationMode) - { - case COMPLETE: - challengeDescriptionMap = new LinkedHashMap<>(); + switch (this.operationMode) + { + case COMPLETE: + challengeDescriptionMap = new LinkedHashMap<>(); - for (Challenge challenge : manager.getAllChallenges(this.world)) - { - if (!manager.isChallengeComplete(player.getUniqueId(), this.world, challenge)) - { - challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player)); - } - } + for (Challenge challenge : manager.getAllChallenges(this.world)) + { + if (!manager.isChallengeComplete(player.getUniqueId(), this.world, challenge)) + { + challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player)); + } + } - new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { - if (status) - { - valueSet.forEach(challenge -> manager.setChallengeComplete(player.getUniqueId(), this.world, challenge, this.user.getUniqueId())); - } + new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { + if (status) + { + valueSet.forEach(challenge -> manager.setChallengeComplete(player.getUniqueId(), this.world, challenge, this.user.getUniqueId())); + } - this.build(); - }); - break; - case RESET: - challengeDescriptionMap = new LinkedHashMap<>(); + this.build(); + }); + break; + case RESET: + challengeDescriptionMap = new LinkedHashMap<>(); - for (Challenge challenge : manager.getAllChallenges(this.world)) - { - if (manager.isChallengeComplete(player.getUniqueId(), this.world, challenge)) - { - challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player)); - } - } + for (Challenge challenge : manager.getAllChallenges(this.world)) + { + if (manager.isChallengeComplete(player.getUniqueId(), this.world, challenge)) + { + challengeDescriptionMap.put(challenge, this.generateChallengeDescription(challenge, player)); + } + } - new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { - if (status) - { - valueSet.forEach(challenge -> manager.resetChallenge(player.getUniqueId(), this.world, challenge, this.user.getUniqueId())); - } + new SelectChallengeGUI(this.user, challengeDescriptionMap, lineLength, (status, valueSet) -> { + if (status) + { + valueSet.forEach(challenge -> manager.resetChallenge(player.getUniqueId(), this.world, challenge, this.user.getUniqueId())); + } - this.build(); - }); - break; - case RESET_ALL: - new ConfirmationGUI(this.user, status -> { - if (status) - { - manager.resetAllChallenges(player.getUniqueId(), this.world, this.user.getUniqueId()); - } + this.build(); + }); + break; + case RESET_ALL: + new ConfirmationGUI(this.user, status -> { + if (status) + { + manager.resetAllChallenges(player.getUniqueId(), this.world, this.user.getUniqueId()); + } - this.build(); - }); - break; - } + this.build(); + }); + break; + } - return true; - }).build(); - } - else - { - return new PanelItemBuilder(). - name(player.getName()). - icon(Material.BARRIER). - description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"), lineLength)). - clickHandler((panel, user1, clickType, slot) -> false). - build(); - } - } + return true; + }).build(); + } + else + { + return new PanelItemBuilder(). + name(player.getName()). + icon(Material.BARRIER). + description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"), lineLength)). + clickHandler((panel, user1, clickType, slot) -> false). + build(); + } + } - /** - * This method collects users based on view mode. - * @param mode Given view mode. - * @return List with players in necessary view mode. - */ - private List collectUsers(ViewMode mode) - { - if (mode.equals(ViewMode.ONLINE)) - { - return new ArrayList<>(Bukkit.getOnlinePlayers()); - } - else if (mode.equals(ViewMode.WITH_ISLAND)) - { - return this.addon.getPlayers().getPlayers().stream(). - filter(player -> this.addon.getIslands().getIsland(this.world, player.getPlayerUUID()) != null). - map(Players::getPlayer). - collect(Collectors.toList()); - } - else - { - return new ArrayList<>(this.world.getPlayers()); - } - } + /** + * This method collects users based on view mode. + * @param mode Given view mode. + * @return List with players in necessary view mode. + */ + private List collectUsers(ViewMode mode) + { + if (mode.equals(ViewMode.ONLINE)) + { + return new ArrayList<>(Bukkit.getOnlinePlayers()); + } + else if (mode.equals(ViewMode.WITH_ISLAND)) + { + return this.addon.getPlayers().getPlayers().stream(). + filter(player -> this.addon.getIslands().getIsland(this.world, player.getPlayerUUID()) != null). + map(Players::getPlayer). + collect(Collectors.toList()); + } + else + { + return new ArrayList<>(this.world.getPlayers()); + } + } - /** - * This method creates Player List view Mode toggle button. - * @return Button that toggles through player view mode. - */ - private PanelItem createToggleButton() - { - List description = new ArrayList<>(ViewMode.values().length + 1); - description.add(this.user.getTranslation("challenges.gui.descriptions.admin.toggle-user-list")); - description.add((ViewMode.ONLINE == ViewMode.values()[this.modeIndex] ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.admin.mode-online")); - description.add((ViewMode.WITH_ISLAND == ViewMode.values()[this.modeIndex] ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.admin.mode-in-world")); - description.add((ViewMode.IN_WORLD == ViewMode.values()[this.modeIndex] ? "&2" : "&c") + - this.user.getTranslation("challenges.gui.descriptions.admin.mode-with-island")); + /** + * This method creates Player List view Mode toggle button. + * @return Button that toggles through player view mode. + */ + private PanelItem createToggleButton() + { + List description = new ArrayList<>(ViewMode.values().length + 1); + description.add(this.user.getTranslation("challenges.gui.descriptions.admin.toggle-user-list")); + description.add((ViewMode.ONLINE == ViewMode.values()[this.modeIndex] ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.admin.mode-online")); + description.add((ViewMode.WITH_ISLAND == ViewMode.values()[this.modeIndex] ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.admin.mode-in-world")); + description.add((ViewMode.IN_WORLD == ViewMode.values()[this.modeIndex] ? "&2" : "&c") + + this.user.getTranslation("challenges.gui.descriptions.admin.mode-with-island")); - return new PanelItemBuilder(). - name(this.user.getTranslation("challenges.gui.buttons.admin.toggle-user-list")). - description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). - icon(Material.STONE_BUTTON). - clickHandler( - (panel, user1, clickType, slot) -> { - if (clickType.isRightClick()) - { - this.modeIndex--; + return new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.buttons.admin.toggle-user-list")). + description(GuiUtils.stringSplit(description, this.addon.getChallengesSettings().getLoreLineLength())). + icon(Material.STONE_BUTTON). + clickHandler( + (panel, user1, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.modeIndex--; - if (this.modeIndex < 0) - { - this.modeIndex = ViewMode.values().length - 1; - } - } - else - { - this.modeIndex++; + if (this.modeIndex < 0) + { + this.modeIndex = ViewMode.values().length - 1; + } + } + else + { + this.modeIndex++; - if (this.modeIndex >= ViewMode.values().length) - { - this.modeIndex = 0; - } - } + if (this.modeIndex >= ViewMode.values().length) + { + this.modeIndex = 0; + } + } - this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]); - this.pageIndex = 0; - this.build(); - return true; - }).build(); - } + this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]); + this.pageIndex = 0; + this.build(); + return true; + }).build(); + } } \ No newline at end of file