diff --git a/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java b/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java index eaf3f73..f59a1d5 100644 --- a/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java +++ b/src/main/java/world/bentobox/challenges/commands/CompleteChallengeCommand.java @@ -4,7 +4,6 @@ package world.bentobox.challenges.commands; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; @@ -115,11 +114,10 @@ public class CompleteChallengeCommand extends CompositeCommand // Create suggestions with all challenges that is available for users. returnList.addAll(this.getAddon().getChallengesManager().getAllChallengesNames(this.getWorld()). - stream(). - filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") || - challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")). - map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)). - collect(Collectors.toList())); + stream(). + filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") || + challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")). + map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList()); break; case 4: // Suggest a number of completions. diff --git a/src/main/java/world/bentobox/challenges/commands/admin/CompleteCommand.java b/src/main/java/world/bentobox/challenges/commands/admin/CompleteCommand.java index 16ba70b..24f8913 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/CompleteCommand.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/CompleteCommand.java @@ -2,11 +2,9 @@ package world.bentobox.challenges.commands.admin; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.stream.Collectors; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.commands.CompositeCommand; @@ -101,7 +99,7 @@ public class CompleteCommand extends CompositeCommand Challenge challenge = this.addon.getChallengesManager().getChallenge(challengeName); User target = User.getInstance(targetUUID); - if (challenge != null && target != null) + if (challenge != null) { if (!this.addon.getChallengesManager().isChallengeComplete(targetUUID, this.getWorld(), challenge)) { @@ -174,10 +172,9 @@ public class CompleteCommand extends CompositeCommand case 4 -> // Create suggestions with all challenges that is available for users. returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream(). - map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)). - collect(Collectors.toList())); + map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList()); default -> - returnList.addAll(Collections.singletonList("help")); + returnList.add("help"); } return Optional.of(Util.tabLimit(returnList, lastString)); diff --git a/src/main/java/world/bentobox/challenges/commands/admin/ResetCommand.java b/src/main/java/world/bentobox/challenges/commands/admin/ResetCommand.java index 4e6a7fe..8955da5 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/ResetCommand.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/ResetCommand.java @@ -2,11 +2,9 @@ package world.bentobox.challenges.commands.admin; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.stream.Collectors; import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.commands.CompositeCommand; @@ -191,12 +189,11 @@ public class ResetCommand extends CompositeCommand case 4 -> { // Create suggestions with all challenges that is available for users. returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream(). - map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)). - collect(Collectors.toList())); + map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList()); returnList.add("all"); } default -> - returnList.addAll(Collections.singletonList("help")); + returnList.add("help"); } return Optional.of(Util.tabLimit(returnList, lastString)); diff --git a/src/main/java/world/bentobox/challenges/database/object/requirements/StatisticRequirements.java b/src/main/java/world/bentobox/challenges/database/object/requirements/StatisticRequirements.java index c0d0f31..b90ec70 100644 --- a/src/main/java/world/bentobox/challenges/database/object/requirements/StatisticRequirements.java +++ b/src/main/java/world/bentobox/challenges/database/object/requirements/StatisticRequirements.java @@ -56,20 +56,18 @@ public class StatisticRequirements extends Requirements return false; } - switch (this.statistic.getType()) + return switch (this.statistic.getType()) { - case ITEM -> { - return this.material != null && this.material.isItem(); - } - case BLOCK -> { - return this.material != null && this.material.isBlock(); - } - case ENTITY -> { - return this.entity != null; - } - } + case ITEM -> this.material != null && this.material.isItem(); + + case BLOCK -> this.material != null && this.material.isBlock(); + + case ENTITY -> this.entity != null; + + case UNTYPED -> true; + + }; - return true; } diff --git a/src/main/java/world/bentobox/challenges/managers/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/managers/ChallengesImportManager.java index 569c223..aa76502 100644 --- a/src/main/java/world/bentobox/challenges/managers/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/managers/ChallengesImportManager.java @@ -27,7 +27,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.annotations.Expose; -import lv.id.bonne.panelutils.PanelUtils; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; diff --git a/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java b/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java index 27f2289..6e19df9 100644 --- a/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/managers/ChallengesManager.java @@ -232,10 +232,6 @@ public class ChallengesManager this.savePlayersData(); } - // this.challengeDatabase = new Database<>(addon, Challenge.class); - // this.levelDatabase = new Database<>(addon, ChallengeLevel.class); - // this.playersDatabase = new Database<>(addon, ChallengesPlayerData.class); - this.loadAndValidate(); } @@ -434,12 +430,6 @@ public class ChallengesManager public void removeFromCache(UUID playerID) { // Remove due possible issues with saving... (#246) -// if (!this.settings.isStoreAsIslandData() && this.playerCacheData.containsKey(playerID.toString())) -// { -// // save before remove -// this.savePlayerData(playerID.toString()); -// this.playerCacheData.remove(playerID.toString()); -// } this.savePlayerData(playerID.toString()); @@ -841,8 +831,6 @@ public class ChallengesManager { // Challenges and Levels are saved on modifications only to avoid issues with // NULL's in data after interrupting server while in saving stage. - // this.saveChallenges(); - // this.saveLevels(); this.savePlayersData(); } diff --git a/src/main/java/world/bentobox/challenges/panel/CommonPanel.java b/src/main/java/world/bentobox/challenges/panel/CommonPanel.java index eb44136..83f2ecd 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonPanel.java @@ -288,9 +288,8 @@ public abstract class CommonPanel { // Yes list duplication for complete menu. List missingPermissions = challenge.getRequirements().getRequiredPermissions().stream(). - filter(permission -> target == null || !target.hasPermission(permission)). - sorted(). - collect(Collectors.toList()); + filter(permission -> target == null || !target.hasPermission(permission)). + sorted().toList(); StringBuilder permissionBuilder = new StringBuilder(); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminPanel.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminPanel.java index f919626..5a1dd21 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminPanel.java @@ -582,12 +582,12 @@ public class AdminPanel extends CommonPanel // --------------------------------------------------------------------- /** - * This indicate if Reset Challenges must work as reset all. + * This indicates if Reset Challenges must work as reset all. */ private boolean resetAllMode; /** - * This indicate if wipe button should clear all data, or only challenges. + * This indicates if wipe button should clear all data, or only challenges. */ private boolean wipeAll; } \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java index 01ed33d..db7e50b 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengePanel.java @@ -52,11 +52,11 @@ public class EditChallengePanel extends CommonPanel * @param challenge - challenge that needs editing */ private EditChallengePanel(ChallengesAddon addon, - User user, - World world, - String topLabel, - String permissionPrefix, - Challenge challenge) + User user, + World world, + String topLabel, + String permissionPrefix, + Challenge challenge) { super(addon, user, world, topLabel, permissionPrefix); this.challenge = challenge; @@ -88,11 +88,11 @@ public class EditChallengePanel extends CommonPanel * @param challenge - challenge that needs editing */ public static void open(ChallengesAddon addon, - User user, - World world, - String topLabel, - String permissionPrefix, - Challenge challenge) + User user, + World world, + String topLabel, + String permissionPrefix, + Challenge challenge) { new EditChallengePanel(addon, user, world, topLabel, permissionPrefix, challenge).build(); } @@ -122,8 +122,8 @@ public class EditChallengePanel extends CommonPanel protected void build() { PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( - this.user.getTranslation(Constants.TITLE + "edit-challenge", - "[challenge]", this.challenge.getFriendlyName())); + this.user.getTranslation(Constants.TITLE + "edit-challenge", + "[challenge]", this.challenge.getFriendlyName())); PanelUtils.fillBorder(panelBuilder); @@ -139,10 +139,10 @@ public class EditChallengePanel extends CommonPanel { switch (this.challenge.getChallengeType()) { - case INVENTORY_TYPE -> this.buildInventoryRequirementsPanel(panelBuilder); - case ISLAND_TYPE -> this.buildIslandRequirementsPanel(panelBuilder); - case OTHER_TYPE -> this.buildOtherRequirementsPanel(panelBuilder); - case STATISTIC_TYPE -> this.buildStatisticRequirementsPanel(panelBuilder); + case INVENTORY_TYPE -> this.buildInventoryRequirementsPanel(panelBuilder); + case ISLAND_TYPE -> this.buildIslandRequirementsPanel(panelBuilder); + case OTHER_TYPE -> this.buildOtherRequirementsPanel(panelBuilder); + case STATISTIC_TYPE -> this.buildStatisticRequirementsPanel(panelBuilder); } } else if (this.currentMenuType.equals(MenuType.REWARDS)) @@ -257,9 +257,10 @@ public class EditChallengePanel extends CommonPanel { switch (requirements.getStatistic().getType()) { - case ITEM -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ITEMS)); - case BLOCK -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_BLOCKS)); - case ENTITY -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ENTITIES)); + case ITEM -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ITEMS)); + case BLOCK -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_BLOCKS)); + case ENTITY -> panelBuilder.item(13, this.createRequirementButton(RequirementButton.STATISTIC_ENTITIES)); + default -> {} } } @@ -333,50 +334,50 @@ public class EditChallengePanel extends CommonPanel switch (menuType) { - case PROPERTIES -> { - icon = new ItemStack(Material.CRAFTING_TABLE); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.PROPERTIES; - this.build(); + case 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); - } - case REQUIREMENTS -> { - icon = new ItemStack(Material.HOPPER); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.REQUIREMENTS; - this.build(); + return true; + }; + glow = this.currentMenuType.equals(MenuType.PROPERTIES); + } + case 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); - } - case REWARDS -> { - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - this.currentMenuType = MenuType.REWARDS; - this.build(); + return true; + }; + glow = this.currentMenuType.equals(MenuType.REQUIREMENTS); + } + case 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); - } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; - } + return true; + }; + glow = this.currentMenuType.equals(MenuType.REWARDS); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(glow). - clickHandler(clickHandler). - build(); + icon(icon). + name(name). + description(description). + glow(glow). + clickHandler(clickHandler). + build(); } @@ -399,173 +400,173 @@ public class EditChallengePanel extends CommonPanel switch (button) { - case NAME -> { - description.add(this.user.getTranslation(reference + "value", + case NAME -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NAME, this.challenge.getFriendlyName())); - icon = new ItemStack(Material.NAME_TAG); + icon = new ItemStack(Material.NAME_TAG); - clickHandler = (panel, user, clickType, i) -> + clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer consumer = value -> { - // Create consumer that process description change - Consumer consumer = value -> + if (value != null) { - if (value != null) - { - this.challenge.setFriendlyName(value); - } + this.challenge.setFriendlyName(value); + } - this.build(); - }; + this.build(); + }; - // start conversation - ConversationUtils.createStringInput(consumer, + // start conversation + ConversationUtils.createStringInput(consumer, user, user.getTranslation(Constants.CONVERSATIONS + "write-name"), user.getTranslation(Constants.CONVERSATIONS + "name-changed")); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case DEPLOYED -> { - description.add(this.user.getTranslation(reference + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case DEPLOYED -> { + description.add(this.user.getTranslation(reference + (this.challenge.isDeployed() ? "enabled" : "disabled"))); - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - if (this.challenge.isValid()) - { - this.challenge.setDeployed(!this.challenge.isDeployed()); - } - else - { - Utils.sendMessage(this.user, - this.user.getTranslation(Constants.CONVERSATIONS + "invalid-challenge", - "[challenge]", this.challenge.getFriendlyName())); - this.challenge.setDeployed(false); - } - - this.build(); - return true; - }; - glow = this.challenge.isDeployed(); - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); - } - case ICON -> { - icon = this.challenge.getIcon(); - clickHandler = (panel, user, clickType, i) -> + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + if (this.challenge.isValid()) { - this.selectedButton = button; - this.build(); - return true; - }; - glow = this.selectedButton == button; - - if (this.selectedButton != button) - { - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + this.challenge.setDeployed(!this.challenge.isDeployed()); } else { - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-on-item")); + Utils.sendMessage(this.user, + this.user.getTranslation(Constants.CONVERSATIONS + "invalid-challenge", + "[challenge]", this.challenge.getFriendlyName())); + this.challenge.setDeployed(false); } + + this.build(); + return true; + }; + glow = this.challenge.isDeployed(); + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case ICON -> { + icon = this.challenge.getIcon(); + clickHandler = (panel, user, clickType, i) -> + { + this.selectedButton = button; + this.build(); + return true; + }; + glow = this.selectedButton == button; + + if (this.selectedButton != button) + { + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); } - case DESCRIPTION -> { - icon = new ItemStack(Material.WRITTEN_BOOK); + else + { + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-on-item")); + } + } + case DESCRIPTION -> { + icon = new ItemStack(Material.WRITTEN_BOOK); - description.add(this.user.getTranslation(reference + "value")); - this.challenge.getDescription().forEach(line -> description.add(Util.translateColorCodes(line))); + description.add(this.user.getTranslation(reference + "value")); + this.challenge.getDescription().forEach(line -> description.add(Util.translateColorCodes(line))); - clickHandler = (panel, user, clickType, i) -> + clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer> consumer = value -> { - // Create consumer that process description change - Consumer> consumer = value -> + if (value != null) { - if (value != null) - { - this.challenge.setDescription(value); - } - - this.build(); - }; - - if (!this.challenge.getDescription().isEmpty() && clickType.isShiftClick()) - { - // Reset to the empty value - consumer.accept(Collections.emptyList()); + this.challenge.setDescription(value); } - else - { - // start conversation - ConversationUtils.createStringListInput(consumer, + + this.build(); + }; + + if (!this.challenge.getDescription().isEmpty() && clickType.isShiftClick()) + { + // Reset to the empty value + consumer.accept(Collections.emptyList()); + } + else + { + // start conversation + ConversationUtils.createStringListInput(consumer, user, user.getTranslation(Constants.CONVERSATIONS + "write-description"), user.getTranslation(Constants.CONVERSATIONS + "description-changed")); - } - - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - - if (!this.challenge.getDescription().isEmpty()) - { - description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); } + + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + + if (!this.challenge.getDescription().isEmpty()) + { + description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); } - case ORDER -> { - description.add(this.user.getTranslation(reference + "value", + } + case ORDER -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(this.challenge.getOrder()))); - icon = new ItemStack(Material.HOPPER, Math.max(1, this.challenge.getOrder())); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setOrder(number.intValue()); - } + icon = new ItemStack(Material.HOPPER, Math.max(1, this.challenge.getOrder())); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setOrder(number.intValue()); + } - // reopen panel - this.build(); - }; + // reopen panel + this.build(); + }; - ConversationUtils.createNumericInput(numberConsumer, + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, 2000); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case ENVIRONMENT -> { - description.add(this.user.getTranslation(this.challenge.getEnvironment().contains(World.Environment.NORMAL) ? + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case ENVIRONMENT -> { + description.add(this.user.getTranslation(this.challenge.getEnvironment().contains(World.Environment.NORMAL) ? reference + "enabled" : reference + "disabled") + Utils.prettifyObject(World.Environment.NORMAL, this.user)); - description.add(this.user.getTranslation(this.challenge.getEnvironment().contains(World.Environment.NETHER) ? + description.add(this.user.getTranslation(this.challenge.getEnvironment().contains(World.Environment.NETHER) ? reference + "enabled" : reference + "disabled") + Utils.prettifyObject(World.Environment.NETHER, this.user)); - description.add(this.user.getTranslation(this.challenge.getEnvironment().contains(World.Environment.THE_END) ? + description.add(this.user.getTranslation(this.challenge.getEnvironment().contains(World.Environment.THE_END) ? reference + "enabled" : reference + "disabled") + Utils.prettifyObject(World.Environment.THE_END, this.user)); - icon = new ItemStack(Material.DROPPER); - clickHandler = (panel, user, clickType, slot) -> { - EnvironmentSelector.open(this.user, + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + EnvironmentSelector.open(this.user, this.challenge.getEnvironment(), (status, value) -> { if (status) @@ -576,39 +577,39 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; - } - case REMOVE_ON_COMPLETE -> { - description.add(this.user.getTranslation(reference + + return true; + }; + glow = false; + } + case REMOVE_ON_COMPLETE -> { + description.add(this.user.getTranslation(reference + (this.challenge.isRemoveWhenCompleted() ? "enabled" : "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(); - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + if (this.challenge.isRemoveWhenCompleted()) + { + icon = new ItemStack(Material.LAVA_BUCKET); } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; + 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(); + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). @@ -630,94 +631,94 @@ public class EditChallengePanel extends CommonPanel { switch (button) { - case REQUIRED_PERMISSIONS -> { - String reference = Constants.BUTTON + button.name().toLowerCase() + "."; + case REQUIRED_PERMISSIONS -> { + String reference = Constants.BUTTON + button.name().toLowerCase() + "."; - String name = this.user.getTranslation(reference + "name"); - final List description = new ArrayList<>(3); - description.add(this.user.getTranslation(reference + "description")); + String name = this.user.getTranslation(reference + "name"); + final List description = new ArrayList<>(3); + description.add(this.user.getTranslation(reference + "description")); - if (this.challenge.getRequirements().getRequiredPermissions().isEmpty()) + if (this.challenge.getRequirements().getRequiredPermissions().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); + } + else + { + description.add(this.user.getTranslation(reference + "title")); + + this.challenge.getRequirements().getRequiredPermissions().forEach(permission -> + description.add(this.user.getTranslation(reference + "permission", + "[permission]", permission))); + } + + ItemStack icon = new ItemStack(Material.REDSTONE_LAMP); + + PanelItem.ClickHandler clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer> consumer = value -> { - description.add(this.user.getTranslation(reference + "none")); + if (value != null) + { + this.challenge.getRequirements().setRequiredPermissions(new HashSet<>(value)); + } + + this.build(); + }; + + if (!this.challenge.getRequirements().getRequiredPermissions().isEmpty() && + clickType.isShiftClick()) + { + // Reset to the empty value + consumer.accept(Collections.emptyList()); } else { - description.add(this.user.getTranslation(reference + "title")); - - this.challenge.getRequirements().getRequiredPermissions().forEach(permission -> - description.add(this.user.getTranslation(reference + "permission", - "[permission]", permission))); - } - - ItemStack icon = new ItemStack(Material.REDSTONE_LAMP); - - PanelItem.ClickHandler clickHandler = (panel, user, clickType, i) -> - { - // Create consumer that process description change - Consumer> consumer = value -> - { - if (value != null) - { - this.challenge.getRequirements().setRequiredPermissions(new HashSet<>(value)); - } - - this.build(); - }; - - if (!this.challenge.getRequirements().getRequiredPermissions().isEmpty() && - clickType.isShiftClick()) - { - // Reset to the empty value - consumer.accept(Collections.emptyList()); - } - else - { - // start conversation - ConversationUtils.createStringListInput(consumer, + // start conversation + ConversationUtils.createStringListInput(consumer, user, user.getTranslation(Constants.CONVERSATIONS + "write-permissions"), user.getTranslation(Constants.CONVERSATIONS + "permissions-changed")); - } - - return true; - }; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - - if (!this.challenge.getRequirements().getRequiredPermissions().isEmpty()) - { - description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); } - return new PanelItemBuilder(). + return true; + }; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + + if (!this.challenge.getRequirements().getRequiredPermissions().isEmpty()) + { + description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); + } + + return new PanelItemBuilder(). icon(icon). name(name). description(description). clickHandler(clickHandler). build(); - } - // Buttons for Island Requirements - case REQUIRED_ENTITIES, REMOVE_ENTITIES, REQUIRED_BLOCKS, REMOVE_BLOCKS, SEARCH_RADIUS -> { - return this.createIslandRequirementButton(button); - } - // Buttons for Inventory Requirements - case REQUIRED_ITEMS, REMOVE_ITEMS, ADD_IGNORED_META, REMOVE_IGNORED_META -> { - return this.createInventoryRequirementButton(button); - } - // Buttons for Other Requirements - case REQUIRED_EXPERIENCE, REMOVE_EXPERIENCE, REQUIRED_LEVEL, REQUIRED_MONEY, REMOVE_MONEY -> { - return this.createOtherRequirementButton(button); - } - // Buttons for Statistic Requirements - case STATISTIC, STATISTIC_BLOCKS, STATISTIC_ITEMS, STATISTIC_ENTITIES, STATISTIC_AMOUNT, REMOVE_STATISTIC -> { - return this.createStatisticRequirementButton(button); - } - // Default behaviour. - default -> { - return PanelItem.empty(); - } + } + // Buttons for Island Requirements + case REQUIRED_ENTITIES, REMOVE_ENTITIES, REQUIRED_BLOCKS, REMOVE_BLOCKS, SEARCH_RADIUS -> { + return this.createIslandRequirementButton(button); + } + // Buttons for Inventory Requirements + case REQUIRED_ITEMS, REMOVE_ITEMS, ADD_IGNORED_META, REMOVE_IGNORED_META -> { + return this.createInventoryRequirementButton(button); + } + // Buttons for Other Requirements + case REQUIRED_EXPERIENCE, REMOVE_EXPERIENCE, REQUIRED_LEVEL, REQUIRED_MONEY, REMOVE_MONEY -> { + return this.createOtherRequirementButton(button); + } + // Buttons for Statistic Requirements + case STATISTIC, STATISTIC_BLOCKS, STATISTIC_ITEMS, STATISTIC_ENTITIES, STATISTIC_AMOUNT, REMOVE_STATISTIC -> { + return this.createStatisticRequirementButton(button); + } + // Default behaviour. + default -> { + return PanelItem.empty(); + } } } @@ -743,132 +744,132 @@ public class EditChallengePanel extends CommonPanel switch (button) { - case REQUIRED_ENTITIES -> { - if (requirements.getRequiredEntities().isEmpty()) - { - description.add(this.user.getTranslation(reference + "none")); - } - else - { - description.add(this.user.getTranslation(reference + "title")); - - requirements.getRequiredEntities().forEach((entity, count) -> - description.add(this.user.getTranslation(reference + "list", - "[entity]", Utils.prettifyObject(entity, this.user), - "[number]", String.valueOf(count)))); - } - - icon = new ItemStack(Material.CREEPER_HEAD); - clickHandler = (panel, user, clickType, slot) -> { - ManageEntitiesPanel.open(this, requirements.getRequiredEntities()); - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + case REQUIRED_ENTITIES -> { + if (requirements.getRequiredEntities().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); } - case REMOVE_ENTITIES -> { - description.add(this.user.getTranslation(reference + + else + { + description.add(this.user.getTranslation(reference + "title")); + + requirements.getRequiredEntities().forEach((entity, count) -> + description.add(this.user.getTranslation(reference + "list", + "[entity]", Utils.prettifyObject(entity, this.user), + "[number]", String.valueOf(count)))); + } + + icon = new ItemStack(Material.CREEPER_HEAD); + clickHandler = (panel, user, clickType, slot) -> { + ManageEntitiesPanel.open(this, requirements.getRequiredEntities()); + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REMOVE_ENTITIES -> { + description.add(this.user.getTranslation(reference + (requirements.isRemoveEntities() ? "enabled" : "disabled"))); - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - requirements.setRemoveEntities(!requirements.isRemoveEntities()); - this.build(); - return true; - }; - glow = requirements.isRemoveEntities(); + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + requirements.setRemoveEntities(!requirements.isRemoveEntities()); + this.build(); + return true; + }; + glow = requirements.isRemoveEntities(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case REQUIRED_BLOCKS -> { + if (requirements.getRequiredBlocks().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); } - case REQUIRED_BLOCKS -> { - if (requirements.getRequiredBlocks().isEmpty()) - { - description.add(this.user.getTranslation(reference + "none")); - } - else - { - description.add(this.user.getTranslation(reference + "title")); + else + { + description.add(this.user.getTranslation(reference + "title")); - requirements.getRequiredBlocks().forEach((block, count) -> - description.add(this.user.getTranslation(reference + "list", - "[block]", Utils.prettifyObject(block, this.user), - "[number]", String.valueOf(count)))); - } - - icon = new ItemStack(Material.STONE); - clickHandler = (panel, user, clickType, slot) -> { - ManageBlocksPanel.open(this, requirements.getRequiredBlocks()); - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + requirements.getRequiredBlocks().forEach((block, count) -> + description.add(this.user.getTranslation(reference + "list", + "[block]", Utils.prettifyObject(block, this.user), + "[number]", String.valueOf(count)))); } - case REMOVE_BLOCKS -> { - description.add(this.user.getTranslation(reference + + + icon = new ItemStack(Material.STONE); + clickHandler = (panel, user, clickType, slot) -> { + ManageBlocksPanel.open(this, requirements.getRequiredBlocks()); + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REMOVE_BLOCKS -> { + description.add(this.user.getTranslation(reference + (requirements.isRemoveBlocks() ? "enabled" : "disabled"))); - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - requirements.setRemoveBlocks(!requirements.isRemoveBlocks()); - this.build(); - return true; - }; - glow = requirements.isRemoveBlocks(); + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + requirements.setRemoveBlocks(!requirements.isRemoveBlocks()); + this.build(); + return true; + }; + glow = requirements.isRemoveBlocks(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); - } - case SEARCH_RADIUS -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case SEARCH_RADIUS -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(requirements.getSearchRadius()))); - icon = new ItemStack(Material.COBBLESTONE_WALL); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - requirements.setSearchRadius(number.intValue()); - } + icon = new ItemStack(Material.COBBLESTONE_WALL); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + requirements.setSearchRadius(number.intValue()); + } - // reopen panel - this.build(); - }; + // reopen panel + this.build(); + }; - int maxSearchDistance = + int maxSearchDistance = this.addon.getPlugin().getIWM().getAddon(this.world).map(gameModeAddon -> - gameModeAddon.getWorldSettings().getIslandDistance()).orElse(100); + gameModeAddon.getWorldSettings().getIslandDistance()).orElse(100); - ConversationUtils.createNumericInput(numberConsumer, + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 1, maxSearchDistance); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; - } + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(glow). - clickHandler(clickHandler). - build(); + icon(icon). + name(name). + description(description). + glow(glow). + clickHandler(clickHandler). + build(); } @@ -893,27 +894,27 @@ public class EditChallengePanel extends CommonPanel switch (button) { - case REQUIRED_ITEMS -> { - if (requirements.getRequiredItems().isEmpty()) - { - description.add(this.user.getTranslation(reference + "none")); - } - else - { - description.add(this.user.getTranslation(reference + "title")); + case REQUIRED_ITEMS -> { + if (requirements.getRequiredItems().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); + } + else + { + description.add(this.user.getTranslation(reference + "title")); - Utils.groupEqualItems(requirements.getRequiredItems(), requirements.getIgnoreMetaData()). - stream(). - sorted(Comparator.comparing(ItemStack::getType)). - forEach(itemStack -> - description.add(this.user.getTranslationOrNothing(reference + "list", - "[number]", String.valueOf(itemStack.getAmount()), - "[item]", Utils.prettifyObject(itemStack, this.user)))); - } + Utils.groupEqualItems(requirements.getRequiredItems(), requirements.getIgnoreMetaData()). + stream(). + sorted(Comparator.comparing(ItemStack::getType)). + forEach(itemStack -> + description.add(this.user.getTranslationOrNothing(reference + "list", + "[number]", String.valueOf(itemStack.getAmount()), + "[item]", Utils.prettifyObject(itemStack, this.user)))); + } - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, slot) -> { - ItemSelector.open(this.user, + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + ItemSelector.open(this.user, requirements.getRequiredItems(), (status, value) -> { if (status) @@ -923,133 +924,133 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REMOVE_ITEMS -> { - description.add(this.user.getTranslation(reference + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REMOVE_ITEMS -> { + description.add(this.user.getTranslation(reference + (requirements.isTakeItems() ? "enabled" : "disabled"))); - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - requirements.setTakeItems(!requirements.isTakeItems()); - this.build(); - return true; - }; - glow = requirements.isTakeItems(); + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + requirements.setTakeItems(!requirements.isTakeItems()); + this.build(); + return true; + }; + glow = requirements.isTakeItems(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case ADD_IGNORED_META -> { + if (requirements.getIgnoreMetaData().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); } - case ADD_IGNORED_META -> { + else + { + description.add(this.user.getTranslation(reference + "title")); + + requirements.getIgnoreMetaData().stream(). + sorted(Comparator.comparing(Material::name)). + forEach(itemStack -> + description.add(this.user.getTranslationOrNothing(reference + "list", + "[item]", Utils.prettifyObject(itemStack, this.user)))); + } + + icon = new ItemStack(Material.GREEN_SHULKER_BOX); + + clickHandler = (panel, user, clickType, slot) -> { + if (requirements.getRequiredItems().isEmpty()) + { + // Do nothing if no requirements are set. + return true; + } + + // Allow choosing only from inventory items. + Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); + requirements.getRequiredItems().stream(). + map(ItemStack::getType). + forEach(collection::remove); + collection.addAll(requirements.getIgnoreMetaData()); + + if (Material.values().length == collection.size()) + { + // If there are no items anymore, then do not allow opening gui. + return true; + } + + MultiBlockSelector.open(this.user, + MultiBlockSelector.Mode.ANY, + collection, + (status, materials) -> + { + if (status) + { + materials.addAll(requirements.getIgnoreMetaData()); + requirements.setIgnoreMetaData(new HashSet<>(materials)); + } + + this.build(); + }); + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-add")); + } + case REMOVE_IGNORED_META -> { + icon = new ItemStack(Material.RED_SHULKER_BOX); + + clickHandler = (panel, user, clickType, slot) -> { if (requirements.getIgnoreMetaData().isEmpty()) { - description.add(this.user.getTranslation(reference + "none")); + // Do nothing if no requirements are set. + return true; } - else + + // Allow choosing only from inventory items. + Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); + collection.removeAll(requirements.getIgnoreMetaData()); + + MultiBlockSelector.open(this.user, + MultiBlockSelector.Mode.ANY, + collection, + (status, materials) -> { - description.add(this.user.getTranslation(reference + "title")); - - requirements.getIgnoreMetaData().stream(). - sorted(Comparator.comparing(Material::name)). - forEach(itemStack -> - description.add(this.user.getTranslationOrNothing(reference + "list", - "[item]", Utils.prettifyObject(itemStack, this.user)))); - } - - icon = new ItemStack(Material.GREEN_SHULKER_BOX); - - clickHandler = (panel, user, clickType, slot) -> { - if (requirements.getRequiredItems().isEmpty()) + if (status) { - // Do nothing if no requirements are set. - return true; + requirements.getIgnoreMetaData().removeAll(materials); } - // Allow choosing only from inventory items. - Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); - requirements.getRequiredItems().stream(). - map(ItemStack::getType). - forEach(collection::remove); - collection.addAll(requirements.getIgnoreMetaData()); + this.build(); + }); + return true; + }; + glow = false; - if (Material.values().length == collection.size()) - { - // If there are no items anymore, then do not allow opening gui. - return true; - } - - MultiBlockSelector.open(this.user, - MultiBlockSelector.Mode.ANY, - collection, - (status, materials) -> - { - if (status) - { - materials.addAll(requirements.getIgnoreMetaData()); - requirements.setIgnoreMetaData(new HashSet<>(materials)); - } - - this.build(); - }); - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-add")); - } - case REMOVE_IGNORED_META -> { - icon = new ItemStack(Material.RED_SHULKER_BOX); - - clickHandler = (panel, user, clickType, slot) -> { - if (requirements.getIgnoreMetaData().isEmpty()) - { - // Do nothing if no requirements are set. - return true; - } - - // Allow choosing only from inventory items. - Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); - collection.removeAll(requirements.getIgnoreMetaData()); - - MultiBlockSelector.open(this.user, - MultiBlockSelector.Mode.ANY, - collection, - (status, materials) -> - { - if (status) - { - requirements.getIgnoreMetaData().removeAll(materials); - } - - this.build(); - }); - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-remove")); - } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; - } + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-remove")); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(glow). - clickHandler(clickHandler). - build(); + icon(icon). + name(name). + description(description). + glow(glow). + clickHandler(clickHandler). + build(); } @@ -1074,131 +1075,131 @@ public class EditChallengePanel extends CommonPanel switch (button) { - case REQUIRED_EXPERIENCE -> { - description.add(this.user.getTranslation(reference + "value", + case REQUIRED_EXPERIENCE -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(requirements.getRequiredExperience()))); - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - requirements.setRequiredExperience(number.intValue()); - } + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + requirements.setRequiredExperience(number.intValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REMOVE_EXPERIENCE -> { - description.add(this.user.getTranslation(reference + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REMOVE_EXPERIENCE -> { + description.add(this.user.getTranslation(reference + (requirements.isTakeExperience() ? "enabled" : "disabled"))); - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - requirements.setTakeExperience(!requirements.isTakeExperience()); - this.build(); - return true; - }; - glow = requirements.isTakeExperience(); + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + requirements.setTakeExperience(!requirements.isTakeExperience()); + this.build(); + return true; + }; + glow = requirements.isTakeExperience(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); - } - case REQUIRED_LEVEL -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case REQUIRED_LEVEL -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(requirements.getRequiredIslandLevel()))); - icon = new ItemStack(this.addon.isLevelProvided() ? Material.BEACON : Material.BARRIER); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - requirements.setRequiredIslandLevel(number.longValue()); - } + icon = new ItemStack(this.addon.isLevelProvided() ? Material.BEACON : Material.BARRIER); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + requirements.setRequiredIslandLevel(number.longValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REQUIRED_MONEY -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REQUIRED_MONEY -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(requirements.getRequiredMoney()))); - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - requirements.setRequiredMoney(number.doubleValue()); - } + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + requirements.setRequiredMoney(number.doubleValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Double.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REMOVE_MONEY -> { - description.add(this.user.getTranslation(reference + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REMOVE_MONEY -> { + description.add(this.user.getTranslation(reference + (requirements.isTakeMoney() ? "enabled" : "disabled"))); - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.LEVER : Material.BARRIER); - clickHandler = (panel, user, clickType, slot) -> { - requirements.setTakeMoney(!requirements.isTakeMoney()); - this.build(); - return true; - }; - glow = requirements.isTakeMoney(); + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.LEVER : Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + requirements.setTakeMoney(!requirements.isTakeMoney()); + this.build(); + return true; + }; + glow = requirements.isTakeMoney(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); - } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; - } + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(glow). - clickHandler(clickHandler). - build(); + icon(icon). + name(name). + description(description). + glow(glow). + clickHandler(clickHandler). + build(); } @@ -1223,81 +1224,81 @@ public class EditChallengePanel extends CommonPanel switch (button) { - case STATISTIC -> { - description.add(this.user.getTranslation(reference + "value", + case STATISTIC -> { + description.add(this.user.getTranslation(reference + "value", "[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user))); - icon = new ItemStack(requirements.getStatistic() == null ? Material.BARRIER : Material.PAPER); - clickHandler = (panel, user, clickType, slot) -> { - StatisticSelector.open(this.user, (status, statistic) -> { - if (status) - { - requirements.setStatistic(statistic); - requirements.setMaterial(null); - requirements.setEntity(null); - requirements.setAmount(0); - } + icon = new ItemStack(requirements.getStatistic() == null ? Material.BARRIER : Material.PAPER); + clickHandler = (panel, user, clickType, slot) -> { + StatisticSelector.open(this.user, (status, statistic) -> { + if (status) + { + requirements.setStatistic(statistic); + requirements.setMaterial(null); + requirements.setEntity(null); + requirements.setAmount(0); + } - this.build(); - }); - return true; - }; - glow = false; + this.build(); + }); + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case STATISTIC_AMOUNT -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case STATISTIC_AMOUNT -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(requirements.getAmount()))); - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - requirements.setAmount(number.intValue()); - } + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + requirements.setAmount(number.intValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REMOVE_STATISTIC -> { - description.add(this.user.getTranslation(reference + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REMOVE_STATISTIC -> { + description.add(this.user.getTranslation(reference + (requirements.isReduceStatistic() ? "enabled" : "disabled"))); - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - requirements.setReduceStatistic(!requirements.isReduceStatistic()); - this.build(); - return true; - }; - glow = requirements.isReduceStatistic(); + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + requirements.setReduceStatistic(!requirements.isReduceStatistic()); + this.build(); + return true; + }; + glow = requirements.isReduceStatistic(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); - } - case STATISTIC_BLOCKS -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case STATISTIC_BLOCKS -> { + description.add(this.user.getTranslation(reference + "value", "[block]", Utils.prettifyObject(requirements.getMaterial(), this.user))); - icon = requirements.getMaterial() == null ? + icon = requirements.getMaterial() == null ? new ItemStack(Material.BARRIER) : - new ItemStack(requirements.getMaterial()); - clickHandler = (panel, user, clickType, slot) -> { - SingleBlockSelector.open(this.user, + new ItemStack(requirements.getMaterial()); + clickHandler = (panel, user, clickType, slot) -> { + SingleBlockSelector.open(this.user, SingleBlockSelector.Mode.BLOCKS, (status, block) -> { if (status) @@ -1308,22 +1309,22 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case STATISTIC_ITEMS -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case STATISTIC_ITEMS -> { + description.add(this.user.getTranslation(reference + "value", "[item]", Utils.prettifyObject(requirements.getMaterial(), this.user))); - icon = requirements.getMaterial() == null ? + icon = requirements.getMaterial() == null ? new ItemStack(Material.BARRIER) : - new ItemStack(requirements.getMaterial()); - clickHandler = (panel, user, clickType, slot) -> { - SingleBlockSelector.open(this.user, + new ItemStack(requirements.getMaterial()); + clickHandler = (panel, user, clickType, slot) -> { + SingleBlockSelector.open(this.user, SingleBlockSelector.Mode.ITEMS, (status, block) -> { if (status) @@ -1334,22 +1335,22 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case STATISTIC_ENTITIES -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case STATISTIC_ENTITIES -> { + description.add(this.user.getTranslation(reference + "value", "[entity]", Utils.prettifyObject(requirements.getEntity(), this.user))); - icon = requirements.getEntity() == null ? + icon = requirements.getEntity() == null ? new ItemStack(Material.BARRIER) : - new ItemStack(PanelUtils.getEntityEgg(requirements.getEntity())); - clickHandler = (panel, user, clickType, slot) -> { - SingleEntitySelector.open(this.user, + new ItemStack(PanelUtils.getEntityEgg(requirements.getEntity())); + clickHandler = (panel, user, clickType, slot) -> { + SingleEntitySelector.open(this.user, true, (status, entity) -> { if (status) @@ -1360,27 +1361,27 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; - } + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(glow). - clickHandler(clickHandler). - build(); + icon(icon). + name(name). + description(description). + glow(glow). + clickHandler(clickHandler). + build(); } @@ -1403,74 +1404,74 @@ public class EditChallengePanel extends CommonPanel switch (button) { - case REWARD_TEXT -> { - icon = new ItemStack(Material.WRITTEN_BOOK); + case REWARD_TEXT -> { + icon = new ItemStack(Material.WRITTEN_BOOK); - description.add(this.user.getTranslation(reference + "value")); - description.add(Util.translateColorCodes(this.challenge.getRewardText())); + description.add(this.user.getTranslation(reference + "value")); + description.add(Util.translateColorCodes(this.challenge.getRewardText())); - clickHandler = (panel, user, clickType, i) -> + clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer> consumer = value -> { - // Create consumer that process description change - Consumer> consumer = value -> + if (value != null) { - if (value != null) - { - this.challenge.setRewardText(String.join("\n", value)); - } - - this.build(); - }; - - if (!this.challenge.getRewardText().isEmpty() && clickType.isShiftClick()) - { - // Reset to the empty value - consumer.accept(Collections.emptyList()); - } - else - { - // start conversation - ConversationUtils.createStringListInput(consumer, - user, - user.getTranslation(Constants.CONVERSATIONS + "write-reward-text"), - user.getTranslation(Constants.CONVERSATIONS + "reward-text-changed")); + this.challenge.setRewardText(String.join("\n", value)); } - - return true; + this.build(); }; - glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - - if (!this.challenge.getRewardText().isEmpty()) + if (!this.challenge.getRewardText().isEmpty() && clickType.isShiftClick()) { - description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); - } - } - case REWARD_ITEMS -> { - - if (this.challenge.getRewardItems().isEmpty()) - { - description.add(this.user.getTranslation(reference + "none")); + // Reset to the empty value + consumer.accept(Collections.emptyList()); } else { - description.add(this.user.getTranslation(reference + "title")); - - Utils.groupEqualItems(this.challenge.getRewardItems(), this.challenge.getIgnoreRewardMetaData()). - stream(). - sorted(Comparator.comparing(ItemStack::getType)). - forEach(itemStack -> - description.add(this.user.getTranslationOrNothing(reference + "list", - "[number]", String.valueOf(itemStack.getAmount()), - "[item]", Utils.prettifyObject(itemStack, this.user)))); + // start conversation + ConversationUtils.createStringListInput(consumer, + user, + user.getTranslation(Constants.CONVERSATIONS + "write-reward-text"), + user.getTranslation(Constants.CONVERSATIONS + "reward-text-changed")); } - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, slot) -> { - ItemSelector.open(this.user, + + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + + if (!this.challenge.getRewardText().isEmpty()) + { + description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); + } + } + case REWARD_ITEMS -> { + + if (this.challenge.getRewardItems().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); + } + else + { + description.add(this.user.getTranslation(reference + "title")); + + Utils.groupEqualItems(this.challenge.getRewardItems(), this.challenge.getIgnoreRewardMetaData()). + stream(). + sorted(Comparator.comparing(ItemStack::getType)). + forEach(itemStack -> + description.add(this.user.getTranslationOrNothing(reference + "list", + "[number]", String.valueOf(itemStack.getAmount()), + "[item]", Utils.prettifyObject(itemStack, this.user)))); + } + + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + ItemSelector.open(this.user, this.challenge.getRewardItems(), (status, value) -> { if (status) @@ -1481,249 +1482,249 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REWARD_EXPERIENCE -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REWARD_EXPERIENCE -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(this.challenge.getRewardExperience()))); - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setRewardExperience(number.intValue()); - } + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setRewardExperience(number.intValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REWARD_MONEY -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REWARD_MONEY -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(this.challenge.getRewardMoney()))); - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setRewardMoney(number.doubleValue()); - } + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_INGOT : Material.BARRIER); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setRewardMoney(number.doubleValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Double.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REWARD_COMMANDS -> { - icon = new ItemStack(Material.COMMAND_BLOCK); + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REWARD_COMMANDS -> { + icon = new ItemStack(Material.COMMAND_BLOCK); - description.add(this.user.getTranslation(reference + "value")); - description.addAll(this.challenge.getRewardCommands()); + description.add(this.user.getTranslation(reference + "value")); + description.addAll(this.challenge.getRewardCommands()); - clickHandler = (panel, user, clickType, i) -> + clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer> consumer = value -> { - // Create consumer that process description change - Consumer> consumer = value -> + if (value != null) { - if (value != null) - { - this.challenge.setRewardCommands(value); - } - - this.build(); - }; - - if (!this.challenge.getRewardCommands().isEmpty() && clickType.isShiftClick()) - { - // Reset to the empty value - consumer.accept(Collections.emptyList()); + this.challenge.setRewardCommands(value); } - else - { - // start conversation - ConversationUtils.createStringListInput(consumer, + + this.build(); + }; + + if (!this.challenge.getRewardCommands().isEmpty() && clickType.isShiftClick()) + { + // Reset to the empty value + consumer.accept(Collections.emptyList()); + } + else + { + // start conversation + ConversationUtils.createStringListInput(consumer, user, user.getTranslation(Constants.CONVERSATIONS + "write-reward-commands"), user.getTranslation(Constants.CONVERSATIONS + "reward-commands-changed")); - } - - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - - if (!this.challenge.getRewardCommands().isEmpty()) - { - description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); } + + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + + if (!this.challenge.getRewardCommands().isEmpty()) + { + description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); } - case REPEATABLE -> { - description.add(this.user.getTranslation(reference + + } + case REPEATABLE -> { + description.add(this.user.getTranslation(reference + (this.challenge.isRepeatable() ? "enabled" : "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(); + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRepeatable(!this.challenge.isRepeatable()); + this.build(); + return true; + }; + glow = this.challenge.isRepeatable(); - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); - } - case REPEAT_COUNT -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle")); + } + case REPEAT_COUNT -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(this.challenge.getMaxTimes()))); - icon = new ItemStack(Material.COBBLESTONE_WALL); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setMaxTimes(number.intValue()); - } + icon = new ItemStack(Material.COBBLESTONE_WALL); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setMaxTimes(number.intValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case COOL_DOWN -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case COOL_DOWN -> { + description.add(this.user.getTranslation(reference + "value", "[time]", Utils.parseDuration(Duration.ofMillis(this.challenge.getTimeout()), this.user))); - icon = new ItemStack(Material.CLOCK); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setTimeout(number.longValue() * 1000); - } + icon = new ItemStack(Material.CLOCK); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setTimeout(number.longValue() * 1000); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-seconds"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REPEAT_REWARD_TEXT -> { - icon = new ItemStack(Material.WRITTEN_BOOK); + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REPEAT_REWARD_TEXT -> { + icon = new ItemStack(Material.WRITTEN_BOOK); - description.add(this.user.getTranslation(reference + "value")); - description.add(Util.translateColorCodes(this.challenge.getRepeatRewardText())); + description.add(this.user.getTranslation(reference + "value")); + description.add(Util.translateColorCodes(this.challenge.getRepeatRewardText())); - clickHandler = (panel, user, clickType, i) -> + clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer> consumer = value -> { - // Create consumer that process description change - Consumer> consumer = value -> + if (value != null) { - if (value != null) - { - this.challenge.setRepeatRewardText(String.join("\n", value)); - } - - this.build(); - }; - - if (!this.challenge.getRepeatRewardText().isEmpty() && clickType.isShiftClick()) - { - // Reset to the empty value - consumer.accept(Collections.emptyList()); - } - else - { - // start conversation - ConversationUtils.createStringListInput(consumer, - user, - user.getTranslation(Constants.CONVERSATIONS + "write-repeat-reward-text"), - user.getTranslation(Constants.CONVERSATIONS + "repeat-reward-text-changed")); + this.challenge.setRepeatRewardText(String.join("\n", value)); } - return true; + this.build(); }; - glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - - if (!this.challenge.getRepeatRewardText().isEmpty()) + if (!this.challenge.getRepeatRewardText().isEmpty() && clickType.isShiftClick()) { - description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); - } - } - case REPEAT_REWARD_ITEMS -> { - - if (this.challenge.getRepeatItemReward().isEmpty()) - { - description.add(this.user.getTranslation(reference + "none")); + // Reset to the empty value + consumer.accept(Collections.emptyList()); } else { - description.add(this.user.getTranslation(reference + "title")); - - Utils.groupEqualItems(this.challenge.getRepeatItemReward(), this.challenge.getIgnoreRewardMetaData()). - stream(). - sorted(Comparator.comparing(ItemStack::getType)). - forEach(itemStack -> - description.add(this.user.getTranslationOrNothing(reference + "list", - "[number]", String.valueOf(itemStack.getAmount()), - "[item]", Utils.prettifyObject(itemStack, this.user)))); + // start conversation + ConversationUtils.createStringListInput(consumer, + user, + user.getTranslation(Constants.CONVERSATIONS + "write-repeat-reward-text"), + user.getTranslation(Constants.CONVERSATIONS + "repeat-reward-text-changed")); } - icon = new ItemStack(Material.CHEST); - clickHandler = (panel, user, clickType, slot) -> { - ItemSelector.open(this.user, + return true; + }; + glow = false; + + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + + if (!this.challenge.getRepeatRewardText().isEmpty()) + { + description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); + } + } + case REPEAT_REWARD_ITEMS -> { + + if (this.challenge.getRepeatItemReward().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); + } + else + { + description.add(this.user.getTranslation(reference + "title")); + + Utils.groupEqualItems(this.challenge.getRepeatItemReward(), this.challenge.getIgnoreRewardMetaData()). + stream(). + sorted(Comparator.comparing(ItemStack::getType)). + forEach(itemStack -> + description.add(this.user.getTranslationOrNothing(reference + "list", + "[number]", String.valueOf(itemStack.getAmount()), + "[item]", Utils.prettifyObject(itemStack, this.user)))); + } + + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + ItemSelector.open(this.user, this.challenge.getRewardItems(), (status, value) -> { if (status) @@ -1734,221 +1735,221 @@ public class EditChallengePanel extends CommonPanel this.build(); }); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REPEAT_REWARD_EXPERIENCE -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REPEAT_REWARD_EXPERIENCE -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(this.challenge.getRepeatExperienceReward()))); - icon = new ItemStack(Material.EXPERIENCE_BOTTLE); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setRepeatExperienceReward(number.intValue()); - } + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setRepeatExperienceReward(number.intValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Integer.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REPEAT_REWARD_MONEY -> { - description.add(this.user.getTranslation(reference + "value", + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REPEAT_REWARD_MONEY -> { + description.add(this.user.getTranslation(reference + "value", Constants.PARAMETER_NUMBER, String.valueOf(this.challenge.getRepeatMoneyReward()))); - icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_NUGGET : Material.BARRIER); - clickHandler = (panel, user, clickType, i) -> { - Consumer numberConsumer = number -> { - if (number != null) - { - this.challenge.setRepeatMoneyReward(number.doubleValue()); - } + icon = new ItemStack(this.addon.isEconomyProvided() ? Material.GOLD_NUGGET : Material.BARRIER); + clickHandler = (panel, user, clickType, i) -> { + Consumer numberConsumer = number -> { + if (number != null) + { + this.challenge.setRepeatMoneyReward(number.doubleValue()); + } - // reopen panel - this.build(); - }; - ConversationUtils.createNumericInput(numberConsumer, + // reopen panel + this.build(); + }; + ConversationUtils.createNumericInput(numberConsumer, this.user, this.user.getTranslation(Constants.CONVERSATIONS + "input-number"), 0, Double.MAX_VALUE); - return true; - }; - glow = false; + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - } - case REPEAT_REWARD_COMMANDS -> { - icon = new ItemStack(Material.COMMAND_BLOCK); + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + } + case REPEAT_REWARD_COMMANDS -> { + icon = new ItemStack(Material.COMMAND_BLOCK); - description.add(this.user.getTranslation(reference + "value")); - description.addAll(this.challenge.getRepeatRewardCommands()); + description.add(this.user.getTranslation(reference + "value")); + description.addAll(this.challenge.getRepeatRewardCommands()); - clickHandler = (panel, user, clickType, i) -> + clickHandler = (panel, user, clickType, i) -> + { + // Create consumer that process description change + Consumer> consumer = value -> { - // Create consumer that process description change - Consumer> consumer = value -> + if (value != null) { - if (value != null) - { - this.challenge.setRepeatRewardCommands(value); - } - - this.build(); - }; - - if (!this.challenge.getRepeatRewardCommands().isEmpty() && clickType.isShiftClick()) - { - // Reset to the empty value - consumer.accept(Collections.emptyList()); - } - else - { - // start conversation - ConversationUtils.createStringListInput(consumer, - user, - user.getTranslation(Constants.CONVERSATIONS + "write-repeat-reward-commands"), - user.getTranslation(Constants.CONVERSATIONS + "repeat-reward-commands-changed")); + this.challenge.setRepeatRewardCommands(value); } - return true; + this.build(); }; - glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); - - if (!this.challenge.getRepeatRewardCommands().isEmpty()) + if (!this.challenge.getRepeatRewardCommands().isEmpty() && clickType.isShiftClick()) { - description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); - } - } - case ADD_IGNORED_META -> { - if (this.challenge.getIgnoreRewardMetaData().isEmpty()) - { - description.add(this.user.getTranslation(reference + "none")); + // Reset to the empty value + consumer.accept(Collections.emptyList()); } else { - description.add(this.user.getTranslation(reference + "title")); - - this.challenge.getIgnoreRewardMetaData().stream(). - sorted(Comparator.comparing(Material::name)). - forEach(itemStack -> - description.add(this.user.getTranslationOrNothing(reference + "list", - "[item]", Utils.prettifyObject(itemStack, this.user)))); + // start conversation + ConversationUtils.createStringListInput(consumer, + user, + user.getTranslation(Constants.CONVERSATIONS + "write-repeat-reward-commands"), + user.getTranslation(Constants.CONVERSATIONS + "repeat-reward-commands-changed")); } - icon = new ItemStack(Material.GREEN_SHULKER_BOX); + return true; + }; + glow = false; - clickHandler = (panel, user, clickType, slot) -> { - if (this.challenge.getRewardItems().isEmpty() && + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-change")); + + if (!this.challenge.getRepeatRewardCommands().isEmpty()) + { + description.add(this.user.getTranslation(Constants.TIPS + "shift-click-to-reset")); + } + } + case ADD_IGNORED_META -> { + if (this.challenge.getIgnoreRewardMetaData().isEmpty()) + { + description.add(this.user.getTranslation(reference + "none")); + } + else + { + description.add(this.user.getTranslation(reference + "title")); + + this.challenge.getIgnoreRewardMetaData().stream(). + sorted(Comparator.comparing(Material::name)). + forEach(itemStack -> + description.add(this.user.getTranslationOrNothing(reference + "list", + "[item]", Utils.prettifyObject(itemStack, this.user)))); + } + + icon = new ItemStack(Material.GREEN_SHULKER_BOX); + + clickHandler = (panel, user, clickType, slot) -> { + if (this.challenge.getRewardItems().isEmpty() && this.challenge.getRepeatItemReward().isEmpty()) - { - // Do nothing if no requirements are set. - return true; - } + { + // Do nothing if no requirements are set. + return true; + } - // Allow choosing only from inventory items. - Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); - this.challenge.getRewardItems().stream(). - map(ItemStack::getType). - forEach(collection::remove); - this.challenge.getRepeatItemReward().stream(). - map(ItemStack::getType). - forEach(collection::remove); - collection.addAll(this.challenge.getIgnoreRewardMetaData()); + // Allow choosing only from inventory items. + Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); + this.challenge.getRewardItems().stream(). + map(ItemStack::getType). + forEach(collection::remove); + this.challenge.getRepeatItemReward().stream(). + map(ItemStack::getType). + forEach(collection::remove); + collection.addAll(this.challenge.getIgnoreRewardMetaData()); - if (Material.values().length == collection.size()) - { - // If there are no items anymore, then do not allow opening gui. - return true; - } + if (Material.values().length == collection.size()) + { + // If there are no items anymore, then do not allow opening gui. + return true; + } - MultiBlockSelector.open(this.user, + MultiBlockSelector.open(this.user, MultiBlockSelector.Mode.ANY, collection, (status, materials) -> - { - if (status) - { - materials.addAll(this.challenge.getIgnoreRewardMetaData()); - this.challenge.setIgnoreRewardMetaData(new HashSet<>(materials)); - } - - this.build(); - }); - return true; - }; - glow = false; - - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-add")); - } - case REMOVE_IGNORED_META -> { - icon = new ItemStack(Material.RED_SHULKER_BOX); - - clickHandler = (panel, user, clickType, slot) -> { - if (this.challenge.getIgnoreRewardMetaData().isEmpty()) + { + if (status) { - // Do nothing if no requirements are set. - return true; + materials.addAll(this.challenge.getIgnoreRewardMetaData()); + this.challenge.setIgnoreRewardMetaData(new HashSet<>(materials)); } - // Allow choosing only from inventory items. - Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); - collection.removeAll(this.challenge.getIgnoreRewardMetaData()); + this.build(); + }); + return true; + }; + glow = false; - MultiBlockSelector.open(this.user, + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-add")); + } + case REMOVE_IGNORED_META -> { + icon = new ItemStack(Material.RED_SHULKER_BOX); + + clickHandler = (panel, user, clickType, slot) -> { + if (this.challenge.getIgnoreRewardMetaData().isEmpty()) + { + // Do nothing if no requirements are set. + return true; + } + + // Allow choosing only from inventory items. + Set collection = Arrays.stream(Material.values()).collect(Collectors.toSet()); + collection.removeAll(this.challenge.getIgnoreRewardMetaData()); + + MultiBlockSelector.open(this.user, MultiBlockSelector.Mode.ANY, collection, (status, materials) -> - { - if (status) - { - this.challenge.getIgnoreRewardMetaData().removeAll(materials); - } + { + if (status) + { + this.challenge.getIgnoreRewardMetaData().removeAll(materials); + } - this.build(); - }); - return true; - }; - glow = false; + this.build(); + }); + return true; + }; + glow = false; - description.add(""); - description.add(this.user.getTranslation(Constants.TIPS + "click-to-remove")); - } - default -> { - icon = new ItemStack(Material.PAPER); - clickHandler = null; - glow = false; - } + description.add(""); + description.add(this.user.getTranslation(Constants.TIPS + "click-to-remove")); + } + default -> { + icon = new ItemStack(Material.PAPER); + clickHandler = null; + glow = false; + } } return new PanelItemBuilder(). - icon(icon). - name(name). - description(description). - glow(glow). - clickHandler(clickHandler). - build(); + icon(icon). + name(name). + description(description). + glow(glow). + clickHandler(clickHandler). + build(); } // --------------------------------------------------------------------- @@ -1973,9 +1974,9 @@ public class EditChallengePanel extends CommonPanel { // Handle icon changing if (EditChallengePanel.this.selectedButton != null && - event.getCurrentItem() != null && - !event.getCurrentItem().getType().equals(Material.AIR) && - event.getRawSlot() > 44) + event.getCurrentItem() != null && + !event.getCurrentItem().getType().equals(Material.AIR) && + event.getRawSlot() > 44) { // set material and amount only. Other data should be removed. diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersPanel.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersPanel.java index 2a6aab3..1fb3596 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersPanel.java @@ -334,13 +334,12 @@ public class ListUsersPanel extends CommonPagedPanel if (clickType.isRightClick()) { this.mode = Utils.getPreviousValue(ViewMode.values(), this.mode); - this.onlineUsers = this.collectUsers(this.mode); } else { this.mode = Utils.getNextValue(ViewMode.values(), this.mode); - this.onlineUsers = this.collectUsers(this.mode); } + this.onlineUsers = this.collectUsers(this.mode); // Reset search this.searchString = ""; diff --git a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java index 9ac4a42..6b8c161 100644 --- a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java @@ -273,7 +273,6 @@ public class TryToComplete { Bukkit.getOnlinePlayers().stream(). map(User::getInstance). - filter(Objects::nonNull). forEach(user -> Utils.sendMessage(user, user.getTranslation( "challenges.messages.name-has-completed-challenge", Constants.PARAMETER_NAME, this.user.getName(), @@ -380,7 +379,6 @@ public class TryToComplete { Bukkit.getOnlinePlayers().stream(). map(User::getInstance). - filter(Objects::nonNull). forEach(user -> Utils.sendMessage(user, user.getTranslation( "challenges.messages.name-has-completed-level", Constants.PARAMETER_NAME, this.user.getName(), diff --git a/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java b/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java index ec052c7..2fc13f2 100644 --- a/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java +++ b/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java @@ -14,10 +14,9 @@ import static org.mockito.Mockito.when; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -154,7 +153,7 @@ public class ChallengesAddonTest { File jFile = new File("addon.jar"); List lines = Arrays.asList("# ChallengesAddon Configuration", "uniqueId: config"); Path path = Paths.get("config.yml"); - Files.write(path, lines, Charset.forName("UTF-8")); + Files.write(path, lines, StandardCharsets.UTF_8); try (JarOutputStream tempJarOutputStream = new JarOutputStream(new FileOutputStream(jFile))) { addToJar(tempJarOutputStream, path); addToJar(tempJarOutputStream, Paths.get("src/main/resources/panels/gamemode_panel.yml")); @@ -206,7 +205,7 @@ public class ChallengesAddonTest { } - private void addToJar(JarOutputStream tempJarOutputStream, Path path) throws FileNotFoundException, IOException { + private void addToJar(JarOutputStream tempJarOutputStream, Path path) throws IOException { //Added the new files to the jar. try (FileInputStream fis = new FileInputStream(path.toFile())) { diff --git a/src/test/java/world/bentobox/challenges/ChallengesManagerTest.java b/src/test/java/world/bentobox/challenges/ChallengesManagerTest.java index af1d35a..06891d4 100644 --- a/src/test/java/world/bentobox/challenges/ChallengesManagerTest.java +++ b/src/test/java/world/bentobox/challenges/ChallengesManagerTest.java @@ -16,7 +16,6 @@ import static org.mockito.Mockito.when; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -105,10 +104,9 @@ public class ChallengesManagerTest { // Variable fields private ChallengesManager cm; private File database; - private String uuid; private Challenge challenge; private @NonNull ChallengeLevel level; - private UUID playerID = UUID.randomUUID(); + private final UUID playerID = UUID.randomUUID(); private String cName; private String levelName; @@ -159,7 +157,7 @@ public class ChallengesManagerTest { // Challenge challenge = new Challenge(); - uuid = UUID.randomUUID().toString(); + String uuid = UUID.randomUUID().toString(); challenge.setUniqueId(GAME_MODE_NAME + "_" + uuid); challenge.setFriendlyName("name"); challenge.setLevel(GAME_MODE_NAME + "_novice"); @@ -438,7 +436,7 @@ public class ChallengesManagerTest { removeLine(check); } - private boolean removeLine(File inputFile) { + private void removeLine(File inputFile) { File tempFile = new File("myTempFile.json"); try (BufferedReader reader = new BufferedReader(new FileReader(inputFile))) { @@ -454,13 +452,11 @@ public class ChallengesManagerTest { writer.write(currentLine + System.getProperty("line.separator")); } } - } catch (FileNotFoundException e) { - e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } - return tempFile.renameTo(inputFile); + tempFile.renameTo(inputFile); } /** * Test method for {@link ChallengesManager#saveLevel(world.bentobox.challenges.database.object.ChallengeLevel)}. diff --git a/src/test/java/world/bentobox/challenges/commands/ChallengesCommandTest.java b/src/test/java/world/bentobox/challenges/commands/ChallengesCommandTest.java index 11182ea..5d12e2a 100644 --- a/src/test/java/world/bentobox/challenges/commands/ChallengesCommandTest.java +++ b/src/test/java/world/bentobox/challenges/commands/ChallengesCommandTest.java @@ -60,7 +60,6 @@ public class ChallengesCommandTest { @Mock private CompositeCommand ic; - private UUID uuid; @Mock private User user; @Mock @@ -79,13 +78,10 @@ public class ChallengesCommandTest { @Mock private GameModeAddon gameModeAddon; - private Settings settings; - /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { // Set up plugin BentoBox plugin = mock(BentoBox.class); Whitebox.setInternalState(BentoBox.class, "instance", plugin); @@ -125,7 +121,7 @@ public class ChallengesCommandTest { Player p = mock(Player.class); // Sometimes use Mockito.withSettings().verboseLogging() when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); + UUID uuid = UUID.randomUUID(); when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); @@ -152,7 +148,7 @@ public class ChallengesCommandTest { when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(1, String.class)); // Settings - settings = new Settings(); + Settings settings = new Settings(); when(addon.getChallengesSettings()).thenReturn(settings); settings.setVisibilityMode(VisibilityMode.VISIBLE); diff --git a/src/test/java/world/bentobox/challenges/commands/CompleteChallengeCommandTest.java b/src/test/java/world/bentobox/challenges/commands/CompleteChallengeCommandTest.java index d118b59..5b9e4f4 100644 --- a/src/test/java/world/bentobox/challenges/commands/CompleteChallengeCommandTest.java +++ b/src/test/java/world/bentobox/challenges/commands/CompleteChallengeCommandTest.java @@ -25,7 +25,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.meta.ItemMeta; import org.eclipse.jdt.annotation.NonNull; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -64,7 +63,6 @@ public class CompleteChallengeCommandTest { @Mock private CompositeCommand ic; - private UUID uuid; @Mock private User user; @Mock @@ -84,16 +82,14 @@ public class CompleteChallengeCommandTest { @Mock private GameModeAddon gameModeAddon; - private Settings settings; @Mock private Challenge challenge; /** - * @throws java.lang.Exception */ @SuppressWarnings("unchecked") @Before - public void setUp() throws Exception { + public void setUp() { // Set up plugin BentoBox plugin = mock(BentoBox.class); Whitebox.setInternalState(BentoBox.class, "instance", plugin); @@ -129,7 +125,7 @@ public class CompleteChallengeCommandTest { Player p = mock(Player.class); // Sometimes use Mockito.withSettings().verboseLogging() when(user.isOp()).thenReturn(false); - uuid = UUID.randomUUID(); + UUID uuid = UUID.randomUUID(); when(user.getUniqueId()).thenReturn(uuid); when(user.getPlayer()).thenReturn(p); when(user.getName()).thenReturn("tastybento"); @@ -159,7 +155,7 @@ public class CompleteChallengeCommandTest { when(ChatColor.translateAlternateColorCodes(any(char.class), anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(1, String.class)); // Settings - settings = new Settings(); + Settings settings = new Settings(); when(addon.getChallengesSettings()).thenReturn(settings); settings.setVisibilityMode(VisibilityMode.VISIBLE); @@ -184,13 +180,6 @@ public class CompleteChallengeCommandTest { cc = new CompleteChallengeCommand(addon, ic); } - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Test method for {@link world.bentobox.challenges.commands.CompleteChallengeCommand#CompleteChallengeCommand(world.bentobox.bentobox.api.addons.Addon, world.bentobox.bentobox.api.commands.CompositeCommand)}. */ diff --git a/src/test/java/world/bentobox/challenges/commands/TestWorldSetting.java b/src/test/java/world/bentobox/challenges/commands/TestWorldSetting.java index 264bb92..f2e7b8b 100644 --- a/src/test/java/world/bentobox/challenges/commands/TestWorldSetting.java +++ b/src/test/java/world/bentobox/challenges/commands/TestWorldSetting.java @@ -15,7 +15,7 @@ import world.bentobox.bentobox.api.flags.Flag; public class TestWorldSetting implements WorldSettings { - private Map flags = new HashMap<>(); + private final Map flags = new HashMap<>(); @Override public GameMode getDefaultGameMode() { diff --git a/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java b/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java index 9ed9ac1..07d18e6 100644 --- a/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java +++ b/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTest.java @@ -36,7 +36,6 @@ import org.bukkit.inventory.PlayerInventory; import org.bukkit.util.BoundingBox; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -86,17 +85,15 @@ public class TryToCompleteTest { private TryToComplete ttc; private Challenge challenge; - private @NonNull ChallengeLevel level; @Mock private ChallengesAddon addon; @Mock private User user; @Mock private World world; - private String topLabel = "island"; - private String permissionPrefix = "perm."; + private final String topLabel = "island"; + private final String permissionPrefix = "perm."; - private String levelName; @Mock private ChallengesManager cm; @Mock @@ -115,18 +112,16 @@ public class TryToCompleteTest { private Settings settings; @Mock private WorldSettings mySettings; - private Map map; @Mock private @Nullable PlayerInventory inv; - private ItemStack[] contents = {}; + private final ItemStack[] contents = {}; @Mock private BoundingBox bb; /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { // Set up plugin Whitebox.setInternalState(BentoBox.class, "instance", plugin); when(addon.getPlugin()).thenReturn(plugin); @@ -143,8 +138,8 @@ public class TryToCompleteTest { when(gameMode.getDescription()).thenReturn(desc2); // Challenge Level - level = new ChallengeLevel(); - levelName = GAME_MODE_NAME + "_novice"; + @NonNull ChallengeLevel level = new ChallengeLevel(); + String levelName = GAME_MODE_NAME + "_novice"; level.setUniqueId(levelName); level.setFriendlyName("Novice"); // Set up challenge @@ -239,19 +234,19 @@ public class TryToCompleteTest { Map online = new HashMap<>(); Set onlinePlayers = new HashSet<>(); - for (int j = 0; j < NAMES.length; j++) { + for (String name : NAMES) { Player p1 = mock(Player.class); UUID uuid2 = UUID.randomUUID(); when(p1.getUniqueId()).thenReturn(uuid2); - when(p1.getName()).thenReturn(NAMES[j]); - online.put(uuid2, NAMES[j]); + when(p1.getName()).thenReturn(name); + online.put(uuid2, name); onlinePlayers.add(p1); } PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getOnlinePlayers()).then((Answer>) invocation -> onlinePlayers); // World settings - map = new HashMap<>(); + Map map = new HashMap<>(); when(mySettings.getWorldFlags()).thenReturn(map); when(iwm.getWorldSettings(any())).thenReturn(mySettings); ChallengesAddon.CHALLENGES_WORLD_PROTECTION.setSetting(world, true); @@ -265,13 +260,6 @@ public class TryToCompleteTest { when(ChatColor.stripColor(anyString())).thenAnswer((Answer) invocation -> invocation.getArgument(0, String.class)); } - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Test method for {@link world.bentobox.challenges.tasks.TryToComplete#TryToComplete(world.bentobox.challenges.ChallengesAddon, world.bentobox.bentobox.api.user.User, world.bentobox.challenges.database.object.Challenge, org.bukkit.World, java.lang.String, java.lang.String)}. */ diff --git a/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTestOld.java b/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTestOld.java index a4e5b4a..fcf45c4 100644 --- a/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTestOld.java +++ b/src/test/java/world/bentobox/challenges/tasks/TryToCompleteTestOld.java @@ -51,20 +51,18 @@ public class TryToCompleteTestOld { }; List required; private ChallengesAddon addon; - private PlayerInventory inv; /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { Server server = mock(Server.class); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getServer()).thenReturn(server); when(Bukkit.getBukkitVersion()).thenReturn("1.13.2"); user = mock(User.class); - inv = mock(PlayerInventory.class); + PlayerInventory inv = mock(PlayerInventory.class); when(inv.getContents()).thenReturn(stacks); when(user.getInventory()).thenReturn(inv); addon = mock(ChallengesAddon.class); diff --git a/src/test/java/world/bentobox/challenges/utils/UtilsTest.java b/src/test/java/world/bentobox/challenges/utils/UtilsTest.java index a9a7295..b8a3c99 100644 --- a/src/test/java/world/bentobox/challenges/utils/UtilsTest.java +++ b/src/test/java/world/bentobox/challenges/utils/UtilsTest.java @@ -1,7 +1,6 @@ package world.bentobox.challenges.utils; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; @@ -18,7 +17,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemStack; -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,10 +47,9 @@ public class UtilsTest { /** - * @throws java.lang.Exception */ @Before - public void setUp() throws Exception { + public void setUp() { // Set up plugin BentoBox plugin = mock(BentoBox.class); Whitebox.setInternalState(BentoBox.class, "instance", plugin); @@ -71,13 +68,6 @@ public class UtilsTest { } - /** - * @throws java.lang.Exception - */ - @After - public void tearDown() throws Exception { - } - /** * Test method for {@link world.bentobox.challenges.utils.Utils#groupEqualItems(java.util.List, java.util.Set)}. */