From 3971519d1d4f8fa9d7f8253bef54beb1867813a4 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 10 Jan 2019 11:16:04 +0200 Subject: [PATCH 001/103] Rename FreshSqueezedChallenges to ChallengesImportManager. ChallengesImportManager name makes more sense then FreshSqueezedChallenges --- .../java/world/bentobox/challenges/ChallengesAddon.java | 6 +++--- ...SqueezedChallenges.java => ChallengesImportManager.java} | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) rename src/main/java/world/bentobox/challenges/{FreshSqueezedChallenges.java => ChallengesImportManager.java} (98%) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 4d3f27d..5fa9b55 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -18,7 +18,7 @@ public class ChallengesAddon extends Addon { private ChallengesManager challengesManager; private String permissionPrefix = "addon"; - private FreshSqueezedChallenges importManager; + private ChallengesImportManager importManager; private boolean hooked; @Override @@ -39,7 +39,7 @@ public class ChallengesAddon extends Addon { // Challenges Manager challengesManager = new ChallengesManager(this); // Challenge import setup - importManager = new FreshSqueezedChallenges(this); + importManager = new ChallengesImportManager(this); // Register commands - run one tick later to allow all addons to load // AcidIsland hook in @@ -98,7 +98,7 @@ public class ChallengesAddon extends Addon { /** * @return the importManager */ - public FreshSqueezedChallenges getImportManager() { + public ChallengesImportManager getImportManager() { return importManager; } diff --git a/src/main/java/world/bentobox/challenges/FreshSqueezedChallenges.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java similarity index 98% rename from src/main/java/world/bentobox/challenges/FreshSqueezedChallenges.java rename to src/main/java/world/bentobox/challenges/ChallengesImportManager.java index ef2af71..f60206c 100644 --- a/src/main/java/world/bentobox/challenges/FreshSqueezedChallenges.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -26,7 +26,8 @@ import world.bentobox.bentobox.util.Util; * @author tastybento * */ -public class FreshSqueezedChallenges { +public class ChallengesImportManager +{ private ChallengesAddon addon; private YamlConfiguration chal; @@ -35,7 +36,7 @@ public class FreshSqueezedChallenges { * Import challenges from challenges.yml * @param challengesAddon */ - public FreshSqueezedChallenges(ChallengesAddon challengesAddon) { + public ChallengesImportManager(ChallengesAddon challengesAddon) { this.addon = challengesAddon; File challengeFile = new File(addon.getDataFolder(), "challenges.yml"); if (!challengeFile.exists()) { From dd6f8caed633b79a8beb3360187901f40a028c71 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 10 Jan 2019 11:30:54 +0200 Subject: [PATCH 002/103] Add Settings class that will process ChallengesAddon configuration. --- .../world/bentobox/challenges/Settings.java | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/Settings.java diff --git a/src/main/java/world/bentobox/challenges/Settings.java b/src/main/java/world/bentobox/challenges/Settings.java new file mode 100644 index 0000000..56340d9 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/Settings.java @@ -0,0 +1,162 @@ +package world.bentobox.challenges; + + +import java.util.HashSet; +import java.util.Set; + +import world.bentobox.bentobox.api.configuration.ConfigComment; +import world.bentobox.bentobox.api.configuration.ConfigEntry; +import world.bentobox.bentobox.api.configuration.StoreAt; +import world.bentobox.bentobox.database.objects.DataObject; + + +@StoreAt(filename="config.yml", path="addons/Challenges") +@ConfigComment("Challenges Configuration [version]") +@ConfigComment("This config file is dynamic and saved when the server is shutdown.") +@ConfigComment("You cannot edit it while the server is running because changes will") +@ConfigComment("be lost! Use in-game settings GUI or edit when server is offline.") +@ConfigComment("") +public class Settings implements DataObject +{ + @ConfigComment("") + @ConfigComment("Reset Challenges - if this is true, player's challenges will reset when they") + @ConfigComment("reset an island or if they are kicked or leave a team. Prevents exploiting the") + @ConfigComment("challenges by doing them repeatedly.") + private boolean resetChallenges = true; + + @ConfigComment("") + @ConfigComment("Broadcast 1st time challenge completion messages to all players.") + @ConfigComment("Change to false if the spam becomes too much.") + private boolean broadcastMessages = true; + + @ConfigComment("") + @ConfigComment("Remove non-repeatable challenges from the challenge GUI when complete.") + private boolean removeCompleteOneTimeChallenges = false; + + @ConfigComment("") + @ConfigComment("Add enchanted glow to completed challenges") + private boolean addCompletedGlow = true; + + @ConfigComment("") + @ConfigComment("This list stores GameModes in which Challenges addon should not work.") + @ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:") + @ConfigComment("disabled-gamemodes:") + @ConfigComment(" - BSkyBlock") + @ConfigEntry(path = "disabled-gamemodes") + private Set disabledGameModes = new HashSet<>(); + + /** + * Default variable. + */ + @ConfigComment("") + private String uniqueId = "config"; + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + @Override + public String getUniqueId() + { + return this.uniqueId; + } + + + /** + * @return resetChallenges value. + */ + public boolean isResetChallenges() + { + return this.resetChallenges; + } + + + /** + * @return broadcastMessages value. + */ + public boolean isBroadcastMessages() + { + return this.broadcastMessages; + } + + + /** + * @return removeCompleteOneTimeChallenges value. + */ + public boolean isRemoveCompleteOneTimeChallenges() + { + return this.removeCompleteOneTimeChallenges; + } + + + /** + * @return addCompletedGlow value. + */ + public boolean isAddCompletedGlow() + { + return this.addCompletedGlow; + } + + + /** + * @return disabledGameModes value. + */ + public Set getDisabledGameModes() + { + return this.disabledGameModes; + } + + + @Override + public void setUniqueId(String uniqueId) + { + this.uniqueId = uniqueId; + } + + + /** + * @param resetChallenges new resetChallenges value. + */ + public void setResetChallenges(boolean resetChallenges) + { + this.resetChallenges = resetChallenges; + } + + + /** + * @param broadcastMessages new broadcastMessages value. + */ + public void setBroadcastMessages(boolean broadcastMessages) + { + this.broadcastMessages = broadcastMessages; + } + + + /** + * @param removeCompleteOneTimeChallenges new removeCompleteOneTimeChallenges value. + */ + public void setRemoveCompleteOneTimeChallenges(boolean removeCompleteOneTimeChallenges) + { + this.removeCompleteOneTimeChallenges = removeCompleteOneTimeChallenges; + } + + + /** + * @param addCompletedGlow new addCompletedGlow value. + */ + public void setAddCompletedGlow(boolean addCompletedGlow) + { + this.addCompletedGlow = addCompletedGlow; + } + + + /** + * @param disabledGameModes new disabledGameModes value. + */ + public void setDisabledGameModes(Set disabledGameModes) + { + this.disabledGameModes = disabledGameModes; + } +} From b8e0ca43316e2ad7490555f5602d99061e9fea47 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 10 Jan 2019 11:36:06 +0200 Subject: [PATCH 003/103] Rework ChallengesAddon main class. Add dependencies to AcidIsland and BSkyBlock addons in pom.xml. Use proper way how to get GameMode admin and user commands. Init Settings object and implement onReload() method. Add check on disabled game modes, to avoid loading challenges in addons, where it should be disabled by settings. --- pom.xml | 12 ++ .../bentobox/challenges/ChallengesAddon.java | 199 ++++++++++++++---- 2 files changed, 165 insertions(+), 46 deletions(-) diff --git a/pom.xml b/pom.xml index 3e5504c..f959305 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,18 @@ 1.0 provided + + world.bentobox + bskyblock + 1.0 + provided + + + world.bentobox + acidisland + 1.0 + provided + world.bentobox level diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 5fa9b55..68923a2 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -2,12 +2,13 @@ package world.bentobox.challenges; import org.bukkit.Bukkit; +import world.bentobox.acidisland.AcidIsland; +import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.commands.admin.Challenges; import world.bentobox.challenges.listeners.ResetListener; import world.bentobox.challenges.listeners.SaveListener; import world.bentobox.bentobox.api.addons.Addon; -import world.bentobox.bentobox.api.commands.CompositeCommand; /** * Add-on to BSkyBlock that enables challenges @@ -16,90 +17,196 @@ import world.bentobox.bentobox.api.commands.CompositeCommand; */ public class ChallengesAddon extends Addon { +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + private ChallengesManager challengesManager; - private String permissionPrefix = "addon"; + private ChallengesImportManager importManager; + + private Settings settings; + private boolean hooked; + +// --------------------------------------------------------------------- +// Section: Constants +// --------------------------------------------------------------------- + + + /** + * Permission prefix for addon. + */ + private static final String PERMISSION_PREFIX = "addon"; + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ @Override public void onLoad() { // Save default config.yml - saveDefaultConfig(); + this.saveDefaultConfig(); + // Load the plugin's config + this.loadSettings(); } + + /** + * {@inheritDoc} + */ @Override public void onEnable() { // Check if it is enabled - it might be loaded, but not enabled. - if (getPlugin() == null || !getPlugin().isEnabled()) { + if (this.getPlugin() == null || !this.getPlugin().isEnabled()) { Bukkit.getLogger().severe("BentoBox is not available or disabled!"); this.setState(State.DISABLED); return; } // Challenges Manager - challengesManager = new ChallengesManager(this); + this.challengesManager = new ChallengesManager(this); // Challenge import setup - importManager = new ChallengesImportManager(this); + this.importManager = new ChallengesImportManager(this); - // Register commands - run one tick later to allow all addons to load - // AcidIsland hook in - getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent(a -> { - CompositeCommand acidIslandCmd = getPlugin().getCommandsManager().getCommand("ai"); - if (acidIslandCmd != null) { - new ChallengesCommand(this, acidIslandCmd); - CompositeCommand acidCmd = getPlugin().getCommandsManager().getCommand("acid"); - new Challenges(this, acidCmd); - hooked = true; + + // Integrate into AcidIsland. + if (this.settings.getDisabledGameModes().isEmpty() || + !this.settings.getDisabledGameModes().contains("AcidIsland")) + { + this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent( + addon -> { + AcidIsland acidIsland = (AcidIsland) addon; + + new Challenges(this, + this.getPlugin().getCommandsManager().getCommand( + acidIsland.getSettings().getAdminCommand())); + + new ChallengesCommand(this, + this.getPlugin().getCommandsManager().getCommand( + acidIsland.getSettings().getIslandCommand())); + + this.hooked = true; + }); + } + + // Integrate into BSkyBlock. + if (this.settings.getDisabledGameModes().isEmpty() || + !this.settings.getDisabledGameModes().contains("BSkyBlock")) + { + this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent( + addon -> { +// BSkyBlock skyBlock = (BSkyBlock) addon; +// SkyBlock addon cannot change commands ;( + + new Challenges(this, + this.getPlugin().getCommandsManager().getCommand("bsbadmin")); + + new ChallengesCommand(this, + this.getPlugin().getCommandsManager().getCommand("island")); + + this.hooked = true; + }); + } + + if (this.hooked) { + // Try to find Level addon and if it does not exist, display a warning + if (!this.getAddonByName("Level").isPresent()) { + this.logWarning("Level add-on not found so level challenges will not work!"); } - }); - getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent(a -> { - // BSkyBlock hook in - CompositeCommand bsbIslandCmd = getPlugin().getCommandsManager().getCommand("island"); - if (bsbIslandCmd != null) { - new ChallengesCommand(this, bsbIslandCmd); - CompositeCommand bsbAdminCmd = getPlugin().getCommandsManager().getCommand("bsbadmin"); - new Challenges(this, bsbAdminCmd); - hooked = true; - } - }); - // If the add-on never hooks in, then it is useless - if (!hooked) { - logError("Challenges could not hook into AcidIsland or BSkyBlock so will not do anything!"); + + // Register the reset listener + this.registerListener(new ResetListener(this)); + // Register the autosave listener. + this.registerListener(new SaveListener(this)); + } else { + this.logError("Challenges could not hook into AcidIsland or BSkyBlock so will not do anything!"); this.setState(State.DISABLED); - return; } - // Try to find Level addon and if it does not exist, display a warning - if (!getAddonByName("Level").isPresent()) { - logWarning("Level add-on not found so level challenges will not work!"); - } - // Register the reset listener - this.registerListener(new ResetListener(this)); - // Register the autosave listener. - this.registerListener(new SaveListener(this)); - // Done } + + /** + * {@inheritDoc} + */ @Override - public void onDisable(){ - if (challengesManager != null) { - challengesManager.save(); + public void onReload() + { + if (this.hooked) { + this.challengesManager.save(); + + this.loadSettings(); + this.getLogger().info("Challenges addon reloaded."); } } - public ChallengesManager getChallengesManager() { - return challengesManager; + + /** + * {@inheritDoc} + */ + @Override + public void onDisable() { + if (this.hooked) { + this.challengesManager.save(); + } } + + /** + * This method loads addon configuration settings in memory. + */ + private void loadSettings() { + this.settings = new Config<>(this, Settings.class).loadConfigObject(); + + if (this.settings == null) { + // Disable + this.logError("Challenges settings could not load! Addon disabled."); + this.setState(State.DISABLED); + } + } + + +// --------------------------------------------------------------------- +// Section: Getters +// --------------------------------------------------------------------- + + + /** + * @return challengesManager + */ + public ChallengesManager getChallengesManager() { + return this.challengesManager; + } + + + /** + * @return Permission Prefix. + */ @Override public String getPermissionPrefix() { - return permissionPrefix ; + return PERMISSION_PREFIX; } + /** * @return the importManager */ public ChallengesImportManager getImportManager() { - return importManager; + return this.importManager; } + + /** + * @return the challenge settings. + */ + public Settings getChallengesSettings() + { + return this.settings; + } } From 6c0ac962514ac341bce66deaa820ed5947e378bf Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 10 Jan 2019 11:40:23 +0200 Subject: [PATCH 004/103] Use proper Addon settings getters. --- .../world/bentobox/challenges/listeners/ResetListener.java | 2 +- .../java/world/bentobox/challenges/panel/TryToComplete.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/listeners/ResetListener.java b/src/main/java/world/bentobox/challenges/listeners/ResetListener.java index 74c2339..df0d401 100644 --- a/src/main/java/world/bentobox/challenges/listeners/ResetListener.java +++ b/src/main/java/world/bentobox/challenges/listeners/ResetListener.java @@ -26,7 +26,7 @@ public class ResetListener implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onIslandReset(IslandEvent e) { - if (e.getReason().equals(Reason.CREATED) || (addon.getConfig().getBoolean("resetchallenges") && e.getReason().equals(Reason.RESETTED))) { + if (e.getReason().equals(Reason.CREATED) || (addon.getChallengesSettings().isResetChallenges() && e.getReason().equals(Reason.RESETTED))) { addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld()); } } diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 2fa22ff..cb50e34 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -101,7 +101,7 @@ public class TryToComplete { // Run commands runCommands(challenge.getRewardCommands()); user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); - if (addon.getConfig().getBoolean("broadcastmessages", false)) { + if (addon.getChallengesSettings().isBroadcastMessages()) { for (Player p : addon.getServer().getOnlinePlayers()) { User.getInstance(p).sendMessage("challenges.name-has-completed", "[name]", user.getName(), "[challenge]", challenge.getFriendlyName()); @@ -166,7 +166,7 @@ public class TryToComplete { // Run commands runCommands(challenge.getRewardCommands()); user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); - if (addon.getConfig().getBoolean("broadcastmessages", false)) { + if (addon.getChallengesSettings().isBroadcastMessages()) { for (Player p : addon.getServer().getOnlinePlayers()) { User.getInstance(p).sendMessage("challenges.name-has-completed", "[name]", user.getName(), "[challenge]", challenge.getFriendlyName()); From c7aafa63ef6a297228a99c2d5fe4669d29e67e7a Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 14 Jan 2019 13:29:10 +0200 Subject: [PATCH 005/103] Create CommonGUI panel that will be used in all other GUIs where it is necessary. --- .../bentobox/challenges/panel/CommonGUI.java | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/CommonGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java new file mode 100644 index 0000000..a31d220 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -0,0 +1,173 @@ +package world.bentobox.challenges.panel; + + +import org.bukkit.Material; +import org.bukkit.World; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; + + +/** + * This class contains common methods that will be used over all GUIs. It also allows + * easier navigation between different GUIs. + */ +public abstract class CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * This variable stores parent gui. + */ + private CommonGUI parentGUI; + + /** + * Variable stores Challenges addon. + */ + protected ChallengesAddon addon; + + /** + * Variable stores world in which panel is referred to. + */ + protected World world; + + /** + * Variable stores user who created this panel. + */ + protected User user; + + /** + * Variable stores top label of command from which panel was called. + */ + protected String topLabel; + + /** + * Variable stores permission prefix of command from which panel was called. + */ + protected String permissionPrefix; + + /** + * Variable stores any value. + */ + protected Object valueObject; + + /** + * This object holds current page index. + */ + protected int pageIndex; + + /** + * This object holds PanelItem that allows to return to previous panel. + */ + protected PanelItem returnButton; + + +// --------------------------------------------------------------------- +// Section: Constants +// --------------------------------------------------------------------- + + + protected static final String ADMIN = "admin"; + + protected static final String CHALLENGES = "challenges"; + + protected static final String IMPORT = "import"; + + protected static final String SETTINGS = "settings"; + + protected static final String DELETE = "delete"; + + protected static final String EDIT = "edit"; + + protected static final String ADD = "add"; + + protected static final String RESET = "reset"; + + protected static final String COMPLETE = "complete"; + + +// --------------------------------------------------------------------- +// Section: Constructors +// --------------------------------------------------------------------- + + + /** + * Default constructor that inits panels with minimal requirements, without parent panel. + * + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + */ + public CommonGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, topLabel, permissionPrefix, null); + } + + + /** + * Default constructor that inits panels with minimal requirements. + * + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + * @param parentGUI Parent panel for current panel. + */ + public CommonGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + this.addon = addon; + this.world = world; + this.user = user; + + this.topLabel = topLabel; + this.permissionPrefix = permissionPrefix; + + this.parentGUI = parentGUI; + + this.pageIndex = 0; + + this.returnButton = new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.buttons.back")). + icon(Material.OAK_DOOR). + clickHandler((panel, user1, clickType, i) -> { + if (this.parentGUI == null) + { + this.user.closeInventory(); + return true; + } + + this.parentGUI.build(); + return true; + }).build(); + + this.build(); + } + + +// --------------------------------------------------------------------- +// Section: Common methods +// --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + public abstract void build(); +} + From 291239e244502a411dca174269619be109bed87d Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 14 Jan 2019 15:05:06 +0200 Subject: [PATCH 006/103] Create Challenges Admin Gui, so admin could choose action that needs to be processed. --- .../panel/admin/ChallengesAdminGUI.java | 309 ++++++++++++++++++ 1 file changed, 309 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java new file mode 100644 index 0000000..3417074 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java @@ -0,0 +1,309 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.inventory.ItemStack; + +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class contains Main + */ +public class ChallengesAdminGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * This boolean holds if import should overwrite existing challenges. + */ + private boolean overwriteMode; + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * This enum contains all button variations. Just for cleaner code. + */ + private enum Button + { + COMPLETE_USER_CHALLENGES, + RESET_USER_CHALLENGES, + ADD_CHALLENGE, + ADD_LEVEL, + EDIT_CHALLENGE, + EDIT_LEVEL, + DELETE_CHALLENGE, + DELETE_LEVEL, + IMPORT_CHALLENGES, + EDIT_SETTINGS + } + + +// --------------------------------------------------------------------- +// Section: Constructor +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + public ChallengesAdminGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + super(addon, world, user, topLabel, permissionPrefix); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.admin.gui-title")); + + + panelBuilder.item(1, this.createButton(Button.COMPLETE_USER_CHALLENGES)); + panelBuilder.item(10, this.createButton(Button.RESET_USER_CHALLENGES)); + + // Add Challenges + panelBuilder.item(3, this.createButton(Button.ADD_CHALLENGE)); + panelBuilder.item(12, this.createButton(Button.ADD_LEVEL)); + + // Edit Challenges + panelBuilder.item(4, this.createButton(Button.EDIT_CHALLENGE)); + panelBuilder.item(13, this.createButton(Button.EDIT_LEVEL)); + + // Remove Challenges + panelBuilder.item(5, this.createButton(Button.DELETE_CHALLENGE)); + panelBuilder.item(14, this.createButton(Button.DELETE_LEVEL)); + + + // Import Challenges + panelBuilder.item(7, this.createButton(Button.IMPORT_CHALLENGES)); + + // Edit Addon Settings + panelBuilder.item(8, this.createButton(Button.EDIT_SETTINGS)); + + panelBuilder.build(); + } + + + /** + * This method is used to create PanelItem for each button type. + * @param button Button which must be created. + * @return PanelItem with necessary functionality. + */ + private PanelItem createButton(Button button) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + String permissionSuffix; + + switch (button) + { + case COMPLETE_USER_CHALLENGES: + permissionSuffix = COMPLETE; + + name = this.user.getTranslation("challenges.gui.admin.buttons.complete"); + description = Collections.emptyList(); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Complete Challenge GUI + + return true; + }; + glow = false; + + break; + case RESET_USER_CHALLENGES: + permissionSuffix = RESET; + + name = this.user.getTranslation("challenges.gui.admin.buttons.reset"); + description = Collections.emptyList(); + icon = new ItemStack(Material.WRITABLE_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Reset Challenge GUI + + return true; + }; + glow = false; + + break; + case ADD_CHALLENGE: + permissionSuffix = ADD; + + name = this.user.getTranslation("challenges.gui.admin.buttons.add-challenge"); + description = Collections.emptyList(); + icon = new ItemStack(Material.BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Add Challenge GUI + + return true; + }; + glow = false; + + break; + case ADD_LEVEL: + permissionSuffix = ADD; + + name = this.user.getTranslation("challenges.gui.admin.buttons.add-level"); + description = Collections.emptyList(); + icon = new ItemStack(Material.BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Add Level GUI + + return true; + }; + glow = false; + + break; + case EDIT_CHALLENGE: + permissionSuffix = EDIT; + + name = this.user.getTranslation("challenges.gui.admin.buttons.edit-challenge"); + description = Collections.emptyList(); + icon = new ItemStack(Material.ANVIL); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Edit Challenge GUI + + return true; + }; + glow = false; + + break; + case EDIT_LEVEL: + { + permissionSuffix = EDIT; + + name = this.user.getTranslation("challenges.gui.admin.buttons.edit-level"); + description = Collections.emptyList(); + icon = new ItemStack(Material.ANVIL); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Edit Level GUI + + return true; + }; + glow = false; + + break; + } + case DELETE_CHALLENGE: + { + permissionSuffix = DELETE; + + name = this.user.getTranslation("challenges.gui.admin.buttons.delete-challenge"); + description = Collections.emptyList(); + icon = new ItemStack(Material.LAVA_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Delete Challenge GUI + + return true; + }; + glow = false; + + break; + } + case DELETE_LEVEL: + { + permissionSuffix = DELETE; + + name = this.user.getTranslation("challenges.gui.admin.buttons.delete-level"); + description = Collections.emptyList(); + icon = new ItemStack(Material.LAVA_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Delete Level GUI + + return true; + }; + glow = false; + + break; + } + case IMPORT_CHALLENGES: + { + permissionSuffix = IMPORT; + + name = this.user.getTranslation("challenges.gui.admin.buttons.import"); + description = Collections.emptyList(); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.overwriteMode = !this.overwriteMode; + this.build(); + } + else + { + // Run import command. + this.user.performCommand(this.topLabel + " " + CHALLENGES + " " + IMPORT + + (this.overwriteMode ? " overwrite" : "")); + } + return true; + }; + glow = this.overwriteMode; + + break; + } + case EDIT_SETTINGS: + { + permissionSuffix = SETTINGS; + + name = this.user.getTranslation("challenges.gui.admin.buttons.settings"); + description = Collections.emptyList(); + icon = new ItemStack(Material.CRAFTING_TABLE); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Settings GUI + + return true; + }; + glow = false; + + break; + } + default: + // This should never happen. + return null; + } + + // If user does not have permission to run command, then change icon and clickHandler. + final String actionPermission = this.permissionPrefix + ADMIN + "." + CHALLENGES + "." + permissionSuffix; + + if (!this.user.hasPermission(actionPermission)) + { + icon = new ItemStack(Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> { + this.user.sendMessage("general.errors.no-permission", "[permission]", actionPermission); + return true; + }; + } + + return new PanelItem(icon, name, description, glow, clickHandler, false); + } +} From 6a5ec144d1c70865fa2b79c8cc60ad5656fcaa93 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 14 Jan 2019 15:20:37 +0200 Subject: [PATCH 007/103] Create ChallengesSettingsGUI class that allows to change Challenges Addon Settings via ingame menu. --- .../panel/admin/ChallengesSettingsGUI.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java new file mode 100644 index 0000000..13d62b4 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java @@ -0,0 +1,120 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.Material; +import org.bukkit.World; + +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This Class creates GUI that allows to change Challenges Addon Settings via in-game + * menu. + */ +public class ChallengesSettingsGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Constructors +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + public ChallengesSettingsGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, topLabel, permissionPrefix, null); + } + + + /** + * {@inheritDoc} + */ + public ChallengesSettingsGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.admin.settings-title")); + + // resetChallenges + panelBuilder.item(0, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.reset")). + description(this.user.getTranslation("challenges.gui.admin.descriptions.reset")). + icon(Material.LAVA_BUCKET). + clickHandler((panel, user1, clickType, i) -> { + this.addon.getChallengesSettings().setResetChallenges( + !this.addon.getChallengesSettings().isResetChallenges()); + return true; + }). + glow(this.addon.getChallengesSettings().isResetChallenges()). + build()); + + // broadcastMessages + panelBuilder.item(1, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.broadcast")). + description(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast")). + icon(Material.JUKEBOX). + clickHandler((panel, user1, clickType, i) -> { + this.addon.getChallengesSettings().setBroadcastMessages( + !this.addon.getChallengesSettings().isBroadcastMessages()); + return true; + }). + glow(this.addon.getChallengesSettings().isBroadcastMessages()). + build()); + + // removeCompleteOneTimeChallenges + panelBuilder.item(2, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.remove-on-complete")). + description(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete")). + icon(Material.MAGMA_BLOCK). + clickHandler((panel, user1, clickType, i) -> { + this.addon.getChallengesSettings().setRemoveCompleteOneTimeChallenges( + !this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges()); + return true; + }). + glow(this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges()). + build()); + + // addCompletedGlow + panelBuilder.item(3, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.glow")). + description(this.user.getTranslation("challenges.gui.admin.descriptions.glow")). + icon(Material.GLOWSTONE). + clickHandler((panel, user1, clickType, i) -> { + this.addon.getChallengesSettings().setAddCompletedGlow( + !this.addon.getChallengesSettings().isAddCompletedGlow()); + return true; + }). + glow(this.addon.getChallengesSettings().isAddCompletedGlow()). + build()); + + // Return Button + panelBuilder.item(8, this.returnButton); + + panelBuilder.build(); + } +} From 594fa0f27faec8f812dab587147af9261ca0b2fd Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 14 Jan 2019 17:21:00 +0200 Subject: [PATCH 008/103] Create common buttons in CommonGUI panel. --- .../bentobox/challenges/panel/CommonGUI.java | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index a31d220..9ff4c1e 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -3,6 +3,10 @@ package world.bentobox.challenges.panel; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.inventory.ItemStack; + +import java.util.Collections; +import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -66,6 +70,17 @@ public abstract class CommonGUI protected PanelItem returnButton; + /** + * This enum contains buttons that is offten used in multiple GUIs. + */ + protected enum CommonButtons + { + NEXT, + PREVIOUS, + RETURN + } + + // --------------------------------------------------------------------- // Section: Constants // --------------------------------------------------------------------- @@ -155,8 +170,6 @@ public abstract class CommonGUI this.parentGUI.build(); return true; }).build(); - - this.build(); } @@ -169,5 +182,55 @@ public abstract class CommonGUI * This method builds all necessary elements in GUI panel. */ public abstract void build(); + + + /** + * This method returns PanelItem that represents given Button. + * @param button Button that must be returned. + * @return PanelItem with requested functionality. + */ + protected PanelItem getButton(CommonButtons button) + { + ItemStack icon; + String name; + List description; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case NEXT: + { + name = this.user.getTranslation("challenges.gui.buttons.next"); + description = Collections.emptyList(); + icon = new ItemStack(Material.SIGN); + clickHandler = (panel, user, clickType, slot) -> { + this.pageIndex++; + this.build(); + return true; + }; + + break; + } + case PREVIOUS: + { + name = this.user.getTranslation("challenges.gui.buttons.previous"); + description = Collections.emptyList(); + icon = new ItemStack(Material.SIGN); + clickHandler = (panel, user, clickType, slot) -> { + this.pageIndex--; + this.build(); + return true; + }; + + break; + } + case RETURN: + return this.returnButton; + default: + return null; + } + + return new PanelItem(icon, name, description, false, clickHandler, false); + } } From d5f19310c825b6fd0053a72f87f4b29e2e47ca33 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 14 Jan 2019 17:21:45 +0200 Subject: [PATCH 009/103] Create ChallengesUserListGUI that will display user heads in rows and allows to select specific user. --- .../panel/admin/ChallengesUserListGUI.java | 243 ++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java new file mode 100644 index 0000000..90d6306 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java @@ -0,0 +1,243 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class contains methods that allows to select specific user. + */ +public class ChallengesUserListGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * List with players that should be in GUI. + */ + private List onlineUsers; + + /** + * Current index of view mode + */ + private int modeIndex = 2; + + + /** + * This allows to switch which users should be in the list. + */ + private enum ViewMode + { + ONLINE, + OFFLINE, + IN_WORLD + } + + +// --------------------------------------------------------------------- +// Section: Constructors +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + public ChallengesUserListGUI(ChallengesAddon addon, + World world, + User user, String topLabel, String permissionPrefix) + { + this(addon, world, user, topLabel, permissionPrefix, null); + } + + + /** + * {@inheritDoc} + */ + public ChallengesUserListGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix, + CommonGUI parentPanel) + { + super(addon, world, user, topLabel, permissionPrefix, parentPanel); + this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.admin.choose-user-title")); + + int MAX_ELEMENTS = 45; + if (this.pageIndex < 0) + { + this.pageIndex = 0; + } + else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS)) + { + this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS; + } + + int playerIndex = MAX_ELEMENTS * this.pageIndex; + + while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + playerIndex < this.onlineUsers.size()) + { + panelBuilder.item(this.createPlayerIcon(this.onlineUsers.get(playerIndex))); + playerIndex++; + } + + int nextIndex = playerIndex % MAX_ELEMENTS == 0 ? + MAX_ELEMENTS : + (((playerIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9; + + if (playerIndex > MAX_ELEMENTS) + { + panelBuilder.item(nextIndex, this.getButton(CommonButtons.PREVIOUS)); + } + + if (playerIndex < this.onlineUsers.size()) + { + panelBuilder.item(nextIndex + 8, this.getButton(CommonButtons.NEXT)); + } + + if (this.returnButton != null) + { + panelBuilder.item(nextIndex + 6, this.returnButton); + } + + panelBuilder.item(nextIndex + 3, this.createToggleButton()); + + panelBuilder.build(); + } + + + /** + * This method creates button for given user. If user has island it will add valid click handler. + * @param player Player which button must be created. + * @return Player button. + */ + private PanelItem createPlayerIcon(Player player) + { + if (this.addon.getIslands().hasIsland(this.world, player.getUniqueId())) + { + return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler( + (panel, user1, clickType, slot) -> { + // TODO Add operations that should be called from here + + return true; + }).build(); + } + else + { + return new PanelItemBuilder(). + name(player.getName()). + icon(Material.BARRIER). + description(this.user.getTranslation("general.errors.player-has-no-island")). + clickHandler((panel, user1, clickType, slot) -> false). + build(); + } + } + + + /** + * This method collects users based on view mode. + * @param mode Given view mode. + * @return List with players in necessary view mode. + */ + private List collectUsers(ViewMode mode) + { + if (mode.equals(ViewMode.ONLINE)) + { + return new ArrayList<>(Bukkit.getOnlinePlayers()); + } + else if (mode.equals(ViewMode.OFFLINE)) + { + List offlinePlayer = new ArrayList<>(Bukkit.getOfflinePlayers().length); + + for (int index = 0; index < Bukkit.getOfflinePlayers().length; index++) + { + OfflinePlayer player = Bukkit.getOfflinePlayers()[index]; + offlinePlayer.add(player.getPlayer()); + } + + return offlinePlayer; + } + else + { + return new ArrayList<>(this.world.getPlayers()); + } + } + + + /** + * This method creates Player List view Mode toggle button. + * @return Button that toggles through player view mode. + */ + private PanelItem createToggleButton() + { + List values = new ArrayList<>(ViewMode.values().length); + + for (int i = 0; i < ViewMode.values().length; i++) + { + values.add((this.modeIndex == i ? "§2" : "§c") + + this.user.getTranslation("challenges.gui.admin.descriptions." + + ViewMode.values()[i].name().toLowerCase())); + } + + return new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.toggle-users", + "[value]", + this.user.getTranslation("challenges.gui.admin.descriptions." + ViewMode.values()[this.modeIndex].name().toLowerCase()))). + description(values). + icon(Material.STONE_BUTTON). + clickHandler( + (panel, user1, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.modeIndex--; + + if (this.modeIndex < 0) + { + this.modeIndex = ViewMode.values().length - 1; + } + } + else + { + this.modeIndex++; + + if (this.modeIndex >= ViewMode.values().length) + { + this.modeIndex = 0; + } + } + + this.onlineUsers = this.collectUsers(ViewMode.values()[this.modeIndex]); + this.pageIndex = 0; + this.build(); + return true; + }).build(); + } +} From 016deec34c60494fc6e763b176a88d316c407d9d Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 16 Jan 2019 19:25:01 +0200 Subject: [PATCH 010/103] Create ChallengesEditGUI class that will allow to edit challenges via ingame GUI. This GUI currently does not have ability to change values. It only contains skeleton for each option, that user should be able to change. Add new parameters to Challenges class. --- .../database/object/Challenges.java | 37 + .../panel/admin/ChallengesEditGUI.java | 1077 +++++++++++++++++ 2 files changed, 1114 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenges.java b/src/main/java/world/bentobox/challenges/database/object/Challenges.java index c494516..2b1d5ab 100644 --- a/src/main/java/world/bentobox/challenges/database/object/Challenges.java +++ b/src/main/java/world/bentobox/challenges/database/object/Challenges.java @@ -25,6 +25,43 @@ public class Challenges implements DataObject { public Challenges() {} + + public boolean isRemoveEntities() + { + return false; + } + + + public void setRemoveEntities(boolean b) + { + + } + + + public boolean isRemoveBlocks() + { + return false; + } + + + public void setRemoveBlocks(boolean b) + { + + } + + + public boolean isTakeExperience() + { + return false; + } + + + public void setTakeExperience(boolean b) + { + + } + + public enum ChallengeType { /** * This challenge only shows and icon in the GUI and doesn't do anything. diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java new file mode 100644 index 0000000..6452cc5 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java @@ -0,0 +1,1077 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class contains all necessary methods that creates GUI and allow to edit challenges + * properties. + */ +public class ChallengesEditGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Constructors +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + * @param challenge challenge that needs editing. + */ + public ChallengesEditGUI(ChallengesAddon addon, + World world, + User user, + Challenges challenge, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, challenge, topLabel, permissionPrefix, null); + } + + + /** + * {@inheritDoc} + * @param challenge challenge that needs editing. + */ + public ChallengesEditGUI(ChallengesAddon addon, + World world, + User user, + Challenges challenge, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.challenge = challenge; + + // Default panel should be Properties. + this.currentMenuType = MenuType.PROPERTIES; + } + + +// --------------------------------------------------------------------- +// Section: Panel Creation related methods +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name( + this.user.getTranslation("challenges.gui.admin.edit-challenge-title")); + + panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); + panelBuilder.item(4, this.createMenuButton(MenuType.REQUIREMENTS)); + panelBuilder.item(6, this.createMenuButton(MenuType.REWARDS)); + + if (this.currentMenuType.equals(MenuType.PROPERTIES)) + { + this.buildMainPropertiesPanel(panelBuilder); + } + else if (this.currentMenuType.equals(MenuType.REQUIREMENTS)) + { + switch (this.challenge.getChallengeType()) + { + case INVENTORY: + this.buildInventoryRequirementsPanel(panelBuilder); + break; + case ISLAND: + this.buildIslandRequirementsPanel(panelBuilder); + break; + case LEVEL: + this.buildOtherRequirementsPanel(panelBuilder); + break; + } + } + else if (this.currentMenuType.equals(MenuType.REWARDS)) + { + this.buildRewardsPanel(panelBuilder); + } + + panelBuilder.item(53, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This class populate ChallengesEditGUI with main challenge settings. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildMainPropertiesPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.NAME)); + panelBuilder.item(13, this.createButton(Button.TYPE)); + panelBuilder.item(16, this.createButton(Button.DEPLOYED)); + + panelBuilder.item(19, this.createButton(Button.ICON)); + panelBuilder.item(22, this.createButton(Button.DESCRIPTION)); + panelBuilder.item(25, this.createButton(Button.ORDER)); + + panelBuilder.item(28, this.createButton(Button.ENVIRONMENT)); + panelBuilder.item(31, this.createButton(Button.REMOVE_ON_COMPLETE)); + } + + + /** + * This class populates ChallengesEditGUI with island challenges requirement elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildIslandRequirementsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.REQUIRED_ENTITIES)); + panelBuilder.item(11, this.createButton(Button.REMOVE_ENTITIES)); + + panelBuilder.item(15, this.createButton(Button.REQUIRED_BLOCKS)); + panelBuilder.item(16, this.createButton(Button.REMOVE_BLOCKS)); + + panelBuilder.item(19, this.createButton(Button.SEARCH_RADIUS)); + panelBuilder.item(28, this.createButton(Button.REQUIRED_PERMISSIONS)); + } + + + /** + * This class populates ChallengesEditGUI with inventory challenges requirement elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildInventoryRequirementsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.REQUIRED_ITEMS)); + panelBuilder.item(11, this.createButton(Button.REMOVE_ITEMS)); + + panelBuilder.item(28, this.createButton(Button.REQUIRED_PERMISSIONS)); + } + + + /** + * This class populates ChallengesEditGUI with other challenges requirement elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildOtherRequirementsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.REQUIRED_EXPERIENCE)); + panelBuilder.item(11, this.createButton(Button.REMOVE_EXPERIENCE)); + + panelBuilder.item(13, this.createButton(Button.REQUIRED_LEVEL)); + + panelBuilder.item(15, this.createButton(Button.REQUIRED_MONEY)); + panelBuilder.item(16, this.createButton(Button.REMOVE_MONEY)); + + panelBuilder.item(28, this.createButton(Button.REQUIRED_PERMISSIONS)); + } + + + /** + * This class populates ChallengesEditGUI with challenges reward elements. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildRewardsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(11, this.createButton(Button.REWARD_TEXT)); + panelBuilder.item(20, this.createButton(Button.REWARD_ITEM)); + panelBuilder.item(29, this.createButton(Button.REWARD_EXPERIENCE)); + panelBuilder.item(38, this.createButton(Button.REWARD_MONEY)); + panelBuilder.item(47, this.createButton(Button.REWARD_COMMANDS)); + + + panelBuilder.item(22, this.createButton(Button.REPEATABLE)); + + if (this.challenge.isRepeatable()) + { + panelBuilder.item(31, this.createButton(Button.REPEAT_COUNT)); + + panelBuilder.item(15, this.createButton(Button.REPEAT_REWARD_TEXT)); + panelBuilder.item(24, this.createButton(Button.REPEAT_REWARD_ITEM)); + panelBuilder.item(33, this.createButton(Button.REPEAT_REWARD_EXPERIENCE)); + panelBuilder.item(42, this.createButton(Button.REPEAT_REWARD_MONEY)); + panelBuilder.item(51, this.createButton(Button.REPEAT_REWARD_COMMANDS)); + } + } + + +// --------------------------------------------------------------------- +// Section: Other methods +// --------------------------------------------------------------------- + + + /** + * This method creates top menu buttons, that allows to switch "tabs". + * @param menuType Menu Type which button must be constructed. + * @return PanelItem that represents given menu type. + */ + private PanelItem createMenuButton(MenuType menuType) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + switch (menuType) + { + case PROPERTIES: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.properties"); + description = Collections.emptyList(); + icon = new ItemStack(Material.CRAFTING_TABLE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.PROPERTIES; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.PROPERTIES); + break; + } + case REQUIREMENTS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.requirements"); + description = Collections.emptyList(); + icon = new ItemStack(Material.HOPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.REQUIREMENTS; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.REQUIREMENTS); + break; + } + case REWARDS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.rewards"); + description = Collections.emptyList(); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.REWARDS; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.REWARDS); + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, glow, clickHandler, false); + } + + + /** + * This method creates buttons for default main menu. + * @param button Button which panel item must be created. + * @return PanelItem that represetns given button. + */ + private PanelItem createButton(Button button) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case TYPE: + { + List values = new ArrayList<>(Challenges.ChallengeType.values().length); + + for (Challenges.ChallengeType type : Challenges.ChallengeType.values()) + { + values.add((this.challenge.getChallengeType().equals(type) ? "§2" : "§c") + + this.user.getTranslation("challenges.gui.admin.descriptions." + type.name().toLowerCase())); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.type"); + description = values; + + if (this.challenge.getChallengeType().equals(Challenges.ChallengeType.ISLAND)) + { + icon = new ItemStack(Material.GRASS_BLOCK); + } + else if (this.challenge.getChallengeType().equals(Challenges.ChallengeType.INVENTORY)) + { + icon = new ItemStack(Material.CHEST); + } + else if (this.challenge.getChallengeType().equals(Challenges.ChallengeType.LEVEL)) + { + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + } + else + { + icon = this.challenge.getIcon(); + } + + clickHandler = (panel, user, clickType, slot) -> { + if (clickType.isRightClick()) + { + this.challenge.setChallengeType( + this.getPreviousType(this.challenge.getChallengeType())); + } + else + { + this.challenge.setChallengeType( + this.getNextType(this.challenge.getChallengeType())); + } + + this.build(); + + return true; + }; + glow = false; + break; + } + case DEPLOYED: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.deployed"); + + if (this.challenge.isDeployed()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setDeployed(!this.challenge.isDeployed()); + + this.build(); + return true; + }; + glow = this.challenge.isDeployed(); + break; + } + case ICON: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.icon"); + description = Collections.emptyList(); + icon = this.challenge.getIcon(); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: how to change icon. + this.build(); + + return true; + }; + glow = false; + break; + } + case DESCRIPTION: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.description"); + description = Collections.emptyList(); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Implement challenges description change GUI. + this.build(); + return true; + }; + glow = false; + break; + } + case ORDER: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.order"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.order", + "[value]", + Integer.toString(this.challenge.getSlot()))); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case ENVIRONMENT: + { + List values = new ArrayList<>(World.Environment.values().length); + + for (World.Environment environment : World.Environment.values()) + { + values.add((this.challenge.getEnvironment().contains(environment.name()) ? "§2" : "§c") + + this.user.getTranslation("challenges.gui.admin.descriptions." + environment.name())); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.environment"); + description = values; + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create change enviroment button + this.build(); + return true; + }; + glow = false; + break; + } + case REMOVE_ON_COMPLETE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-on-complete"); + description = Collections.emptyList(); + + if (this.challenge.isRemoveWhenCompleted()) + { + icon = new ItemStack(Material.LAVA_BUCKET); + } + else + { + icon = new ItemStack(Material.BUCKET); + } + + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRemoveWhenCompleted(!this.challenge.isRemoveWhenCompleted()); + this.build(); + + return true; + }; + glow = this.challenge.isRemoveWhenCompleted(); + break; + } + case NAME: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.name"); + description = Collections.emptyList(); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + + case REQUIRED_ENTITIES: + { + List values = new ArrayList<>(this.challenge.getRequiredEntities().size()); + + for (Map.Entry entry : this.challenge.getRequiredEntities().entrySet()) + { + values.add(entry.getKey().name() + " " + entry.getValue()); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.entities"); + description = values; + icon = new ItemStack(Material.CREEPER_HEAD); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Panel + this.build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_ENTITIES: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-entities"); + + if (this.challenge.isRemoveEntities()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRemoveEntities(!this.challenge.isRemoveEntities()); + + this.build(); + return true; + }; + glow = this.challenge.isRemoveEntities(); + break; + } + case REQUIRED_BLOCKS: + { + List values = new ArrayList<>(this.challenge.getRequiredBlocks().size()); + + for (Map.Entry entry : this.challenge.getRequiredBlocks().entrySet()) + { + values.add(entry.getKey().name() + " " + entry.getValue()); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.blocks"); + description = values; + icon = new ItemStack(Material.STONE); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Panel + this.build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_BLOCKS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-blocks"); + + if (this.challenge.isRemoveBlocks()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRemoveBlocks(!this.challenge.isRemoveBlocks()); + + this.build(); + return true; + }; + glow = this.challenge.isRemoveBlocks(); + break; + } + case SEARCH_RADIUS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.search-radius"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.search-radius", + "[value]", + Integer.toString(this.challenge.getSearchRadius()))); + icon = new ItemStack(Material.COBBLESTONE_WALL); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REQUIRED_PERMISSIONS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.permissions"); + description = new ArrayList<>(this.challenge.getReqPerms()); + icon = new ItemStack(Material.REDSTONE_LAMP); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + case REQUIRED_ITEMS: + { + List values = new ArrayList<>(this.challenge.getRequiredItems().size()); + + for (ItemStack itemStack : this.challenge.getRequiredItems()) + { + values.add(itemStack.getType().name() + " " + itemStack.getAmount()); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.required-items"); + description = values; + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Panel + this.build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_ITEMS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-items"); + + if (this.challenge.isTakeItems()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeItems(!this.challenge.isTakeItems()); + + this.build(); + return true; + }; + glow = this.challenge.isTakeItems(); + break; + } + case REQUIRED_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.required-exp"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.required-exp", + "[value]", + Integer.toString(this.challenge.getMaxTimes()))); + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-exp"); + + if (this.challenge.isTakeExperience()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeExperience(!this.challenge.isTakeExperience()); + + this.build(); + return true; + }; + glow = this.challenge.isTakeExperience(); + break; + } + case REQUIRED_LEVEL: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.required-level"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.required-level", + "[value]", + Long.toString(this.challenge.getReqIslandlevel()))); + icon = new ItemStack(Material.BEACON); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REQUIRED_MONEY: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.required-money"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.required-money", + "[value]", + Integer.toString(this.challenge.getReqMoney()))); + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_MONEY: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-money"); + + if (this.challenge.isTakeMoney()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); + + this.build(); + return true; + }; + glow = this.challenge.isTakeMoney(); + break; + } + + case REWARD_TEXT: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-text"); + description = Collections.singletonList(this.challenge.getRewardText()); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Implement challenges description change GUI. + this.build(); + return true; + }; + glow = false; + break; + } + case REWARD_ITEM: + { + List values = new ArrayList<>(this.challenge.getRewardItems().size()); + + for (ItemStack itemStack : this.challenge.getRewardItems()) + { + values.add(itemStack.getType().name() + " " + itemStack.getAmount()); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-items"); + description = values; + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Panel + this.build(); + + return true; + }; + glow = false; + break; + } + case REWARD_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-exp"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp", + "[value]", + Integer.toString(this.challenge.getRewardExp()))); + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REWARD_MONEY: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-money"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", + "[value]", + Integer.toString(this.challenge.getRewardMoney()))); + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REWARD_COMMANDS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-command"); + description = this.challenge.getRewardCommands(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + + case REPEATABLE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.repeatable"); + + if (this.challenge.isRepeatable()) + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + } + else + { + description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + } + + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setRepeatable(!this.challenge.isRepeatable()); + + this.build(); + return true; + }; + glow = this.challenge.isRepeatable(); + break; + } + case REPEAT_COUNT: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.repeat-count"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.repeat-count", + "[value]", + Integer.toString(this.challenge.getMaxTimes()))); + icon = new ItemStack(Material.COBBLESTONE_WALL); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + + case REPEAT_REWARD_TEXT: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.repeat-reward-text"); + description = Collections.singletonList(this.challenge.getRepeatRewardText()); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Implement challenges description change GUI. + this.build(); + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_ITEM: + { + List values = new ArrayList<>(this.challenge.getRepeatItemReward().size()); + + for (ItemStack itemStack : this.challenge.getRepeatItemReward()) + { + values.add(itemStack.getType().name() + " " + itemStack.getAmount()); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.repeat-reward-items"); + description = values; + icon = new ItemStack(Material.TRAPPED_CHEST); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Panel + this.build(); + + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.repeat-reward-exp"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-exp", + "[value]", + Integer.toString(this.challenge.getRepeatExpReward()))); + icon = new ItemStack(Material.GLASS_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_MONEY: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.repeat-reward-money"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-money", + "[value]", + Integer.toString(this.challenge.getRepeatMoneyReward()))); + icon = new ItemStack(Material.GOLD_NUGGET); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REPEAT_REWARD_COMMANDS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.repeat-reward-command"); + description = this.challenge.getRepeatRewardCommands(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, glow, clickHandler, false); + } + + + /** + * This method returns next challenge type from given. + * @param type Given challenge type. + * @return Next Challenge Type. + */ + private Challenges.ChallengeType getNextType(Challenges.ChallengeType type) + { + Challenges.ChallengeType[] values = Challenges.ChallengeType.values(); + + for (int i = 0; i < values.length; i++) + { + if (values[i].equals(type)) + { + if (i + 1 == values.length) + { + return values[0]; + } + else + { + return values[i + 1]; + } + } + } + + return type; + } + + + /** + * This method returns previous challenge type from given. + * @param type Given challenge type. + * @return Previous Challenge Type. + */ + private Challenges.ChallengeType getPreviousType(Challenges.ChallengeType type) + { + Challenges.ChallengeType[] values = Challenges.ChallengeType.values(); + + for (int i = 0; i < values.length; i++) + { + if (values[i].equals(type)) + { + if (i > 0) + { + return values[i - 1]; + } + else + { + return values[values.length - 1]; + } + } + } + + return type; + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * Represents different types of menus + */ + private enum MenuType + { + PROPERTIES, + REQUIREMENTS, + REWARDS + } + + + /** + * Represents different buttons that could be in menus. + */ + private enum Button + { + NAME, + TYPE, + DEPLOYED, + ICON, + DESCRIPTION, + ORDER, + ENVIRONMENT, + REMOVE_ON_COMPLETE, + + REQUIRED_ENTITIES, + REMOVE_ENTITIES, + REQUIRED_BLOCKS, + REMOVE_BLOCKS, + SEARCH_RADIUS, + REQUIRED_PERMISSIONS, + REQUIRED_ITEMS, + REMOVE_ITEMS, + REQUIRED_EXPERIENCE, + REMOVE_EXPERIENCE, + REQUIRED_LEVEL, + REQUIRED_MONEY, + REMOVE_MONEY, + + REWARD_TEXT, + REWARD_ITEM, + REWARD_EXPERIENCE, + REWARD_MONEY, + REWARD_COMMANDS, + + REPEATABLE, + REPEAT_COUNT, + + REPEAT_REWARD_TEXT, + REPEAT_REWARD_ITEM, + REPEAT_REWARD_EXPERIENCE, + REPEAT_REWARD_MONEY, + REPEAT_REWARD_COMMANDS, + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + + /** + * Variable holds challenge thats needs editing. + */ + private Challenges challenge; + + /** + * Variable holds current active menu. + */ + private MenuType currentMenuType; +} From 818892e618c0343edc0f40689d475f3ee6898c86 Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 16 Jan 2019 22:23:12 +0200 Subject: [PATCH 011/103] Create GUI that could edit challenges levels. --- .../challenges/ChallengesManager.java | 33 +- .../database/object/ChallengeLevels.java | 13 +- .../challenges/panel/admin/LevelsEditGUI.java | 532 ++++++++++++++++++ 3 files changed, 558 insertions(+), 20 deletions(-) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 7e2dfdb..7ff6270 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -1,17 +1,5 @@ package world.bentobox.challenges; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; -import java.util.stream.Collectors; import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; @@ -19,17 +7,20 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; +import world.bentobox.bentobox.api.configuration.Config; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.database.Database; +import world.bentobox.bentobox.util.Util; import world.bentobox.challenges.commands.admin.SurroundChallengeBuilder; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.database.object.Challenges.ChallengeType; import world.bentobox.challenges.database.object.ChallengesPlayerData; import world.bentobox.challenges.panel.ChallengesPanels; -import world.bentobox.bentobox.api.configuration.Config; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.Database; -import world.bentobox.bentobox.util.Util; public class ChallengesManager { @@ -514,4 +505,14 @@ public class ChallengesManager { } + public Challenges createChallenge() + { + return new Challenges(); + } + + + public List getChallenges(ChallengeLevels challengeLevel) + { + return new ArrayList<>(this.challengeMap.get(challengeLevel)); + } } diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java index 7f77fd8..dda7590 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java @@ -1,13 +1,13 @@ package world.bentobox.challenges.database.object; + +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; -import org.bukkit.inventory.ItemStack; - -import world.bentobox.challenges.ChallengesManager; import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.database.objects.DataObject; +import world.bentobox.challenges.ChallengesManager; /** * Represent a challenge level @@ -221,5 +221,10 @@ public class ChallengeLevels implements DataObject, Comparable } return true; } - + + + public ItemStack getIcon() + { + return null; + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java new file mode 100644 index 0000000..3532399 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java @@ -0,0 +1,532 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.database.object.ChallengeLevels; +import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class contains all necessary elements to create Levels Edit GUI. + */ +public class LevelsEditGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Constructors +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + * @param challengeLevel ChallengeLevel that must be edited. + */ + public LevelsEditGUI(ChallengesAddon addon, + World world, + User user, + ChallengeLevels challengeLevel, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, challengeLevel, topLabel, permissionPrefix, null); + } + + + /** + * {@inheritDoc} + * @param challengeLevel ChallengeLevel that must be edited. + */ + public LevelsEditGUI(ChallengesAddon addon, + World world, + User user, + ChallengeLevels challengeLevel, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.challengeLevel = challengeLevel; + this.currentMenuType = MenuType.PROPERTIES; + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name( + this.user.getTranslation("challenges.gui.admin.edit-level-title")); + + panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); + panelBuilder.item(4, this.createMenuButton(MenuType.REWARDS)); + panelBuilder.item(6, this.createMenuButton(MenuType.CHALLENGES)); + + if (this.currentMenuType.equals(MenuType.PROPERTIES)) + { + this.buildMainPropertiesPanel(panelBuilder); + } + else if (this.currentMenuType.equals(MenuType.CHALLENGES)) + { + this.buildChallengesPanel(panelBuilder); + } + else if (this.currentMenuType.equals(MenuType.REWARDS)) + { + this.buildRewardsPanel(panelBuilder); + } + + panelBuilder.item(53, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This class populate LevelsEditGUI with main level settings. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildMainPropertiesPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(10, this.createButton(Button.NAME)); + + panelBuilder.item(19, this.createButton(Button.ICON)); + panelBuilder.item(22, this.createButton(Button.UNLOCK_MESSAGE)); + panelBuilder.item(25, this.createButton(Button.ORDER)); + + panelBuilder.item(31, this.createButton(Button.WAIVER_AMOUNT)); + } + + + /** + * This class populate LevelsEditGUI with level rewards. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildRewardsPanel(PanelBuilder panelBuilder) + { + panelBuilder.item(11, this.createButton(Button.REWARD_DESCRIPTION)); + panelBuilder.item(20, this.createButton(Button.REWARD_ITEM)); + panelBuilder.item(29, this.createButton(Button.REWARD_EXPERIENCE)); + panelBuilder.item(38, this.createButton(Button.REWARD_MONEY)); + panelBuilder.item(47, this.createButton(Button.REWARD_COMMANDS)); + } + + + /** + * This class populate LevelsEditGUI with level challenges. + * @param panelBuilder PanelBuilder where icons must be added. + */ + private void buildChallengesPanel(PanelBuilder panelBuilder) + { + List challenges = this.addon.getChallengesManager().getChallenges(this.challengeLevel); + + if (this.pageIndex < 0) + { + this.pageIndex = 0; + } + else if (this.pageIndex > (challenges.size() / 18)) + { + this.pageIndex = challenges.size() / 18; + } + + int challengeIndex = 18 * this.pageIndex; + int elementIndex = 9; + + while (challengeIndex < ((this.pageIndex + 1) * 18) && + challengeIndex < challenges.size()) + { + panelBuilder.item(elementIndex++, this.createChallengeIcon(challenges.get(challengeIndex))); + challengeIndex++; + } + + if (this.pageIndex > 0) + { + panelBuilder.item(29, this.getButton(CommonButtons.PREVIOUS)); + } + + if (challengeIndex < challenges.size()) + { + panelBuilder.item(33, this.getButton(CommonButtons.NEXT)); + } + + panelBuilder.item(30, this.createButton(Button.ADD_CHALLENGE)); + panelBuilder.item(32, this.createButton(Button.REMOVE_CHALLENGE)); + } + + +// --------------------------------------------------------------------- +// Section: Other methods +// --------------------------------------------------------------------- + + + /** + * This method creates top menu buttons, that allows to switch "tabs". + * @param menuType Menu Type which button must be constructed. + * @return PanelItem that represents given menu type. + */ + private PanelItem createMenuButton(MenuType menuType) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + switch (menuType) + { + case PROPERTIES: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.properties"); + description = Collections.emptyList(); + icon = new ItemStack(Material.CRAFTING_TABLE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.PROPERTIES; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.PROPERTIES); + break; + } + case CHALLENGES: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.challenges"); + description = Collections.emptyList(); + icon = new ItemStack(Material.RAIL); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.CHALLENGES; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.CHALLENGES); + break; + } + case REWARDS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.rewards"); + description = Collections.emptyList(); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + this.currentMenuType = MenuType.REWARDS; + this.build(); + + return true; + }; + glow = this.currentMenuType.equals(MenuType.REWARDS); + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, glow, clickHandler, false); + } + + + /** + * This method creates given challenge icon. On click it should open Edit Challenge GUI. + * @param challenge Challenge which icon must be created. + * @return PanelItem that represents given challenge. + */ + private PanelItem createChallengeIcon(Challenges challenge) + { + return new PanelItemBuilder(). + name(challenge.getFriendlyName()). + description(challenge.getDescription()). + icon(challenge.getIcon()). + clickHandler((panel, user1, clickType, slot) -> { + // Open challenges edit screen. + new ChallengesEditGUI(this.addon, + this.world, + this.user, + challenge, + this.topLabel, + this.permissionPrefix, + this).build(); + return true; + }). + glow(!challenge.isDeployed()). + build(); + + } + + + /** + * This method creates buttons for default main menu. + * @param button Button which panel item must be created. + * @return PanelItem that represetns given button. + */ + private PanelItem createButton(Button button) + { + ItemStack icon; + String name; + List description; + boolean glow; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case NAME: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.name"); + description = Collections.singletonList(this.challengeLevel.getFriendlyName()); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + case ICON: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.icon"); + description = Collections.emptyList(); + icon = this.challengeLevel.getIcon(); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: how to change icon. + this.build(); + + return true; + }; + glow = false; + break; + } + case UNLOCK_MESSAGE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.description"); + description = Collections.singletonList(this.challengeLevel.getUnlockMessage()); + icon = new ItemStack(Material.WRITABLE_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Implement challenges description change GUI. + this.build(); + return true; + }; + glow = false; + break; + } + case ORDER: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.order"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.order", + "[value]", + Integer.toString(this.challengeLevel.getOrder()))); + icon = new ItemStack(Material.DROPPER); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case WAIVER_AMOUNT: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.waiver-amount"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.waiver-amount", + "[value]", + Integer.toString(this.challengeLevel.getWaiveramount()))); + icon = new ItemStack(Material.REDSTONE_TORCH); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + + case REWARD_DESCRIPTION: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-text"); + description = Collections.singletonList(this.challengeLevel.getRewardDescription()); + icon = new ItemStack(Material.WRITTEN_BOOK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Implement challenges description change GUI. + this.build(); + return true; + }; + glow = false; + break; + } + case REWARD_ITEM: + { + List values = new ArrayList<>(this.challengeLevel.getRewardItems().size()); + + for (ItemStack itemStack : this.challengeLevel.getRewardItems()) + { + values.add(itemStack.getType().name() + " " + itemStack.getAmount()); + } + + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-items"); + description = values; + icon = new ItemStack(Material.CHEST); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create Panel + this.build(); + + return true; + }; + glow = false; + break; + } + case REWARD_EXPERIENCE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-exp"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp", + "[value]", + Integer.toString(this.challengeLevel.getExpReward()))); + icon = new ItemStack(Material.EXPERIENCE_BOTTLE); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REWARD_MONEY: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-money"); + description = Collections.singletonList( + this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", + "[value]", + Integer.toString(this.challengeLevel.getMoneyReward()))); + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Possibility to change order. + this.build(); + + return true; + }; + glow = false; + break; + } + case REWARD_COMMANDS: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.reward-command"); + description = this.challengeLevel.getRewardCommands(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + + case ADD_CHALLENGE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.add-challenge"); + description = Collections.emptyList(); + icon = new ItemStack(Material.WATER_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + case REMOVE_CHALLENGE: + { + name = this.user.getTranslation("challenges.gui.admin.buttons.remove-challenge"); + description = Collections.emptyList(); + icon = new ItemStack(Material.LAVA_BUCKET); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Create naming + this.build(); + + return true; + }; + glow = false; + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, glow, clickHandler, false); + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * Represents different buttons that could be in menus. + */ + private enum Button + { + NAME, + ICON, + UNLOCK_MESSAGE, + ORDER, + WAIVER_AMOUNT, + + REWARD_DESCRIPTION, + REWARD_ITEM, + REWARD_EXPERIENCE, + REWARD_MONEY, + REWARD_COMMANDS, + + ADD_CHALLENGE, + REMOVE_CHALLENGE + } + + + /** + * Represents different types of menus + */ + private enum MenuType + { + PROPERTIES, + CHALLENGES, + REWARDS + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * This variable holds current challenge level that is in editing GUI. + */ + private ChallengeLevels challengeLevel; + + /** + * Variable holds current active menu. + */ + private MenuType currentMenuType; +} From dbe8cc50df3521fd530b2f3e1b89f9d973330740 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 11:33:13 +0200 Subject: [PATCH 012/103] Rename some GUIs. --- .../{ChallengesEditGUI.java => ChallengeEditGUI.java} | 6 +++--- .../panel/admin/{LevelsEditGUI.java => LevelEditGUI.java} | 8 ++++---- .../{ChallengesUserListGUI.java => UserListGUI.java} | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) rename src/main/java/world/bentobox/challenges/panel/admin/{ChallengesEditGUI.java => ChallengeEditGUI.java} (99%) rename src/main/java/world/bentobox/challenges/panel/admin/{LevelsEditGUI.java => LevelEditGUI.java} (98%) rename src/main/java/world/bentobox/challenges/panel/admin/{ChallengesUserListGUI.java => UserListGUI.java} (97%) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ChallengeEditGUI.java similarity index 99% rename from src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/ChallengeEditGUI.java index 6452cc5..874d92a 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesEditGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ChallengeEditGUI.java @@ -23,7 +23,7 @@ import world.bentobox.challenges.panel.CommonGUI; * This class contains all necessary methods that creates GUI and allow to edit challenges * properties. */ -public class ChallengesEditGUI extends CommonGUI +public class ChallengeEditGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Constructors @@ -34,7 +34,7 @@ public class ChallengesEditGUI extends CommonGUI * {@inheritDoc} * @param challenge challenge that needs editing. */ - public ChallengesEditGUI(ChallengesAddon addon, + public ChallengeEditGUI(ChallengesAddon addon, World world, User user, Challenges challenge, @@ -49,7 +49,7 @@ public class ChallengesEditGUI extends CommonGUI * {@inheritDoc} * @param challenge challenge that needs editing. */ - public ChallengesEditGUI(ChallengesAddon addon, + public ChallengeEditGUI(ChallengesAddon addon, World world, User user, Challenges challenge, diff --git a/src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/LevelEditGUI.java similarity index 98% rename from src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/LevelEditGUI.java index 3532399..5dfc036 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/LevelsEditGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/LevelEditGUI.java @@ -21,7 +21,7 @@ import world.bentobox.challenges.panel.CommonGUI; /** * This class contains all necessary elements to create Levels Edit GUI. */ -public class LevelsEditGUI extends CommonGUI +public class LevelEditGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Constructors @@ -32,7 +32,7 @@ public class LevelsEditGUI extends CommonGUI * {@inheritDoc} * @param challengeLevel ChallengeLevel that must be edited. */ - public LevelsEditGUI(ChallengesAddon addon, + public LevelEditGUI(ChallengesAddon addon, World world, User user, ChallengeLevels challengeLevel, @@ -47,7 +47,7 @@ public class LevelsEditGUI extends CommonGUI * {@inheritDoc} * @param challengeLevel ChallengeLevel that must be edited. */ - public LevelsEditGUI(ChallengesAddon addon, + public LevelEditGUI(ChallengesAddon addon, World world, User user, ChallengeLevels challengeLevel, @@ -253,7 +253,7 @@ public class LevelsEditGUI extends CommonGUI icon(challenge.getIcon()). clickHandler((panel, user1, clickType, slot) -> { // Open challenges edit screen. - new ChallengesEditGUI(this.addon, + new ChallengeEditGUI(this.addon, this.world, this.user, challenge, diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/UserListGUI.java similarity index 97% rename from src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/UserListGUI.java index 90d6306..3ee1232 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesUserListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/UserListGUI.java @@ -20,7 +20,7 @@ import world.bentobox.challenges.panel.CommonGUI; /** * This class contains methods that allows to select specific user. */ -public class ChallengesUserListGUI extends CommonGUI +public class UserListGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Variables @@ -56,7 +56,7 @@ public class ChallengesUserListGUI extends CommonGUI /** * {@inheritDoc} */ - public ChallengesUserListGUI(ChallengesAddon addon, + public UserListGUI(ChallengesAddon addon, World world, User user, String topLabel, String permissionPrefix) { @@ -67,7 +67,7 @@ public class ChallengesUserListGUI extends CommonGUI /** * {@inheritDoc} */ - public ChallengesUserListGUI(ChallengesAddon addon, + public UserListGUI(ChallengesAddon addon, World world, User user, String topLabel, From efab8f7e243952610abeae128ebdbc7dcbf4aa95 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 11:36:39 +0200 Subject: [PATCH 013/103] Improve GUIs naming. --- .../admin/{ChallengesAdminGUI.java => AdminGUI.java} | 4 ++-- .../{ChallengeEditGUI.java => EditChallengeGUI.java} | 6 +++--- .../panel/admin/{LevelEditGUI.java => EditLevelGUI.java} | 8 ++++---- .../{ChallengesSettingsGUI.java => EditSettingsGUI.java} | 6 +++--- .../panel/admin/{UserListGUI.java => ListUsersGUI.java} | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) rename src/main/java/world/bentobox/challenges/panel/admin/{ChallengesAdminGUI.java => AdminGUI.java} (98%) rename src/main/java/world/bentobox/challenges/panel/admin/{ChallengeEditGUI.java => EditChallengeGUI.java} (99%) rename src/main/java/world/bentobox/challenges/panel/admin/{LevelEditGUI.java => EditLevelGUI.java} (98%) rename src/main/java/world/bentobox/challenges/panel/admin/{ChallengesSettingsGUI.java => EditSettingsGUI.java} (95%) rename src/main/java/world/bentobox/challenges/panel/admin/{UserListGUI.java => ListUsersGUI.java} (97%) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java similarity index 98% rename from src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 3417074..7f0f405 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesAdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -18,7 +18,7 @@ import world.bentobox.challenges.panel.CommonGUI; /** * This class contains Main */ -public class ChallengesAdminGUI extends CommonGUI +public class AdminGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Variables @@ -61,7 +61,7 @@ public class ChallengesAdminGUI extends CommonGUI /** * {@inheritDoc} */ - public ChallengesAdminGUI(ChallengesAddon addon, + public AdminGUI(ChallengesAddon addon, World world, User user, String topLabel, diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengeEditGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java similarity index 99% rename from src/main/java/world/bentobox/challenges/panel/admin/ChallengeEditGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 874d92a..84cf021 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ChallengeEditGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -23,7 +23,7 @@ import world.bentobox.challenges.panel.CommonGUI; * This class contains all necessary methods that creates GUI and allow to edit challenges * properties. */ -public class ChallengeEditGUI extends CommonGUI +public class EditChallengeGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Constructors @@ -34,7 +34,7 @@ public class ChallengeEditGUI extends CommonGUI * {@inheritDoc} * @param challenge challenge that needs editing. */ - public ChallengeEditGUI(ChallengesAddon addon, + public EditChallengeGUI(ChallengesAddon addon, World world, User user, Challenges challenge, @@ -49,7 +49,7 @@ public class ChallengeEditGUI extends CommonGUI * {@inheritDoc} * @param challenge challenge that needs editing. */ - public ChallengeEditGUI(ChallengesAddon addon, + public EditChallengeGUI(ChallengesAddon addon, World world, User user, Challenges challenge, diff --git a/src/main/java/world/bentobox/challenges/panel/admin/LevelEditGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java similarity index 98% rename from src/main/java/world/bentobox/challenges/panel/admin/LevelEditGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 5dfc036..7b12de6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/LevelEditGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -21,7 +21,7 @@ import world.bentobox.challenges.panel.CommonGUI; /** * This class contains all necessary elements to create Levels Edit GUI. */ -public class LevelEditGUI extends CommonGUI +public class EditLevelGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Constructors @@ -32,7 +32,7 @@ public class LevelEditGUI extends CommonGUI * {@inheritDoc} * @param challengeLevel ChallengeLevel that must be edited. */ - public LevelEditGUI(ChallengesAddon addon, + public EditLevelGUI(ChallengesAddon addon, World world, User user, ChallengeLevels challengeLevel, @@ -47,7 +47,7 @@ public class LevelEditGUI extends CommonGUI * {@inheritDoc} * @param challengeLevel ChallengeLevel that must be edited. */ - public LevelEditGUI(ChallengesAddon addon, + public EditLevelGUI(ChallengesAddon addon, World world, User user, ChallengeLevels challengeLevel, @@ -253,7 +253,7 @@ public class LevelEditGUI extends CommonGUI icon(challenge.getIcon()). clickHandler((panel, user1, clickType, slot) -> { // Open challenges edit screen. - new ChallengeEditGUI(this.addon, + new EditChallengeGUI(this.addon, this.world, this.user, challenge, diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java similarity index 95% rename from src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java index 13d62b4..a8a2252 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ChallengesSettingsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java @@ -15,7 +15,7 @@ import world.bentobox.challenges.panel.CommonGUI; * This Class creates GUI that allows to change Challenges Addon Settings via in-game * menu. */ -public class ChallengesSettingsGUI extends CommonGUI +public class EditSettingsGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Constructors @@ -25,7 +25,7 @@ public class ChallengesSettingsGUI extends CommonGUI /** * {@inheritDoc} */ - public ChallengesSettingsGUI(ChallengesAddon addon, + public EditSettingsGUI(ChallengesAddon addon, World world, User user, String topLabel, @@ -38,7 +38,7 @@ public class ChallengesSettingsGUI extends CommonGUI /** * {@inheritDoc} */ - public ChallengesSettingsGUI(ChallengesAddon addon, + public EditSettingsGUI(ChallengesAddon addon, World world, User user, String topLabel, diff --git a/src/main/java/world/bentobox/challenges/panel/admin/UserListGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java similarity index 97% rename from src/main/java/world/bentobox/challenges/panel/admin/UserListGUI.java rename to src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index 3ee1232..63c99ae 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/UserListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -20,7 +20,7 @@ import world.bentobox.challenges.panel.CommonGUI; /** * This class contains methods that allows to select specific user. */ -public class UserListGUI extends CommonGUI +public class ListUsersGUI extends CommonGUI { // --------------------------------------------------------------------- // Section: Variables @@ -56,7 +56,7 @@ public class UserListGUI extends CommonGUI /** * {@inheritDoc} */ - public UserListGUI(ChallengesAddon addon, + public ListUsersGUI(ChallengesAddon addon, World world, User user, String topLabel, String permissionPrefix) { @@ -67,7 +67,7 @@ public class UserListGUI extends CommonGUI /** * {@inheritDoc} */ - public UserListGUI(ChallengesAddon addon, + public ListUsersGUI(ChallengesAddon addon, World world, User user, String topLabel, From 7060afd33d99759ebdccc7a4bc89559f43920838 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 12:04:16 +0200 Subject: [PATCH 014/103] Create ListLevelsGUI class that allows to view all Levels. It has 2 modes: edit mode and delete mode. --- .../challenges/ChallengesManager.java | 6 + .../challenges/panel/admin/ListLevelsGUI.java | 176 ++++++++++++++++++ 2 files changed, 182 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 7ff6270..44e7664 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -515,4 +515,10 @@ public class ChallengesManager { { return new ArrayList<>(this.challengeMap.get(challengeLevel)); } + + + public List getChallengeLevelList() + { + return new ArrayList<>(this.challengeMap.keySet()); + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java new file mode 100644 index 0000000..5167706 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -0,0 +1,176 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.World; + +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.database.object.ChallengeLevels; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class creates GUI that lists all Levels. Clicking on Level icon will be processed + * by input mode. + */ +public class ListLevelsGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Constructor +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + * @param mode - mode that indicate what should do icon clicking. + */ + public ListLevelsGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, mode, topLabel, permissionPrefix, null); + } + + + /** + * {@inheritDoc} + * @param mode - mode that indicate what should do icon clicking. + */ + public ListLevelsGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.currentMode = mode; + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.admin.choose-level-title")); + + List levelList = this.addon.getChallengesManager().getChallengeLevelList(); + + int MAX_ELEMENTS = 45; + if (this.pageIndex < 0) + { + this.pageIndex = 0; + } + else if (this.pageIndex > (levelList.size() / MAX_ELEMENTS)) + { + this.pageIndex = levelList.size() / MAX_ELEMENTS; + } + + int levelIndex = MAX_ELEMENTS * this.pageIndex; + + while (levelIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + levelIndex < levelList.size()) + { + panelBuilder.item(this.createLevelIcon(levelList.get(levelIndex))); + levelIndex++; + } + + int nextIndex = levelIndex % MAX_ELEMENTS == 0 ? + MAX_ELEMENTS : + (((levelIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9; + + if (levelIndex > MAX_ELEMENTS) + { + panelBuilder.item(nextIndex + 2, this.getButton(CommonButtons.PREVIOUS)); + } + + if (levelIndex < levelList.size()) + { + panelBuilder.item(nextIndex + 6, this.getButton(CommonButtons.NEXT)); + } + + panelBuilder.item(nextIndex + 8, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This method creates button for given level + * @param challengeLevel Level which button must be created. + * @return Level button. + */ + private PanelItem createLevelIcon(ChallengeLevels challengeLevel) + { + PanelItemBuilder itemBuilder = new PanelItemBuilder(). + name(challengeLevel.getFriendlyName()). + description(challengeLevel.getUnlockMessage()). + icon(challengeLevel.getIcon()). + glow(false); + + if (this.currentMode.equals(Mode.EDIT)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + new EditLevelGUI(this.addon, + this.world, + this.user, + challengeLevel, + this.topLabel, + this.permissionPrefix, + this).build(); + return true; + }); + } + else if (this.currentMode.equals(Mode.DELETE)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + // TODO: Conformation GUI for DELETING. + return true; + }); + } + + return itemBuilder.build(); + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * Mode in which gui icons should processed. + */ + public enum Mode + { + EDIT, + DELETE + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * Current mode in which icons will act. + */ + private Mode currentMode; +} From aaaf774952acc316ea049adcd41c11a2491c93e6 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 12:10:29 +0200 Subject: [PATCH 015/103] Create ListChallengesGUI that allows to view all challenges and Edit or Remove them, depending on given mode. --- .../challenges/ChallengesManager.java | 6 + .../panel/admin/ListChallengesGUI.java | 175 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 44e7664..75081f2 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -521,4 +521,10 @@ public class ChallengesManager { { return new ArrayList<>(this.challengeMap.keySet()); } + + + public List getChallengesList() + { + return new ArrayList<>(); + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java new file mode 100644 index 0000000..20464e3 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -0,0 +1,175 @@ +package world.bentobox.challenges.panel.admin; + + +import org.bukkit.World; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class contains all necessary elements to create GUI that lists all challenges. + * It allows to edit them or remove, depending on given input mode. + */ +public class ListChallengesGUI extends CommonGUI +{ + // --------------------------------------------------------------------- +// Section: Constructor +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + * @param mode - mode that indicate what should do icon clicking. + */ + public ListChallengesGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix) + { + this(addon, world, user, mode, topLabel, permissionPrefix, null); + } + + + /** + * {@inheritDoc} + * @param mode - mode that indicate what should do icon clicking. + */ + public ListChallengesGUI(ChallengesAddon addon, + World world, + User user, + Mode mode, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.currentMode = mode; + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( + this.user.getTranslation("challenges.gui.admin.choose-challenge-title")); + + List challengeList = this.addon.getChallengesManager().getChallengesList(); + + int MAX_ELEMENTS = 45; + if (this.pageIndex < 0) + { + this.pageIndex = 0; + } + else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) + { + this.pageIndex = challengeList.size() / MAX_ELEMENTS; + } + + int challengeIndex = MAX_ELEMENTS * this.pageIndex; + + while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + challengeIndex < challengeList.size()) + { + panelBuilder.item(this.createChallengeIcon(challengeList.get(challengeIndex))); + challengeIndex++; + } + + int nextIndex = challengeIndex % MAX_ELEMENTS == 0 ? + MAX_ELEMENTS : + (((challengeIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9; + + if (challengeIndex > MAX_ELEMENTS) + { + panelBuilder.item(nextIndex + 2, this.getButton(CommonButtons.PREVIOUS)); + } + + if (challengeIndex < challengeList.size()) + { + panelBuilder.item(nextIndex + 6, this.getButton(CommonButtons.NEXT)); + } + + panelBuilder.item(nextIndex + 8, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This method creates button for given challenge. + * @param challenge Challenge which button must be created. + * @return Challenge button. + */ + private PanelItem createChallengeIcon(Challenges challenge) + { + PanelItemBuilder itemBuilder = new PanelItemBuilder(). + name(challenge.getFriendlyName()). + description(challenge.getDescription()). + icon(challenge.getIcon()). + glow(challenge.isDeployed()); + + if (this.currentMode.equals(Mode.EDIT)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + new EditChallengeGUI(this.addon, + this.world, + this.user, + challenge, + this.topLabel, + this.permissionPrefix, + this).build(); + return true; + }); + } + else if (this.currentMode.equals(Mode.DELETE)) + { + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + // TODO: Conformation GUI for DELETING. + return true; + }); + } + + return itemBuilder.build(); + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * Mode in which gui icons should processed. + */ + public enum Mode + { + EDIT, + DELETE + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * Current mode in which icons will act. + */ + private Mode currentMode; +} From 35cea3344a99330b0234ebfa7d8e366136db31a0 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 12:19:33 +0200 Subject: [PATCH 016/103] Add different operation modes for ListUsersGUI. --- .../challenges/panel/admin/ListUsersGUI.java | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index 63c99ae..3365ad6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -31,12 +31,16 @@ public class ListUsersGUI extends CommonGUI */ private List onlineUsers; + /** + * Current operation mode. + */ + private Mode operationMode; + /** * Current index of view mode */ private int modeIndex = 2; - /** * This allows to switch which users should be in the list. */ @@ -47,6 +51,16 @@ public class ListUsersGUI extends CommonGUI IN_WORLD } + /** + * This allows to decide what User Icon should do. + */ + private enum Mode + { + COMPLETE, + RESET, + RESET_ALL + } + // --------------------------------------------------------------------- // Section: Constructors @@ -55,27 +69,34 @@ public class ListUsersGUI extends CommonGUI /** * {@inheritDoc} + * @param operationMode Indicate what should happen on player icon click. */ public ListUsersGUI(ChallengesAddon addon, World world, - User user, String topLabel, String permissionPrefix) + User user, + Mode operationMode, + String topLabel, + String permissionPrefix) { - this(addon, world, user, topLabel, permissionPrefix, null); + this(addon, world, user, operationMode, topLabel, permissionPrefix, null); } /** * {@inheritDoc} + * @param operationMode Indicate what should happen on player icon click. */ public ListUsersGUI(ChallengesAddon addon, World world, User user, + Mode operationMode, String topLabel, String permissionPrefix, CommonGUI parentPanel) { super(addon, world, user, topLabel, permissionPrefix, parentPanel); this.onlineUsers = this.collectUsers(ViewMode.IN_WORLD); + this.operationMode = operationMode; } @@ -145,7 +166,18 @@ public class ListUsersGUI extends CommonGUI { return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler( (panel, user1, clickType, slot) -> { - // TODO Add operations that should be called from here + switch (this.operationMode) + { + case COMPLETE: + // TODO: Open Complete Challenge GUI. + break; + case RESET: + // TODO: Open Reset Challenge GUI. + break; + case RESET_ALL: + // TODO: Confirmation GUI for resetting all challenges. + break; + } return true; }).build(); From e1f6cc8b47b4c9cf1f891a6c079a0470b7dd29bc Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 13:16:42 +0200 Subject: [PATCH 017/103] Create ConfirmationGUI class that creates GUI with 2 buttons. On Cancel it should return to previous GUI. On Accept it should process given command. If command does not exist, it should throw error message in chat. At the end it should return to previous GUI. --- .../panel/util/ConfirmationGUI.java | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java new file mode 100644 index 0000000..9ba7ac1 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -0,0 +1,138 @@ +package world.bentobox.challenges.panel.util; + + + + +import org.bukkit.Material; + +import java.util.*; + +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This GUI is used to confirm that user wants to run command, that should be created from + * command string list. + */ +public class ConfirmationGUI +{ + /** + * This constructor inits and opens ConfirmationGUI. + * @param user Gui Caller. + * @param parentGUI Parent GUI. + * @param commandLabels Command labels. + * @param variables Variables at the end of command. + */ + public ConfirmationGUI(BentoBox plugin, + User user, + CommonGUI parentGUI, + List commandLabels, + String... variables) + { + this.plugin = plugin; + this.user = user; + this.parentGUI = parentGUI; + this.commandLabels = commandLabels; + this.variables = variables; + + if (this.commandLabels.isEmpty()) + { + this.user.sendMessage("challenges.errors.missing-command"); + } + else + { + this.build(); + } + } + + + /** + * This method builds confirmation panel with 2 buttons. + */ + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.admin.confirm-title")); + + panelBuilder.item(3, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")). + icon(Material.GREEN_STAINED_GLASS_PANE). + clickHandler((panel, user1, clickType, index) -> + { + Iterator iterator = this.commandLabels.iterator(); + + CompositeCommand command = this.plugin.getCommandsManager().getCommand(iterator.next()); + + while (iterator.hasNext() && command != null) + { + Optional commandOptional = command.getSubCommand(iterator.next()); + + if (commandOptional.isPresent()) + { + command = commandOptional.get(); + } + else + { + this.user.sendMessage("challenges.errors.missing-command"); + command = null; + } + } + + if (command != null) + { + command.execute(this.user, "CONFIRMATION", Arrays.asList(this.variables)); + } + + this.user.closeInventory(); + this.parentGUI.build(); + return true; + }). + build()); + + panelBuilder.item(5, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.cancel")). + icon(Material.RED_STAINED_GLASS_PANE). + clickHandler((panel, user1, clickType, i) -> + { + this.parentGUI.build(); + return true; + }). + build()); + + panelBuilder.build(); + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * BentoBox plugin. + */ + private BentoBox plugin; + + /** + * User who wants to run command. + */ + private User user; + + /** + * Parent GUI where should return on cancel or proceed. + */ + private CommonGUI parentGUI; + + /** + * List of command labels. + */ + private List commandLabels; + + /** + * List of variables. + */ + private String[] variables; +} From 6903fa5d40a24bf4bc6c9d8da8e2427d9bcfa97d Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 16:23:03 +0200 Subject: [PATCH 018/103] Create NumberGUI that allows to change integer value and run command that will apply this integer. --- .../challenges/panel/util/NumberGUI.java | 338 ++++++++++++++++++ 1 file changed, 338 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java new file mode 100644 index 0000000..5844eb8 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -0,0 +1,338 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This gui allows to change current number and returns it to previous GUI + */ +public class NumberGUI +{ + public NumberGUI(CommonGUI parentGUI, + User user, + int value, + CompositeCommand command, + String... parameters) + { + this.parentGUI = parentGUI; + this.user = user; + this.value = value; + this.command = command; + this.parameters = parameters; + + this.currentOperation = Button.SET; + + this.build(); + } + + + /** + * This method builds panel that allows to change given number value. + */ + private void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.edit-number-title")); + + // Others + panelBuilder.item(0, this.getButton(Button.SAVE)); + panelBuilder.item(1, this.getButton(Button.VALUE)); + panelBuilder.item(8, this.getButton(Button.CANCEL)); + panelBuilder.item(10, this.getButton(Button.INPUT)); + + // operations + panelBuilder.item(3, this.getButton(Button.SET)); + panelBuilder.item(4, this.getButton(Button.INCREASE)); + panelBuilder.item(5, this.getButton(Button.REDUCE)); + panelBuilder.item(6, this.getButton(Button.MULTIPLY)); + + // Numbers + panelBuilder.item(20, this.createNumberButton(1)); + panelBuilder.item(21, this.createNumberButton(10)); + panelBuilder.item(22, this.createNumberButton(100)); + panelBuilder.item(23, this.createNumberButton(1000)); + panelBuilder.item(24, this.createNumberButton(10000)); + + panelBuilder.item(29, this.createNumberButton(2)); + panelBuilder.item(30, this.createNumberButton(20)); + panelBuilder.item(31, this.createNumberButton(200)); + panelBuilder.item(32, this.createNumberButton(2000)); + panelBuilder.item(33, this.createNumberButton(20000)); + + panelBuilder.item(38, this.createNumberButton(5)); + panelBuilder.item(39, this.createNumberButton(50)); + panelBuilder.item(40, this.createNumberButton(500)); + panelBuilder.item(41, this.createNumberButton(5000)); + panelBuilder.item(42, this.createNumberButton(50000)); + + panelBuilder.build(); + } + + + /** + * This method creates PanelItem with required functionality. + * @param button Functionality requirement. + * @return PanelItem with functionality. + */ + private PanelItem getButton(Button button) + { + ItemStack icon; + String name; + List description; + PanelItem.ClickHandler clickHandler; + boolean glow; + + switch (button) + { + case SAVE: + { + name = this.user.getTranslation("challenges.gui.buttons.save"); + description = Collections.emptyList(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + List values = Arrays.asList(this.parameters); + values.add(Integer.toString(this.value)); + + if (this.command.execute(this.user, "NUMBER_GUI", values)) + { + this.user.closeInventory(); + this.parentGUI.build(); + } + else + { + this.build(); + } + + return true; + }; + glow = false; + break; + } + case CANCEL: + { + name = this.user.getTranslation("challenges.gui.buttons.cancel"); + description = Collections.emptyList(); + icon = new ItemStack(Material.IRON_DOOR); + clickHandler = (panel, user, clickType, slot) -> { + this.parentGUI.build(); + return true; + }; + glow = false; + break; + } + case INPUT: + { + name = this.user.getTranslation("challenges.gui.buttons.input"); + description = Collections.emptyList(); + icon = new ItemStack(Material.ANVIL); + clickHandler = (panel, user, clickType, slot) -> { + // TODO: Build Anvil GUI for editing value. + + this.build(); + return true; + }; + glow = false; + break; + } + case VALUE: + { + name = this.user.getTranslation("challenges.gui.buttons.value"); + description = Collections.singletonList(Integer.toString(this.value)); + icon = new ItemStack(Material.PAPER); + clickHandler = (panel, user, clickType, slot) -> true; + glow = false; + break; + } + case SET: + { + name = this.user.getTranslation("challenges.gui.buttons.set"); + description = Collections.emptyList(); + icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentOperation = Button.SET; + this.build(); + return true; + }; + glow = this.currentOperation.equals(Button.SET); + break; + } + case INCREASE: + { + name = this.user.getTranslation("challenges.gui.buttons.increase"); + description = Collections.emptyList(); + icon = new ItemStack(Material.GREEN_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentOperation = Button.INCREASE; + this.build(); + return true; + }; + glow = this.currentOperation.equals(Button.INCREASE); + break; + } + case REDUCE: + { + name = this.user.getTranslation("challenges.gui.buttons.reduce"); + description = Collections.emptyList(); + icon = new ItemStack(Material.RED_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentOperation = Button.REDUCE; + this.build(); + return true; + }; + glow = this.currentOperation.equals(Button.REDUCE); + break; + } + case MULTIPLY: + { + name = this.user.getTranslation("challenges.gui.buttons.multiply"); + description = Collections.emptyList(); + icon = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + this.currentOperation = Button.MULTIPLY; + this.build(); + return true; + }; + glow = this.currentOperation.equals(Button.MULTIPLY); + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, glow, clickHandler, false); + } + + + /** + * This method creates Number Button based on input number. + * @param number Number which button must be created. + * @return PanelItem that represents number button. + */ + private PanelItem createNumberButton(int number) + { + PanelItemBuilder itemBuilder = new PanelItemBuilder(); + + switch (this.currentOperation) + { + case SET: + { + itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.set","[number]", Integer.toString(number))); + itemBuilder.icon(Material.WHITE_STAINED_GLASS_PANE); + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + this.value = number; + this.build(); + return true; + }); + + break; + } + case INCREASE: + { + itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.increase","[number]", Integer.toString(number))); + itemBuilder.icon(Material.GREEN_STAINED_GLASS_PANE); + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + this.value += number; + this.build(); + return true; + }); + + break; + } + case REDUCE: + { + itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.reduce","[number]", Integer.toString(number))); + itemBuilder.icon(Material.RED_STAINED_GLASS_PANE); + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + this.value -= number; + this.build(); + return true; + }); + + break; + } + case MULTIPLY: + { + itemBuilder.name(this.user.getTranslation("biomes.gui.buttons.multiply","[number]", Integer.toString(number))); + itemBuilder.icon(Material.BLUE_STAINED_GLASS_PANE); + itemBuilder.clickHandler((panel, user1, clickType, i) -> { + this.value *= number; + this.build(); + return true; + }); + + break; + } + } + + return itemBuilder.build(); + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * This enum contains all button types. + */ + private enum Button + { + SAVE, + CANCEL, + INPUT, + + VALUE, + + SET, + INCREASE, + REDUCE, + MULTIPLY + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * This variable stores return GUI. + */ + private CommonGUI parentGUI; + + /** + * User who runs GUI. + */ + private User user; + + /** + * Current value. + */ + private int value; + + /** + * Command that must be processed on save. + */ + private CompositeCommand command; + + /** + * Command input parameters before number. + */ + private String[] parameters; + + /** + * This variable holds which operation now is processed. + */ + private Button currentOperation; +} From c79173b41141d63680f94f331111d8f35cc2d98d Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 16:27:16 +0200 Subject: [PATCH 019/103] Remove command existing check from ConfirmationGUI. Add CompositeCommand as class variable. --- .../panel/util/ConfirmationGUI.java | 69 +++++-------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java index 9ba7ac1..1fa7178 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -1,13 +1,9 @@ package world.bentobox.challenges.panel.util; - - - import org.bukkit.Material; import java.util.*; -import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -23,31 +19,23 @@ public class ConfirmationGUI { /** * This constructor inits and opens ConfirmationGUI. + * * @param user Gui Caller. * @param parentGUI Parent GUI. - * @param commandLabels Command labels. - * @param variables Variables at the end of command. + * @param command Command . + * @param parameters Variables at the end of command. */ - public ConfirmationGUI(BentoBox plugin, + public ConfirmationGUI(CommonGUI parentGUI, User user, - CommonGUI parentGUI, - List commandLabels, - String... variables) + CompositeCommand command, + String... parameters) { - this.plugin = plugin; this.user = user; this.parentGUI = parentGUI; - this.commandLabels = commandLabels; - this.variables = variables; + this.command = command; + this.parameters = parameters; - if (this.commandLabels.isEmpty()) - { - this.user.sendMessage("challenges.errors.missing-command"); - } - else - { - this.build(); - } + this.build(); } @@ -56,36 +44,16 @@ public class ConfirmationGUI */ public void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.admin.confirm-title")); + PanelBuilder panelBuilder = new PanelBuilder() + .name(this.user.getTranslation("challenges.gui.admin.confirm-title")); panelBuilder.item(3, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")). icon(Material.GREEN_STAINED_GLASS_PANE). clickHandler((panel, user1, clickType, index) -> { - Iterator iterator = this.commandLabels.iterator(); - - CompositeCommand command = this.plugin.getCommandsManager().getCommand(iterator.next()); - - while (iterator.hasNext() && command != null) - { - Optional commandOptional = command.getSubCommand(iterator.next()); - - if (commandOptional.isPresent()) - { - command = commandOptional.get(); - } - else - { - this.user.sendMessage("challenges.errors.missing-command"); - command = null; - } - } - - if (command != null) - { - command.execute(this.user, "CONFIRMATION", Arrays.asList(this.variables)); - } + this.command + .execute(this.user, "CONFIRMATION", Arrays.asList(this.parameters)); this.user.closeInventory(); this.parentGUI.build(); @@ -111,11 +79,6 @@ public class ConfirmationGUI // Section: Variables // --------------------------------------------------------------------- - /** - * BentoBox plugin. - */ - private BentoBox plugin; - /** * User who wants to run command. */ @@ -127,12 +90,12 @@ public class ConfirmationGUI private CommonGUI parentGUI; /** - * List of command labels. + * Command that must be run on confirmation. */ - private List commandLabels; + private CompositeCommand command; /** * List of variables. */ - private String[] variables; + private String[] parameters; } From 1508492a692dc46b76abb223c4e854c65bd22255 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 16:55:32 +0200 Subject: [PATCH 020/103] Create StringListGUI class that allows to edit list of strings. --- .../challenges/panel/util/StringListGUI.java | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java new file mode 100644 index 0000000..3ba79a8 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -0,0 +1,241 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.commands.CompositeCommand; +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This GUI allows to edit List of strings. AnvilGUI has limited text space, so splitting + * text in multiple rows allows to edit each row separately. + */ +public class StringListGUI +{ + public StringListGUI(CommonGUI parentGUI, + User user, + List value, + CompositeCommand command, + String... parameters) + { + this.parentGUI = parentGUI; + this.user = user; + this.value = value; + this.command = command; + this.parameters = parameters; + + if (this.value.size() > 18) + { + // TODO: throw error that so large list cannot be edited. + this.parentGUI.build(); + } + else + { + this.build(); + } + } + + + /** + * This method builds panel that allows to change given string value. + */ + private void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.text-edit-title")); + + panelBuilder.item(0, this.getButton(Button.SAVE)); + panelBuilder.item(1, this.getButton(Button.VALUE)); + + panelBuilder.item(3, this.getButton(Button.ADD)); + panelBuilder.item(4, this.getButton(Button.REMOVE)); + panelBuilder.item(4, this.getButton(Button.CLEAR)); + + panelBuilder.item(8, this.getButton(Button.CANCEL)); + + for (String element : this.value) + { + panelBuilder.item(this.createStringElement(element)); + } + + panelBuilder.build(); + } + + + /** + * This method create button that does some functionality in current gui. + * @param button Button functionality. + * @return PanelItem. + */ + private PanelItem getButton(Button button) + { + ItemStack icon; + String name; + List description; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case SAVE: + { + name = this.user.getTranslation("challenges.gui.buttons.save"); + description = Collections.emptyList(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + List values = Arrays.asList(this.parameters); + values.addAll(this.value); + + if (this.command.execute(this.user, "STRING_LIST_GUI", values)) + { + this.user.closeInventory(); + this.parentGUI.build(); + } + else + { + this.build(); + } + + return true; + }; + break; + } + case CANCEL: + { + name = this.user.getTranslation("challenges.gui.buttons.cancel"); + description = Collections.emptyList(); + icon = new ItemStack(Material.IRON_DOOR); + clickHandler = (panel, user, clickType, slot) -> { + this.parentGUI.build(); + return true; + }; + break; + } + case VALUE: + { + name = this.user.getTranslation("challenges.gui.buttons.value"); + description = this.value; + icon = new ItemStack(Material.PAPER); + clickHandler = (panel, user, clickType, slot) -> true; + break; + } + case ADD: + { + name = this.user.getTranslation("challenges.gui.buttons.add"); + description = Collections.emptyList(); + icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + + // TODO: Open Anvil GUI. + + this.build(); + return true; + }; + break; + } + case CLEAR: + { + name = this.user.getTranslation("challenges.gui.buttons.clear"); + description = Collections.emptyList(); + icon = new ItemStack(Material.RED_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + this.value.clear(); + this.build(); + return true; + }; + break; + } + case REMOVE: + { + name = this.user.getTranslation("challenges.gui.buttons.remove"); + description = Collections.emptyList(); + icon = new ItemStack(Material.BLUE_STAINED_GLASS_PANE); + clickHandler = (panel, user, clickType, slot) -> { + this.value.removeIf(String::isEmpty); + + this.build(); + return true; + }; + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, false, clickHandler, false); + } + + + /** + * This method creates paper icon that represents single line from list. + * @param element Paper Icon name + * @return PanelItem. + */ + private PanelItem createStringElement(String element) + { + return new PanelItemBuilder(). + name(element). + icon(Material.PAPER). + clickHandler((panel, user1, clickType, i) -> { + // TODO: open anvil gui. + return true; + }).build(); + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * This enum holds all button values in current gui. + */ + private enum Button + { + VALUE, + ADD, + REMOVE, + CANCEL, + CLEAR, + SAVE + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + + /** + * This variable stores return GUI. + */ + private CommonGUI parentGUI; + + /** + * User who runs GUI. + */ + private User user; + + /** + * Current value. + */ + private List value; + + /** + * Command that must be processed on save. + */ + private CompositeCommand command; + + /** + * Command input parameters before number. + */ + private String[] parameters; +} From 2ae8a5d63460198fe77b2dfc334ffba3b2de84d6 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Thu, 17 Jan 2019 17:49:51 +0200 Subject: [PATCH 021/103] Create ItemGUI class that will be used to change all required and reward item stacks. --- .../challenges/panel/util/ItemGUI.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java new file mode 100644 index 0000000..552c77b --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java @@ -0,0 +1,129 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.ItemStack; +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.PanelListener; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.user.User; + + +/** + * This class allows to change Input ItemStacks to different ItemStacks. + */ +public class ItemGUI +{ + public ItemGUI(User user, List itemStacks) + { + this.user = user; + this.itemStacks = itemStacks; + this.build(); + } + + + /** + * This method builds panel that allows to change given number value. + */ + private void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); + panelBuilder.listener(new CustomPanelListener()); + + for (ItemStack itemStack : this.itemStacks) + { + panelBuilder.item(new CustomPanelItem(itemStack)); + } + + panelBuilder.build().open(this.user); + } + + +// --------------------------------------------------------------------- +// Section: Private classes +// --------------------------------------------------------------------- + + + /** + * This CustomPanelItem does no lose Item original MetaData. After PanelItem has been + * created it restores original meta data. It also does not allow to change anything that + * could destroy meta data. + */ + private class CustomPanelItem extends PanelItem + { + CustomPanelItem(ItemStack item) + { + super(item.clone(), "", Collections.emptyList(), false, null, false); + this.getItem().setItemMeta(item.getItemMeta()); + } + + + @Override + public void setGlow(boolean glow) + { + } + + + @Override + public void setDescription(List description) + { + } + + + @Override + public void setName(String name) + { + } + + + @Override + public void setHead(ItemStack itemStack) + { + } + } + + + /** + * This CustomPanelListener allows to move items in current panel. + */ + private class CustomPanelListener implements PanelListener + { + @Override + public void setup() + { + } + + + @Override + public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) + { + } + + + @Override + public void onInventoryClick(User user, InventoryClickEvent event) + { + event.setCancelled(false); + } + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + + /** + * User who opens current gui. + */ + private User user; + + /** + * List with original items. + */ + private List itemStacks; +} From bd48e85fcc500882dd87cd70e5ee1a45fd55c34a Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 22:38:45 +0200 Subject: [PATCH 022/103] Create method that allows to change ValueObject value. --- .../world/bentobox/challenges/panel/CommonGUI.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 9ff4c1e..5e08cbe 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -4,7 +4,6 @@ package world.bentobox.challenges.panel; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; - import java.util.Collections; import java.util.List; @@ -232,5 +231,15 @@ public abstract class CommonGUI return new PanelItem(icon, name, description, false, clickHandler, false); } + + + /** + * This method sets new value to ValueObject variable. + * @param value new Value of valueObject. + */ + public void setValue(Object value) + { + this.valueObject = value; + } } From dab5f2b331c8481929822810ab056497cbe1a3df Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 22:44:48 +0200 Subject: [PATCH 023/103] Remove commands from UtilGuis, instead use CommonGUI.valueObject to store new value. Proper ItemSwitchGUI implementation. --- .../panel/util/ConfirmationGUI.java | 31 +-- .../challenges/panel/util/ItemGUI.java | 129 ---------- .../challenges/panel/util/ItemSwitchGUI.java | 236 ++++++++++++++++++ .../challenges/panel/util/NumberGUI.java | 35 +-- .../challenges/panel/util/StringListGUI.java | 35 +-- 5 files changed, 249 insertions(+), 217 deletions(-) delete mode 100644 src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java create mode 100644 src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java index 1fa7178..f12edbd 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -1,10 +1,8 @@ package world.bentobox.challenges.panel.util; + import org.bukkit.Material; -import java.util.*; - -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; @@ -22,18 +20,11 @@ public class ConfirmationGUI * * @param user Gui Caller. * @param parentGUI Parent GUI. - * @param command Command . - * @param parameters Variables at the end of command. */ - public ConfirmationGUI(CommonGUI parentGUI, - User user, - CompositeCommand command, - String... parameters) + public ConfirmationGUI(CommonGUI parentGUI, User user) { this.user = user; this.parentGUI = parentGUI; - this.command = command; - this.parameters = parameters; this.build(); } @@ -50,11 +41,8 @@ public class ConfirmationGUI panelBuilder.item(3, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")). icon(Material.GREEN_STAINED_GLASS_PANE). - clickHandler((panel, user1, clickType, index) -> - { - this.command - .execute(this.user, "CONFIRMATION", Arrays.asList(this.parameters)); - + clickHandler((panel, user1, clickType, index) -> { + this.parentGUI.setValue(true); this.user.closeInventory(); this.parentGUI.build(); return true; @@ -66,6 +54,7 @@ public class ConfirmationGUI icon(Material.RED_STAINED_GLASS_PANE). clickHandler((panel, user1, clickType, i) -> { + this.parentGUI.setValue(null); this.parentGUI.build(); return true; }). @@ -88,14 +77,4 @@ public class ConfirmationGUI * Parent GUI where should return on cancel or proceed. */ private CommonGUI parentGUI; - - /** - * Command that must be run on confirmation. - */ - private CompositeCommand command; - - /** - * List of variables. - */ - private String[] parameters; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java deleted file mode 100644 index 552c77b..0000000 --- a/src/main/java/world/bentobox/challenges/panel/util/ItemGUI.java +++ /dev/null @@ -1,129 +0,0 @@ -package world.bentobox.challenges.panel.util; - - -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import org.bukkit.inventory.ItemStack; -import java.util.Collections; -import java.util.List; - -import world.bentobox.bentobox.api.panels.PanelItem; -import world.bentobox.bentobox.api.panels.PanelListener; -import world.bentobox.bentobox.api.panels.builders.PanelBuilder; -import world.bentobox.bentobox.api.user.User; - - -/** - * This class allows to change Input ItemStacks to different ItemStacks. - */ -public class ItemGUI -{ - public ItemGUI(User user, List itemStacks) - { - this.user = user; - this.itemStacks = itemStacks; - this.build(); - } - - - /** - * This method builds panel that allows to change given number value. - */ - private void build() - { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); - panelBuilder.listener(new CustomPanelListener()); - - for (ItemStack itemStack : this.itemStacks) - { - panelBuilder.item(new CustomPanelItem(itemStack)); - } - - panelBuilder.build().open(this.user); - } - - -// --------------------------------------------------------------------- -// Section: Private classes -// --------------------------------------------------------------------- - - - /** - * This CustomPanelItem does no lose Item original MetaData. After PanelItem has been - * created it restores original meta data. It also does not allow to change anything that - * could destroy meta data. - */ - private class CustomPanelItem extends PanelItem - { - CustomPanelItem(ItemStack item) - { - super(item.clone(), "", Collections.emptyList(), false, null, false); - this.getItem().setItemMeta(item.getItemMeta()); - } - - - @Override - public void setGlow(boolean glow) - { - } - - - @Override - public void setDescription(List description) - { - } - - - @Override - public void setName(String name) - { - } - - - @Override - public void setHead(ItemStack itemStack) - { - } - } - - - /** - * This CustomPanelListener allows to move items in current panel. - */ - private class CustomPanelListener implements PanelListener - { - @Override - public void setup() - { - } - - - @Override - public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) - { - } - - - @Override - public void onInventoryClick(User user, InventoryClickEvent event) - { - event.setCancelled(false); - } - } - - -// --------------------------------------------------------------------- -// Section: Variables -// --------------------------------------------------------------------- - - - /** - * User who opens current gui. - */ - private User user; - - /** - * List with original items. - */ - private List itemStacks; -} diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java new file mode 100644 index 0000000..83e6992 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java @@ -0,0 +1,236 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.Material; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.PanelListener; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.panel.CommonGUI; + + +/** + * This class allows to change Input ItemStacks to different ItemStacks. + */ +public class ItemSwitchGUI +{ + public ItemSwitchGUI(CommonGUI parentGUI, User user, List itemStacks) + { + this.parentGUI = parentGUI; + this.user = user; + this.itemStacks = itemStacks; + this.build(); + } + + + /** + * This method builds panel that allows to change given number value. + */ + private void build() + { + PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); + + // Size of inventory that user can set via GUI. + panelBuilder.size(45); + + panelBuilder.listener(new CustomPanelListener()); + + panelBuilder.item(0, this.getButton(Button.SAVE)); + + for (int i = 1; i < 8; i++) + { + panelBuilder.item(i, this.getButton(Button.EMPTY)); + } + + panelBuilder.item(8, this.getButton(Button.CANCEL)); + + for (ItemStack itemStack : this.itemStacks) + { + panelBuilder.item(new CustomPanelItem(itemStack)); + } + + panelBuilder.build().open(this.user); + } + + + /** + * This method create button that does some functionality in current gui. + * @param button Button functionality. + * @return PanelItem. + */ + private PanelItem getButton(Button button) + { + ItemStack icon; + String name; + List description; + PanelItem.ClickHandler clickHandler; + + switch (button) + { + case SAVE: + { + name = this.user.getTranslation("challenges.gui.buttons.save"); + description = Collections.emptyList(); + icon = new ItemStack(Material.COMMAND_BLOCK); + clickHandler = (panel, user, clickType, slot) -> { + // Magic number 9 - second row. First row is for custom buttons. + // Magic number 45 - This GUI is initialed with 45 elements. + List returnItems = new ArrayList<>(36); + + for (int i = 9; i < 45; i++) + { + ItemStack itemStack = panel.getInventory().getItem(i); + + if (itemStack != null) + { + returnItems.add(itemStack); + } + } + + this.parentGUI.setValue(returnItems); + this.user.closeInventory(); + this.parentGUI.build(); + + return true; + }; + break; + } + case CANCEL: + { + name = this.user.getTranslation("challenges.gui.buttons.cancel"); + description = Collections.emptyList(); + icon = new ItemStack(Material.IRON_DOOR); + clickHandler = (panel, user, clickType, slot) -> { + this.parentGUI.build(); + return true; + }; + break; + } + case EMPTY: + { + name = ""; + description = Collections.emptyList(); + icon = new ItemStack(Material.BARRIER); + clickHandler = (panel, user, clickType, slot) -> true; + break; + } + default: + return null; + } + + return new PanelItem(icon, name, description, false, clickHandler, false); + } + + +// --------------------------------------------------------------------- +// Section: Private classes +// --------------------------------------------------------------------- + + + /** + * This CustomPanelItem does no lose Item original MetaData. After PanelItem has been + * created it restores original meta data. It also does not allow to change anything that + * could destroy meta data. + */ + private class CustomPanelItem extends PanelItem + { + CustomPanelItem(ItemStack item) + { + super(item.clone(), "", Collections.emptyList(), false, null, false); + this.getItem().setItemMeta(item.getItemMeta()); + } + + + @Override + public void setGlow(boolean glow) + { + } + + + @Override + public void setDescription(List description) + { + } + + + @Override + public void setName(String name) + { + } + + + @Override + public void setHead(ItemStack itemStack) + { + } + } + + + /** + * This CustomPanelListener allows to move items in current panel. + */ + private class CustomPanelListener implements PanelListener + { + @Override + public void setup() + { + } + + + @Override + public void onInventoryClose(InventoryCloseEvent inventoryCloseEvent) + { + } + + + @Override + public void onInventoryClick(User user, InventoryClickEvent event) + { + // First row of elements should be ignored, as it contains buttons and blocked slots. + event.setCancelled(event.getRawSlot() < 9); + } + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * This enum holds all button values in current gui. + */ + private enum Button + { + CANCEL, + SAVE, + EMPTY + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * ParentGUI from which current gui is called. + */ + private CommonGUI parentGUI; + + /** + * User who opens current gui. + */ + private User user; + + /** + * List with original items. + */ + private List itemStacks; +} diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index 5844eb8..e16e81a 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -3,11 +3,9 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -20,17 +18,11 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class NumberGUI { - public NumberGUI(CommonGUI parentGUI, - User user, - int value, - CompositeCommand command, - String... parameters) + public NumberGUI(CommonGUI parentGUI, User user, int value) { this.parentGUI = parentGUI; this.user = user; this.value = value; - this.command = command; - this.parameters = parameters; this.currentOperation = Button.SET; @@ -101,18 +93,9 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - List values = Arrays.asList(this.parameters); - values.add(Integer.toString(this.value)); - - if (this.command.execute(this.user, "NUMBER_GUI", values)) - { - this.user.closeInventory(); - this.parentGUI.build(); - } - else - { - this.build(); - } + this.parentGUI.setValue(this.value); + this.user.closeInventory(); + this.parentGUI.build(); return true; }; @@ -321,16 +304,6 @@ public class NumberGUI */ private int value; - /** - * Command that must be processed on save. - */ - private CompositeCommand command; - - /** - * Command input parameters before number. - */ - private String[] parameters; - /** * This variable holds which operation now is processed. */ diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index 3ba79a8..081e0ce 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -3,11 +3,9 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.Arrays; import java.util.Collections; import java.util.List; -import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -21,17 +19,11 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class StringListGUI { - public StringListGUI(CommonGUI parentGUI, - User user, - List value, - CompositeCommand command, - String... parameters) + public StringListGUI(CommonGUI parentGUI, User user, List value) { this.parentGUI = parentGUI; this.user = user; this.value = value; - this.command = command; - this.parameters = parameters; if (this.value.size() > 18) { @@ -90,18 +82,9 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - List values = Arrays.asList(this.parameters); - values.addAll(this.value); - - if (this.command.execute(this.user, "STRING_LIST_GUI", values)) - { - this.user.closeInventory(); - this.parentGUI.build(); - } - else - { - this.build(); - } + this.parentGUI.setValue(this.value); + this.user.closeInventory(); + this.parentGUI.build(); return true; }; @@ -228,14 +211,4 @@ public class StringListGUI * Current value. */ private List value; - - /** - * Command that must be processed on save. - */ - private CompositeCommand command; - - /** - * Command input parameters before number. - */ - private String[] parameters; } From 29dadf38411f118ac09369c67ee274b87222cb2d Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 22:56:05 +0200 Subject: [PATCH 024/103] Implement existing GUIs in AdminGUI. Update TODO comments. --- .../challenges/panel/admin/AdminGUI.java | 70 ++++++++++++++++--- .../challenges/panel/admin/ListUsersGUI.java | 2 +- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 7f0f405..77334ac 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -4,7 +4,6 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; - import java.util.Collections; import java.util.List; @@ -29,6 +28,11 @@ public class AdminGUI extends CommonGUI */ private boolean overwriteMode; + /** + * This indicate if Reset Challenges must work as reset all. + */ + private boolean resetAllMode; + // --------------------------------------------------------------------- // Section: Enums @@ -135,7 +139,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Complete Challenge GUI + new ListUsersGUI(this.addon, + this.world, + this.user, + ListUsersGUI.Mode.COMPLETE, + this.topLabel, + this.permissionPrefix, + this).build(); return true; }; @@ -148,12 +158,28 @@ public class AdminGUI extends CommonGUI name = this.user.getTranslation("challenges.gui.admin.buttons.reset"); description = Collections.emptyList(); icon = new ItemStack(Material.WRITABLE_BOOK); + + glow = this.resetAllMode; + clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Reset Challenge GUI + if (clickType.isRightClick()) + { + this.resetAllMode = !this.resetAllMode; + this.build(); + } + else + { + new ListUsersGUI(this.addon, + this.world, + this.user, + this.resetAllMode ? ListUsersGUI.Mode.RESET_ALL : ListUsersGUI.Mode.RESET, + this.topLabel, + this.permissionPrefix, + this).build(); + } return true; }; - glow = false; break; case ADD_CHALLENGE: @@ -163,7 +189,7 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Add Challenge GUI + // TODO: Create AnvilGUI that force to create String for "unique_id" return true; }; @@ -177,7 +203,7 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Add Level GUI + // TODO: Create AnvilGUI that force to create String for "unique_id" return true; }; @@ -191,7 +217,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.ANVIL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Edit Challenge GUI + new ListChallengesGUI(this.addon, + this.world, + this.user, + ListChallengesGUI.Mode.EDIT, + this.topLabel, + this.permissionPrefix, + this); return true; }; @@ -206,7 +238,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.ANVIL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Edit Level GUI + new ListLevelsGUI(this.addon, + this.world, + this.user, + ListLevelsGUI.Mode.EDIT, + this.topLabel, + this.permissionPrefix, + this); return true; }; @@ -222,7 +260,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.LAVA_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Delete Challenge GUI + new ListChallengesGUI(this.addon, + this.world, + this.user, + ListChallengesGUI.Mode.DELETE, + this.topLabel, + this.permissionPrefix, + this); return true; }; @@ -238,7 +282,13 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.LAVA_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Delete Level GUI + new ListLevelsGUI(this.addon, + this.world, + this.user, + ListLevelsGUI.Mode.DELETE, + this.topLabel, + this.permissionPrefix, + this); return true; }; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index 3365ad6..c7304a6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -54,7 +54,7 @@ public class ListUsersGUI extends CommonGUI /** * This allows to decide what User Icon should do. */ - private enum Mode + public enum Mode { COMPLETE, RESET, From 13291b450cbc6a42cc1395f71de8f8d37c0c0cc1 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 17 Jan 2019 23:09:32 +0200 Subject: [PATCH 025/103] Implement ConfirmationGUIs in Delete operation for ListLevelsGUI and ListChallengesGUI. --- .../challenges/ChallengesManager.java | 12 ++++++++++ .../panel/admin/ListChallengesGUI.java | 23 +++++++++++++++++- .../challenges/panel/admin/ListLevelsGUI.java | 24 +++++++++++++++++-- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 75081f2..e050e70 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -527,4 +527,16 @@ public class ChallengesManager { { return new ArrayList<>(); } + + + public void deleteChallenge(Challenges selectedChallenge) + { + + } + + + public void deleteChallengeLevel(ChallengeLevels valueObject) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 20464e3..69ad0d6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -11,6 +11,7 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ConfirmationGUI; /** @@ -140,7 +141,8 @@ public class ListChallengesGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - // TODO: Conformation GUI for DELETING. + new ConfirmationGUI(this, this.user); + this.valueObject = challenge; return true; }); } @@ -149,6 +151,25 @@ public class ListChallengesGUI extends CommonGUI } + /** + * Overwriting set value allows to catch if ConfirmationGui returns true. + * @param value new Value of valueObject. + */ + @Override + public void setValue(Object value) + { + if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null) + { + this.addon.getChallengesManager().deleteChallenge((Challenges) this.valueObject); + this.valueObject = null; + } + else + { + this.valueObject = null; + } + } + + // --------------------------------------------------------------------- // Section: Enums // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 5167706..511d6a3 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -2,7 +2,6 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.World; - import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; @@ -12,6 +11,7 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ConfirmationGUI; /** @@ -141,7 +141,8 @@ public class ListLevelsGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - // TODO: Conformation GUI for DELETING. + new ConfirmationGUI(this, this.user); + this.valueObject = challengeLevel; return true; }); } @@ -150,6 +151,25 @@ public class ListLevelsGUI extends CommonGUI } + /** + * Overwriting set value allows to catch if ConfirmationGui returns true. + * @param value new Value of valueObject. + */ + @Override + public void setValue(Object value) + { + if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null) + { + this.addon.getChallengesManager().deleteChallengeLevel((ChallengeLevels) this.valueObject); + this.valueObject = null; + } + else + { + this.valueObject = null; + } + } + + // --------------------------------------------------------------------- // Section: Enums // --------------------------------------------------------------------- From 09f69bd46a1d904e969620c8b7ef17d752e17213 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 16:49:39 +0200 Subject: [PATCH 026/103] Implement Consumer in ConfirmationGUI instead of depending on setValue method. --- .../panel/admin/ListChallengesGUI.java | 27 ++++-------------- .../challenges/panel/admin/ListLevelsGUI.java | 28 +++++-------------- .../panel/util/ConfirmationGUI.java | 25 +++++++---------- 3 files changed, 23 insertions(+), 57 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 69ad0d6..0dd0cfc 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -141,8 +141,12 @@ public class ListChallengesGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new ConfirmationGUI(this, this.user); - this.valueObject = challenge; + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager().deleteChallenge(challenge); + } + }); return true; }); } @@ -151,25 +155,6 @@ public class ListChallengesGUI extends CommonGUI } - /** - * Overwriting set value allows to catch if ConfirmationGui returns true. - * @param value new Value of valueObject. - */ - @Override - public void setValue(Object value) - { - if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null) - { - this.addon.getChallengesManager().deleteChallenge((Challenges) this.valueObject); - this.valueObject = null; - } - else - { - this.valueObject = null; - } - } - - // --------------------------------------------------------------------- // Section: Enums // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 511d6a3..e89ff2f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -141,8 +141,13 @@ public class ListLevelsGUI extends CommonGUI else if (this.currentMode.equals(Mode.DELETE)) { itemBuilder.clickHandler((panel, user1, clickType, i) -> { - new ConfirmationGUI(this, this.user); - this.valueObject = challengeLevel; + new ConfirmationGUI(this.user, value -> { + if (value) + { + this.addon.getChallengesManager(). + deleteChallengeLevel(challengeLevel); + } + }); return true; }); } @@ -151,25 +156,6 @@ public class ListLevelsGUI extends CommonGUI } - /** - * Overwriting set value allows to catch if ConfirmationGui returns true. - * @param value new Value of valueObject. - */ - @Override - public void setValue(Object value) - { - if (value instanceof Boolean && ((Boolean) value) && this.valueObject != null) - { - this.addon.getChallengesManager().deleteChallengeLevel((ChallengeLevels) this.valueObject); - this.valueObject = null; - } - else - { - this.valueObject = null; - } - } - - // --------------------------------------------------------------------- // Section: Enums // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java index f12edbd..921c32f 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -3,10 +3,11 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; +import java.util.function.Consumer; + import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -19,12 +20,11 @@ public class ConfirmationGUI * This constructor inits and opens ConfirmationGUI. * * @param user Gui Caller. - * @param parentGUI Parent GUI. */ - public ConfirmationGUI(CommonGUI parentGUI, User user) + public ConfirmationGUI(User user, Consumer consumer) { this.user = user; - this.parentGUI = parentGUI; + this.consumer = consumer; this.build(); } @@ -35,16 +35,13 @@ public class ConfirmationGUI */ public void build() { - PanelBuilder panelBuilder = new PanelBuilder() - .name(this.user.getTranslation("challenges.gui.admin.confirm-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.admin.confirm-title")); panelBuilder.item(3, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")). icon(Material.GREEN_STAINED_GLASS_PANE). clickHandler((panel, user1, clickType, index) -> { - this.parentGUI.setValue(true); - this.user.closeInventory(); - this.parentGUI.build(); + this.consumer.accept(true); return true; }). build()); @@ -52,10 +49,8 @@ public class ConfirmationGUI panelBuilder.item(5, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.cancel")). icon(Material.RED_STAINED_GLASS_PANE). - clickHandler((panel, user1, clickType, i) -> - { - this.parentGUI.setValue(null); - this.parentGUI.build(); + clickHandler((panel, user1, clickType, i) -> { + this.consumer.accept(false); return true; }). build()); @@ -74,7 +69,7 @@ public class ConfirmationGUI private User user; /** - * Parent GUI where should return on cancel or proceed. + * Stores current Consumer */ - private CommonGUI parentGUI; + private Consumer consumer; } From 25371fc6aa7779974fba248239fa3fb5c2f8c816 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 16:50:34 +0200 Subject: [PATCH 027/103] Replace setValue method with BiConsumer. This will provide ability to use setters directly in caller GUIs. --- .../challenges/panel/util/ItemSwitchGUI.java | 23 +++++++++---------- .../challenges/panel/util/NumberGUI.java | 19 +++++++-------- .../challenges/panel/util/StringListGUI.java | 21 ++++++++--------- 3 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java index 83e6992..1188ec5 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java @@ -8,12 +8,12 @@ import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelListener; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -21,9 +21,9 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class ItemSwitchGUI { - public ItemSwitchGUI(CommonGUI parentGUI, User user, List itemStacks) + public ItemSwitchGUI(User user, List itemStacks, BiConsumer> consumer) { - this.parentGUI = parentGUI; + this.consumer = consumer; this.user = user; this.itemStacks = itemStacks; this.build(); @@ -35,7 +35,7 @@ public class ItemSwitchGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.change-items")); // Size of inventory that user can set via GUI. panelBuilder.size(45); @@ -94,9 +94,7 @@ public class ItemSwitchGUI } } - this.parentGUI.setValue(returnItems); - this.user.closeInventory(); - this.parentGUI.build(); + this.consumer.accept(true, returnItems); return true; }; @@ -108,7 +106,7 @@ public class ItemSwitchGUI description = Collections.emptyList(); icon = new ItemStack(Material.IRON_DOOR); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.build(); + this.consumer.accept(false, Collections.emptyList()); return true; }; break; @@ -219,10 +217,6 @@ public class ItemSwitchGUI // Section: Variables // --------------------------------------------------------------------- - /** - * ParentGUI from which current gui is called. - */ - private CommonGUI parentGUI; /** * User who opens current gui. @@ -233,4 +227,9 @@ public class ItemSwitchGUI * List with original items. */ private List itemStacks; + + /** + * Consumer that returns item stacks on save action. + */ + private BiConsumer> consumer; } diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index e16e81a..d625547 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -5,12 +5,12 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -18,11 +18,11 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class NumberGUI { - public NumberGUI(CommonGUI parentGUI, User user, int value) + public NumberGUI(User user, int value, BiConsumer consumer) { - this.parentGUI = parentGUI; this.user = user; this.value = value; + this.consumer = consumer; this.currentOperation = Button.SET; @@ -35,7 +35,7 @@ public class NumberGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.edit-number-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.edit-number-title")); // Others panelBuilder.item(0, this.getButton(Button.SAVE)); @@ -93,10 +93,7 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.setValue(this.value); - this.user.closeInventory(); - this.parentGUI.build(); - + this.consumer.accept(true, this.value); return true; }; glow = false; @@ -108,7 +105,7 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.IRON_DOOR); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.build(); + this.consumer.accept(false, this.value); return true; }; glow = false; @@ -290,9 +287,9 @@ public class NumberGUI // --------------------------------------------------------------------- /** - * This variable stores return GUI. + * This variable stores current GUI consumer. */ - private CommonGUI parentGUI; + private BiConsumer consumer; /** * User who runs GUI. diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index 081e0ce..452c2d9 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -5,12 +5,12 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.Collections; import java.util.List; +import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.panel.CommonGUI; /** @@ -19,16 +19,16 @@ import world.bentobox.challenges.panel.CommonGUI; */ public class StringListGUI { - public StringListGUI(CommonGUI parentGUI, User user, List value) + public StringListGUI(User user, List value, BiConsumer> consumer) { - this.parentGUI = parentGUI; + this.consumer = consumer; this.user = user; this.value = value; if (this.value.size() > 18) { // TODO: throw error that so large list cannot be edited. - this.parentGUI.build(); + this.consumer.accept(false, this.value); } else { @@ -42,7 +42,7 @@ public class StringListGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.text-edit-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.text-edit-title")); panelBuilder.item(0, this.getButton(Button.SAVE)); panelBuilder.item(1, this.getButton(Button.VALUE)); @@ -82,9 +82,7 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.setValue(this.value); - this.user.closeInventory(); - this.parentGUI.build(); + this.consumer.accept(true, this.value); return true; }; @@ -96,7 +94,8 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.IRON_DOOR); clickHandler = (panel, user, clickType, slot) -> { - this.parentGUI.build(); + this.consumer.accept(false, this.value); + return true; }; break; @@ -198,9 +197,9 @@ public class StringListGUI /** - * This variable stores return GUI. + * This variable stores consumer. */ - private CommonGUI parentGUI; + private BiConsumer> consumer; /** * User who runs GUI. From fb06dae7ab652ef509bba03f0203a0432de414a4 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 17:03:08 +0200 Subject: [PATCH 028/103] Add constructors that allows to set minimal and maximal return value. --- .../challenges/panel/util/NumberGUI.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index d625547..94cf859 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -19,11 +19,26 @@ import world.bentobox.bentobox.api.user.User; public class NumberGUI { public NumberGUI(User user, int value, BiConsumer consumer) + { + this(user, value, Integer.MIN_VALUE, Integer.MAX_VALUE, consumer); + } + + + public NumberGUI(User user, int value, int minValue, BiConsumer consumer) + { + this(user, value, minValue, Integer.MAX_VALUE, consumer); + } + + + public NumberGUI(User user, int value, int minValue, int maxValue, BiConsumer consumer) { this.user = user; this.value = value; this.consumer = consumer; + this.minValue = minValue; + this.maxValue = maxValue; + this.currentOperation = Button.SET; this.build(); @@ -119,6 +134,18 @@ public class NumberGUI clickHandler = (panel, user, clickType, slot) -> { // TODO: Build Anvil GUI for editing value. + if (this.value > this.maxValue) + { + // TODO: Throw warning message. + this.value = this.maxValue; + } + + if (this.value < this.minValue) + { + // TODO: Throw warning message. + this.value = this.minValue; + } + this.build(); return true; }; @@ -211,6 +238,19 @@ public class NumberGUI itemBuilder.icon(Material.WHITE_STAINED_GLASS_PANE); itemBuilder.clickHandler((panel, user1, clickType, i) -> { this.value = number; + + if (this.value > this.maxValue) + { + // TODO: Throw warning message. + this.value = this.maxValue; + } + + if (this.value < this.minValue) + { + // TODO: Throw warning message. + this.value = this.minValue; + } + this.build(); return true; }); @@ -223,6 +263,13 @@ public class NumberGUI itemBuilder.icon(Material.GREEN_STAINED_GLASS_PANE); itemBuilder.clickHandler((panel, user1, clickType, i) -> { this.value += number; + + if (this.value > this.maxValue) + { + // TODO: Throw warning message. + this.value = this.maxValue; + } + this.build(); return true; }); @@ -235,6 +282,13 @@ public class NumberGUI itemBuilder.icon(Material.RED_STAINED_GLASS_PANE); itemBuilder.clickHandler((panel, user1, clickType, i) -> { this.value -= number; + + if (this.value < this.minValue) + { + // TODO: Throw warning message. + this.value = this.minValue; + } + this.build(); return true; }); @@ -247,6 +301,13 @@ public class NumberGUI itemBuilder.icon(Material.BLUE_STAINED_GLASS_PANE); itemBuilder.clickHandler((panel, user1, clickType, i) -> { this.value *= number; + + if (this.value > this.maxValue) + { + // TODO: Throw warning message. + this.value = this.maxValue; + } + this.build(); return true; }); @@ -301,6 +362,16 @@ public class NumberGUI */ private int value; + /** + * Minimal value that is allowed to set. + */ + private int minValue; + + /** + * Maximal value that is allowed to set. + */ + private int maxValue; + /** * This variable holds which operation now is processed. */ From 97174930d5ba2b7eee6b7f2c0a7f22e5e0af41a1 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 17:22:44 +0200 Subject: [PATCH 029/103] Create constructor that allows to input any String Collection. --- .../bentobox/challenges/panel/util/StringListGUI.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index 452c2d9..be575c1 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -3,6 +3,8 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; @@ -19,6 +21,12 @@ import world.bentobox.bentobox.api.user.User; */ public class StringListGUI { + public StringListGUI(User user, Collection value, BiConsumer> consumer) + { + this(user, new ArrayList<>(value), consumer); + } + + public StringListGUI(User user, List value, BiConsumer> consumer) { this.consumer = consumer; From 1b1b081a42365ae8a3e45d3fc97fc511d19fc886 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 17:29:24 +0200 Subject: [PATCH 030/103] Add existing GUIs in EditChallengeGUI. --- .../panel/admin/EditChallengeGUI.java | 196 +++++++++++++----- 1 file changed, 149 insertions(+), 47 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 84cf021..13c8a7b 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -6,10 +6,7 @@ import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -17,6 +14,9 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ItemSwitchGUI; +import world.bentobox.challenges.panel.util.NumberGUI; +import world.bentobox.challenges.panel.util.StringListGUI; /** @@ -76,7 +76,7 @@ public class EditChallengeGUI extends CommonGUI @Override public void build() { - PanelBuilder panelBuilder = new PanelBuilder().name( + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.edit-challenge-title")); panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); @@ -385,8 +385,15 @@ public class EditChallengeGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement challenges description change GUI. - this.build(); + new StringListGUI(this.user, this.challenge.getDescription(), (status, value) -> { + if (status) + { + this.challenge.setDescription(value); + } + + this.build(); + }); + return true; }; glow = false; @@ -401,8 +408,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getSlot()))); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getSlot(), -1, 54, (status, value) -> { + if (status) + { + this.challenge.setSlot(value); + } + + this.build(); + }); return true; }; @@ -423,7 +436,7 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create change enviroment button + // TODO: Create Enviroment Change GUI this.build(); return true; }; @@ -459,7 +472,7 @@ public class EditChallengeGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming + // TODO: Implement AnvilGUI. this.build(); return true; @@ -481,7 +494,7 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.CREEPER_HEAD); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Panel + // TODO: Entities GUI this.build(); return true; @@ -525,7 +538,7 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.STONE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Panel + // TODO: Block GUI this.build(); return true; @@ -565,8 +578,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getSearchRadius()))); icon = new ItemStack(Material.COBBLESTONE_WALL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getSearchRadius(), 0, (status, value) -> { + if (status) + { + this.challenge.setSearchRadius(value); + } + + this.build(); + }); return true; }; @@ -579,8 +598,14 @@ public class EditChallengeGUI extends CommonGUI description = new ArrayList<>(this.challenge.getReqPerms()); icon = new ItemStack(Material.REDSTONE_LAMP); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming - this.build(); + new StringListGUI(this.user, this.challenge.getReqPerms(), (status, value) -> { + if (status) + { + this.challenge.setReqPerms(new HashSet<>(value)); + } + + this.build(); + }); return true; }; @@ -600,8 +625,14 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.CHEST); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Panel - this.build(); + new ItemSwitchGUI(this.user, this.challenge.getRequiredItems(), (status, value) -> { + if (status) + { + this.challenge.setRequiredItems(value); + } + + this.build(); + }); return true; }; @@ -640,9 +671,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getMaxTimes()))); icon = new ItemStack(Material.EXPERIENCE_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getReqExp(), 0, (status, value) -> { + if (status) + { + this.challenge.setReqExp(value); + } + this.build(); + }); return true; }; glow = false; @@ -680,8 +716,14 @@ public class EditChallengeGUI extends CommonGUI Long.toString(this.challenge.getReqIslandlevel()))); icon = new ItemStack(Material.BEACON); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, (int) this.challenge.getReqIslandlevel(), (status, value) -> { + if (status) + { + this.challenge.setReqIslandlevel(value); + } + + this.build(); + }); return true; }; @@ -697,9 +739,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getReqMoney()))); icon = new ItemStack(Material.GOLD_INGOT); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getReqMoney(), 0, (status, value) -> { + if (status) + { + this.challenge.setReqMoney(value); + } + this.build(); + }); return true; }; glow = false; @@ -735,8 +782,8 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList(this.challenge.getRewardText()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement challenges description change GUI. - this.build(); + // TODO: Implement AnvilGUI + return true; }; glow = false; @@ -755,8 +802,14 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.CHEST); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Panel - this.build(); + new ItemSwitchGUI(this.user, this.challenge.getRewardItems(), (status, value) -> { + if (status) + { + this.challenge.setRewardItems(value); + } + + this.build(); + }); return true; }; @@ -772,8 +825,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getRewardExp()))); icon = new ItemStack(Material.EXPERIENCE_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getReqExp(), 0, (status, value) -> { + if (status) + { + this.challenge.setRewardExp(value); + } + + this.build(); + }); return true; }; @@ -789,8 +848,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getRewardMoney()))); icon = new ItemStack(Material.GOLD_INGOT); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> { + if (status) + { + this.challenge.setRewardMoney(value); + } + + this.build(); + }); return true; }; @@ -803,8 +868,14 @@ public class EditChallengeGUI extends CommonGUI description = this.challenge.getRewardCommands(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming - this.build(); + new StringListGUI(this.user, this.challenge.getRewardCommands(), (status, value) -> { + if (status) + { + this.challenge.setRewardCommands(value); + } + + this.build(); + }); return true; }; @@ -844,8 +915,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getMaxTimes()))); icon = new ItemStack(Material.COBBLESTONE_WALL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getMaxTimes(), 0, (status, value) -> { + if (status) + { + this.challenge.setMaxTimes(value); + } + + this.build(); + }); return true; }; @@ -859,8 +936,9 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList(this.challenge.getRepeatRewardText()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement challenges description change GUI. - this.build(); + // TODO: Implement AnvilGUI + + return true; }; glow = false; @@ -879,8 +957,14 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.TRAPPED_CHEST); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Panel - this.build(); + new ItemSwitchGUI(this.user, this.challenge.getRepeatItemReward(), (status, value) -> { + if (status) + { + this.challenge.setRepeatItemReward(value); + } + + this.build(); + }); return true; }; @@ -896,8 +980,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getRepeatExpReward()))); icon = new ItemStack(Material.GLASS_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getRepeatExpReward(), 0, (status, value) -> { + if (status) + { + this.challenge.setRepeatExpReward(value); + } + + this.build(); + }); return true; }; @@ -913,8 +1003,14 @@ public class EditChallengeGUI extends CommonGUI Integer.toString(this.challenge.getRepeatMoneyReward()))); icon = new ItemStack(Material.GOLD_NUGGET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challenge.getRepeatMoneyReward(), 0, (status, value) -> { + if (status) + { + this.challenge.setRepeatMoneyReward(value); + } + + this.build(); + }); return true; }; @@ -927,8 +1023,14 @@ public class EditChallengeGUI extends CommonGUI description = this.challenge.getRepeatRewardCommands(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming - this.build(); + new StringListGUI(this.user, this.challenge.getRepeatRewardCommands(), (status, value) -> { + if (status) + { + this.challenge.setRepeatRewardCommands(value); + } + + this.build(); + }); return true; }; From 6cdc619cf06506eccb0f697811ceed92863372d8 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 17:38:34 +0200 Subject: [PATCH 031/103] Implement existing GUIs in EditLevelGUI. --- .../challenges/panel/admin/EditLevelGUI.java | 77 ++++++++++++++----- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 7b12de6..70812e2 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -16,6 +16,9 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ItemSwitchGUI; +import world.bentobox.challenges.panel.util.NumberGUI; +import world.bentobox.challenges.panel.util.StringListGUI; /** @@ -72,7 +75,7 @@ public class EditLevelGUI extends CommonGUI @Override public void build() { - PanelBuilder panelBuilder = new PanelBuilder().name( + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.edit-level-title")); panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); @@ -289,7 +292,7 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList(this.challengeLevel.getFriendlyName()); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming + // TODO: Implement AnvilGui. this.build(); return true; @@ -317,7 +320,7 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList(this.challengeLevel.getUnlockMessage()); icon = new ItemStack(Material.WRITABLE_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement challenges description change GUI. + // TODO: Implement AnvilGUI this.build(); return true; }; @@ -333,8 +336,14 @@ public class EditLevelGUI extends CommonGUI Integer.toString(this.challengeLevel.getOrder()))); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challengeLevel.getOrder(), -1, 54, (status, value) -> { + if (status) + { + this.challengeLevel.setOrder(value); + } + + this.build(); + }); return true; }; @@ -350,8 +359,14 @@ public class EditLevelGUI extends CommonGUI Integer.toString(this.challengeLevel.getWaiveramount()))); icon = new ItemStack(Material.REDSTONE_TORCH); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challengeLevel.getWaiveramount(), 0, (status, value) -> { + if (status) + { + this.challengeLevel.setWaiveramount(value); + } + + this.build(); + }); return true; }; @@ -365,8 +380,8 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList(this.challengeLevel.getRewardDescription()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement challenges description change GUI. - this.build(); + // TODO: Implement AnvilGui + return true; }; glow = false; @@ -385,8 +400,14 @@ public class EditLevelGUI extends CommonGUI description = values; icon = new ItemStack(Material.CHEST); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Panel - this.build(); + new ItemSwitchGUI(this.user, this.challengeLevel.getRewardItems(), (status, value) -> { + if (status) + { + this.challengeLevel.setRewardItems(value); + } + + this.build(); + }); return true; }; @@ -402,8 +423,14 @@ public class EditLevelGUI extends CommonGUI Integer.toString(this.challengeLevel.getExpReward()))); icon = new ItemStack(Material.EXPERIENCE_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challengeLevel.getExpReward(), 0, (status, value) -> { + if (status) + { + this.challengeLevel.setExpReward(value); + } + + this.build(); + }); return true; }; @@ -419,8 +446,14 @@ public class EditLevelGUI extends CommonGUI Integer.toString(this.challengeLevel.getMoneyReward()))); icon = new ItemStack(Material.GOLD_INGOT); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Possibility to change order. - this.build(); + new NumberGUI(this.user, this.challengeLevel.getMoneyReward(), 0, (status, value) -> { + if (status) + { + this.challengeLevel.setMoneyReward(value); + } + + this.build(); + }); return true; }; @@ -433,8 +466,14 @@ public class EditLevelGUI extends CommonGUI description = this.challengeLevel.getRewardCommands(); icon = new ItemStack(Material.COMMAND_BLOCK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming - this.build(); + new StringListGUI(this.user, this.challengeLevel.getRewardCommands(), (status, value) -> { + if (status) + { + this.challengeLevel.setRewardCommands(value); + } + + this.build(); + }); return true; }; @@ -448,7 +487,7 @@ public class EditLevelGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.WATER_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming + // TODO: Create Challenge List GUI this.build(); return true; @@ -462,7 +501,7 @@ public class EditLevelGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.LAVA_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create naming + // TODO: Create Levels List GUI this.build(); return true; From 0f56eb7185379377de6607756b5885a640dd5e31 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Fri, 18 Jan 2019 17:40:01 +0200 Subject: [PATCH 032/103] Add EditSettingsGUI to AdminGUI. Fix issue when other GUIs were not opened. --- .../bentobox/challenges/panel/admin/AdminGUI.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 77334ac..2893d6f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -223,7 +223,7 @@ public class AdminGUI extends CommonGUI ListChallengesGUI.Mode.EDIT, this.topLabel, this.permissionPrefix, - this); + this).build(); return true; }; @@ -244,7 +244,7 @@ public class AdminGUI extends CommonGUI ListLevelsGUI.Mode.EDIT, this.topLabel, this.permissionPrefix, - this); + this).build(); return true; }; @@ -266,7 +266,7 @@ public class AdminGUI extends CommonGUI ListChallengesGUI.Mode.DELETE, this.topLabel, this.permissionPrefix, - this); + this).build(); return true; }; @@ -288,7 +288,7 @@ public class AdminGUI extends CommonGUI ListLevelsGUI.Mode.DELETE, this.topLabel, this.permissionPrefix, - this); + this).build(); return true; }; @@ -329,7 +329,12 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.CRAFTING_TABLE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Settings GUI + new EditSettingsGUI(this.addon, + this.world, + this.user, + this.topLabel, + this.permissionPrefix, + this).build(); return true; }; From 870bf6d232efa9d2b39be7518bb2d9ac12f58e42 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 18 Jan 2019 19:13:39 +0200 Subject: [PATCH 033/103] Implement ResetAllChallenges confirmation GUI to ListUsersGUI. --- .../java/world/bentobox/challenges/ChallengesManager.java | 5 +++++ .../bentobox/challenges/panel/admin/ListUsersGUI.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index e050e70..f61e0cd 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -539,4 +539,9 @@ public class ChallengesManager { { } + + public void resetAllChallenges(User uuid, World world) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index c7304a6..fc4612c 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -15,6 +15,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.ConfirmationGUI; /** @@ -175,7 +176,12 @@ public class ListUsersGUI extends CommonGUI // TODO: Open Reset Challenge GUI. break; case RESET_ALL: - // TODO: Confirmation GUI for resetting all challenges. + new ConfirmationGUI(this.user, status -> { + if (status) + { + this.addon.getChallengesManager().resetAllChallenges(this.user, this.world); + } + }); break; } From c2b809f509920257c8295d9e884e466971746f86 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 18 Jan 2019 19:15:50 +0200 Subject: [PATCH 034/103] Add AnvilGUI dependency. --- pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pom.xml b/pom.xml index 141102f..86d7e22 100644 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,10 @@ vault-repo http://nexus.hc.to/content/repositories/pub_releases + + wesjd-repo + https://nexus.wesjd.net/repository/thirdparty/ + @@ -123,6 +127,11 @@ + + net.wesjd + anvilgui + 1.2.1-SNAPSHOT + From 1ecbac43bf5a7e433975be43f1c477f0426c9b08 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 18 Jan 2019 19:26:03 +0200 Subject: [PATCH 035/103] Add last missing element in AdminGUI. Now AdminGUI all icons are functional. --- .../challenges/ChallengesManager.java | 24 +++++++++ .../challenges/panel/admin/AdminGUI.java | 49 ++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index f61e0cd..4d03187 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -544,4 +544,28 @@ public class ChallengesManager { { } + + + public Challenges createChallenge(String reply) + { + return new Challenges(); + } + + + public boolean validateChallengeUniqueID(World world, String reply) + { + return false; + } + + + public boolean validateLevelUniqueID(World world, String reply) + { + return false; + } + + + public ChallengeLevels createLevel(String reply) + { + return new ChallengeLevels(); + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 2893d6f..273a161 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import java.util.Collections; import java.util.List; +import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; @@ -189,7 +190,29 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create AnvilGUI that force to create String for "unique_id" + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + "unique_id", + (player, reply) -> { + + if (this.addon.getChallengesManager().validateChallengeUniqueID(this.world, reply)) + { + new EditChallengeGUI(this.addon, + this.world, + this.user, + this.addon.getChallengesManager().createChallenge(reply), + this.topLabel, + this.permissionPrefix, + this).build(); + } + else + { + // TODO: Throw message that uniqueID is not valid. + this.build(); + } + + return reply; + }); return true; }; @@ -203,7 +226,29 @@ public class AdminGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create AnvilGUI that force to create String for "unique_id" + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + "unique_id", + (player, reply) -> { + + if (this.addon.getChallengesManager().validateLevelUniqueID(this.world, reply)) + { + new EditLevelGUI(this.addon, + this.world, + this.user, + this.addon.getChallengesManager().createLevel(reply), + this.topLabel, + this.permissionPrefix, + this).build(); + } + else + { + // TODO: Throw message that uniqueID is not valid. + this.build(); + } + + return reply; + }); return true; }; From 11c3637b2a32d2493bd5661b8290c48088bcf5cd Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 18 Jan 2019 19:28:12 +0200 Subject: [PATCH 036/103] Add error messages when unique ID is not unique. --- .../java/world/bentobox/challenges/panel/admin/AdminGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 273a161..c745c6a 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -207,7 +207,7 @@ public class AdminGUI extends CommonGUI } else { - // TODO: Throw message that uniqueID is not valid. + this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); this.build(); } @@ -243,7 +243,7 @@ public class AdminGUI extends CommonGUI } else { - // TODO: Throw message that uniqueID is not valid. + this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); this.build(); } From 433484d9f7f22b02c1e22bb79d5d7331edf524a0 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 15:49:54 +0200 Subject: [PATCH 037/103] Add new enum HeadLib that contains library with all mob heads from Minecraft. --- pom.xml | 16 +- .../bentobox/challenges/utils/HeadLib.java | 298 ++++++++++++++++++ 2 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 src/main/java/world/bentobox/challenges/utils/HeadLib.java diff --git a/pom.xml b/pom.xml index 86d7e22..e9e4c9c 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,12 @@ 1.13.2-R0.1-SNAPSHOT provided + + org.spigotmc + spigot + 1.13.2-R0.1-SNAPSHOT + provided + org.mockito mockito-all @@ -216,8 +222,16 @@ maven-shade-plugin 3.1.1 - false + true + + + package + + shade + + + org.apache.maven.plugins diff --git a/src/main/java/world/bentobox/challenges/utils/HeadLib.java b/src/main/java/world/bentobox/challenges/utils/HeadLib.java new file mode 100644 index 0000000..3492d0a --- /dev/null +++ b/src/main/java/world/bentobox/challenges/utils/HeadLib.java @@ -0,0 +1,298 @@ +/* + * Written in 2018 by Daniel Saukel + * + * To the extent possible under law, the author(s) have dedicated all + * copyright and related and neighboring rights to this software + * to the public domain worldwide. + * + * This software is distributed without any warranty. + * + * You should have received a copy of the CC0 Public Domain Dedication + * along with this software. If not, see . + * + * @url https://github.com/DRE2N/HeadLib + */ +package world.bentobox.challenges.utils; + + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import java.util.*; + +import net.minecraft.server.v1_13_R2.NBTBase; +import net.minecraft.server.v1_13_R2.NBTTagCompound; +import net.minecraft.server.v1_13_R2.NBTTagList; + + +/** + * @author Daniel Saukel + * + * BONNe modified it for BentoBox by leaving only mob heads and removing unused code. + */ +public enum HeadLib +{ +// --------------------------------------------------------------------- +// Section: Library of All Mob heads +// --------------------------------------------------------------------- + + /** + * All enum values. + */ + SPIDER("8bdb71d0-4724-48b2-9344-e79480424798", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q1NDE1NDFkYWFmZjUwODk2Y2QyNThiZGJkZDRjZjgwYzNiYTgxNjczNTcyNjA3OGJmZTM5MzkyN2U1N2YxIn19fQ=="), + CAVE_SPIDER("39173a7a-c957-4ec1-ac1a-43e5a64983df", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDE2NDVkZmQ3N2QwOTkyMzEwN2IzNDk2ZTk0ZWViNWMzMDMyOWY5N2VmYzk2ZWQ3NmUyMjZlOTgyMjQifX19"), + ENDERMAN("0de98464-1274-4dd6-bba8-370efa5d41a8", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2E1OWJiMGE3YTMyOTY1YjNkOTBkOGVhZmE4OTlkMTgzNWY0MjQ1MDllYWRkNGU2YjcwOWFkYTUwYjljZiJ9fX0="), + SLIME("7f0b0873-df6a-4a19-9bcd-f6c90ef804c7", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODk1YWVlYzZiODQyYWRhODY2OWY4NDZkNjViYzQ5NzYyNTk3ODI0YWI5NDRmMjJmNDViZjNiYmI5NDFhYmU2YyJ9fX0="), + GUARDIAN("f3898fe0-04fb-4f9c-8f8b-146a1d894007", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzI1YWY5NjZhMzI2ZjlkOTg0NjZhN2JmODU4MmNhNGRhNjQ1M2RlMjcxYjNiYzllNTlmNTdhOTliNjM1MTFjNiJ9fX0="), + GHAST("807f287f-6499-4e93-a887-0a298ab3091f", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGI2YTcyMTM4ZDY5ZmJiZDJmZWEzZmEyNTFjYWJkODcxNTJlNGYxYzk3ZTVmOTg2YmY2ODU1NzFkYjNjYzAifX19"), + BLAZE("7ceb88b2-7f5f-4399-abb9-7068251baa9d", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjc4ZWYyZTRjZjJjNDFhMmQxNGJmZGU5Y2FmZjEwMjE5ZjViMWJmNWIzNWE0OWViNTFjNjQ2Nzg4MmNiNWYwIn19fQ=="), + MAGMA_CUBE("96aced64-5b85-4b99-b825-53cd7a9f9726", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzg5NTdkNTAyM2M5MzdjNGM0MWFhMjQxMmQ0MzQxMGJkYTIzY2Y3OWE5ZjZhYjM2Yjc2ZmVmMmQ3YzQyOSJ9fX0="), + WITHER("119c371b-ea16-47c9-ad7f-23b3d894520a", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2RmNzRlMzIzZWQ0MTQzNjk2NWY1YzU3ZGRmMjgxNWQ1MzMyZmU5OTllNjhmYmI5ZDZjZjVjOGJkNDEzOWYifX19"), + ENDER_DRAGON("433562fa-9e23-443e-93b0-d67228435e77", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzRlY2MwNDA3ODVlNTQ2NjNlODU1ZWYwNDg2ZGE3MjE1NGQ2OWJiNGI3NDI0YjczODFjY2Y5NWIwOTVhIn19fQ=="), + SHULKER("d700b0b9-be74-4630-8cb5-62c979828ef6", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjFkMzUzNGQyMWZlODQ5OTI2MmRlODdhZmZiZWFjNGQyNWZmZGUzNWM4YmRjYTA2OWU2MWUxNzg3ZmYyZiJ9fX0="), + CREEPER("eed2d903-ca32-4cc7-b33b-ca3bdbe18da4", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjQyNTQ4MzhjMzNlYTIyN2ZmY2EyMjNkZGRhYWJmZTBiMDIxNWY3MGRhNjQ5ZTk0NDQ3N2Y0NDM3MGNhNjk1MiJ9fX0="), + ZOMBIE("9959dd98-efb3-4ee9-a8fb-2fda0218cda0", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTZmYzg1NGJiODRjZjRiNzY5NzI5Nzk3M2UwMmI3OWJjMTA2OTg0NjBiNTFhNjM5YzYwZTVlNDE3NzM0ZTExIn19fQ=="), + ZOMBIE_VILLAGER("bcaf2b85-d421-47cc-a40a-455e77bfb60b", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzdlODM4Y2NjMjY3NzZhMjE3YzY3ODM4NmY2YTY1NzkxZmU4Y2RhYjhjZTljYTRhYzZiMjgzOTdhNGQ4MWMyMiJ9fX0="), + ZOMBIE_PIGMAN("6540c046-d6ea-4aff-9766-32a54ebe6958", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzRlOWM2ZTk4NTgyZmZkOGZmOGZlYjMzMjJjZDE4NDljNDNmYjE2YjE1OGFiYjExY2E3YjQyZWRhNzc0M2ViIn19fQ=="), + DOG("9655594c-5b1c-48a5-8e12-ffd7e0c735f2", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDk1MTgzY2E0Y2RkMjk2MjhmZTZjNzIyZjc3OTA4N2I4M2MyMWJhOTdmNDIyNWU0YWQ5YjNlNjE4ZWNjZDMwIn19fQ=="), + HORSE("c6abc94e-a5ff-45fe-a0d7-4e479f290a6f", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDJlYjk2N2FiOTRmZGQ0MWE2MzI1ZjEyNzdkNmRjMDE5MjI2ZTVjZjM0OTc3ZWVlNjk1OTdmYWZjZjVlIn19fQ=="), + TURTLE("ef56c7a3-a5e7-4a7f-9786-a4b6273a591d", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTJlNTQ4NDA4YWI3NWQ3ZGY4ZTZkNWQyNDQ2ZDkwYjZlYzYyYWE0ZjdmZWI3OTMwZDFlZTcxZWVmZGRmNjE4OSJ9fX0="), + OCELOT("664dd492-3fcd-443b-9e61-4c7ebd9e4e10", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTY1N2NkNWMyOTg5ZmY5NzU3MGZlYzRkZGNkYzY5MjZhNjhhMzM5MzI1MGMxYmUxZjBiMTE0YTFkYjEifX19"), + SHEEP("fa234925-9dbe-4b8f-a544-7c70fb6b6ac5", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZjMxZjljY2M2YjNlMzJlY2YxM2I4YTExYWMyOWNkMzNkMThjOTVmYzczZGI4YTY2YzVkNjU3Y2NiOGJlNzAifX19"), + COW("97ddf3b3-9dbe-4a3b-8a0f-1b19ddeac0bd", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWQ2YzZlZGE5NDJmN2Y1ZjcxYzMxNjFjNzMwNmY0YWVkMzA3ZDgyODk1ZjlkMmIwN2FiNDUyNTcxOGVkYzUifX19"), + CHICKEN("7d3a8ace-e045-4eba-ab71-71dbf525daf1", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTYzODQ2OWE1OTljZWVmNzIwNzUzNzYwMzI0OGE5YWIxMWZmNTkxZmQzNzhiZWE0NzM1YjM0NmE3ZmFlODkzIn19fQ=="), + PIG("e1e1c2e4-1ed2-473d-bde2-3ec718535399", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjIxNjY4ZWY3Y2I3OWRkOWMyMmNlM2QxZjNmNGNiNmUyNTU5ODkzYjZkZjRhNDY5NTE0ZTY2N2MxNmFhNCJ9fX0="), + SQUID("f95d9504-ea2b-4b89-b2d0-d400654a7010", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMDE0MzNiZTI0MjM2NmFmMTI2ZGE0MzRiODczNWRmMWViNWIzY2IyY2VkZTM5MTQ1OTc0ZTljNDgzNjA3YmFjIn19fQ=="), + MUSHROOM_COW("e206ac29-ae69-475b-909a-fb523d894336", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDBiYzYxYjk3NTdhN2I4M2UwM2NkMjUwN2EyMTU3OTEzYzJjZjAxNmU3YzA5NmE0ZDZjZjFmZTFiOGRiIn19fQ=="), + ELDER_GUARDIAN("f2e933a7-614f-44e0-bf18-289b102104ab", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMWM3OTc0ODJhMTRiZmNiODc3MjU3Y2IyY2ZmMWI2ZTZhOGI4NDEzMzM2ZmZiNGMyOWE2MTM5Mjc4YjQzNmIifX19"), + STRAY("644c9bad-958b-43ce-9d2f-199d85be607c", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzhkZGY3NmU1NTVkZDVjNGFhOGEwYTVmYzU4NDUyMGNkNjNkNDg5YzI1M2RlOTY5ZjdmMjJmODVhOWEyZDU2In19fQ=="), + HUSK("2e387bc6-774b-4fda-ba22-eb54a26dfd9e", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzc3MDY4MWQxYTI1NWZiNGY3NTQ3OTNhYTA1NWIyMjA0NDFjZGFiOWUxMTQxZGZhNTIzN2I0OTkzMWQ5YjkxYyJ9fX0="), + SKELETON_HORSE("bcbce5bf-86c4-4e62-9fc5-0cc90de94b6d", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDdlZmZjZTM1MTMyYzg2ZmY3MmJjYWU3N2RmYmIxZDIyNTg3ZTk0ZGYzY2JjMjU3MGVkMTdjZjg5NzNhIn19fQ=="), + ZOMBIE_HORSE("506ced1a-dac8-4d84-b341-645fbb297335", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q2YjllZjhkZDEwYmE2NDE0MjJiNDQ5ZWQxNWFkYzI5MmQ3M2Y1NzI5ODRkNDdlMjhhMjI2YWE2ZWRkODcifX19"), + DONKEY("3da7917b-cb95-40b3-a516-9befa4f4d71d", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjEyNTJjMjI1MGM0NjhkOWZkZTUzODY3Nzg1NWJjOWYyODQzM2RmNjkyNDdkNzEzODY4NzgxYjgyZDE0YjU1In19fQ=="), + MULE("fac6815e-02d5-4776-a5d6-f6d6535b7831", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzY5Y2E0YzI5NTZhNTY3Yzk2ZWUwNGM1MzE0OWYxODY0NjIxODM5M2JjN2IyMWVkNDVmZGFhMTNiZWJjZGFkIn19fQ=="), + EVOKER("36ee7e5b-c092-48ad-9673-2a73b0a44b4f", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYTAwZDNmZmYxNmMyZGNhNTliOWM1OGYwOTY1MjVjODY5NzExNjZkYmFlMTMzYjFiMDUwZTVlZTcxNjQ0MyJ9fX0="), + VEX("f83bcfc1-0213-4957-888e-d3e2fae71203", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNWU3MzMwYzdkNWNkOGEwYTU1YWI5ZTk1MzIxNTM1YWM3YWUzMGZlODM3YzM3ZWE5ZTUzYmVhN2JhMmRlODZiIn19fQ=="), + VINDICATOR("5f958e1c-91ea-42d3-9d26-09e5925f2d9c", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2RhNTg1ZWJkZGNjNDhmMzA3YmU2YTgzOTE2Zjg3OGVkNGEwMTRlYzNkNGYyODZhMmNmZDk1MzI4MTk2OSJ9fX0="), + ILLUSIONER("ccb79aa9-1764-4e5b-8ff3-e7be661ac7e2", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjYxNWUxMjQ1ZDBkODJkODFkZmEzNzUzMDYzZDhhYWQwZmE2NjU3NTk5ODcxY2Y0YzY5YmFiNzNjNjk5MDU1In19fQ=="), + PIG_ZOMBIE("6540c046-d6ea-4aff-9766-32a54ebe6958", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzRlOWM2ZTk4NTgyZmZkOGZmOGZlYjMzMjJjZDE4NDljNDNmYjE2YjE1OGFiYjExY2E3YjQyZWRhNzc0M2ViIn19fQ=="), + SILVERFISH("30a4cd5c-5754-4db8-8960-18022a74627d", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZGE5MWRhYjgzOTFhZjVmZGE1NGFjZDJjMGIxOGZiZDgxOWI4NjVlMWE4ZjFkNjIzODEzZmE3NjFlOTI0NTQwIn19fQ=="), + BAT("cfdaf903-18cf-4a92-acf2-efa8626cf0b2", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOWU5OWRlZWY5MTlkYjY2YWMyYmQyOGQ2MzAyNzU2Y2NkNTdjN2Y4YjEyYjlkY2E4ZjQxYzNlMGEwNGFjMWNjIn19fQ=="), + WITCH("7f92b3d6-5ee0-4ab6-afae-2206b9514a63", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMjBlMTNkMTg0NzRmYzk0ZWQ1NWFlYjcwNjk1NjZlNDY4N2Q3NzNkYWMxNmY0YzNmODcyMmZjOTViZjlmMmRmYSJ9fX0="), + ENDERMITE("33c425bb-a294-4e01-9b5b-a8ad652bb5cf", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODRhYWZmYTRjMDllMmVhZmI4NWQzNTIyMTIyZGIwYWE0NTg3NGJlYTRlM2Y1ZTc1NjZiNGQxNjZjN2RmOCJ9fX0="), + WOLF("4aabc2be-340a-46ad-a42b-0c348344750a", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdhZGU0OWY1MDEzMTExNTExZGM1MWJhYjc2OWMxYWQ2OTUzMTlhNWQzNTViMzZhZTkyMzRlYTlkMWZmOGUifX19"), + SNOWMAN("d71e165b-b49d-4180-9ccf-8ad3084df1dc", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTdlOTgzMWRhZjY4MWY4YzRjNDc3NWNiNDY1M2MzNGJlMjg5OGY4N2VmZDNiNTk4ZDU1NTUxOGYyZmFjNiJ9fX0="), + IRON_GOLEM("7cb6e9a5-994f-40d5-9bfc-4ba5d796d21e", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvODkwOTFkNzllYTBmNTllZjdlZjk0ZDdiYmE2ZTVmMTdmMmY3ZDQ1NzJjNDRmOTBmNzZjNDgxOWE3MTQifX19"), + RABBIT("2186bdc6-55b1-4b44-8a46-3c8a11d40f3d", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2QxMTY5YjI2OTRhNmFiYTgyNjM2MDk5MjM2NWJjZGE1YTEwYzg5YTNhYTJiNDhjNDM4NTMxZGQ4Njg1YzNhNyJ9fX0="), + POLAR_BEAR("87324464-1700-468f-8333-e7779ec8c21e", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDQ2ZDIzZjA0ODQ2MzY5ZmEyYTM3MDJjMTBmNzU5MTAxYWY3YmZlODQxOTk2NjQyOTUzM2NkODFhMTFkMmIifX19"), + LLAMA("75fb08e5-2419-46fa-bf09-57362138f234", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzJiMWVjZmY3N2ZmZTNiNTAzYzMwYTU0OGViMjNhMWEwOGZhMjZmZDY3Y2RmZjM4OTg1NWQ3NDkyMTM2OCJ9fX0="), + PARROT("da0cac14-3763-45df-b884-c99a567882ac", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTZkZTFlYjllMzI1ZTYyZjI4ZjJjMTgzZDM5YTY4MzExMzY0NDYzNjU3MjY0Njc1YThiNDYxY2QyOGM5In19fQ=="), + VILLAGER("b3ed4a1b-dfff-464c-87c0-c8029e1de47b", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzZhYjYxYWNlMTM2MDE3YTg3YjFiODFiMTQ1ZWJjNjNlMmU2ZGE5ZDM2NGM4MTE5NGIzM2VlODY2ZmU0ZCJ9fX0="), + PHANTOM("9290add8-c291-4a5a-8f8a-594f165406a3", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvN2U5NTE1M2VjMjMyODRiMjgzZjAwZDE5ZDI5NzU2ZjI0NDMxM2EwNjFiNzBhYzAzYjk3ZDIzNmVlNTdiZDk4MiJ9fX0="), + COD("d6d4c744-06b4-4a8a-bc7a-bdb0770bb1cf", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzg5MmQ3ZGQ2YWFkZjM1Zjg2ZGEyN2ZiNjNkYTRlZGRhMjExZGY5NmQyODI5ZjY5MTQ2MmE0ZmIxY2FiMCJ9fX0="), + SALMON("0354c430-3979-4b6e-8e65-a99eb3ea8818", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGFlYjIxYTI1ZTQ2ODA2Y2U4NTM3ZmJkNjY2ODI4MWNmMTc2Y2VhZmU5NWFmOTBlOTRhNWZkODQ5MjQ4NzgifX19"), + PUFFERFISH("258e3114-368c-48a1-85fd-be580912f0df", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTcxNTI4NzZiYzNhOTZkZDJhMjI5OTI0NWVkYjNiZWVmNjQ3YzhhNTZhYzg4NTNhNjg3YzNlN2I1ZDhiYiJ9fX0="), + TROPICAL_FISH("d93c1bf6-616f-401a-af6e-f9b9803a0024", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTc5ZTQ4ZDgxNGFhM2JjOTg0ZThhNmZkNGZiMTcwYmEwYmI0ODkzZjRiYmViZGU1ZmRmM2Y4Zjg3MWNiMjkyZiJ9fX0="), + DROWNED("2f169660-61be-46bd-acb5-1abef9fe5731", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzNmN2NjZjYxZGJjM2Y5ZmU5YTYzMzNjZGUwYzBlMTQzOTllYjJlZWE3MWQzNGNmMjIzYjNhY2UyMjA1MSJ9fX0="), + DOLPHIN("8b7ccd6d-36de-47e0-8d5a-6f6799c6feb8", "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOGU5Njg4Yjk1MGQ4ODBiNTViN2FhMmNmY2Q3NmU1YTBmYTk0YWFjNmQxNmY3OGU4MzNmNzQ0M2VhMjlmZWQzIn19fQ=="); + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * User UUID that has given skin. + */ + private String uuid; + + /** + * Base64 Encoded link to Minecraft texture. + */ + private String textureValue; + + /** + * Skull owner. + */ + private Object skullOwner; + + /** + * This map allows to access all enum values via their string. + */ + private final static Map BY_NAME = new HashMap<>(); + + +// --------------------------------------------------------------------- +// Section: Constructor +// --------------------------------------------------------------------- + + + /** + * This inits new enum value by given UUID and textureValue that is encoded in Base64. + * @param uuid User UUID String which skin must be loaded. + * @param textureValue Texture link encoded in Base64. + */ + HeadLib(String uuid, String textureValue) + { + this.uuid = uuid; + this.textureValue = textureValue; + } + + +// --------------------------------------------------------------------- +// Section: Methods that returns ItemStacks +// --------------------------------------------------------------------- + + /** + * Returns an ItemStack of the size 1 of the custom head. + * + * @return an ItemStack of the custom head. + */ + public ItemStack toItemStack() + { + return this.toItemStack(1); + } + + + /** + * Returns an ItemStack of the custom head. + * + * @param amount the amount of items in the stack + * @return an ItemStack of the custom head. + */ + public ItemStack toItemStack(int amount) + { + return this.toItemStack(amount, null); + } + + + /** + * Returns an ItemStack of the size 1 of the custom head. + * + * @param displayName the name to display. Supports "&" color codes + * @param loreLines optional lore lines. Supports "&" color codes + * @return an ItemStack of the custom head. + */ + public ItemStack toItemStack(String displayName, String... loreLines) + { + return this.toItemStack(1, displayName, loreLines); + } + + + /** + * Returns an ItemStack of the custom head. + * + * @param amount the amount of items in the stack + * @param displayName the name to display. Supports "&" color codes + * @param loreLines optional lore lines. Supports "&" color codes + * @return an ItemStack of the custom head. + */ + public ItemStack toItemStack(int amount, String displayName, String... loreLines) + { + ItemStack item = new ItemStack(Material.PLAYER_HEAD, amount); + + if (displayName != null) + { + ItemMeta meta = item.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName)); + + if (loreLines.length != 0) + { + List loreCC = new ArrayList<>(); + Arrays.stream(loreLines).forEach(l -> loreCC.add(ChatColor.translateAlternateColorCodes('&', l))); + meta.setLore(loreCC); + } + + item.setItemMeta(meta); + } + + return this.setSkullOwner(item, this.getSkullOwner()); + } + + +// --------------------------------------------------------------------- +// Section: Private inner methods +// --------------------------------------------------------------------- + + + /** + * This method returns SkullOwner or create new one if it is not created yet. + * SkullOwner is NBTTagCompound object that contains information about player_head skin. + * @return skullOwner object. + */ + private Object getSkullOwner() + { + if (this.skullOwner == null) + { + this.skullOwner = this.createOwnerCompound(this.uuid, this.textureValue); + } + + return this.skullOwner; + } + + + /** + * This method creates new NBTTagCompound object that contains UUID and texture link. + * @param id - UUID of user. + * @param textureValue - Encoded texture string. + * @return NBTTagCompound object that contains all necessary information about player_head skin. + */ + private NBTTagCompound createOwnerCompound(String id, String textureValue) + { + NBTTagCompound skullOwner = new NBTTagCompound(); + skullOwner.setString("Id", id); + NBTTagCompound properties = new NBTTagCompound(); + NBTTagList textures = new NBTTagList(); + NBTTagCompound value = new NBTTagCompound(); + value.setString("Value", textureValue); + textures.add(value); + properties.set("textures", textures); + skullOwner.set("Properties", properties); + + return skullOwner; + } + + + /** + * This method adds SkullOwner tag to given item. + * @param item Item whom SkullOwner tag must be added. + * @param compound NBTTagCompound object that contains UUID and texture link. + * @return new copy of given item with SkullOwner tag. + */ + private ItemStack setSkullOwner(ItemStack item, Object compound) + { + net.minecraft.server.v1_13_R2.ItemStack nmsStack = CraftItemStack.asNMSCopy(item); + nmsStack.getOrCreateTag().set("SkullOwner", (NBTBase) compound); + return CraftItemStack.asBukkitCopy(nmsStack); + } + + +// --------------------------------------------------------------------- +// Section: Other methods +// --------------------------------------------------------------------- + + + /** + * This method returns HeadLib enum object with given name. If enum value with given name does not exist, + * then return null. + * @param name Name of object that must be returned. + * @return HeadLib with given name or null. + */ + public static HeadLib getHead(String name) + { + return BY_NAME.get(name.toUpperCase()); + } + + + // + // This static call populates all existing enum values into static map. + // + static + { + for (HeadLib head : values()) + { + BY_NAME.put(head.name(), head); + } + } +} \ No newline at end of file From 17d0f0b8f372283e7c5b973e883fb1150506764e Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 16:54:43 +0200 Subject: [PATCH 038/103] Create SelectEntityGUI that allows to select an entity from all living creatures. It displays mobs in two ways: as Mob eggs or as Mob Heads. --- .../panel/util/SelectEntityGUI.java | 275 ++++++++++++++++++ 1 file changed, 275 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java new file mode 100644 index 0000000..22f6c70 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java @@ -0,0 +1,275 @@ +package world.bentobox.challenges.panel.util; + + +import org.apache.commons.lang.WordUtils; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; +import java.util.*; +import java.util.function.BiConsumer; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.HeadLib; + + +/** + * This GUI allows to select single entity and return it via Consumer. + */ +public class SelectEntityGUI +{ + public SelectEntityGUI(User user, BiConsumer consumer) + { + this(user, Collections.emptySet(), true, consumer); + } + + + public SelectEntityGUI(User user, Set excludedEntities, boolean asEggs, BiConsumer consumer) + { + this.consumer = consumer; + this.user = user; + this.asEggs = asEggs; + + this.entities = new ArrayList<>(EntityType.values().length); + + for (EntityType entityType : EntityType.values()) + { + if (entityType.isAlive() && !excludedEntities.contains(entityType)) + { + this.entities.add(entityType); + } + } + + // Sort mobs by their name for easier search. + this.entities.sort(Comparator.comparing(Enum::name)); + + this.build(0); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method builds + */ + private void build(int pageIndex) + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.choose-entity-title")); + + // Maximal elements in page. + final int MAX_ELEMENTS = 36; + + final int correctPage; + + if (pageIndex < 0) + { + correctPage = this.entities.size() / MAX_ELEMENTS; + } + else if (pageIndex > (this.entities.size() / MAX_ELEMENTS)) + { + correctPage = 0; + } + else + { + correctPage = pageIndex; + } + + // Navigation buttons + + panelBuilder.item(3, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.previous")). + clickHandler( (panel, user1, clickType, slot) -> { + this.build(correctPage - 1); + return true; + }).build()); + + panelBuilder.item(4, + new PanelItemBuilder(). + icon(Material.OAK_DOOR). + name(this.user.getTranslation("challenges.gui.buttons.return")). + clickHandler( (panel, user1, clickType, slot) -> { + this.consumer.accept(false, null); + return true; + }).build()); + + panelBuilder.item(5, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.next")). + clickHandler( (panel, user1, clickType, slot) -> { + this.build(correctPage + 1); + return true; + }).build()); + + int entitiesIndex = MAX_ELEMENTS * correctPage; + + // I want first row to be only for navigation and return button. + int index = 9; + + while (entitiesIndex < ((correctPage + 1) * MAX_ELEMENTS) && + entitiesIndex < this.entities.size()) + { + panelBuilder.item(index++, this.createEntityButton(this.entities.get(entitiesIndex++))); + } + + panelBuilder.build(); + + panelBuilder.build(); + } + + + /** + * This method builds PanelItem for given entity. + * @param entity Entity which PanelItem must be created. + * @return new PanelItem for given Entity. + */ + private PanelItem createEntityButton(EntityType entity) + { + return new PanelItemBuilder(). + name(WordUtils.capitalize(entity.name().toLowerCase().replace("_", " "))). + icon(this.asEggs ? this.getEntityEgg(entity) : this.getEntityHead(entity)). + clickHandler((panel, user1, clickType, slot) -> { + this.consumer.accept(true, entity); + return true; + }).build(); + } + + + /** + * This method transforms entity into egg or block that corresponds given entity. If entity egg is not + * found, then it is replaced by block that represents entity or barrier block. + * @param entity Entity which egg must be returned. + * @return ItemStack that may be egg for given entity. + */ + private ItemStack getEntityEgg(EntityType entity) + { + ItemStack itemStack; + + switch (entity) + { + case PIG_ZOMBIE: + itemStack = new ItemStack(Material.ZOMBIE_PIGMAN_SPAWN_EGG); + break; + case ENDER_DRAGON: + itemStack = new ItemStack(Material.DRAGON_EGG); + break; + case WITHER: + itemStack = new ItemStack(Material.SOUL_SAND); + break; + case PLAYER: + itemStack = new ItemStack(Material.PLAYER_HEAD); + break; + case MUSHROOM_COW: + itemStack = new ItemStack(Material.MOOSHROOM_SPAWN_EGG); + break; + case SNOWMAN: + itemStack = new ItemStack(Material.CARVED_PUMPKIN); + break; + case IRON_GOLEM: + itemStack = new ItemStack(Material.IRON_BLOCK); + break; + case ARMOR_STAND: + itemStack = new ItemStack(Material.ARMOR_STAND); + break; + default: + Material material = Material.getMaterial(entity.name() + "_SPAWN_EGG"); + + if (material == null) + { + itemStack = new ItemStack(Material.BARRIER); + } + else + { + itemStack = new ItemStack(material); + } + + break; + } + + return itemStack; + } + + + /** + * This method transforms entity into player head with skin that corresponds given entity. If entity head + * is not found, then it is replaced by barrier block. + * @param entity Entity which head must be returned. + * @return ItemStack that may be head for given entity. + */ + private ItemStack getEntityHead(EntityType entity) + { + ItemStack itemStack; + + switch (entity) + { + case PLAYER: + itemStack = new ItemStack(Material.PLAYER_HEAD); + break; + case WITHER_SKELETON: + itemStack = new ItemStack(Material.WITHER_SKELETON_SKULL); + break; + case ARMOR_STAND: + itemStack = new ItemStack(Material.ARMOR_STAND); + break; + case SKELETON: + itemStack = new ItemStack(Material.SKELETON_SKULL); + break; + case GIANT: + case ZOMBIE: + itemStack = new ItemStack(Material.ZOMBIE_HEAD); + break; + case CREEPER: + itemStack = new ItemStack(Material.CREEPER_HEAD); + break; + case ENDER_DRAGON: + itemStack = new ItemStack(Material.DRAGON_HEAD); + break; + default: + HeadLib head = HeadLib.getHead(entity.name()); + + if (head == null) + { + itemStack = new ItemStack(Material.BARRIER); + } + else + { + itemStack = head.toItemStack(); + } + break; + } + + return itemStack; + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * This variable stores consumer. + */ + private BiConsumer consumer; + + /** + * User who runs GUI. + */ + private User user; + + /** + * This variable stores if mobs must be displayed as Eggs "true" or Heads "false". + */ + private boolean asEggs; + + /** + * Entities that must be in list. + */ + private List entities; +} From 865fa626af57c9457384a5b4d5d04e0668eda28a Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 17:12:00 +0200 Subject: [PATCH 039/103] Create SelectEnvironmentGUI that allows to select and deselect different world environments. --- .../panel/util/SelectEnvironmentGUI.java | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java new file mode 100644 index 0000000..01b1e1c --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java @@ -0,0 +1,134 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.Material; +import org.bukkit.World; +import java.util.Collections; +import java.util.Set; +import java.util.function.BiConsumer; + +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; + + +/** + * This class creates panel that allows to select and deselect World Environments. On save it runs + * input consumer with true and selected values. + */ +public class SelectEnvironmentGUI +{ + public SelectEnvironmentGUI(User user, Set values, BiConsumer> consumer) + { + this.user = user; + this.values = values; + this.consumer = consumer; + + this.build(); + } + + + /** + * This method builds environment select panel. + */ + private void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.admin.environment-title")); + + panelBuilder.item(3, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.save")). + icon(Material.GREEN_STAINED_GLASS_PANE). + clickHandler((panel, user1, clickType, index) -> { + this.consumer.accept(true, this.values); + return true; + }). + build()); + + panelBuilder.item(5, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.cancel")). + icon(Material.RED_STAINED_GLASS_PANE). + clickHandler((panel, user1, clickType, i) -> { + this.consumer.accept(false, Collections.emptySet()); + return true; + }). + build()); + + panelBuilder.item(12, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.nether")). + icon(Material.NETHERRACK). + clickHandler((panel, user1, clickType, i) -> { + if (this.values.contains(World.Environment.NETHER)) + { + this.values.remove(World.Environment.NETHER); + } + else + { + this.values.add(World.Environment.NETHER); + } + + this.build(); + return true; + }). + glow(this.values.contains(World.Environment.NETHER)). + build()); + panelBuilder.item(13, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.normal")). + icon(Material.DIRT). + clickHandler((panel, user1, clickType, i) -> { + if (this.values.contains(World.Environment.NORMAL)) + { + this.values.remove(World.Environment.NORMAL); + } + else + { + this.values.add(World.Environment.NORMAL); + } + + this.build(); + return true; + }). + glow(this.values.contains(World.Environment.NORMAL)). + build()); + panelBuilder.item(14, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.end")). + icon(Material.END_STONE). + clickHandler((panel, user1, clickType, i) -> { + if (this.values.contains(World.Environment.THE_END)) + { + this.values.remove(World.Environment.THE_END); + } + else + { + this.values.add(World.Environment.THE_END); + } + + this.build(); + return true; + }). + glow(this.values.contains(World.Environment.THE_END)). + build()); + + panelBuilder.build(); + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * User who wants to run command. + */ + private User user; + + /** + * List with selected environments. + */ + private Set values; + + /** + * Stores current Consumer + */ + private BiConsumer> consumer; + +} From 1d0f090948a85780989fdd46a35b9aa2f29f0d53 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 17:27:41 +0200 Subject: [PATCH 040/103] Implement existing GUIs in EditChallengeGUI. Change Challenges.environment from list to set. --- .../database/object/Challenges.java | 15 ++--- .../panel/admin/EditChallengeGUI.java | 64 ++++++++++++++++--- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenges.java b/src/main/java/world/bentobox/challenges/database/object/Challenges.java index 2b1d5ab..f717fe1 100644 --- a/src/main/java/world/bentobox/challenges/database/object/Challenges.java +++ b/src/main/java/world/bentobox/challenges/database/object/Challenges.java @@ -1,20 +1,15 @@ package world.bentobox.challenges.database.object; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import java.util.*; -import world.bentobox.challenges.ChallengesManager; import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.database.objects.DataObject; +import world.bentobox.challenges.ChallengesManager; /** * Data object for challenges @@ -103,7 +98,7 @@ public class Challenges implements DataObject { @ConfigComment("World where this challenge operates. List only overworld. Nether and end are automatically covered.") private String world = ""; @ConfigComment("List of environments where this challenge will occur: NETHER, NORMAL, THE_END. Leave blank for all.") - private List environment = new ArrayList<>(); + private Set environment = new HashSet<>(); @ConfigComment("The required permissions to see this challenge. String list.") private Set reqPerms = new HashSet<>(); @ConfigComment("The number of blocks around the player to search for items on an island") @@ -591,14 +586,14 @@ public class Challenges implements DataObject { /** * @return the environment */ - public List getEnvironment() { + public Set getEnvironment() { return environment; } /** * @param environment the environment to set */ - public void setEnvironment(List environment) { + public void setEnvironment(Set environment) { this.environment = environment; } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 13c8a7b..bfe63d6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -5,17 +5,19 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; - import java.util.*; +import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; +import world.bentobox.challenges.panel.util.SelectEnvironmentGUI; import world.bentobox.challenges.panel.util.StringListGUI; @@ -371,8 +373,24 @@ public class EditChallengeGUI extends CommonGUI description = Collections.emptyList(); icon = this.challenge.getIcon(); clickHandler = (panel, user, clickType, slot) -> { - // TODO: how to change icon. - this.build(); + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challenge.getIcon().getType().name(), + (player, reply) -> { + ItemStack newIcon = ItemParser.parse(reply); + + if (newIcon != null) + { + this.challenge.setIcon(newIcon); + } + else + { + this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); + } + + this.build(); + return reply; + }); return true; }; @@ -436,8 +454,15 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Enviroment Change GUI - this.build(); + new SelectEnvironmentGUI(this.user, this.challenge.getEnvironment(), (status, value) -> { + if (status) + { + this.challenge.setEnvironment(value); + } + + this.build(); + }); + return true; }; glow = false; @@ -472,8 +497,14 @@ public class EditChallengeGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement AnvilGUI. - this.build(); + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challenge.getFriendlyName(), + (player, reply) -> { + this.challenge.setFriendlyName(reply); + this.build(); + return reply; + }); return true; }; @@ -782,7 +813,14 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList(this.challenge.getRewardText()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement AnvilGUI + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challenge.getRewardText(), + (player, reply) -> { + this.challenge.setRewardText(reply); + this.build(); + return reply; + }); return true; }; @@ -936,8 +974,14 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList(this.challenge.getRepeatRewardText()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement AnvilGUI - + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challenge.getRepeatRewardText(), + (player, reply) -> { + this.challenge.setRepeatRewardText(reply); + this.build(); + return reply; + }); return true; }; From 9415452e33481859a2bd4305d5c94631ae583986 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 17:41:27 +0200 Subject: [PATCH 041/103] Implement AnvilGUIs into EditLevelGUI for editing Text fields. --- .../database/object/ChallengeLevels.java | 6 +++ .../challenges/panel/admin/EditLevelGUI.java | 54 +++++++++++++++---- 2 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java index dda7590..304ac2c 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java @@ -227,4 +227,10 @@ public class ChallengeLevels implements DataObject, Comparable { return null; } + + + public void setIcon(ItemStack newIcon) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 70812e2..22b92ba 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -8,10 +8,12 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.database.object.Challenges; @@ -274,7 +276,7 @@ public class EditLevelGUI extends CommonGUI /** * This method creates buttons for default main menu. * @param button Button which panel item must be created. - * @return PanelItem that represetns given button. + * @return PanelItem that represents given button. */ private PanelItem createButton(Button button) { @@ -292,8 +294,14 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList(this.challengeLevel.getFriendlyName()); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement AnvilGui. - this.build(); + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challengeLevel.getFriendlyName(), + (player, reply) -> { + this.challengeLevel.setFriendlyName(reply); + this.build(); + return reply; + }); return true; }; @@ -306,8 +314,24 @@ public class EditLevelGUI extends CommonGUI description = Collections.emptyList(); icon = this.challengeLevel.getIcon(); clickHandler = (panel, user, clickType, slot) -> { - // TODO: how to change icon. - this.build(); + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challengeLevel.getIcon().getType().name(), + (player, reply) -> { + ItemStack newIcon = ItemParser.parse(reply); + + if (newIcon != null) + { + this.challengeLevel.setIcon(newIcon); + } + else + { + this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); + } + + this.build(); + return reply; + }); return true; }; @@ -320,8 +344,14 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList(this.challengeLevel.getUnlockMessage()); icon = new ItemStack(Material.WRITABLE_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement AnvilGUI - this.build(); + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challengeLevel.getUnlockMessage(), + (player, reply) -> { + this.challengeLevel.setUnlockMessage(reply); + this.build(); + return reply; + }); return true; }; glow = false; @@ -380,8 +410,14 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList(this.challengeLevel.getRewardDescription()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Implement AnvilGui - + new AnvilGUI(this.addon.getPlugin(), + this.user.getPlayer(), + this.challengeLevel.getRewardDescription(), + (player, reply) -> { + this.challengeLevel.setRewardDescription(reply); + this.build(); + return reply; + }); return true; }; glow = false; From 6125eb5d3417a4ac608e4836270aa328c6b6b5eb Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 17:53:50 +0200 Subject: [PATCH 042/103] Create SelectChallengeGUI that allows to choose one challenge from input challenge list and return it into GUI. --- .../panel/util/SelectChallengeGUI.java | 138 ++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java new file mode 100644 index 0000000..f7563e2 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java @@ -0,0 +1,138 @@ +package world.bentobox.challenges.panel.util; + + +import org.bukkit.Material; +import java.util.List; +import java.util.function.BiConsumer; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.database.object.Challenges; + + +/** + * This class creates new GUI that allows to select single challenge, which is returned via consumer. + */ +public class SelectChallengeGUI +{ + public SelectChallengeGUI(User user, List challengesList, BiConsumer consumer) + { + this.consumer = consumer; + this.user = user; + this.challengesList = challengesList; + + this.build(0); + } + + + /** + * This method builds panel that allows to select single challenge from input challenges. + */ + private void build(int pageIndex) + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.choose-challenge-title")); + + // Maximal elements in page. + final int MAX_ELEMENTS = 36; + + final int correctPage; + + if (pageIndex < 0) + { + correctPage = this.challengesList.size() / MAX_ELEMENTS; + } + else if (pageIndex > (this.challengesList.size() / MAX_ELEMENTS)) + { + correctPage = 0; + } + else + { + correctPage = pageIndex; + } + + // Navigation buttons + + panelBuilder.item(3, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.previous")). + clickHandler( (panel, user1, clickType, slot) -> { + this.build(correctPage - 1); + return true; + }).build()); + + panelBuilder.item(4, + new PanelItemBuilder(). + icon(Material.OAK_DOOR). + name(this.user.getTranslation("challenges.gui.buttons.return")). + clickHandler( (panel, user1, clickType, slot) -> { + this.consumer.accept(false, null); + return true; + }).build()); + + panelBuilder.item(5, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.next")). + clickHandler( (panel, user1, clickType, slot) -> { + this.build(correctPage + 1); + return true; + }).build()); + + int challengesIndex = MAX_ELEMENTS * correctPage; + + // I want first row to be only for navigation and return button. + int index = 9; + + while (challengesIndex < ((correctPage + 1) * MAX_ELEMENTS) && + challengesIndex < this.challengesList.size()) + { + panelBuilder.item(index++, this.createChallengeButton(this.challengesList.get(challengesIndex++))); + } + + panelBuilder.build(); + + panelBuilder.build(); + } + + + /** + * This method builds PanelItem for given challenge. + * @param challenge Challenge which PanelItem must be created. + * @return new PanelItem for given Challenge. + */ + private PanelItem createChallengeButton(Challenges challenge) + { + return new PanelItemBuilder(). + name(challenge.getFriendlyName()). + description(challenge.getDescription()). + icon(challenge.getIcon()). + clickHandler((panel, user1, clickType, slot) -> { + this.consumer.accept(true, challenge); + return true; + }).build(); + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + + /** + * This variable stores consumer. + */ + private BiConsumer consumer; + + /** + * User who runs GUI. + */ + private User user; + + /** + * Current value. + */ + private List challengesList; +} From c42652dde88a13141e58e67dfc02f242a05d5b00 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 18:02:19 +0200 Subject: [PATCH 043/103] Implement add and remove challenge from challenge level panels in EditLevelGUI. --- .../challenges/ChallengesManager.java | 14 ++++++++- .../challenges/panel/admin/EditLevelGUI.java | 30 ++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 4d03187..e4972c7 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -554,7 +554,7 @@ public class ChallengesManager { public boolean validateChallengeUniqueID(World world, String reply) { - return false; + return true; } @@ -568,4 +568,16 @@ public class ChallengesManager { { return new ChallengeLevels(); } + + + public void unlinkChallenge(ChallengeLevels challengeLevel, Challenges value) + { + + } + + + public void linkChallenge(ChallengeLevels challengeLevel, Challenges value) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 22b92ba..fec1e01 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -15,11 +15,13 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; +import world.bentobox.challenges.panel.util.SelectChallengeGUI; import world.bentobox.challenges.panel.util.StringListGUI; @@ -523,8 +525,20 @@ public class EditLevelGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.WATER_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Challenge List GUI - this.build(); + ChallengesManager manager = this.addon.getChallengesManager(); + + // Get all challenge that is not in current challenge. + List challengeList = manager.getChallengesList(); + challengeList.removeAll(manager.getChallenges(this.challengeLevel)); + + new SelectChallengeGUI(this.user, challengeList, (status, value) -> { + if (status) + { + manager.linkChallenge(this.challengeLevel, value); + } + + this.build(); + }); return true; }; @@ -537,8 +551,16 @@ public class EditLevelGUI extends CommonGUI description = Collections.emptyList(); icon = new ItemStack(Material.LAVA_BUCKET); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Create Levels List GUI - this.build(); + ChallengesManager manager = this.addon.getChallengesManager(); + + new SelectChallengeGUI(this.user, manager.getChallenges(this.challengeLevel), (status, value) -> { + if (status) + { + manager.unlinkChallenge(this.challengeLevel, value); + } + + this.build(); + }); return true; }; From faa237ddf0db8f673ab52498e88baecfdc99c659 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 18:13:15 +0200 Subject: [PATCH 044/103] Integrate AnvilGUI into NumberGUI so users could manually write numbers in GUI. Add error messages, if number is not valid. --- .../challenges/panel/util/NumberGUI.java | 70 ++++++++++++++----- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index 94cf859..a1fcba3 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -7,6 +7,8 @@ import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import net.wesjd.anvilgui.AnvilGUI; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -132,21 +134,35 @@ public class NumberGUI description = Collections.emptyList(); icon = new ItemStack(Material.ANVIL); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Build Anvil GUI for editing value. + new AnvilGUI(BentoBox.getInstance(), + this.user.getPlayer(), + Integer.toString(this.value), + (player, reply) -> { + try + { + this.value = Integer.parseInt(reply); - if (this.value > this.maxValue) - { - // TODO: Throw warning message. - this.value = this.maxValue; - } + if (this.value > this.maxValue || this.value < this.minValue) + { + this.user.sendMessage("challenges.error.not-valid-integer", + "[value]", reply, + "[min]", Integer.toString(this.minValue), + "[max]", Integer.toString(this.maxValue)); + } + else + { + this.build(); + } + } + catch (Exception e) + { + reply = Integer.toString(this.value); + this.user.sendMessage("challenges.error.not-a-integer", "[value]", reply); + } - if (this.value < this.minValue) - { - // TODO: Throw warning message. - this.value = this.minValue; - } + return reply; + }); - this.build(); return true; }; glow = false; @@ -241,13 +257,21 @@ public class NumberGUI if (this.value > this.maxValue) { - // TODO: Throw warning message. + this.user.sendMessage("challenges.error.not-valid-integer", + "[value]", Integer.toString(this.value), + "[min]", Integer.toString(this.minValue), + "[max]", Integer.toString(this.maxValue)); + this.value = this.maxValue; } if (this.value < this.minValue) { - // TODO: Throw warning message. + this.user.sendMessage("challenges.error.not-valid-integer", + "[value]", Integer.toString(this.value), + "[min]", Integer.toString(this.minValue), + "[max]", Integer.toString(this.maxValue)); + this.value = this.minValue; } @@ -266,7 +290,11 @@ public class NumberGUI if (this.value > this.maxValue) { - // TODO: Throw warning message. + this.user.sendMessage("challenges.error.not-valid-integer", + "[value]", Integer.toString(this.value), + "[min]", Integer.toString(this.minValue), + "[max]", Integer.toString(this.maxValue)); + this.value = this.maxValue; } @@ -285,7 +313,11 @@ public class NumberGUI if (this.value < this.minValue) { - // TODO: Throw warning message. + this.user.sendMessage("challenges.error.not-valid-integer", + "[value]", Integer.toString(this.value), + "[min]", Integer.toString(this.minValue), + "[max]", Integer.toString(this.maxValue)); + this.value = this.minValue; } @@ -304,7 +336,11 @@ public class NumberGUI if (this.value > this.maxValue) { - // TODO: Throw warning message. + this.user.sendMessage("challenges.error.not-valid-integer", + "[value]", Integer.toString(this.value), + "[min]", Integer.toString(this.minValue), + "[max]", Integer.toString(this.maxValue)); + this.value = this.maxValue; } From be7435f73a92e218b720b978f1c2c433720a2f0e Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 18:21:37 +0200 Subject: [PATCH 045/103] Implement AnvilGUI into StringListGui so users could edit text via Anvil. --- .../challenges/panel/util/StringListGUI.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index be575c1..f0f8782 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -9,6 +9,8 @@ import java.util.Collections; import java.util.List; import java.util.function.BiConsumer; +import net.wesjd.anvilgui.AnvilGUI; +import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; @@ -61,9 +63,9 @@ public class StringListGUI panelBuilder.item(8, this.getButton(Button.CANCEL)); - for (String element : this.value) + for (int i = 0; i < this.value.size(); i++) { - panelBuilder.item(this.createStringElement(element)); + panelBuilder.item(this.createStringElement(this.value.get(i), i)); } panelBuilder.build(); @@ -122,10 +124,14 @@ public class StringListGUI description = Collections.emptyList(); icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE); clickHandler = (panel, user, clickType, slot) -> { - - // TODO: Open Anvil GUI. - - this.build(); + new AnvilGUI(BentoBox.getInstance(), + this.user.getPlayer(), + " ", + (player, reply) -> { + this.value.add(reply); + this.build(); + return reply; + }); return true; }; break; @@ -168,13 +174,20 @@ public class StringListGUI * @param element Paper Icon name * @return PanelItem. */ - private PanelItem createStringElement(String element) + private PanelItem createStringElement(String element, int stringIndex) { return new PanelItemBuilder(). name(element). icon(Material.PAPER). clickHandler((panel, user1, clickType, i) -> { - // TODO: open anvil gui. + new AnvilGUI(BentoBox.getInstance(), + this.user.getPlayer(), + element, + (player, reply) -> { + this.value.set(stringIndex, reply); + this.build(); + return reply; + }); return true; }).build(); } From 88f9d328626b4334edc32b3353c1154a10ec85ac Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 18:29:08 +0200 Subject: [PATCH 046/103] Implement Reset and Complete Challenge for ListUsersGUI. --- .../challenges/ChallengesManager.java | 12 ++++++++++ .../challenges/panel/admin/ListUsersGUI.java | 24 ++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index e4972c7..84e90b6 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -580,4 +580,16 @@ public class ChallengesManager { { } + + + public void resetChallenge(UUID uniqueId, Challenges value) + { + + } + + + public void completeChallenge(UUID uniqueId, Challenges value) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index fc4612c..c4be7f8 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -14,8 +14,10 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; +import world.bentobox.challenges.panel.util.SelectChallengeGUI; /** @@ -167,19 +169,35 @@ public class ListUsersGUI extends CommonGUI { return new PanelItemBuilder().name(player.getName()).icon(player.getName()).clickHandler( (panel, user1, clickType, slot) -> { + ChallengesManager manager = this.addon.getChallengesManager(); + switch (this.operationMode) { case COMPLETE: - // TODO: Open Complete Challenge GUI. + new SelectChallengeGUI(this.user, manager.getChallengesList(), (status, value) -> { + if (status) + { + manager.completeChallenge(player.getUniqueId(), value); + } + + this.build(); + }); break; case RESET: - // TODO: Open Reset Challenge GUI. + new SelectChallengeGUI(this.user, manager.getChallengesList(), (status, value) -> { + if (status) + { + manager.resetChallenge(player.getUniqueId(), value); + } + + this.build(); + }); break; case RESET_ALL: new ConfirmationGUI(this.user, status -> { if (status) { - this.addon.getChallengesManager().resetAllChallenges(this.user, this.world); + manager.resetAllChallenges(this.user, this.world); } }); break; From 010943126216c24c74b81aa7e9b33da5be4b04cd Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 21:25:48 +0200 Subject: [PATCH 047/103] Create new method in CommonGUI, that allows to fill border with black stained glass around Panel. --- .../bentobox/challenges/panel/CommonGUI.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 5e08cbe..7380eb5 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -8,6 +8,7 @@ import java.util.Collections; import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; @@ -233,6 +234,26 @@ public abstract class CommonGUI } + /** + * This method creates border of black panes around given panel. + * @param panelBuilder PanelBuilder which must be filled with border blocks. + */ + protected void fillBorder(PanelBuilder panelBuilder) + { + for (int i = 0; i < 45; i++) + { + // First (i < 9) and last (i > 35) rows must be filled + // First column (i % 9 == 0) and last column (i % 9 == 8) also must be filled. + + if (i < 9 || i > 35 || i % 9 == 0 || i % 9 == 8) + { + panelBuilder.item(i, + new PanelItemBuilder().name("").icon(Material.BLACK_STAINED_GLASS_PANE).build()); + } + } + } + + /** * This method sets new value to ValueObject variable. * @param value new Value of valueObject. From 16be7f26a1e216a9c2aa6444796ee7123fa00853 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 21:26:16 +0200 Subject: [PATCH 048/103] Create class that allows to change required entities for challenge. --- .../panel/admin/ManageEntitiesGUI.java | 339 ++++++++++++++++++ 1 file changed, 339 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java new file mode 100644 index 0000000..7d3651b --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java @@ -0,0 +1,339 @@ +package world.bentobox.challenges.panel.admin; + + +import org.apache.commons.lang.WordUtils; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; +import java.util.*; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.NumberGUI; +import world.bentobox.challenges.panel.util.SelectEntityGUI; +import world.bentobox.challenges.utils.HeadLib; + + +/** + * This class allows to edit entities that are in required entities map. + */ +public class ManageEntitiesGUI extends CommonGUI +{ + public ManageEntitiesGUI(ChallengesAddon addon, + World world, + User user, + Map requiredEntities, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.requiredEntities = requiredEntities; + + this.entityList = new ArrayList<>(this.requiredEntities.keySet()); + this.entityList.sort(Comparator.comparing(Enum::name)); + + this.selectedEntities = new HashSet<>(EntityType.values().length); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user). + name(this.user.getTranslation("challenges.gui.admin.edit-entities")); + + // create border + this.fillBorder(panelBuilder); + + panelBuilder.item(3, this.createButton(Button.ADD)); + panelBuilder.item(5, this.createButton(Button.REMOVE)); + + final int MAX_ELEMENTS = 21; + + if (this.pageIndex < 0) + { + this.pageIndex = this.entityList.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (this.entityList.size() / MAX_ELEMENTS)) + { + this.pageIndex = 0; + } + + int entitiesIndex = MAX_ELEMENTS * this.pageIndex; + + // I want first row to be only for navigation and return button. + int index = 10; + + while (entitiesIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + entitiesIndex < this.entityList.size()) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createEntityButton(this.entityList.get(entitiesIndex++))); + } + + index++; + } + + // Navigation buttons only if necessary + if (this.entityList.size() > MAX_ELEMENTS) + { + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); + } + + // Add return button. + panelBuilder.item(44, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This method creates PanelItem button of requested type. + * @param button Button which must be created. + * @return new PanelItem with requested functionality. + */ + private PanelItem createButton(Button button) + { + PanelItemBuilder builder = new PanelItemBuilder(); + + switch (button) + { + case ADD: + builder.name(this.user.getTranslation("challenges.gui.button.add")); + builder.icon(Material.BUCKET); + builder.clickHandler((panel, user1, clickType, slot) -> { + new SelectEntityGUI(this.user, (status, entity) -> { + if (status) + { + if (!this.requiredEntities.containsKey(entity)) + { + this.requiredEntities.put(entity, 1); + this.entityList.add(entity); + } + } + + this.build(); + }); + return true; + }); + break; + case REMOVE: + builder.name(this.user.getTranslation("challenges.gui.button.remove-selected")); + builder.icon(Material.LAVA_BUCKET); + builder.clickHandler((panel, user1, clickType, slot) -> { + this.requiredEntities.keySet().removeAll(this.selectedEntities); + this.entityList.removeAll(this.selectedEntities); + return true; + }); + break; + } + + return builder.build(); + } + + + /** + * This method creates button for given entity. + * @param entity Entity which button must be created. + * @return new Button for entity. + */ + private PanelItem createEntityButton(EntityType entity) + { + return new PanelItemBuilder(). + name(WordUtils.capitalize(entity.name().toLowerCase().replace("_", " "))). + icon(this.asEggs ? this.getEntityEgg(entity) : this.getEntityHead(entity)). + clickHandler((panel, user1, clickType, slot) -> { + // On right click change which entities are selected for deletion. + if (clickType.isRightClick()) + { + if (!this.selectedEntities.add(entity)) + { + // Remove entity if it is already selected + this.selectedEntities.remove(entity); + } + + this.build(); + } + else + { + new NumberGUI(this.user, this.requiredEntities.get(entity), 1, (status, value) -> { + if (status) + { + // Update value only when something changes. + this.requiredEntities.put(entity, value); + } + + this.build(); + }); + } + return true; + }). + glow(this.selectedEntities.contains(entity)). + build(); + } + + + /** + * This method transforms entity into egg or block that corresponds given entity. If entity egg is not + * found, then it is replaced by block that represents entity or barrier block. + * @param entity Entity which egg must be returned. + * @return ItemStack that may be egg for given entity. + */ + private ItemStack getEntityEgg(EntityType entity) + { + ItemStack itemStack; + + switch (entity) + { + case PIG_ZOMBIE: + itemStack = new ItemStack(Material.ZOMBIE_PIGMAN_SPAWN_EGG); + break; + case ENDER_DRAGON: + itemStack = new ItemStack(Material.DRAGON_EGG); + break; + case WITHER: + itemStack = new ItemStack(Material.SOUL_SAND); + break; + case PLAYER: + itemStack = new ItemStack(Material.PLAYER_HEAD); + break; + case MUSHROOM_COW: + itemStack = new ItemStack(Material.MOOSHROOM_SPAWN_EGG); + break; + case SNOWMAN: + itemStack = new ItemStack(Material.CARVED_PUMPKIN); + break; + case IRON_GOLEM: + itemStack = new ItemStack(Material.IRON_BLOCK); + break; + case ARMOR_STAND: + itemStack = new ItemStack(Material.ARMOR_STAND); + break; + default: + Material material = Material.getMaterial(entity.name() + "_SPAWN_EGG"); + + if (material == null) + { + itemStack = new ItemStack(Material.BARRIER); + } + else + { + itemStack = new ItemStack(material); + } + + break; + } + + itemStack.setAmount(this.requiredEntities.get(entity)); + + return itemStack; + } + + + /** + * This method transforms entity into player head with skin that corresponds given entity. If entity head + * is not found, then it is replaced by barrier block. + * @param entity Entity which head must be returned. + * @return ItemStack that may be head for given entity. + */ + private ItemStack getEntityHead(EntityType entity) + { + ItemStack itemStack; + + switch (entity) + { + case PLAYER: + itemStack = new ItemStack(Material.PLAYER_HEAD); + break; + case WITHER_SKELETON: + itemStack = new ItemStack(Material.WITHER_SKELETON_SKULL); + break; + case ARMOR_STAND: + itemStack = new ItemStack(Material.ARMOR_STAND); + break; + case SKELETON: + itemStack = new ItemStack(Material.SKELETON_SKULL); + break; + case GIANT: + case ZOMBIE: + itemStack = new ItemStack(Material.ZOMBIE_HEAD); + break; + case CREEPER: + itemStack = new ItemStack(Material.CREEPER_HEAD); + break; + case ENDER_DRAGON: + itemStack = new ItemStack(Material.DRAGON_HEAD); + break; + default: + HeadLib head = HeadLib.getHead(entity.name()); + + if (head == null) + { + itemStack = new ItemStack(Material.BARRIER); + } + else + { + itemStack = head.toItemStack(this.requiredEntities.get(entity)); + } + break; + } + + return itemStack; + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * Functional buttons in current GUI. + */ + private enum Button + { + ADD, + REMOVE + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * List with entities to avoid list irregularities. + */ + private List entityList; + + /** + * Set with entities that are selected. + */ + private Set selectedEntities; + + /** + * Map that contains all entities and their cound. + */ + private Map requiredEntities; + + /** + * Boolean indicate if entities should be displayed as eggs or mob heads. + */ + private boolean asEggs; +} From 43fe78e0f9f6bf64fa840219b547b86604e5202e Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 22:20:42 +0200 Subject: [PATCH 049/103] Fix issue when delete function was not working. --- .../world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java index 7d3651b..68642a3 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java @@ -139,6 +139,7 @@ public class ManageEntitiesGUI extends CommonGUI builder.clickHandler((panel, user1, clickType, slot) -> { this.requiredEntities.keySet().removeAll(this.selectedEntities); this.entityList.removeAll(this.selectedEntities); + this.build(); return true; }); break; From 3d5dbca4228f9084106477d8a7e608b8686d9f59 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 19 Jan 2019 23:48:38 +0200 Subject: [PATCH 050/103] Improves panel border creating method. Allow to change row count in panel and border material. --- .../bentobox/challenges/panel/CommonGUI.java | 49 +++++++++++++++++-- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index 7380eb5..d28c165 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -235,20 +235,59 @@ public abstract class CommonGUI /** - * This method creates border of black panes around given panel. + * This method creates border of black panes around given panel with 5 rows. * @param panelBuilder PanelBuilder which must be filled with border blocks. */ protected void fillBorder(PanelBuilder panelBuilder) { - for (int i = 0; i < 45; i++) + this.fillBorder(panelBuilder, 5, Material.BLACK_STAINED_GLASS_PANE); + } + + + /** + * This method sets black stained glass pane around Panel with given row count. + * @param panelBuilder object that builds Panel. + * @param rowCount in Panel. + */ + protected void fillBorder(PanelBuilder panelBuilder, int rowCount) + { + this.fillBorder(panelBuilder, rowCount, Material.BLACK_STAINED_GLASS_PANE); + } + + + /** + * This method sets blocks with given Material around Panel with 5 rows. + * @param panelBuilder object that builds Panel. + * @param material that will be around Panel. + */ + protected void fillBorder(PanelBuilder panelBuilder, Material material) + { + this.fillBorder(panelBuilder, 5, material); + } + + + /** + * This method sets blocks with given Material around Panel with given row count. + * @param panelBuilder object that builds Panel. + * @param rowCount in Panel. + * @param material that will be around Panel. + */ + protected void fillBorder(PanelBuilder panelBuilder, int rowCount, Material material) + { + // Only for useful filling. + if (rowCount < 3) + { + return; + } + + for (int i = 0; i < 9 * rowCount; i++) { // First (i < 9) and last (i > 35) rows must be filled // First column (i % 9 == 0) and last column (i % 9 == 8) also must be filled. - if (i < 9 || i > 35 || i % 9 == 0 || i % 9 == 8) + if (i < 9 || i > 9 * (rowCount - 1) || i % 9 == 0 || i % 9 == 8) { - panelBuilder.item(i, - new PanelItemBuilder().name("").icon(Material.BLACK_STAINED_GLASS_PANE).build()); + panelBuilder.item(i, new PanelItemBuilder().name("&2").icon(material).build()); } } } From dadf907efb91e935ec06063b4a23ab225d951e8c Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 11:54:40 +0200 Subject: [PATCH 051/103] Create SelectBlocksGUI that allows to select single Material that is block from GUI. --- .../panel/util/SelectBlocksGUI.java | 277 ++++++++++++++++++ 1 file changed, 277 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java new file mode 100644 index 0000000..e1c8315 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java @@ -0,0 +1,277 @@ +package world.bentobox.challenges.panel.util; + + +import org.apache.commons.lang.WordUtils; +import org.bukkit.Material; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.function.BiConsumer; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; + + +/** + * This class contains all necessary things that allows to select single block from all ingame blocks. Selected + * block will be returned via BiConsumer. + */ +public class SelectBlocksGUI +{ + public SelectBlocksGUI(User user, BiConsumer consumer) + { + this(user, Collections.emptySet(), consumer); + } + + + public SelectBlocksGUI(User user, Set excludedMaterial, BiConsumer consumer) + { + this.consumer = consumer; + this.user = user; + + // Current GUI cannot display air blocks. It crashes with null-pointer + excludedMaterial.add(Material.AIR); + excludedMaterial.add(Material.CAVE_AIR); + excludedMaterial.add(Material.VOID_AIR); + + // Piston head and moving piston is not necessary. useless. + excludedMaterial.add(Material.PISTON_HEAD); + excludedMaterial.add(Material.MOVING_PISTON); + + // Barrier cannot be accessible to user. + excludedMaterial.add(Material.BARRIER); + + this.elements = new ArrayList<>(); + + for (Material material : Material.values()) + { + if (material.isBlock() && !material.isLegacy() && !excludedMaterial.contains(material)) + { + this.elements.add(material); + } + } + + this.build(0); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + public void build(int pageIndex) + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user). + name(this.user.getTranslation("challenges.gui.admin.select-block")); + + + final int MAX_ELEMENTS = 21; + final int correctPage; + + if (pageIndex < 0) + { + correctPage = this.elements.size() / MAX_ELEMENTS; + } + else if (pageIndex > (this.elements.size() / MAX_ELEMENTS)) + { + correctPage = 0; + } + else + { + correctPage = pageIndex; + } + + int entitiesIndex = MAX_ELEMENTS * correctPage; + + // I want first row to be only for navigation and return button. + int index = 9; + + while (entitiesIndex < ((correctPage + 1) * MAX_ELEMENTS) && + entitiesIndex < this.elements.size()) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createMaterialButton(this.elements.get(entitiesIndex++))); + } + + index++; + } + + // Add navigation Buttons + panelBuilder.item(3, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.previous")). + clickHandler( (panel, user1, clickType, slot) -> { + this.build(correctPage - 1); + return true; + }).build()); + + panelBuilder.item(4, + new PanelItemBuilder(). + icon(Material.OAK_DOOR). + name(this.user.getTranslation("challenges.gui.buttons.return")). + clickHandler( (panel, user1, clickType, slot) -> { + this.consumer.accept(false, null); + return true; + }).build()); + + panelBuilder.item(5, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.next")). + clickHandler( (panel, user1, clickType, slot) -> { + this.build(correctPage + 1); + return true; + }).build()); + + panelBuilder.build(); + } + + + /** + * This method creates PanelItem that represents given material. + * Some materials is not displayable in Inventory GUI, so they are replaced with "placeholder" items. + * @param material Material which icon must be created. + * @return PanelItem that represents given material. + */ + private PanelItem createMaterialButton(Material material) + { + PanelItemBuilder builder = new PanelItemBuilder(). + name(WordUtils.capitalize(material.name().toLowerCase().replace("_", " "))); + + // Process items that cannot be item-stacks. + if (material.name().contains("_WALL")) + { + // Materials that is attached to wall cannot be showed in GUI. But they should be in list. + builder.icon(Material.getMaterial(material.name().replace("WALL_", ""))); + builder.glow(true); + } + else if (material.name().startsWith("POTTED_")) + { + // Materials Potted elements cannot be in inventory. + builder.icon(Material.getMaterial(material.name().replace("POTTED_", ""))); + builder.glow(true); + } + else if (material.name().startsWith("POTTED_")) + { + // Materials Potted elements cannot be in inventory. + builder.icon(Material.getMaterial(material.name().replace("POTTED_", ""))); + builder.glow(true); + } + else if (material.equals(Material.MELON_STEM) || material.equals(Material.ATTACHED_MELON_STEM)) + { + builder.icon(Material.MELON_SEEDS); + builder.glow(true); + } + else if (material.equals(Material.PUMPKIN_STEM) || material.equals(Material.ATTACHED_PUMPKIN_STEM)) + { + builder.icon(Material.PUMPKIN_SEEDS); + builder.glow(true); + } + else if (material.equals(Material.TALL_SEAGRASS)) + { + builder.icon(Material.SEAGRASS); + builder.glow(true); + } + else if (material.equals(Material.CARROTS)) + { + builder.icon(Material.CARROT); + builder.glow(true); + } + else if (material.equals(Material.BEETROOTS)) + { + builder.icon(Material.BEETROOT); + builder.glow(true); + } + else if (material.equals(Material.POTATOES)) + { + builder.icon(Material.POTATO); + builder.glow(true); + } + else if (material.equals(Material.COCOA)) + { + builder.icon(Material.COCOA_BEANS); + builder.glow(true); + } + else if (material.equals(Material.KELP_PLANT)) + { + builder.icon(Material.KELP); + builder.glow(true); + } + else if (material.equals(Material.REDSTONE_WIRE)) + { + builder.icon(Material.REDSTONE); + builder.glow(true); + } + else if (material.equals(Material.TRIPWIRE)) + { + builder.icon(Material.STRING); + builder.glow(true); + } + else if (material.equals(Material.FROSTED_ICE)) + { + builder.icon(Material.ICE); + builder.glow(true); + } + else if (material.equals(Material.END_PORTAL) || material.equals(Material.END_GATEWAY) || material.equals(Material.NETHER_PORTAL)) + { + builder.icon(Material.PAPER); + builder.glow(true); + } + else if (material.equals(Material.BUBBLE_COLUMN) || material.equals(Material.WATER)) + { + builder.icon(Material.WATER_BUCKET); + builder.glow(true); + } + else if (material.equals(Material.LAVA)) + { + builder.icon(Material.LAVA_BUCKET); + builder.glow(true); + } + else if (material.equals(Material.FIRE)) + { + builder.icon(Material.FIRE_CHARGE); + builder.glow(true); + } + else + { + builder.icon(material); + builder.glow(false); + } + + builder.clickHandler((panel, user1, clickType, slot) -> { + this.consumer.accept(true, material); + return true; + }); + + return builder.build(); + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * List with elements that will be displayed in current GUI. + */ + private List elements; + + /** + * This variable stores consumer. + */ + private BiConsumer consumer; + + /** + * User who runs GUI. + */ + private User user; +} From 0645f7cb1158ec07db0a1b9a3377daf84f9ad969 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Sun, 20 Jan 2019 15:55:12 +0200 Subject: [PATCH 052/103] Create new class GuiUtils that contains methods, that is frequently used and can be static. --- .../bentobox/challenges/panel/CommonGUI.java | 60 ----- .../panel/admin/ManageEntitiesGUI.java | 117 +-------- .../bentobox/challenges/utils/GuiUtils.java | 222 ++++++++++++++++++ 3 files changed, 227 insertions(+), 172 deletions(-) create mode 100644 src/main/java/world/bentobox/challenges/utils/GuiUtils.java diff --git a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java index d28c165..5e08cbe 100644 --- a/src/main/java/world/bentobox/challenges/panel/CommonGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/CommonGUI.java @@ -8,7 +8,6 @@ import java.util.Collections; import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; -import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; @@ -234,65 +233,6 @@ public abstract class CommonGUI } - /** - * This method creates border of black panes around given panel with 5 rows. - * @param panelBuilder PanelBuilder which must be filled with border blocks. - */ - protected void fillBorder(PanelBuilder panelBuilder) - { - this.fillBorder(panelBuilder, 5, Material.BLACK_STAINED_GLASS_PANE); - } - - - /** - * This method sets black stained glass pane around Panel with given row count. - * @param panelBuilder object that builds Panel. - * @param rowCount in Panel. - */ - protected void fillBorder(PanelBuilder panelBuilder, int rowCount) - { - this.fillBorder(panelBuilder, rowCount, Material.BLACK_STAINED_GLASS_PANE); - } - - - /** - * This method sets blocks with given Material around Panel with 5 rows. - * @param panelBuilder object that builds Panel. - * @param material that will be around Panel. - */ - protected void fillBorder(PanelBuilder panelBuilder, Material material) - { - this.fillBorder(panelBuilder, 5, material); - } - - - /** - * This method sets blocks with given Material around Panel with given row count. - * @param panelBuilder object that builds Panel. - * @param rowCount in Panel. - * @param material that will be around Panel. - */ - protected void fillBorder(PanelBuilder panelBuilder, int rowCount, Material material) - { - // Only for useful filling. - if (rowCount < 3) - { - return; - } - - for (int i = 0; i < 9 * rowCount; i++) - { - // First (i < 9) and last (i > 35) rows must be filled - // First column (i % 9 == 0) and last column (i % 9 == 8) also must be filled. - - if (i < 9 || i > 9 * (rowCount - 1) || i % 9 == 0 || i % 9 == 8) - { - panelBuilder.item(i, new PanelItemBuilder().name("&2").icon(material).build()); - } - } - } - - /** * This method sets new value to ValueObject variable. * @param value new Value of valueObject. diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java index 68642a3..f11d92e 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java @@ -16,7 +16,7 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.NumberGUI; import world.bentobox.challenges.panel.util.SelectEntityGUI; -import world.bentobox.challenges.utils.HeadLib; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -57,7 +57,7 @@ public class ManageEntitiesGUI extends CommonGUI name(this.user.getTranslation("challenges.gui.admin.edit-entities")); // create border - this.fillBorder(panelBuilder); + GuiUtils.fillBorder(panelBuilder); panelBuilder.item(3, this.createButton(Button.ADD)); panelBuilder.item(5, this.createButton(Button.REMOVE)); @@ -158,7 +158,9 @@ public class ManageEntitiesGUI extends CommonGUI { return new PanelItemBuilder(). name(WordUtils.capitalize(entity.name().toLowerCase().replace("_", " "))). - icon(this.asEggs ? this.getEntityEgg(entity) : this.getEntityHead(entity)). + icon(this.asEggs ? + GuiUtils.getEntityEgg(entity, this.requiredEntities.get(entity)) : + GuiUtils.getEntityHead(entity, this.requiredEntities.get(entity))). clickHandler((panel, user1, clickType, slot) -> { // On right click change which entities are selected for deletion. if (clickType.isRightClick()) @@ -190,115 +192,6 @@ public class ManageEntitiesGUI extends CommonGUI } - /** - * This method transforms entity into egg or block that corresponds given entity. If entity egg is not - * found, then it is replaced by block that represents entity or barrier block. - * @param entity Entity which egg must be returned. - * @return ItemStack that may be egg for given entity. - */ - private ItemStack getEntityEgg(EntityType entity) - { - ItemStack itemStack; - - switch (entity) - { - case PIG_ZOMBIE: - itemStack = new ItemStack(Material.ZOMBIE_PIGMAN_SPAWN_EGG); - break; - case ENDER_DRAGON: - itemStack = new ItemStack(Material.DRAGON_EGG); - break; - case WITHER: - itemStack = new ItemStack(Material.SOUL_SAND); - break; - case PLAYER: - itemStack = new ItemStack(Material.PLAYER_HEAD); - break; - case MUSHROOM_COW: - itemStack = new ItemStack(Material.MOOSHROOM_SPAWN_EGG); - break; - case SNOWMAN: - itemStack = new ItemStack(Material.CARVED_PUMPKIN); - break; - case IRON_GOLEM: - itemStack = new ItemStack(Material.IRON_BLOCK); - break; - case ARMOR_STAND: - itemStack = new ItemStack(Material.ARMOR_STAND); - break; - default: - Material material = Material.getMaterial(entity.name() + "_SPAWN_EGG"); - - if (material == null) - { - itemStack = new ItemStack(Material.BARRIER); - } - else - { - itemStack = new ItemStack(material); - } - - break; - } - - itemStack.setAmount(this.requiredEntities.get(entity)); - - return itemStack; - } - - - /** - * This method transforms entity into player head with skin that corresponds given entity. If entity head - * is not found, then it is replaced by barrier block. - * @param entity Entity which head must be returned. - * @return ItemStack that may be head for given entity. - */ - private ItemStack getEntityHead(EntityType entity) - { - ItemStack itemStack; - - switch (entity) - { - case PLAYER: - itemStack = new ItemStack(Material.PLAYER_HEAD); - break; - case WITHER_SKELETON: - itemStack = new ItemStack(Material.WITHER_SKELETON_SKULL); - break; - case ARMOR_STAND: - itemStack = new ItemStack(Material.ARMOR_STAND); - break; - case SKELETON: - itemStack = new ItemStack(Material.SKELETON_SKULL); - break; - case GIANT: - case ZOMBIE: - itemStack = new ItemStack(Material.ZOMBIE_HEAD); - break; - case CREEPER: - itemStack = new ItemStack(Material.CREEPER_HEAD); - break; - case ENDER_DRAGON: - itemStack = new ItemStack(Material.DRAGON_HEAD); - break; - default: - HeadLib head = HeadLib.getHead(entity.name()); - - if (head == null) - { - itemStack = new ItemStack(Material.BARRIER); - } - else - { - itemStack = head.toItemStack(this.requiredEntities.get(entity)); - } - break; - } - - return itemStack; - } - - // --------------------------------------------------------------------- // Section: Enums // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java new file mode 100644 index 0000000..43f7834 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -0,0 +1,222 @@ +package world.bentobox.challenges.utils; + + +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; + + +/** + * This class contains static methods that is used through multiple GUIs. + */ +public class GuiUtils +{ +// --------------------------------------------------------------------- +// Section: Border around GUIs +// --------------------------------------------------------------------- + + + /** + * This method creates border of black panes around given panel with 5 rows. + * @param panelBuilder PanelBuilder which must be filled with border blocks. + */ + public static void fillBorder(PanelBuilder panelBuilder) + { + GuiUtils.fillBorder(panelBuilder, 5, Material.BLACK_STAINED_GLASS_PANE); + } + + + /** + * This method sets black stained glass pane around Panel with given row count. + * @param panelBuilder object that builds Panel. + * @param rowCount in Panel. + */ + public static void fillBorder(PanelBuilder panelBuilder, int rowCount) + { + GuiUtils.fillBorder(panelBuilder, rowCount, Material.BLACK_STAINED_GLASS_PANE); + } + + + /** + * This method sets blocks with given Material around Panel with 5 rows. + * @param panelBuilder object that builds Panel. + * @param material that will be around Panel. + */ + public static void fillBorder(PanelBuilder panelBuilder, Material material) + { + GuiUtils.fillBorder(panelBuilder, 5, material); + } + + + /** + * This method sets blocks with given Material around Panel with given row count. + * @param panelBuilder object that builds Panel. + * @param rowCount in Panel. + * @param material that will be around Panel. + */ + public static void fillBorder(PanelBuilder panelBuilder, int rowCount, Material material) + { + // Only for useful filling. + if (rowCount < 3) + { + return; + } + + for (int i = 0; i < 9 * rowCount; i++) + { + // First (i < 9) and last (i > 35) rows must be filled + // First column (i % 9 == 0) and last column (i % 9 == 8) also must be filled. + + if (i < 9 || i > 9 * (rowCount - 1) || i % 9 == 0 || i % 9 == 8) + { + panelBuilder.item(i, new PanelItemBuilder().name("&2").icon(material).build()); + } + } + } + + +// --------------------------------------------------------------------- +// Section: Entities Visualization Block +// --------------------------------------------------------------------- + + /** + * This method transforms entity into egg or block that corresponds given entity. + * If entity egg is not found, then it is replaced by block that represents entity or + * barrier block. + * @param entity Entity which egg must be returned. + * @return ItemStack that may be egg for given entity. + */ + public static ItemStack getEntityEgg(EntityType entity) + { + return GuiUtils.getEntityEgg(entity, 1); + } + + + /** + * This method transforms entity into egg or block that corresponds given entity. + * If entity egg is not found, then it is replaced by block that represents entity or + * barrier block. + * @param entity Entity which egg must be returned. + * @param amount Amount of ItemStack elements. + * @return ItemStack that may be egg for given entity. + */ + public static ItemStack getEntityEgg(EntityType entity, int amount) + { + ItemStack itemStack; + + switch (entity) + { + case PIG_ZOMBIE: + itemStack = new ItemStack(Material.ZOMBIE_PIGMAN_SPAWN_EGG); + break; + case ENDER_DRAGON: + itemStack = new ItemStack(Material.DRAGON_EGG); + break; + case WITHER: + itemStack = new ItemStack(Material.SOUL_SAND); + break; + case PLAYER: + itemStack = new ItemStack(Material.PLAYER_HEAD); + break; + case MUSHROOM_COW: + itemStack = new ItemStack(Material.MOOSHROOM_SPAWN_EGG); + break; + case SNOWMAN: + itemStack = new ItemStack(Material.CARVED_PUMPKIN); + break; + case IRON_GOLEM: + itemStack = new ItemStack(Material.IRON_BLOCK); + break; + case ARMOR_STAND: + itemStack = new ItemStack(Material.ARMOR_STAND); + break; + default: + Material material = Material.getMaterial(entity.name() + "_SPAWN_EGG"); + + if (material == null) + { + itemStack = new ItemStack(Material.BARRIER); + } + else + { + itemStack = new ItemStack(material); + } + + break; + } + + itemStack.setAmount(amount); + + return itemStack; + } + + + /** + * This method transforms entity into player head with skin that corresponds given + * entity. If entity head is not found, then it is replaced by barrier block. + * @param entity Entity which head must be returned. + * @return ItemStack that may be head for given entity. + */ + public static ItemStack getEntityHead(EntityType entity) + { + return GuiUtils.getEntityHead(entity, 1); + } + + + /** + * This method transforms entity into player head with skin that corresponds given + * entity. If entity head is not found, then it is replaced by barrier block. + * @param entity Entity which head must be returned. + * @param amount Amount of ItemStack elements. + * @return ItemStack that may be head for given entity. + */ + public static ItemStack getEntityHead(EntityType entity, int amount) + { + ItemStack itemStack; + + switch (entity) + { + case PLAYER: + itemStack = new ItemStack(Material.PLAYER_HEAD); + break; + case WITHER_SKELETON: + itemStack = new ItemStack(Material.WITHER_SKELETON_SKULL); + break; + case ARMOR_STAND: + itemStack = new ItemStack(Material.ARMOR_STAND); + break; + case SKELETON: + itemStack = new ItemStack(Material.SKELETON_SKULL); + break; + case GIANT: + case ZOMBIE: + itemStack = new ItemStack(Material.ZOMBIE_HEAD); + break; + case CREEPER: + itemStack = new ItemStack(Material.CREEPER_HEAD); + break; + case ENDER_DRAGON: + itemStack = new ItemStack(Material.DRAGON_HEAD); + break; + default: + HeadLib head = HeadLib.getHead(entity.name()); + + if (head == null) + { + itemStack = new ItemStack(Material.BARRIER); + } + else + { + itemStack = head.toItemStack(); + } + break; + } + + itemStack.setAmount(amount); + + return itemStack; + } +} From 7b0df2d5a7d04d441d9bfe65b61b84fd0925e304 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Sun, 20 Jan 2019 16:12:20 +0200 Subject: [PATCH 053/103] Add Material to ItemStack transformation in GuiUtils class. --- .../bentobox/challenges/utils/GuiUtils.java | 120 +++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 43f7834..1a2d695 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -79,7 +79,7 @@ public class GuiUtils // --------------------------------------------------------------------- -// Section: Entities Visualization Block +// Section: ItemStack transformations // --------------------------------------------------------------------- /** @@ -219,4 +219,122 @@ public class GuiUtils return itemStack; } + + + /** + * This method transforms material into item stack that can be displayed in users + * inventory. + * @param material Material which item stack must be returned. + * @return ItemStack that represents given material. + */ + public static ItemStack getMaterialItem(Material material) + { + return GuiUtils.getMaterialItem(material, 1); + } + + + /** + * This method transforms material into item stack that can be displayed in users + * inventory. + * @param material Material which item stack must be returned. + * @param amount Amount of ItemStack elements. + * @return ItemStack that represents given material. + */ + public static ItemStack getMaterialItem(Material material, int amount) + { + ItemStack itemStack; + + // Process items that cannot be item-stacks. + if (material.name().contains("_WALL")) + { + // Materials that is attached to wall cannot be showed in GUI. But they should be in list. + itemStack = new ItemStack(Material.getMaterial(material.name().replace("WALL_", ""))); + } + else if (material.name().startsWith("POTTED_")) + { + // Materials Potted elements cannot be in inventory. + itemStack = new ItemStack(Material.getMaterial(material.name().replace("POTTED_", ""))); + } + else if (material.name().startsWith("POTTED_")) + { + // Materials Potted elements cannot be in inventory. + itemStack = new ItemStack(Material.getMaterial(material.name().replace("POTTED_", ""))); + } + else if (material.equals(Material.MELON_STEM) || material.equals(Material.ATTACHED_MELON_STEM)) + { + itemStack = new ItemStack(Material.MELON_SEEDS); + } + else if (material.equals(Material.PUMPKIN_STEM) || material.equals(Material.ATTACHED_PUMPKIN_STEM)) + { + itemStack = new ItemStack(Material.PUMPKIN_SEEDS); + } + else if (material.equals(Material.TALL_SEAGRASS)) + { + itemStack = new ItemStack(Material.SEAGRASS); + } + else if (material.equals(Material.CARROTS)) + { + itemStack = new ItemStack(Material.CARROT); + } + else if (material.equals(Material.BEETROOTS)) + { + itemStack = new ItemStack(Material.BEETROOT); + } + else if (material.equals(Material.POTATOES)) + { + itemStack = new ItemStack(Material.POTATO); + } + else if (material.equals(Material.COCOA)) + { + itemStack = new ItemStack(Material.COCOA_BEANS); + } + else if (material.equals(Material.KELP_PLANT)) + { + itemStack = new ItemStack(Material.KELP); + } + else if (material.equals(Material.REDSTONE_WIRE)) + { + itemStack = new ItemStack(Material.REDSTONE); + } + else if (material.equals(Material.TRIPWIRE)) + { + itemStack = new ItemStack(Material.STRING); + } + else if (material.equals(Material.FROSTED_ICE)) + { + itemStack = new ItemStack(Material.ICE); + } + else if (material.equals(Material.END_PORTAL) || material.equals(Material.END_GATEWAY) || material.equals(Material.NETHER_PORTAL)) + { + itemStack = new ItemStack(Material.PAPER); + } + else if (material.equals(Material.BUBBLE_COLUMN) || material.equals(Material.WATER)) + { + itemStack = new ItemStack(Material.WATER_BUCKET); + } + else if (material.equals(Material.LAVA)) + { + itemStack = new ItemStack(Material.LAVA_BUCKET); + } + else if (material.equals(Material.FIRE)) + { + itemStack = new ItemStack(Material.FIRE_CHARGE); + } + else if (material.equals(Material.AIR) || material.equals(Material.CAVE_AIR) || material.equals(Material.VOID_AIR)) + { + itemStack = new ItemStack(Material.GLASS_BOTTLE); + } + else if (material.equals(Material.PISTON_HEAD) || material.equals(Material.MOVING_PISTON)) + { + itemStack = new ItemStack(Material.PISTON); + } + else + { + itemStack = new ItemStack(material); + } + + itemStack.setAmount(amount); + + return itemStack; + } } From 24646678bf0924831acaef7192a3d392e92643aa Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 17:54:51 +0200 Subject: [PATCH 054/103] Remove code duplication. Material icon and Entities icon creation now are in GuiUtils class. --- .../panel/util/SelectBlocksGUI.java | 120 ++---------------- .../panel/util/SelectEntityGUI.java | 114 +---------------- 2 files changed, 16 insertions(+), 218 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java index e1c8315..e5b5e8d 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java @@ -3,6 +3,7 @@ package world.bentobox.challenges.panel.util; import org.apache.commons.lang.WordUtils; import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -13,6 +14,7 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -144,115 +146,17 @@ public class SelectBlocksGUI */ private PanelItem createMaterialButton(Material material) { - PanelItemBuilder builder = new PanelItemBuilder(). - name(WordUtils.capitalize(material.name().toLowerCase().replace("_", " "))); + ItemStack itemStack = GuiUtils.getMaterialItem(material); - // Process items that cannot be item-stacks. - if (material.name().contains("_WALL")) - { - // Materials that is attached to wall cannot be showed in GUI. But they should be in list. - builder.icon(Material.getMaterial(material.name().replace("WALL_", ""))); - builder.glow(true); - } - else if (material.name().startsWith("POTTED_")) - { - // Materials Potted elements cannot be in inventory. - builder.icon(Material.getMaterial(material.name().replace("POTTED_", ""))); - builder.glow(true); - } - else if (material.name().startsWith("POTTED_")) - { - // Materials Potted elements cannot be in inventory. - builder.icon(Material.getMaterial(material.name().replace("POTTED_", ""))); - builder.glow(true); - } - else if (material.equals(Material.MELON_STEM) || material.equals(Material.ATTACHED_MELON_STEM)) - { - builder.icon(Material.MELON_SEEDS); - builder.glow(true); - } - else if (material.equals(Material.PUMPKIN_STEM) || material.equals(Material.ATTACHED_PUMPKIN_STEM)) - { - builder.icon(Material.PUMPKIN_SEEDS); - builder.glow(true); - } - else if (material.equals(Material.TALL_SEAGRASS)) - { - builder.icon(Material.SEAGRASS); - builder.glow(true); - } - else if (material.equals(Material.CARROTS)) - { - builder.icon(Material.CARROT); - builder.glow(true); - } - else if (material.equals(Material.BEETROOTS)) - { - builder.icon(Material.BEETROOT); - builder.glow(true); - } - else if (material.equals(Material.POTATOES)) - { - builder.icon(Material.POTATO); - builder.glow(true); - } - else if (material.equals(Material.COCOA)) - { - builder.icon(Material.COCOA_BEANS); - builder.glow(true); - } - else if (material.equals(Material.KELP_PLANT)) - { - builder.icon(Material.KELP); - builder.glow(true); - } - else if (material.equals(Material.REDSTONE_WIRE)) - { - builder.icon(Material.REDSTONE); - builder.glow(true); - } - else if (material.equals(Material.TRIPWIRE)) - { - builder.icon(Material.STRING); - builder.glow(true); - } - else if (material.equals(Material.FROSTED_ICE)) - { - builder.icon(Material.ICE); - builder.glow(true); - } - else if (material.equals(Material.END_PORTAL) || material.equals(Material.END_GATEWAY) || material.equals(Material.NETHER_PORTAL)) - { - builder.icon(Material.PAPER); - builder.glow(true); - } - else if (material.equals(Material.BUBBLE_COLUMN) || material.equals(Material.WATER)) - { - builder.icon(Material.WATER_BUCKET); - builder.glow(true); - } - else if (material.equals(Material.LAVA)) - { - builder.icon(Material.LAVA_BUCKET); - builder.glow(true); - } - else if (material.equals(Material.FIRE)) - { - builder.icon(Material.FIRE_CHARGE); - builder.glow(true); - } - else - { - builder.icon(material); - builder.glow(false); - } - - builder.clickHandler((panel, user1, clickType, slot) -> { - this.consumer.accept(true, material); - return true; - }); - - return builder.build(); + return new PanelItemBuilder(). + name(WordUtils.capitalize(material.name().toLowerCase().replace("_", " "))). + icon(itemStack). + clickHandler((panel, user1, clickType, slot) -> { + this.consumer.accept(true, material); + return true; + }). + glow(!itemStack.getType().equals(material)). + build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java index 22f6c70..c16c5a2 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java @@ -12,7 +12,7 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.utils.HeadLib; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -120,8 +120,6 @@ public class SelectEntityGUI } panelBuilder.build(); - - panelBuilder.build(); } @@ -132,9 +130,11 @@ public class SelectEntityGUI */ private PanelItem createEntityButton(EntityType entity) { + ItemStack itemStack = this.asEggs ? GuiUtils.getEntityEgg(entity) : GuiUtils.getEntityHead(entity); + return new PanelItemBuilder(). name(WordUtils.capitalize(entity.name().toLowerCase().replace("_", " "))). - icon(this.asEggs ? this.getEntityEgg(entity) : this.getEntityHead(entity)). + icon(itemStack). clickHandler((panel, user1, clickType, slot) -> { this.consumer.accept(true, entity); return true; @@ -142,112 +142,6 @@ public class SelectEntityGUI } - /** - * This method transforms entity into egg or block that corresponds given entity. If entity egg is not - * found, then it is replaced by block that represents entity or barrier block. - * @param entity Entity which egg must be returned. - * @return ItemStack that may be egg for given entity. - */ - private ItemStack getEntityEgg(EntityType entity) - { - ItemStack itemStack; - - switch (entity) - { - case PIG_ZOMBIE: - itemStack = new ItemStack(Material.ZOMBIE_PIGMAN_SPAWN_EGG); - break; - case ENDER_DRAGON: - itemStack = new ItemStack(Material.DRAGON_EGG); - break; - case WITHER: - itemStack = new ItemStack(Material.SOUL_SAND); - break; - case PLAYER: - itemStack = new ItemStack(Material.PLAYER_HEAD); - break; - case MUSHROOM_COW: - itemStack = new ItemStack(Material.MOOSHROOM_SPAWN_EGG); - break; - case SNOWMAN: - itemStack = new ItemStack(Material.CARVED_PUMPKIN); - break; - case IRON_GOLEM: - itemStack = new ItemStack(Material.IRON_BLOCK); - break; - case ARMOR_STAND: - itemStack = new ItemStack(Material.ARMOR_STAND); - break; - default: - Material material = Material.getMaterial(entity.name() + "_SPAWN_EGG"); - - if (material == null) - { - itemStack = new ItemStack(Material.BARRIER); - } - else - { - itemStack = new ItemStack(material); - } - - break; - } - - return itemStack; - } - - - /** - * This method transforms entity into player head with skin that corresponds given entity. If entity head - * is not found, then it is replaced by barrier block. - * @param entity Entity which head must be returned. - * @return ItemStack that may be head for given entity. - */ - private ItemStack getEntityHead(EntityType entity) - { - ItemStack itemStack; - - switch (entity) - { - case PLAYER: - itemStack = new ItemStack(Material.PLAYER_HEAD); - break; - case WITHER_SKELETON: - itemStack = new ItemStack(Material.WITHER_SKELETON_SKULL); - break; - case ARMOR_STAND: - itemStack = new ItemStack(Material.ARMOR_STAND); - break; - case SKELETON: - itemStack = new ItemStack(Material.SKELETON_SKULL); - break; - case GIANT: - case ZOMBIE: - itemStack = new ItemStack(Material.ZOMBIE_HEAD); - break; - case CREEPER: - itemStack = new ItemStack(Material.CREEPER_HEAD); - break; - case ENDER_DRAGON: - itemStack = new ItemStack(Material.DRAGON_HEAD); - break; - default: - HeadLib head = HeadLib.getHead(entity.name()); - - if (head == null) - { - itemStack = new ItemStack(Material.BARRIER); - } - else - { - itemStack = head.toItemStack(); - } - break; - } - - return itemStack; - } - // --------------------------------------------------------------------- // Section: Variables From 7e3876f3914af9103c0d2e20e8586b94c8280167 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 19:28:32 +0200 Subject: [PATCH 055/103] Fix issue when WALL_TORCH and WALL_SING was without icon. --- src/main/java/world/bentobox/challenges/utils/GuiUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 1a2d695..46a42b9 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -245,7 +245,7 @@ public class GuiUtils ItemStack itemStack; // Process items that cannot be item-stacks. - if (material.name().contains("_WALL")) + if (material.name().contains("WALL_")) { // Materials that is attached to wall cannot be showed in GUI. But they should be in list. itemStack = new ItemStack(Material.getMaterial(material.name().replace("WALL_", ""))); From e9b20feac4ee382c7c1e843e77bc298198301f2e Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 19:29:55 +0200 Subject: [PATCH 056/103] Remove unnecessary else if. --- src/main/java/world/bentobox/challenges/utils/GuiUtils.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 46a42b9..8315910 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -255,11 +255,6 @@ public class GuiUtils // Materials Potted elements cannot be in inventory. itemStack = new ItemStack(Material.getMaterial(material.name().replace("POTTED_", ""))); } - else if (material.name().startsWith("POTTED_")) - { - // Materials Potted elements cannot be in inventory. - itemStack = new ItemStack(Material.getMaterial(material.name().replace("POTTED_", ""))); - } else if (material.equals(Material.MELON_STEM) || material.equals(Material.ATTACHED_MELON_STEM)) { itemStack = new ItemStack(Material.MELON_SEEDS); From a90f29e472d50de5634da993b32c8c01031e0ae6 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 19:33:27 +0200 Subject: [PATCH 057/103] Add GUI that allows to edit required blocks. --- .../panel/admin/ManageBlocksGUI.java | 224 ++++++++++++++++++ 1 file changed, 224 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java new file mode 100644 index 0000000..032fe72 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java @@ -0,0 +1,224 @@ +package world.bentobox.challenges.panel.admin; + + +import org.apache.commons.lang.WordUtils; +import org.bukkit.Material; +import org.bukkit.World; +import java.util.*; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.util.NumberGUI; +import world.bentobox.challenges.panel.util.SelectBlocksGUI; +import world.bentobox.challenges.utils.GuiUtils; + + +/** + * This class allows to edit material that are in required material map. + */ +public class ManageBlocksGUI extends CommonGUI +{ + public ManageBlocksGUI(ChallengesAddon addon, + World world, + User user, + Map materialMap, + String topLabel, + String permissionPrefix, + CommonGUI parentGUI) + { + super(addon, world, user, topLabel, permissionPrefix, parentGUI); + this.materialMap = materialMap; + + this.materialList = new ArrayList<>(this.materialMap.keySet()); + + // Sort materials by their ordinal value. + this.materialList.sort(Comparator.comparing(Enum::ordinal)); + + this.selectedMaterials = new HashSet<>(); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user). + name(this.user.getTranslation("challenges.gui.admin.manage-blocks")); + + // Create nice border. + GuiUtils.fillBorder(panelBuilder); + + panelBuilder.item(3, this.createButton(Button.ADD)); + panelBuilder.item(5, this.createButton(Button.REMOVE)); + + final int MAX_ELEMENTS = 21; + + if (this.pageIndex < 0) + { + this.pageIndex = this.materialList.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (this.materialList.size() / MAX_ELEMENTS)) + { + this.pageIndex = 0; + } + + int entitiesIndex = MAX_ELEMENTS * this.pageIndex; + + // I want first row to be only for navigation and return button. + int index = 10; + + while (entitiesIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + entitiesIndex < this.materialList.size()) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createElementButton(this.materialList.get(entitiesIndex++))); + } + + index++; + } + + // Navigation buttons only if necessary + if (this.materialList.size() > MAX_ELEMENTS) + { + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); + } + + // Add return button. + panelBuilder.item(44, this.returnButton); + + panelBuilder.build(); + } + + + /** + * This method creates PanelItem button of requested type. + * @param button Button which must be created. + * @return new PanelItem with requested functionality. + */ + private PanelItem createButton(Button button) + { + PanelItemBuilder builder = new PanelItemBuilder(); + + switch (button) + { + case ADD: + builder.name(this.user.getTranslation("challenges.gui.button.add")); + builder.icon(Material.BUCKET); + builder.clickHandler((panel, user1, clickType, slot) -> { + + new SelectBlocksGUI(this.user, new HashSet<>(this.materialList), (status, material) -> { + if (status) + { + this.materialMap.put(material, 1); + this.materialList.add(material); + } + + this.build(); + }); + return true; + }); + break; + case REMOVE: + builder.name(this.user.getTranslation("challenges.gui.button.remove-selected")); + builder.icon(Material.LAVA_BUCKET); + builder.clickHandler((panel, user1, clickType, slot) -> { + this.materialMap.keySet().removeAll(this.selectedMaterials); + this.materialList.removeAll(this.selectedMaterials); + this.build(); + return true; + }); + break; + } + + return builder.build(); + } + + + /** + * This method creates button for given material. + * @param material material which button must be created. + * @return new Button for material. + */ + private PanelItem createElementButton(Material material) + { + return new PanelItemBuilder(). + name(WordUtils.capitalize(material.name().toLowerCase().replace("_", " "))). + icon(GuiUtils.getMaterialItem(material, this.materialMap.get(material))). + clickHandler((panel, user1, clickType, slot) -> { + // On right click change which entities are selected for deletion. + if (clickType.isRightClick()) + { + if (!this.selectedMaterials.add(material)) + { + // Remove material if it is already selected + this.selectedMaterials.remove(material); + } + + this.build(); + } + else + { + new NumberGUI(this.user, this.materialMap.get(material), 1, (status, value) -> { + if (status) + { + // Update value only when something changes. + this.materialMap.put(material, value); + } + + this.build(); + }); + } + return true; + }). + glow(this.selectedMaterials.contains(material)). + build(); + } + + +// --------------------------------------------------------------------- +// Section: Enums +// --------------------------------------------------------------------- + + + /** + * Functional buttons in current GUI. + */ + private enum Button + { + ADD, + REMOVE + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * Contains selected materials. + */ + private Set selectedMaterials; + + /** + * List of materials to avoid order issues. + */ + private List materialList; + + /** + * List of required materials. + */ + private Map materialMap; +} From 8143059e172303fc5d2aa95cdc21cddd53bd1c1b Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 19:35:08 +0200 Subject: [PATCH 058/103] Add ManageEntitiesGUI and ManageBlocksGUI to EditChallengesGUI. --- .../panel/admin/EditChallengeGUI.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index bfe63d6..eb5971e 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -525,8 +525,13 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.CREEPER_HEAD); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Entities GUI - this.build(); + new ManageEntitiesGUI(this.addon, + this.world, + this.user, + this.challenge.getRequiredEntities(), + this.topLabel, + this.permissionPrefix, + this).build(); return true; }; @@ -569,8 +574,13 @@ public class EditChallengeGUI extends CommonGUI description = values; icon = new ItemStack(Material.STONE); clickHandler = (panel, user, clickType, slot) -> { - // TODO: Block GUI - this.build(); + new ManageBlocksGUI(this.addon, + this.world, + this.user, + this.challenge.getRequiredBlocks(), + this.topLabel, + this.permissionPrefix, + this).build(); return true; }; From d902e4b615d5f323dfd302b23dca52878e3ebaed Mon Sep 17 00:00:00 2001 From: BONNe Date: Sun, 20 Jan 2019 22:25:38 +0200 Subject: [PATCH 059/103] Add ability to move free challenges from start of the list to end of it. --- .../world/bentobox/challenges/Settings.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/Settings.java b/src/main/java/world/bentobox/challenges/Settings.java index 56340d9..39c8248 100644 --- a/src/main/java/world/bentobox/challenges/Settings.java +++ b/src/main/java/world/bentobox/challenges/Settings.java @@ -37,6 +37,10 @@ public class Settings implements DataObject @ConfigComment("Add enchanted glow to completed challenges") private boolean addCompletedGlow = true; + @ConfigComment("") + @ConfigComment("This indicate if free challenges must be at the start (true) or at the end (false) of list.") + private boolean freeChallengesFirst = true; + @ConfigComment("") @ConfigComment("This list stores GameModes in which Challenges addon should not work.") @ConfigComment("To disable addon it is necessary to write its name in new line that starts with -. Example:") @@ -109,6 +113,15 @@ public class Settings implements DataObject } + /** + * @return freeChallengesFirst value. + */ + public boolean isFreeChallengesFirst() + { + return this.freeChallengesFirst; + } + + @Override public void setUniqueId(String uniqueId) { @@ -159,4 +172,13 @@ public class Settings implements DataObject { this.disabledGameModes = disabledGameModes; } + + + /** + * @param freeChallengesFirst new freeChallengesFirst value. + */ + public void setFreeChallengesFirst(boolean freeChallengesFirst) + { + this.freeChallengesFirst = freeChallengesFirst; + } } From ce794d771ca0673b5eb441304e68b45694d259ca Mon Sep 17 00:00:00 2001 From: BONNe Date: Mon, 21 Jan 2019 00:01:26 +0200 Subject: [PATCH 060/103] Create ChallengesGUI that will be opened for users. --- .../challenges/panel/user/ChallengesGUI.java | 543 ++++++++++++++++++ 1 file changed, 543 insertions(+) create mode 100644 src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java new file mode 100644 index 0000000..00f8264 --- /dev/null +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -0,0 +1,543 @@ +package world.bentobox.challenges.panel.user; + + +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import world.bentobox.bentobox.api.panels.PanelItem; +import world.bentobox.bentobox.api.panels.builders.PanelBuilder; +import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.ChallengesManager; +import world.bentobox.challenges.LevelStatus; +import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.panel.TryToComplete; + + +/** + * This is UserGUI class. It contains everything necessary for user to use it. + */ +public class ChallengesGUI extends CommonGUI +{ +// --------------------------------------------------------------------- +// Section: Constructors +// --------------------------------------------------------------------- + + /** + * Default constructor that inits panels with minimal requirements, without parent panel. + * + * @param addon Addon where panel operates. + * @param world World from which panel was created. + * @param user User who created panel. + * @param topLabel Command top label which creates panel (f.e. island or ai) + * @param permissionPrefix Command permission prefix (f.e. bskyblock.) + */ + public ChallengesGUI(ChallengesAddon addon, + World world, + User user, + String topLabel, + String permissionPrefix) + { + super(addon, world, user, topLabel, permissionPrefix); + this.challengesManager = this.addon.getChallengesManager(); + + this.levelStatusList = this.challengesManager.getChallengeLevelStatus(this.user, this.world); + this.lastSelectedLevel = this.levelStatusList.get(0); + } + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method builds all necessary elements in GUI panel. + */ + @Override + public void build() + { + PanelBuilder panelBuilder = new PanelBuilder().user(this.user). + name(this.user.getTranslation("challenges.gui.title")); + + // TODO: get last completed level. + + if (this.addon.getChallengesSettings().isFreeChallengesFirst()) + { + this.addFreeChallenges(panelBuilder); + + // Start new row for challenges. + while (panelBuilder.nextSlot() % 9 != 0) + { + panelBuilder.item( + new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()); + } + } + + this.addChallenges(panelBuilder); + + // Start new row for levels. + while (panelBuilder.nextSlot() % 9 != 0) + { + panelBuilder.item( + new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()); + } + + this.addChallengeLevels(panelBuilder); + + if (!this.addon.getChallengesSettings().isFreeChallengesFirst()) + { + // Start new row for free challenges. + while (panelBuilder.nextSlot() % 9 != 0) + { + panelBuilder.item( + new PanelItemBuilder().icon(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()); + } + + this.addFreeChallenges(panelBuilder); + } + + panelBuilder.build(); + } + + + /** + * This method adds free challenges to panelBuilder. + * @param panelBuilder where free challenges must be added. + */ + private void addFreeChallenges(PanelBuilder panelBuilder) + { + List freeChallenges = this.challengesManager.getFreeChallenges(this.user, this.world); + final int freeChallengesCount = freeChallenges.size(); + + if (freeChallengesCount > 18) + { + int firstIndex = panelBuilder.nextSlot(); + + if (this.freeChallengeIndex > 0) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Previous"). + clickHandler((panel, user1, clickType, slot) -> { + this.freeChallengeIndex--; + this.build(); + return true; + }).build()); + } + + int currentIndex = this.freeChallengeIndex; + + while (panelBuilder.nextSlot() != firstIndex + 18 && currentIndex < freeChallengesCount) + { + panelBuilder.item(this.getChallengeButton(freeChallenges.get(currentIndex++))); + } + + // Check if one challenge is left + if (currentIndex + 1 == freeChallengesCount) + { + panelBuilder.item(this.getChallengeButton(freeChallenges.get(currentIndex))); + } + else if (currentIndex < freeChallengesCount) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Next"). + clickHandler((panel, user1, clickType, slot) -> { + this.freeChallengeIndex++; + this.build(); + return true; + }).build()); + } + } + else + { + for (Challenges challenge : freeChallenges) + { + // there are no limitations. Just bunch insert. + panelBuilder.item(this.getChallengeButton(challenge)); + } + } + } + + + /** + * This method adds last selected level challenges to panelBuilder. + * @param panelBuilder where last selected level challenges must be added. + */ + private void addChallenges(PanelBuilder panelBuilder) + { + List challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel()); + final int challengesCount = challenges.size(); + + if (challengesCount > 18) + { + int firstIndex = panelBuilder.nextSlot(); + + if (this.pageIndex > 0) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Previous"). + clickHandler((panel, user1, clickType, slot) -> { + this.pageIndex--; + this.build(); + return true; + }).build()); + } + + int currentIndex = this.pageIndex; + + while (panelBuilder.nextSlot() != firstIndex + 18 && currentIndex < challengesCount) + { + panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex++))); + } + + // Check if one challenge is left + if (currentIndex + 1 == challengesCount) + { + panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex))); + } + else if (currentIndex < challengesCount) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Next"). + clickHandler((panel, user1, clickType, slot) -> { + this.pageIndex++; + this.build(); + return true; + }).build()); + } + } + else + { + for (Challenges challenge : challenges) + { + // there are no limitations. Just bunch insert. + panelBuilder.item(this.getChallengeButton(challenge)); + } + } + } + + + /** + * This method adds challenge levels to panelBuilder. + * @param panelBuilder where challenge levels must be added. + */ + private void addChallengeLevels(PanelBuilder panelBuilder) + { + // Clone to avoid creating new level on each build. + List leftLevels = new ArrayList<>(this.levelStatusList); + leftLevels.remove(this.lastSelectedLevel); + + // TODO: Focusing on middle should be awsome. + + final int levelCounts = leftLevels.size(); + + if (levelCounts > 9) + { + int firstIndex = panelBuilder.nextSlot(); + + if (this.levelIndex > 0) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Previous"). + clickHandler((panel, user1, clickType, slot) -> { + this.levelIndex--; + this.build(); + return true; + }).build()); + } + + int currentIndex = this.levelIndex; + + while (panelBuilder.nextSlot() != firstIndex + 9 && currentIndex < levelCounts) + { + panelBuilder.item(this.getLevelButton(leftLevels.get(currentIndex++))); + } + + // Check if one challenge is left + if (currentIndex + 1 == levelCounts) + { + panelBuilder.item(this.getLevelButton(leftLevels.get(currentIndex))); + } + else if (currentIndex < levelCounts) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Next"). + clickHandler((panel, user1, clickType, slot) -> { + this.levelIndex++; + this.build(); + return true; + }).build()); + } + } + else + { + for (LevelStatus level : leftLevels) + { + // there are no limitations. Just bunch insert. + panelBuilder.item(this.getLevelButton(level)); + } + } + } + + +// --------------------------------------------------------------------- +// Section: Icon building +// --------------------------------------------------------------------- + + + /** + * This method creates given challenges icon that on press tries to complete it. + * @param challenge which icon must be constructed. + * @return PanelItem icon for challenge. + */ + private PanelItem getChallengeButton(Challenges challenge) + { + return new PanelItemBuilder(). + icon(challenge.getIcon()). + name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()). + description(this.createChallengeDescription(challenge)). + clickHandler((panel, user1, clickType, slot) -> { + new TryToComplete(this.addon, + this.user, + this.challengesManager, + challenge, + this.world, + this.permissionPrefix, + this.topLabel); + return true; + }). + glow(this.challengesManager.isChallengeComplete(this.user, challenge)). + build(); + } + + + /** + * This method creates challenges description by adding all information that is necessary for this challenge. + * @param challenge Which information must be retrieved. + * @return List with strings that contains information about given challenge. + */ + private List createChallengeDescription(Challenges challenge) + { + List result = new ArrayList<>(); + + result.add(this.user.getTranslation("challenges.level", + "[level]", this.challengesManager.getChallengesLevel(challenge))); + + boolean completed = this.challengesManager.isChallengeComplete(this.user, challenge); + + if (completed) + { + result.add(this.user.getTranslation("challenges.complete")); + } + + if (challenge.isRepeatable()) + { + int maxTimes = challenge.getMaxTimes(); + long doneTimes = this.challengesManager.checkChallengeTimes(this.user, challenge); + + if (maxTimes > 0) + { + if (doneTimes < maxTimes) + { + result.add(this.user.getTranslation("challenges.completed-times", + "[donetimes]", String.valueOf(doneTimes), + "[maxtimes]", String.valueOf(maxTimes))); + + // Change value to false, as max count not reached. + completed = false; + } + else + { + result.add(this.user.getTranslation("challenges.maxed-reached", + "[donetimes]", String.valueOf(doneTimes), + "[maxtimes]", String.valueOf(maxTimes))); + } + } + else + { + result.add(this.user.getTranslation("challenges.completed-times", + "[donetimes]", String.valueOf(doneTimes))); + + // Change value to false, as max count not reached. + completed = false; + } + } + + if (!completed) + { + result.addAll(challenge.getDescription()); + + if (challenge.getChallengeType().equals(Challenges.ChallengeType.INVENTORY)) + { + if (challenge.isTakeItems()) + { + result.add(this.user.getTranslation("challenges.item-take-warning")); + } + } + else if (challenge.getChallengeType().equals(Challenges.ChallengeType.ISLAND)) + { + result.add(this.user.getTranslation("challenges.items-closeby")); + + if (challenge.isRemoveEntities() && !challenge.getRequiredEntities().isEmpty()) + { + result.add(this.user.getTranslation("challenges.entities-kill-warning")); + } + + if (challenge.isRemoveBlocks() && !challenge.getRequiredBlocks().isEmpty()) + { + result.add(this.user.getTranslation("challenges.blocks-take-warning")); + } + } + } + + if (completed) + { + result.add(this.user.getTranslation("challenges.not-repeatable")); + } + else + { + result.addAll(this.challengeRewards(challenge)); + } + + return result; + } + + + /** + * This method returns list of strings that contains basic information about challenge rewards. + * @param challenge which reward message must be created. + * @return list of strings that contains rewards message. + */ + private List challengeRewards(Challenges challenge) + { + String rewardText; + double rewardMoney; + int rewardExperience; + + if (!this.challengesManager.isChallengeComplete(this.user, challenge)) + { + rewardText = challenge.getRewardText(); + rewardMoney = challenge.getRewardMoney(); + rewardExperience = challenge.getRewardExp(); + } + else + { + rewardText = challenge.getRepeatRewardText(); + rewardMoney = challenge.getRepeatMoneyReward(); + rewardExperience = challenge.getRepeatExpReward(); + } + + List result = new ArrayList<>(); + + // Add reward text + result.add(rewardText); + + // Add message about reward XP + if (rewardExperience > 0) + { + result.add(this.user.getTranslation("challenges.exp-reward", + "[reward]", Integer.toString(rewardExperience))); + } + + // Add message about reward money + if (this.addon.getPlugin().getSettings().isUseEconomy() && rewardMoney > 0) + { + result.add(this.user.getTranslation("challenges.money-reward", + "[reward]", Double.toString(rewardMoney))); + } + + return result; + } + + + /** + * This method creates button for given level. + * @param level which button must be created. + * @return Button for given level. + */ + private PanelItem getLevelButton(LevelStatus level) + { + // Create a nice name for the level + String name = level.getLevel().getFriendlyName().isEmpty() ? + level.getLevel().getUniqueId() : + level.getLevel().getFriendlyName(); + + ItemStack icon; + List description; + PanelItem.ClickHandler clickHandler; + + if (level.isUnlocked()) + { + icon = level.getLevel().getIcon(); + description = Collections.singletonList( + this.user.getTranslation("challenges.navigation", "[level]", name)); + clickHandler = (panel, user1, clickType, slot) -> { + this.lastSelectedLevel = level; + + // Reset level and page index. + this.levelIndex = 0; + this.pageIndex = 0; + + this.build(); + return true; + }; + } + else + { + icon = new ItemStack(Material.BOOK); + + // This should be safe as first level always should be unlocked. + LevelStatus previousLevel = this.levelStatusList.get(this.levelStatusList.indexOf(level) - 1); + + description = Collections.singletonList( + this.user.getTranslation("challenges.to-complete", + "[challengesToDo]", Integer.toString(previousLevel.getNumberOfChallengesStillToDo()), + "[thisLevel]", previousLevel.getLevel().getFriendlyName())); + + clickHandler = null; + } + + return new PanelItem(icon, name, description, false, clickHandler, false); + } + + +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + + /** + * This will be used if free challenges are more then 18. + */ + private int freeChallengeIndex = 0; + + /** + * This will be used if levels are more then 9. + */ + private int levelIndex; + + /** + * This list contains all information about level completion in current world. + */ + private List levelStatusList; + + /** + * This indicate last selected level. + */ + private LevelStatus lastSelectedLevel; + + /** + * Challenge Manager object. + */ + private ChallengesManager challengesManager; +} From 60789276be55f6725ddbb1de9ddf460d9efadad7 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 21 Jan 2019 12:21:53 +0200 Subject: [PATCH 061/103] Set all util guis to 45 element size. Add Glass Pane Borders to these guis. --- .../panel/util/ConfirmationGUI.java | 71 ++++++++++++---- .../challenges/panel/util/NumberGUI.java | 45 ++++++----- .../panel/util/SelectBlocksGUI.java | 48 +++++++---- .../panel/util/SelectChallengeGUI.java | 80 ++++++++++++------- .../panel/util/SelectEntityGUI.java | 71 ++++++++++------ .../panel/util/SelectEnvironmentGUI.java | 19 ++++- .../challenges/panel/util/StringListGUI.java | 41 ++++++---- 7 files changed, 248 insertions(+), 127 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java index 921c32f..3d36baf 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ConfirmationGUI.java @@ -5,9 +5,11 @@ import org.bukkit.Material; import java.util.function.Consumer; +import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -37,28 +39,65 @@ public class ConfirmationGUI { PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.admin.confirm-title")); - panelBuilder.item(3, new PanelItemBuilder(). - name(this.user.getTranslation("challenges.gui.admin.buttons.proceed")). - icon(Material.GREEN_STAINED_GLASS_PANE). - clickHandler((panel, user1, clickType, index) -> { - this.consumer.accept(true); - return true; - }). - build()); + GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE); - panelBuilder.item(5, new PanelItemBuilder(). - name(this.user.getTranslation("challenges.gui.admin.buttons.cancel")). - icon(Material.RED_STAINED_GLASS_PANE). - clickHandler((panel, user1, clickType, i) -> { - this.consumer.accept(false); - return true; - }). - build()); + // Accept buttons + panelBuilder.item(10, this.getButton(true)); + panelBuilder.item(11, this.getButton(true)); + panelBuilder.item(12, this.getButton(true)); + + panelBuilder.item(19, this.getButton(true)); + panelBuilder.item(20, this.getButton(true)); + panelBuilder.item(21, this.getButton(true)); + + panelBuilder.item(28, this.getButton(true)); + panelBuilder.item(29, this.getButton(true)); + panelBuilder.item(30, this.getButton(true)); + + // Cancel Buttons + panelBuilder.item(14, this.getButton(false)); + panelBuilder.item(15, this.getButton(false)); + panelBuilder.item(16, this.getButton(false)); + + panelBuilder.item(23, this.getButton(false)); + panelBuilder.item(24, this.getButton(false)); + panelBuilder.item(25, this.getButton(false)); + + panelBuilder.item(32, this.getButton(false)); + panelBuilder.item(33, this.getButton(false)); + panelBuilder.item(34, this.getButton(false)); + + panelBuilder.item(44, + new PanelItemBuilder(). + icon(Material.OAK_DOOR). + name(this.user.getTranslation("challenges.gui.buttons.return")). + clickHandler( (panel, user1, clickType, slot) -> { + this.consumer.accept(false); + return true; + }).build()); panelBuilder.build(); } + /** + * This method creates button with requested value. + * @param returnValue requested value + * @return PanelItem button. + */ + private PanelItem getButton(boolean returnValue) + { + return new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons." + (returnValue ? "accept" : "cancel"))). + icon(returnValue ? Material.GRAY_STAINED_GLASS_PANE : Material.RED_STAINED_GLASS_PANE). + clickHandler((panel, user1, clickType, i) -> { + this.consumer.accept(returnValue); + return true; + }). + build(); + } + + // --------------------------------------------------------------------- // Section: Variables // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index a1fcba3..8917303 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -54,11 +55,15 @@ public class NumberGUI { PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.edit-number-title")); + GuiUtils.fillBorder(panelBuilder); + // Others - panelBuilder.item(0, this.getButton(Button.SAVE)); - panelBuilder.item(1, this.getButton(Button.VALUE)); - panelBuilder.item(8, this.getButton(Button.CANCEL)); - panelBuilder.item(10, this.getButton(Button.INPUT)); + panelBuilder.item(1, this.getButton(Button.SAVE)); + + panelBuilder.item(19, this.getButton(Button.VALUE)); + panelBuilder.item(44, this.getButton(Button.CANCEL)); + + panelBuilder.item(2, this.getButton(Button.INPUT)); // operations panelBuilder.item(3, this.getButton(Button.SET)); @@ -67,23 +72,23 @@ public class NumberGUI panelBuilder.item(6, this.getButton(Button.MULTIPLY)); // Numbers - panelBuilder.item(20, this.createNumberButton(1)); - panelBuilder.item(21, this.createNumberButton(10)); - panelBuilder.item(22, this.createNumberButton(100)); - panelBuilder.item(23, this.createNumberButton(1000)); - panelBuilder.item(24, this.createNumberButton(10000)); + panelBuilder.item(11, this.createNumberButton(1)); + panelBuilder.item(12, this.createNumberButton(10)); + panelBuilder.item(13, this.createNumberButton(100)); + panelBuilder.item(14, this.createNumberButton(1000)); + panelBuilder.item(15, this.createNumberButton(10000)); - panelBuilder.item(29, this.createNumberButton(2)); - panelBuilder.item(30, this.createNumberButton(20)); - panelBuilder.item(31, this.createNumberButton(200)); - panelBuilder.item(32, this.createNumberButton(2000)); - panelBuilder.item(33, this.createNumberButton(20000)); + panelBuilder.item(20, this.createNumberButton(2)); + panelBuilder.item(21, this.createNumberButton(20)); + panelBuilder.item(22, this.createNumberButton(200)); + panelBuilder.item(23, this.createNumberButton(2000)); + panelBuilder.item(24, this.createNumberButton(20000)); - panelBuilder.item(38, this.createNumberButton(5)); - panelBuilder.item(39, this.createNumberButton(50)); - panelBuilder.item(40, this.createNumberButton(500)); - panelBuilder.item(41, this.createNumberButton(5000)); - panelBuilder.item(42, this.createNumberButton(50000)); + panelBuilder.item(29, this.createNumberButton(5)); + panelBuilder.item(30, this.createNumberButton(50)); + panelBuilder.item(31, this.createNumberButton(500)); + panelBuilder.item(32, this.createNumberButton(5000)); + panelBuilder.item(33, this.createNumberButton(50000)); panelBuilder.build(); } @@ -120,7 +125,7 @@ public class NumberGUI { name = this.user.getTranslation("challenges.gui.buttons.cancel"); description = Collections.emptyList(); - icon = new ItemStack(Material.IRON_DOOR); + icon = new ItemStack(Material.OAK_DOOR); clickHandler = (panel, user, clickType, slot) -> { this.consumer.accept(false, this.value); return true; diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java index e5b5e8d..4870d04 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectBlocksGUI.java @@ -73,6 +73,7 @@ public class SelectBlocksGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user). name(this.user.getTranslation("challenges.gui.admin.select-block")); + GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE); final int MAX_ELEMENTS = 21; final int correctPage; @@ -93,7 +94,7 @@ public class SelectBlocksGUI int entitiesIndex = MAX_ELEMENTS * correctPage; // I want first row to be only for navigation and return button. - int index = 9; + int index = 10; while (entitiesIndex < ((correctPage + 1) * MAX_ELEMENTS) && entitiesIndex < this.elements.size()) @@ -106,31 +107,44 @@ public class SelectBlocksGUI index++; } - // Add navigation Buttons - panelBuilder.item(3, - new PanelItemBuilder(). - icon(Material.SIGN). - name(this.user.getTranslation("challenges.gui.buttons.previous")). - clickHandler( (panel, user1, clickType, slot) -> { - this.build(correctPage - 1); - return true; - }).build()); - panelBuilder.item(4, new PanelItemBuilder(). - icon(Material.OAK_DOOR). - name(this.user.getTranslation("challenges.gui.buttons.return")). + icon(Material.RED_STAINED_GLASS_PANE). + name(this.user.getTranslation("challenges.gui.buttons.cancel")). clickHandler( (panel, user1, clickType, slot) -> { this.consumer.accept(false, null); return true; }).build()); - panelBuilder.item(5, + if (this.elements.size() > MAX_ELEMENTS) + { + // Navigation buttons if necessary + + panelBuilder.item(18, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.previous")). + clickHandler((panel, user1, clickType, slot) -> { + this.build(correctPage - 1); + return true; + }).build()); + + panelBuilder.item(26, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.next")). + clickHandler((panel, user1, clickType, slot) -> { + this.build(correctPage + 1); + return true; + }).build()); + } + + panelBuilder.item(44, new PanelItemBuilder(). - icon(Material.SIGN). - name(this.user.getTranslation("challenges.gui.buttons.next")). + icon(Material.OAK_DOOR). + name(this.user.getTranslation("challenges.gui.buttons.return")). clickHandler( (panel, user1, clickType, slot) -> { - this.build(correctPage + 1); + this.consumer.accept(false, null); return true; }).build()); diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java index f7563e2..2682d8f 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java @@ -10,6 +10,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -34,8 +35,10 @@ public class SelectChallengeGUI { PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.choose-challenge-title")); + GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE); + // Maximal elements in page. - final int MAX_ELEMENTS = 36; + final int MAX_ELEMENTS = 21; final int correctPage; @@ -52,18 +55,57 @@ public class SelectChallengeGUI correctPage = pageIndex; } - // Navigation buttons - - panelBuilder.item(3, + panelBuilder.item(4, new PanelItemBuilder(). - icon(Material.SIGN). - name(this.user.getTranslation("challenges.gui.buttons.previous")). + icon(Material.RED_STAINED_GLASS_PANE). + name(this.user.getTranslation("challenges.gui.buttons.return")). clickHandler( (panel, user1, clickType, slot) -> { - this.build(correctPage - 1); + this.consumer.accept(false, null); return true; }).build()); - panelBuilder.item(4, + if (this.challengesList.size() > MAX_ELEMENTS) + { + // Navigation buttons if necessary + + panelBuilder.item(18, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.previous")). + clickHandler((panel, user1, clickType, slot) -> { + this.build(correctPage - 1); + return true; + }).build()); + + panelBuilder.item(26, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.next")). + clickHandler((panel, user1, clickType, slot) -> { + this.build(correctPage + 1); + return true; + }).build()); + } + + int challengesIndex = MAX_ELEMENTS * correctPage; + + // I want first row to be only for navigation and return button. + int index = 10; + + while (challengesIndex < ((correctPage + 1) * MAX_ELEMENTS) && + challengesIndex < this.challengesList.size() && + index < 36) + { + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, + this.createChallengeButton(this.challengesList.get(challengesIndex++))); + } + + index++; + } + + panelBuilder.item(44, new PanelItemBuilder(). icon(Material.OAK_DOOR). name(this.user.getTranslation("challenges.gui.buttons.return")). @@ -72,28 +114,6 @@ public class SelectChallengeGUI return true; }).build()); - panelBuilder.item(5, - new PanelItemBuilder(). - icon(Material.SIGN). - name(this.user.getTranslation("challenges.gui.buttons.next")). - clickHandler( (panel, user1, clickType, slot) -> { - this.build(correctPage + 1); - return true; - }).build()); - - int challengesIndex = MAX_ELEMENTS * correctPage; - - // I want first row to be only for navigation and return button. - int index = 9; - - while (challengesIndex < ((correctPage + 1) * MAX_ELEMENTS) && - challengesIndex < this.challengesList.size()) - { - panelBuilder.item(index++, this.createChallengeButton(this.challengesList.get(challengesIndex++))); - } - - panelBuilder.build(); - panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java index c16c5a2..31114c3 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectEntityGUI.java @@ -61,8 +61,10 @@ public class SelectEntityGUI { PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.choose-entity-title")); + GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE); + // Maximal elements in page. - final int MAX_ELEMENTS = 36; + final int MAX_ELEMENTS = 21; final int correctPage; @@ -79,46 +81,65 @@ public class SelectEntityGUI correctPage = pageIndex; } - // Navigation buttons - - panelBuilder.item(3, - new PanelItemBuilder(). - icon(Material.SIGN). - name(this.user.getTranslation("challenges.gui.buttons.previous")). - clickHandler( (panel, user1, clickType, slot) -> { - this.build(correctPage - 1); - return true; - }).build()); - panelBuilder.item(4, new PanelItemBuilder(). - icon(Material.OAK_DOOR). - name(this.user.getTranslation("challenges.gui.buttons.return")). + icon(Material.RED_STAINED_GLASS_PANE). + name(this.user.getTranslation("challenges.gui.buttons.cancel")). clickHandler( (panel, user1, clickType, slot) -> { this.consumer.accept(false, null); return true; }).build()); - panelBuilder.item(5, - new PanelItemBuilder(). - icon(Material.SIGN). - name(this.user.getTranslation("challenges.gui.buttons.next")). - clickHandler( (panel, user1, clickType, slot) -> { - this.build(correctPage + 1); - return true; - }).build()); + if (this.entities.size() > MAX_ELEMENTS) + { + // Navigation buttons if necessary + + panelBuilder.item(18, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.previous")). + clickHandler((panel, user1, clickType, slot) -> { + this.build(correctPage - 1); + return true; + }).build()); + + panelBuilder.item(26, + new PanelItemBuilder(). + icon(Material.SIGN). + name(this.user.getTranslation("challenges.gui.buttons.next")). + clickHandler((panel, user1, clickType, slot) -> { + this.build(correctPage + 1); + return true; + }).build()); + } int entitiesIndex = MAX_ELEMENTS * correctPage; // I want first row to be only for navigation and return button. - int index = 9; + int slot = 10; while (entitiesIndex < ((correctPage + 1) * MAX_ELEMENTS) && - entitiesIndex < this.entities.size()) + entitiesIndex < this.entities.size() && + slot < 36) { - panelBuilder.item(index++, this.createEntityButton(this.entities.get(entitiesIndex++))); + if (!panelBuilder.slotOccupied(slot)) + { + panelBuilder.item(slot, + this.createEntityButton(this.entities.get(entitiesIndex++))); + } + + slot++; } + panelBuilder.item(44, + new PanelItemBuilder(). + icon(Material.OAK_DOOR). + name(this.user.getTranslation("challenges.gui.buttons.return")). + clickHandler( (panel, user1, clickType, i) -> { + this.consumer.accept(false, null); + return true; + }).build()); + panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java index 01b1e1c..a0a42e8 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java @@ -10,6 +10,7 @@ import java.util.function.BiConsumer; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -35,6 +36,8 @@ public class SelectEnvironmentGUI { PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.admin.environment-title")); + GuiUtils.fillBorder(panelBuilder, Material.BLUE_STAINED_GLASS_PANE); + panelBuilder.item(3, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.save")). icon(Material.GREEN_STAINED_GLASS_PANE). @@ -53,7 +56,7 @@ public class SelectEnvironmentGUI }). build()); - panelBuilder.item(12, new PanelItemBuilder(). + panelBuilder.item(20, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.nether")). icon(Material.NETHERRACK). clickHandler((panel, user1, clickType, i) -> { @@ -71,7 +74,7 @@ public class SelectEnvironmentGUI }). glow(this.values.contains(World.Environment.NETHER)). build()); - panelBuilder.item(13, new PanelItemBuilder(). + panelBuilder.item(22, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.normal")). icon(Material.DIRT). clickHandler((panel, user1, clickType, i) -> { @@ -89,7 +92,7 @@ public class SelectEnvironmentGUI }). glow(this.values.contains(World.Environment.NORMAL)). build()); - panelBuilder.item(14, new PanelItemBuilder(). + panelBuilder.item(24, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.end")). icon(Material.END_STONE). clickHandler((panel, user1, clickType, i) -> { @@ -108,6 +111,16 @@ public class SelectEnvironmentGUI glow(this.values.contains(World.Environment.THE_END)). build()); + + panelBuilder.item(44, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.return")). + icon(Material.OAK_DOOR). + clickHandler((panel, user1, clickType, i) -> { + this.consumer.accept(false, Collections.emptySet()); + return true; + }). + build()); + panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index f0f8782..2a7c169 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -3,10 +3,7 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; import java.util.function.BiConsumer; import net.wesjd.anvilgui.AnvilGUI; @@ -15,6 +12,7 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -35,7 +33,7 @@ public class StringListGUI this.user = user; this.value = value; - if (this.value.size() > 18) + if (this.value.size() > 21) { // TODO: throw error that so large list cannot be edited. this.consumer.accept(false, this.value); @@ -52,20 +50,31 @@ public class StringListGUI */ private void build() { - PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.text-edit-title")); + PanelBuilder panelBuilder = new PanelBuilder().user(this.user). + name(this.user.getTranslation("challenges.gui.text-edit-title")); - panelBuilder.item(0, this.getButton(Button.SAVE)); - panelBuilder.item(1, this.getButton(Button.VALUE)); + GuiUtils.fillBorder(panelBuilder, Material.BLACK_STAINED_GLASS_PANE); - panelBuilder.item(3, this.getButton(Button.ADD)); - panelBuilder.item(4, this.getButton(Button.REMOVE)); - panelBuilder.item(4, this.getButton(Button.CLEAR)); + panelBuilder.item(1, this.getButton(Button.SAVE)); + panelBuilder.item(2, this.getButton(Button.VALUE)); - panelBuilder.item(8, this.getButton(Button.CANCEL)); + panelBuilder.item(4, this.getButton(Button.ADD)); + panelBuilder.item(5, this.getButton(Button.REMOVE)); + panelBuilder.item(6, this.getButton(Button.CLEAR)); - for (int i = 0; i < this.value.size(); i++) + panelBuilder.item(44, this.getButton(Button.CANCEL)); + + int slot = 10; + + for (int stringIndex = 0; stringIndex < this.value.size() && slot < 36; stringIndex++) { - panelBuilder.item(this.createStringElement(this.value.get(i), i)); + if (!panelBuilder.slotOccupied(slot)) + { + panelBuilder.item(slot, + this.createStringElement(this.value.get(stringIndex), stringIndex)); + } + + slot++; } panelBuilder.build(); @@ -90,7 +99,7 @@ public class StringListGUI { name = this.user.getTranslation("challenges.gui.buttons.save"); description = Collections.emptyList(); - icon = new ItemStack(Material.COMMAND_BLOCK); + icon = new ItemStack(Material.GREEN_STAINED_GLASS_PANE); clickHandler = (panel, user, clickType, slot) -> { this.consumer.accept(true, this.value); @@ -102,7 +111,7 @@ public class StringListGUI { name = this.user.getTranslation("challenges.gui.buttons.cancel"); description = Collections.emptyList(); - icon = new ItemStack(Material.IRON_DOOR); + icon = new ItemStack(Material.OAK_DOOR); clickHandler = (panel, user, clickType, slot) -> { this.consumer.accept(false, this.value); From c78c69081819b1c8f962e973b1ccf63b75f4218e Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 21 Jan 2019 14:00:13 +0200 Subject: [PATCH 062/103] Remove item name from Border Items --- .../bentobox/challenges/utils/GuiUtils.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 8315910..34b6107 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -5,8 +5,10 @@ import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import java.util.Collections; + +import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; -import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; /** @@ -72,7 +74,7 @@ public class GuiUtils if (i < 9 || i > 9 * (rowCount - 1) || i % 9 == 0 || i % 9 == 8) { - panelBuilder.item(i, new PanelItemBuilder().name("&2").icon(material).build()); + panelBuilder.item(i, BorderBlock.getPanelBorder(material)); } } } @@ -332,4 +334,30 @@ public class GuiUtils return itemStack; } + + + /** + * This BorderBlock is simple PanelItem but without item meta data. + */ + private static class BorderBlock extends PanelItem + { + private BorderBlock(ItemStack icon) + { + super(icon.clone(), " ", Collections.emptyList(), false, null, false); + } + + + /** + * This method retunrs BorderBlock with requested item stack. + * @param material of which broder must be created. + * @return PanelItem that acts like border. + */ + private static BorderBlock getPanelBorder(Material material) + { + ItemStack itemStack = new ItemStack(material); + itemStack.getItemMeta().setDisplayName(" "); + + return new BorderBlock(itemStack); + } + } } From 10a5dc194020131761c502f6a78b849b1cacc587 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Mon, 21 Jan 2019 15:23:16 +0200 Subject: [PATCH 063/103] Apply single GUI style to all admin GUIs. --- .../challenges/panel/admin/AdminGUI.java | 24 ++++--- .../panel/admin/EditChallengeGUI.java | 50 +++++++------- .../challenges/panel/admin/EditLevelGUI.java | 66 +++++++++++-------- .../panel/admin/EditSettingsGUI.java | 26 ++++++-- .../panel/admin/ListChallengesGUI.java | 49 +++++++++----- .../challenges/panel/admin/ListLevelsGUI.java | 49 +++++++++----- .../challenges/panel/admin/ListUsersGUI.java | 60 ++++++++--------- .../panel/admin/ManageBlocksGUI.java | 3 +- .../panel/admin/ManageEntitiesGUI.java | 3 +- 9 files changed, 194 insertions(+), 136 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index c745c6a..97ae16e 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -13,6 +13,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -89,28 +90,31 @@ public class AdminGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.admin.gui-title")); + GuiUtils.fillBorder(panelBuilder); - panelBuilder.item(1, this.createButton(Button.COMPLETE_USER_CHALLENGES)); - panelBuilder.item(10, this.createButton(Button.RESET_USER_CHALLENGES)); + panelBuilder.item(10, this.createButton(Button.COMPLETE_USER_CHALLENGES)); + panelBuilder.item(19, this.createButton(Button.RESET_USER_CHALLENGES)); // Add Challenges - panelBuilder.item(3, this.createButton(Button.ADD_CHALLENGE)); - panelBuilder.item(12, this.createButton(Button.ADD_LEVEL)); + panelBuilder.item(12, this.createButton(Button.ADD_CHALLENGE)); + panelBuilder.item(13, this.createButton(Button.ADD_LEVEL)); // Edit Challenges - panelBuilder.item(4, this.createButton(Button.EDIT_CHALLENGE)); - panelBuilder.item(13, this.createButton(Button.EDIT_LEVEL)); + panelBuilder.item(21, this.createButton(Button.EDIT_CHALLENGE)); + panelBuilder.item(22, this.createButton(Button.EDIT_LEVEL)); // Remove Challenges - panelBuilder.item(5, this.createButton(Button.DELETE_CHALLENGE)); - panelBuilder.item(14, this.createButton(Button.DELETE_LEVEL)); + panelBuilder.item(30, this.createButton(Button.DELETE_CHALLENGE)); + panelBuilder.item(31, this.createButton(Button.DELETE_LEVEL)); // Import Challenges - panelBuilder.item(7, this.createButton(Button.IMPORT_CHALLENGES)); + panelBuilder.item(15, this.createButton(Button.IMPORT_CHALLENGES)); // Edit Addon Settings - panelBuilder.item(8, this.createButton(Button.EDIT_SETTINGS)); + panelBuilder.item(16, this.createButton(Button.EDIT_SETTINGS)); + + panelBuilder.item(44, this.returnButton); panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index eb5971e..2635fef 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -19,6 +19,7 @@ import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; import world.bentobox.challenges.panel.util.SelectEnvironmentGUI; import world.bentobox.challenges.panel.util.StringListGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -81,6 +82,8 @@ public class EditChallengeGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.edit-challenge-title")); + GuiUtils.fillBorder(panelBuilder); + panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); panelBuilder.item(4, this.createMenuButton(MenuType.REQUIREMENTS)); panelBuilder.item(6, this.createMenuButton(MenuType.REWARDS)); @@ -109,7 +112,7 @@ public class EditChallengeGUI extends CommonGUI this.buildRewardsPanel(panelBuilder); } - panelBuilder.item(53, this.returnButton); + panelBuilder.item(44, this.returnButton); panelBuilder.build(); } @@ -140,14 +143,14 @@ public class EditChallengeGUI extends CommonGUI */ private void buildIslandRequirementsPanel(PanelBuilder panelBuilder) { - panelBuilder.item(10, this.createButton(Button.REQUIRED_ENTITIES)); - panelBuilder.item(11, this.createButton(Button.REMOVE_ENTITIES)); + panelBuilder.item(19, this.createButton(Button.REQUIRED_ENTITIES)); + panelBuilder.item(28, this.createButton(Button.REMOVE_ENTITIES)); - panelBuilder.item(15, this.createButton(Button.REQUIRED_BLOCKS)); - panelBuilder.item(16, this.createButton(Button.REMOVE_BLOCKS)); + panelBuilder.item(21, this.createButton(Button.REQUIRED_BLOCKS)); + panelBuilder.item(29, this.createButton(Button.REMOVE_BLOCKS)); - panelBuilder.item(19, this.createButton(Button.SEARCH_RADIUS)); - panelBuilder.item(28, this.createButton(Button.REQUIRED_PERMISSIONS)); + panelBuilder.item(23, this.createButton(Button.SEARCH_RADIUS)); + panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); } @@ -158,9 +161,9 @@ public class EditChallengeGUI extends CommonGUI private void buildInventoryRequirementsPanel(PanelBuilder panelBuilder) { panelBuilder.item(10, this.createButton(Button.REQUIRED_ITEMS)); - panelBuilder.item(11, this.createButton(Button.REMOVE_ITEMS)); + panelBuilder.item(19, this.createButton(Button.REMOVE_ITEMS)); - panelBuilder.item(28, this.createButton(Button.REQUIRED_PERMISSIONS)); + panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); } @@ -171,14 +174,14 @@ public class EditChallengeGUI extends CommonGUI private void buildOtherRequirementsPanel(PanelBuilder panelBuilder) { panelBuilder.item(10, this.createButton(Button.REQUIRED_EXPERIENCE)); - panelBuilder.item(11, this.createButton(Button.REMOVE_EXPERIENCE)); + panelBuilder.item(19, this.createButton(Button.REMOVE_EXPERIENCE)); - panelBuilder.item(13, this.createButton(Button.REQUIRED_LEVEL)); + panelBuilder.item(12, this.createButton(Button.REQUIRED_MONEY)); + panelBuilder.item(21, this.createButton(Button.REMOVE_MONEY)); - panelBuilder.item(15, this.createButton(Button.REQUIRED_MONEY)); - panelBuilder.item(16, this.createButton(Button.REMOVE_MONEY)); + panelBuilder.item(23, this.createButton(Button.REQUIRED_LEVEL)); - panelBuilder.item(28, this.createButton(Button.REQUIRED_PERMISSIONS)); + panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); } @@ -188,12 +191,12 @@ public class EditChallengeGUI extends CommonGUI */ private void buildRewardsPanel(PanelBuilder panelBuilder) { - panelBuilder.item(11, this.createButton(Button.REWARD_TEXT)); - panelBuilder.item(20, this.createButton(Button.REWARD_ITEM)); - panelBuilder.item(29, this.createButton(Button.REWARD_EXPERIENCE)); - panelBuilder.item(38, this.createButton(Button.REWARD_MONEY)); - panelBuilder.item(47, this.createButton(Button.REWARD_COMMANDS)); + panelBuilder.item(10, this.createButton(Button.REWARD_TEXT)); + panelBuilder.item(19, this.createButton(Button.REWARD_COMMANDS)); + panelBuilder.item(11, this.createButton(Button.REWARD_ITEM)); + panelBuilder.item(20, this.createButton(Button.REWARD_EXPERIENCE)); + panelBuilder.item(29, this.createButton(Button.REWARD_MONEY)); panelBuilder.item(22, this.createButton(Button.REPEATABLE)); @@ -202,10 +205,11 @@ public class EditChallengeGUI extends CommonGUI panelBuilder.item(31, this.createButton(Button.REPEAT_COUNT)); panelBuilder.item(15, this.createButton(Button.REPEAT_REWARD_TEXT)); - panelBuilder.item(24, this.createButton(Button.REPEAT_REWARD_ITEM)); - panelBuilder.item(33, this.createButton(Button.REPEAT_REWARD_EXPERIENCE)); - panelBuilder.item(42, this.createButton(Button.REPEAT_REWARD_MONEY)); - panelBuilder.item(51, this.createButton(Button.REPEAT_REWARD_COMMANDS)); + panelBuilder.item(24, this.createButton(Button.REPEAT_REWARD_COMMANDS)); + + panelBuilder.item(16, this.createButton(Button.REPEAT_REWARD_ITEM)); + panelBuilder.item(25, this.createButton(Button.REPEAT_REWARD_EXPERIENCE)); + panelBuilder.item(34, this.createButton(Button.REPEAT_REWARD_MONEY)); } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index fec1e01..1bf87a5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -23,6 +23,7 @@ import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; import world.bentobox.challenges.panel.util.SelectChallengeGUI; import world.bentobox.challenges.panel.util.StringListGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -82,6 +83,8 @@ public class EditLevelGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.edit-level-title")); + GuiUtils.fillBorder(panelBuilder); + panelBuilder.item(2, this.createMenuButton(MenuType.PROPERTIES)); panelBuilder.item(4, this.createMenuButton(MenuType.REWARDS)); panelBuilder.item(6, this.createMenuButton(MenuType.CHALLENGES)); @@ -99,7 +102,7 @@ public class EditLevelGUI extends CommonGUI this.buildRewardsPanel(panelBuilder); } - panelBuilder.item(53, this.returnButton); + panelBuilder.item(44, this.returnButton); panelBuilder.build(); } @@ -127,11 +130,12 @@ public class EditLevelGUI extends CommonGUI */ private void buildRewardsPanel(PanelBuilder panelBuilder) { - panelBuilder.item(11, this.createButton(Button.REWARD_DESCRIPTION)); - panelBuilder.item(20, this.createButton(Button.REWARD_ITEM)); - panelBuilder.item(29, this.createButton(Button.REWARD_EXPERIENCE)); - panelBuilder.item(38, this.createButton(Button.REWARD_MONEY)); - panelBuilder.item(47, this.createButton(Button.REWARD_COMMANDS)); + panelBuilder.item(12, this.createButton(Button.REWARD_DESCRIPTION)); + panelBuilder.item(21, this.createButton(Button.REWARD_COMMANDS)); + + panelBuilder.item(13, this.createButton(Button.REWARD_ITEM)); + panelBuilder.item(22, this.createButton(Button.REWARD_EXPERIENCE)); + panelBuilder.item(31, this.createButton(Button.REWARD_MONEY)); } @@ -141,39 +145,45 @@ public class EditLevelGUI extends CommonGUI */ private void buildChallengesPanel(PanelBuilder panelBuilder) { - List challenges = this.addon.getChallengesManager().getChallenges(this.challengeLevel); + List challengeList = this.addon.getChallengesManager().getChallenges(this.challengeLevel); + + final int MAX_ELEMENTS = 21; if (this.pageIndex < 0) + { + this.pageIndex = challengeList.size() / MAX_ELEMENTS; + } + else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) { this.pageIndex = 0; } - else if (this.pageIndex > (challenges.size() / 18)) + + int challengeIndex = MAX_ELEMENTS * this.pageIndex; + + // I want first row to be only for navigation and return button. + int index = 10; + + while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && + challengeIndex < challengeList.size() && + index < 36) { - this.pageIndex = challenges.size() / 18; + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++))); + } + + index++; } - int challengeIndex = 18 * this.pageIndex; - int elementIndex = 9; - - while (challengeIndex < ((this.pageIndex + 1) * 18) && - challengeIndex < challenges.size()) + // Navigation buttons only if necessary + if (challengeList.size() > MAX_ELEMENTS) { - panelBuilder.item(elementIndex++, this.createChallengeIcon(challenges.get(challengeIndex))); - challengeIndex++; + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); } - if (this.pageIndex > 0) - { - panelBuilder.item(29, this.getButton(CommonButtons.PREVIOUS)); - } - - if (challengeIndex < challenges.size()) - { - panelBuilder.item(33, this.getButton(CommonButtons.NEXT)); - } - - panelBuilder.item(30, this.createButton(Button.ADD_CHALLENGE)); - panelBuilder.item(32, this.createButton(Button.REMOVE_CHALLENGE)); + panelBuilder.item(39, this.createButton(Button.ADD_CHALLENGE)); + panelBuilder.item(41, this.createButton(Button.REMOVE_CHALLENGE)); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java index a8a2252..16625d6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java @@ -9,6 +9,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -60,8 +61,10 @@ public class EditSettingsGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.settings-title")); + GuiUtils.fillBorder(panelBuilder); + // resetChallenges - panelBuilder.item(0, new PanelItemBuilder(). + panelBuilder.item(19, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.reset")). description(this.user.getTranslation("challenges.gui.admin.descriptions.reset")). icon(Material.LAVA_BUCKET). @@ -74,7 +77,7 @@ public class EditSettingsGUI extends CommonGUI build()); // broadcastMessages - panelBuilder.item(1, new PanelItemBuilder(). + panelBuilder.item(20, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.broadcast")). description(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast")). icon(Material.JUKEBOX). @@ -87,7 +90,7 @@ public class EditSettingsGUI extends CommonGUI build()); // removeCompleteOneTimeChallenges - panelBuilder.item(2, new PanelItemBuilder(). + panelBuilder.item(21, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.remove-on-complete")). description(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete")). icon(Material.MAGMA_BLOCK). @@ -100,7 +103,7 @@ public class EditSettingsGUI extends CommonGUI build()); // addCompletedGlow - panelBuilder.item(3, new PanelItemBuilder(). + panelBuilder.item(22, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.glow")). description(this.user.getTranslation("challenges.gui.admin.descriptions.glow")). icon(Material.GLOWSTONE). @@ -112,8 +115,21 @@ public class EditSettingsGUI extends CommonGUI glow(this.addon.getChallengesSettings().isAddCompletedGlow()). build()); + // freeChallengesAtTheTop + panelBuilder.item(23, new PanelItemBuilder(). + name(this.user.getTranslation("challenges.gui.admin.buttons.free-challenges")). + description(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges")). + icon(Material.FILLED_MAP). + clickHandler((panel, user1, clickType, i) -> { + this.addon.getChallengesSettings().setFreeChallengesFirst( + !this.addon.getChallengesSettings().isFreeChallengesFirst()); + return true; + }). + glow(this.addon.getChallengesSettings().isFreeChallengesFirst()). + build()); + // Return Button - panelBuilder.item(8, this.returnButton); + panelBuilder.item(44, this.returnButton); panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 0dd0cfc..4a50298 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -1,6 +1,7 @@ package world.bentobox.challenges.panel.admin; +import org.bukkit.Material; import org.bukkit.World; import java.util.List; @@ -12,6 +13,7 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenges; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -71,42 +73,53 @@ public class ListChallengesGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.choose-challenge-title")); + if (this.currentMode.equals(Mode.DELETE)) + { + GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE); + } + else + { + GuiUtils.fillBorder(panelBuilder); + } + List challengeList = this.addon.getChallengesManager().getChallengesList(); - int MAX_ELEMENTS = 45; + final int MAX_ELEMENTS = 21; + if (this.pageIndex < 0) { - this.pageIndex = 0; + this.pageIndex = challengeList.size() / MAX_ELEMENTS; } else if (this.pageIndex > (challengeList.size() / MAX_ELEMENTS)) { - this.pageIndex = challengeList.size() / MAX_ELEMENTS; + this.pageIndex = 0; } int challengeIndex = MAX_ELEMENTS * this.pageIndex; + // I want first row to be only for navigation and return button. + int index = 10; + while (challengeIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - challengeIndex < challengeList.size()) + challengeIndex < challengeList.size() && + index < 36) { - panelBuilder.item(this.createChallengeIcon(challengeList.get(challengeIndex))); - challengeIndex++; + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createChallengeIcon(challengeList.get(challengeIndex++))); + } + + index++; } - int nextIndex = challengeIndex % MAX_ELEMENTS == 0 ? - MAX_ELEMENTS : - (((challengeIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9; - - if (challengeIndex > MAX_ELEMENTS) + // Navigation buttons only if necessary + if (challengeList.size() > MAX_ELEMENTS) { - panelBuilder.item(nextIndex + 2, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); } - if (challengeIndex < challengeList.size()) - { - panelBuilder.item(nextIndex + 6, this.getButton(CommonButtons.NEXT)); - } - - panelBuilder.item(nextIndex + 8, this.returnButton); + panelBuilder.item(44, this.returnButton); panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index e89ff2f..2953f0b 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -1,6 +1,7 @@ package world.bentobox.challenges.panel.admin; +import org.bukkit.Material; import org.bukkit.World; import java.util.List; @@ -12,6 +13,7 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.ChallengeLevels; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -71,42 +73,53 @@ public class ListLevelsGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.choose-level-title")); + if (this.currentMode.equals(Mode.DELETE)) + { + GuiUtils.fillBorder(panelBuilder, Material.RED_STAINED_GLASS_PANE); + } + else + { + GuiUtils.fillBorder(panelBuilder); + } + List levelList = this.addon.getChallengesManager().getChallengeLevelList(); - int MAX_ELEMENTS = 45; + final int MAX_ELEMENTS = 21; + if (this.pageIndex < 0) { - this.pageIndex = 0; + this.pageIndex = levelList.size() / MAX_ELEMENTS; } else if (this.pageIndex > (levelList.size() / MAX_ELEMENTS)) { - this.pageIndex = levelList.size() / MAX_ELEMENTS; + this.pageIndex = 0; } int levelIndex = MAX_ELEMENTS * this.pageIndex; + // I want first row to be only for navigation and return button. + int index = 10; + while (levelIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - levelIndex < levelList.size()) + levelIndex < levelList.size() && + index < 36) { - panelBuilder.item(this.createLevelIcon(levelList.get(levelIndex))); - levelIndex++; + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createLevelIcon(levelList.get(levelIndex++))); + } + + index++; } - int nextIndex = levelIndex % MAX_ELEMENTS == 0 ? - MAX_ELEMENTS : - (((levelIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9; - - if (levelIndex > MAX_ELEMENTS) + // Navigation buttons only if necessary + if (levelList.size() > MAX_ELEMENTS) { - panelBuilder.item(nextIndex + 2, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); } - if (levelIndex < levelList.size()) - { - panelBuilder.item(nextIndex + 6, this.getButton(CommonButtons.NEXT)); - } - - panelBuilder.item(nextIndex + 8, this.returnButton); + panelBuilder.item(44, this.returnButton); panelBuilder.build(); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index c4be7f8..b6c9d99 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -18,6 +18,7 @@ import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; import world.bentobox.challenges.panel.util.SelectChallengeGUI; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -50,7 +51,7 @@ public class ListUsersGUI extends CommonGUI private enum ViewMode { ONLINE, - OFFLINE, + WITH_ISLAND, IN_WORLD } @@ -114,45 +115,48 @@ public class ListUsersGUI extends CommonGUI PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name( this.user.getTranslation("challenges.gui.admin.choose-user-title")); - int MAX_ELEMENTS = 45; + GuiUtils.fillBorder(panelBuilder); + + final int MAX_ELEMENTS = 21; + if (this.pageIndex < 0) { - this.pageIndex = 0; + this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS; } else if (this.pageIndex > (this.onlineUsers.size() / MAX_ELEMENTS)) { - this.pageIndex = this.onlineUsers.size() / MAX_ELEMENTS; + this.pageIndex = 0; } int playerIndex = MAX_ELEMENTS * this.pageIndex; + // I want first row to be only for navigation and return button. + int index = 10; + while (playerIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - playerIndex < this.onlineUsers.size()) + playerIndex < this.onlineUsers.size() && + index < 36) { - panelBuilder.item(this.createPlayerIcon(this.onlineUsers.get(playerIndex))); - playerIndex++; + if (!panelBuilder.slotOccupied(index)) + { + panelBuilder.item(index, this.createPlayerIcon(this.onlineUsers.get(playerIndex++))); + } + + index++; } - int nextIndex = playerIndex % MAX_ELEMENTS == 0 ? - MAX_ELEMENTS : - (((playerIndex % MAX_ELEMENTS) - 1) / 9 + 1) * 9; + // Add button that allows to toogle different player lists. + panelBuilder.item( 4, this.createToggleButton()); - if (playerIndex > MAX_ELEMENTS) + // Navigation buttons only if necessary + if (this.onlineUsers.size() > MAX_ELEMENTS) { - panelBuilder.item(nextIndex, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(18, this.getButton(CommonButtons.PREVIOUS)); + panelBuilder.item(26, this.getButton(CommonButtons.NEXT)); } - if (playerIndex < this.onlineUsers.size()) - { - panelBuilder.item(nextIndex + 8, this.getButton(CommonButtons.NEXT)); - } + panelBuilder.item(44, this.returnButton); - if (this.returnButton != null) - { - panelBuilder.item(nextIndex + 6, this.returnButton); - } - - panelBuilder.item(nextIndex + 3, this.createToggleButton()); panelBuilder.build(); } @@ -229,17 +233,9 @@ public class ListUsersGUI extends CommonGUI { return new ArrayList<>(Bukkit.getOnlinePlayers()); } - else if (mode.equals(ViewMode.OFFLINE)) + else if (mode.equals(ViewMode.WITH_ISLAND)) { - List offlinePlayer = new ArrayList<>(Bukkit.getOfflinePlayers().length); - - for (int index = 0; index < Bukkit.getOfflinePlayers().length; index++) - { - OfflinePlayer player = Bukkit.getOfflinePlayers()[index]; - offlinePlayer.add(player.getPlayer()); - } - - return offlinePlayer; + return this.addon.getChallengesManager().getPlayers(this.world); } else { diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java index 032fe72..28ec03d 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageBlocksGUI.java @@ -79,7 +79,8 @@ public class ManageBlocksGUI extends CommonGUI int index = 10; while (entitiesIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - entitiesIndex < this.materialList.size()) + entitiesIndex < this.materialList.size() && + index < 36) { if (!panelBuilder.slotOccupied(index)) { diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java index f11d92e..d2b4d71 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ManageEntitiesGUI.java @@ -79,7 +79,8 @@ public class ManageEntitiesGUI extends CommonGUI int index = 10; while (entitiesIndex < ((this.pageIndex + 1) * MAX_ELEMENTS) && - entitiesIndex < this.entityList.size()) + entitiesIndex < this.entityList.size() && + index < 26) { if (!panelBuilder.slotOccupied(index)) { From 8711d7ad0834f2d1c17ab73c31659ebb791a3f82 Mon Sep 17 00:00:00 2001 From: BONNe Date: Tue, 22 Jan 2019 09:10:13 +0200 Subject: [PATCH 064/103] Rework Challenges Level Status checking. In previous code challenges level status holds information for next level. It is fixed now, and current implementation allows to get everything that is needed. --- .../challenges/ChallengesManager.java | 73 +++++++++++++++---- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 84e90b6..40459b4 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -5,6 +5,7 @@ import org.apache.commons.lang.WordUtils; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import java.util.*; @@ -215,26 +216,37 @@ public class ChallengesManager { * @param world - world to check * @return Level status - how many challenges still to do on which level */ - public List getChallengeLevelStatus(User user, World world) { - addPlayer(user); - ChallengesPlayerData pd = playerData.get(user.getUniqueId()); + public List getChallengeLevelStatus(User user, World world) + { + this.addPlayer(user); + ChallengesPlayerData playerData = this.playerData.get(user.getUniqueId()); List result = new ArrayList<>(); - ChallengeLevels previousLevel = null; + // The first level is always unlocked - boolean isUnlocked = true; + ChallengeLevels previousLevel = null; + int doneChallengeCount = Integer.MAX_VALUE; + // For each challenge level, check how many the user has done - for (Entry> en : challengeMap.entrySet()) { - int total = challengeMap.values().size(); - int waiverAmount = en.getKey().getWaiveramount(); - int challengesDone = (int) en.getValue().stream().filter(ch -> pd.isChallengeDone(world, ch.getUniqueId())).count(); - int challsToDo = Math.max(0,total - challengesDone - waiverAmount); - boolean complete = challsToDo > 0 ? false : true; + for (Entry> entry : this.challengeMap.entrySet()) + { + // Check how much challenges must be done in previous level. + int challengesToDo = Math.max(0, entry.getKey().getWaiveramount() - doneChallengeCount); + + doneChallengeCount = (int) entry.getValue().stream().filter( + ch -> playerData.isChallengeDone(world, ch.getUniqueId())).count(); + // Create result class with the data - result.add(new LevelStatus(en.getKey(), previousLevel, challsToDo, complete, isUnlocked)); + result.add(new LevelStatus( + entry.getKey(), + previousLevel, + challengesToDo, + entry.getValue().size() == doneChallengeCount, + challengesToDo <= 0)); + // Set up the next level for the next loop - previousLevel = en.getKey(); - isUnlocked = complete; + previousLevel = entry.getKey(); } + return result; } @@ -592,4 +604,37 @@ public class ChallengesManager { { } + + + public List getFreeChallenges(User user, World world) + { + return Collections.emptyList(); + } + + + public String getChallengesLevel(Challenges challenge) + { + return "HERE NEED LEVEL NAME"; + } + + + public boolean isChallengeComplete(User user, Challenges challenge) + { + return this.isChallengeComplete(user, challenge.getUniqueId(), user.getWorld()); + } + + + public long checkChallengeTimes(User user, Challenges challenge) + { + return this.checkChallengeTimes(user, challenge, user.getWorld()); + } + + + public List getPlayers(World world) + { + List playerList = new ArrayList<>(); + + + return playerList; + } } From 20dfc6a760cbb98e9569894749f31fd67a343874 Mon Sep 17 00:00:00 2001 From: BONNe Date: Tue, 22 Jan 2019 09:12:12 +0200 Subject: [PATCH 065/103] Perform LevelStatus improvements in ChallengesGUI. --- .../challenges/panel/user/ChallengesGUI.java | 105 ++++++++++-------- 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index 00f8264..2501adf 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -48,7 +48,18 @@ public class ChallengesGUI extends CommonGUI this.challengesManager = this.addon.getChallengesManager(); this.levelStatusList = this.challengesManager.getChallengeLevelStatus(this.user, this.world); - this.lastSelectedLevel = this.levelStatusList.get(0); + + for (int i = 0; i < this.levelStatusList.size(); i++) + { + if (this.levelStatusList.get(i).isUnlocked()) + { + this.lastSelectedLevel = this.levelStatusList.get(i); + } + else + { + break; + } + } } // --------------------------------------------------------------------- @@ -172,55 +183,58 @@ public class ChallengesGUI extends CommonGUI */ private void addChallenges(PanelBuilder panelBuilder) { - List challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel()); - final int challengesCount = challenges.size(); - - if (challengesCount > 18) + if (this.lastSelectedLevel != null) { - int firstIndex = panelBuilder.nextSlot(); + List challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel()); + final int challengesCount = challenges.size(); - if (this.pageIndex > 0) + if (challengesCount > 18) { - panelBuilder.item(new PanelItemBuilder(). - icon(Material.SIGN). - name("Previous"). - clickHandler((panel, user1, clickType, slot) -> { - this.pageIndex--; - this.build(); - return true; - }).build()); - } + int firstIndex = panelBuilder.nextSlot(); - int currentIndex = this.pageIndex; + if (this.pageIndex > 0) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Previous"). + clickHandler((panel, user1, clickType, slot) -> { + this.pageIndex--; + this.build(); + return true; + }).build()); + } - while (panelBuilder.nextSlot() != firstIndex + 18 && currentIndex < challengesCount) - { - panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex++))); - } + int currentIndex = this.pageIndex; - // Check if one challenge is left - if (currentIndex + 1 == challengesCount) - { - panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex))); + while (panelBuilder.nextSlot() != firstIndex + 18 && currentIndex < challengesCount) + { + panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex++))); + } + + // Check if one challenge is left + if (currentIndex + 1 == challengesCount) + { + panelBuilder.item(this.getChallengeButton(challenges.get(currentIndex))); + } + else if (currentIndex < challengesCount) + { + panelBuilder.item(new PanelItemBuilder(). + icon(Material.SIGN). + name("Next"). + clickHandler((panel, user1, clickType, slot) -> { + this.pageIndex++; + this.build(); + return true; + }).build()); + } } - else if (currentIndex < challengesCount) + else { - panelBuilder.item(new PanelItemBuilder(). - icon(Material.SIGN). - name("Next"). - clickHandler((panel, user1, clickType, slot) -> { - this.pageIndex++; - this.build(); - return true; - }).build()); - } - } - else - { - for (Challenges challenge : challenges) - { - // there are no limitations. Just bunch insert. - panelBuilder.item(this.getChallengeButton(challenge)); + for (Challenges challenge : challenges) + { + // there are no limitations. Just bunch insert. + panelBuilder.item(this.getChallengeButton(challenge)); + } } } } @@ -497,13 +511,10 @@ public class ChallengesGUI extends CommonGUI { icon = new ItemStack(Material.BOOK); - // This should be safe as first level always should be unlocked. - LevelStatus previousLevel = this.levelStatusList.get(this.levelStatusList.indexOf(level) - 1); - description = Collections.singletonList( this.user.getTranslation("challenges.to-complete", - "[challengesToDo]", Integer.toString(previousLevel.getNumberOfChallengesStillToDo()), - "[thisLevel]", previousLevel.getLevel().getFriendlyName())); + "[challengesToDo]", Integer.toString(level.getNumberOfChallengesStillToDo()), + "[thisLevel]", level.getPreviousLevel().getFriendlyName())); clickHandler = null; } From 59c0f6bfeaf4217e65d5c995fdf98eee44ad3b69 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 16:08:18 +0200 Subject: [PATCH 066/103] Deprecate all classes that are not necessary anymore. --- src/main/java/world/bentobox/challenges/ParseItem.java | 3 +++ .../bentobox/challenges/commands/admin/CreateChallenge.java | 5 +++++ .../challenges/commands/admin/CreateSurrounding.java | 3 ++- .../bentobox/challenges/commands/admin/ResetChallenge.java | 5 +++++ .../challenges/commands/admin/SurroundChallengeBuilder.java | 3 ++- .../java/world/bentobox/challenges/panel/AdminEditGUI.java | 5 +++++ src/main/java/world/bentobox/challenges/panel/AdminGUI.java | 5 +++++ .../world/bentobox/challenges/panel/ChallengesPanels.java | 4 ++++ .../world/bentobox/challenges/panel/ChallengesPanels2.java | 4 ++++ .../bentobox/challenges/panel/CreateChallengeListener.java | 5 +++++ .../bentobox/challenges/panel/CreateChallengePanel.java | 5 +++++ .../java/world/bentobox/challenges/panel/RequiredPanel.java | 3 ++- src/test/java/world/bentobox/challenges/ParseItemTest.java | 1 + 13 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ParseItem.java b/src/main/java/world/bentobox/challenges/ParseItem.java index f3272a4..67fd806 100644 --- a/src/main/java/world/bentobox/challenges/ParseItem.java +++ b/src/main/java/world/bentobox/challenges/ParseItem.java @@ -11,7 +11,10 @@ import org.bukkit.potion.PotionType; * Used for converting config file entries to objects * @author tastybento * + * @deprecated + * @see world.bentobox.bentobox.util.ItemParser#parse(String) */ +@Deprecated public class ParseItem { private final ItemStack item; diff --git a/src/main/java/world/bentobox/challenges/commands/admin/CreateChallenge.java b/src/main/java/world/bentobox/challenges/commands/admin/CreateChallenge.java index 2024ccc..4d3f69d 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/CreateChallenge.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/CreateChallenge.java @@ -9,6 +9,11 @@ import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; + +/** + * @deprecated Challenges can be creaded via GUI. + */ +@Deprecated public class CreateChallenge extends CompositeCommand { /** diff --git a/src/main/java/world/bentobox/challenges/commands/admin/CreateSurrounding.java b/src/main/java/world/bentobox/challenges/commands/admin/CreateSurrounding.java index e55c6d3..3ce860a 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/CreateSurrounding.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/CreateSurrounding.java @@ -25,8 +25,9 @@ import world.bentobox.bentobox.util.Util; /** * Command to create a surrounding type challenge * @author tastybento - * + * @deprecated Required blocks can be added via GUI. Not necessary. */ +@Deprecated public class CreateSurrounding extends CompositeCommand implements Listener { HashMap inProgress = new HashMap<>(); diff --git a/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java b/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java index a644015..0774072 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java @@ -13,6 +13,11 @@ import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.Util; + +/** + * @deprecated Challenges can be reset via GUI. + */ +@Deprecated public class ResetChallenge extends CompositeCommand { private ChallengesManager manager; diff --git a/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java b/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java index 5ff9bce..ed4791c 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java @@ -12,8 +12,9 @@ import world.bentobox.bentobox.api.user.User; /** * Enables the state of a Surrounding Challenge to be stored as it is built * @author tastybento - * + * @deprecated Levels and challenges can be created via GUI. Not necessary command. */ +@Deprecated public class SurroundChallengeBuilder { private ChallengesAddon addon; private String name; diff --git a/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java b/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java index 49bc3f5..b6aa579 100644 --- a/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java @@ -13,6 +13,11 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; + +/** + * @deprecated All panels are reworked. + */ +@Deprecated public class AdminEditGUI implements ClickHandler { private ChallengesAddon addon; diff --git a/src/main/java/world/bentobox/challenges/panel/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/AdminGUI.java index 2cd9940..8883820 100644 --- a/src/main/java/world/bentobox/challenges/panel/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/AdminGUI.java @@ -13,6 +13,11 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; + +/** + * @deprecated All panels are reworked. + */ +@Deprecated public class AdminGUI implements ClickHandler { private ChallengesAddon addon; diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java index 85e9c68..ed39f2b 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java @@ -22,6 +22,10 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +/** + * @deprecated All panels are reworked. + */ +@Deprecated public class ChallengesPanels { private ChallengesAddon addon; private ChallengesManager manager; diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index 22ee2c3..3dfe4c9 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -21,6 +21,10 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +/** + * @deprecated All panels are reworked. + */ +@Deprecated public class ChallengesPanels2 { public enum Mode { diff --git a/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java b/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java index feb0621..978b64b 100644 --- a/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java +++ b/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java @@ -7,6 +7,11 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.bentobox.api.panels.PanelListener; import world.bentobox.bentobox.api.user.User; + +/** + * @deprecated All panels are reworked. + */ +@Deprecated public class CreateChallengeListener implements PanelListener { private ChallengesAddon addon; diff --git a/src/main/java/world/bentobox/challenges/panel/CreateChallengePanel.java b/src/main/java/world/bentobox/challenges/panel/CreateChallengePanel.java index 93d8bb3..1c7473a 100644 --- a/src/main/java/world/bentobox/challenges/panel/CreateChallengePanel.java +++ b/src/main/java/world/bentobox/challenges/panel/CreateChallengePanel.java @@ -4,6 +4,11 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; + +/** + * @deprecated All panels are reworked. + */ +@Deprecated public class CreateChallengePanel { public CreateChallengePanel(ChallengesAddon addon, User user) { diff --git a/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java b/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java index 13affcb..59221fc 100644 --- a/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java @@ -25,8 +25,9 @@ import world.bentobox.bentobox.util.Util; * Handles the requirements for a challenge * Items, blocks, entities * @author tastybento - * + * @deprecated All panels are reworked. */ +@Deprecated public class RequiredPanel implements ClickHandler, PanelListener { private static final int CONTROL_NUMBER = 4; private Challenges challenge; diff --git a/src/test/java/world/bentobox/challenges/ParseItemTest.java b/src/test/java/world/bentobox/challenges/ParseItemTest.java index f5eb767..7a46f8a 100644 --- a/src/test/java/world/bentobox/challenges/ParseItemTest.java +++ b/src/test/java/world/bentobox/challenges/ParseItemTest.java @@ -26,6 +26,7 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ParseItem; @RunWith(PowerMockRunner.class) +@Deprecated public class ParseItemTest { private static ChallengesAddon addon; From dba5a4446164a29d37f4f91fb197d8fdadc8e7cc Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 16:09:38 +0200 Subject: [PATCH 067/103] Rename Challenges and ChallengeLevels classes. --- .../challenges/ChallengesImportManager.java | 18 ++-- .../challenges/ChallengesManager.java | 98 +++++++++---------- .../bentobox/challenges/LevelStatus.java | 12 +-- .../{Challenges.java => Challenge.java} | 8 +- ...allengeLevels.java => ChallengeLevel.java} | 10 +- .../challenges/panel/AdminEditGUI.java | 6 +- .../bentobox/challenges/panel/AdminGUI.java | 6 +- .../challenges/panel/ChallengesPanels.java | 12 +-- .../challenges/panel/ChallengesPanels2.java | 12 +-- .../challenges/panel/RequiredPanel.java | 6 +- .../challenges/panel/TryToComplete.java | 10 +- .../panel/admin/EditChallengeGUI.java | 26 ++--- .../challenges/panel/admin/EditLevelGUI.java | 16 +-- .../panel/admin/ListChallengesGUI.java | 6 +- .../challenges/panel/admin/ListLevelsGUI.java | 6 +- .../challenges/panel/user/ChallengesGUI.java | 20 ++-- .../panel/util/SelectChallengeGUI.java | 10 +- .../challenges/ChallengesAddonTest.java | 6 +- 18 files changed, 144 insertions(+), 144 deletions(-) rename src/main/java/world/bentobox/challenges/database/object/{Challenges.java => Challenge.java} (98%) rename src/main/java/world/bentobox/challenges/database/object/{ChallengeLevels.java => ChallengeLevel.java} (95%) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index f60206c..1b4b294 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -16,8 +16,8 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; -import world.bentobox.challenges.database.object.ChallengeLevels; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.Util; @@ -78,7 +78,7 @@ public class ChallengesImportManager String[] lvs = levels.split(" "); int order = 0; for (String level : lvs) { - ChallengeLevels challengeLevel = new ChallengeLevels(); + ChallengeLevel challengeLevel = new ChallengeLevel(); challengeLevel.setFriendlyName(level); challengeLevel.setUniqueId(level); challengeLevel.setOrder(order++); @@ -110,7 +110,7 @@ public class ChallengesImportManager // Parse the challenge file ConfigurationSection chals = chal.getConfigurationSection("challenges.challengeList"); for (String challenge : chals.getKeys(false)) { - Challenges newChallenge = new Challenges(); + Challenge newChallenge = new Challenge(); newChallenge.setUniqueId(Util.getWorld(world).getName() + "_" + challenge); newChallenge.setDeployed(true); ConfigurationSection details = chals.getConfigurationSection(challenge); @@ -119,7 +119,7 @@ public class ChallengesImportManager newChallenge.setDescription(addon.getChallengesManager().stringSplit(details.getString("description", ""))); newChallenge.setIcon(new ParseItem(addon, details.getString("icon") + ":1").getItem()); newChallenge.setLevel(details.getString("level", ChallengesManager.FREE)); - newChallenge.setChallengeType(Challenges.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); + newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); newChallenge.setTakeItems(details.getBoolean("takeItems",true)); newChallenge.setRewardText(details.getString("rewardText", "")); newChallenge.setRewardCommands(details.getStringList("rewardcommands")); @@ -135,11 +135,11 @@ public class ChallengesImportManager newChallenge.setReqMoney(details.getInt("requiredMoney")); newChallenge.setReqExp(details.getInt("requiredExp")); String reqItems = details.getString("requiredItems",""); - if (newChallenge.getChallengeType().equals(Challenges.ChallengeType.INVENTORY)) { + if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) { newChallenge.setRequiredItems(parseItems(reqItems)); - } else if (newChallenge.getChallengeType().equals(Challenges.ChallengeType.LEVEL)) { + } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.LEVEL)) { newChallenge.setReqIslandlevel(Long.parseLong(reqItems)); - } else if (newChallenge.getChallengeType().equals(Challenges.ChallengeType.ISLAND)) { + } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) { parseEntities(newChallenge, reqItems); } newChallenge.setRewardItems(parseItems(details.getString("itemReward"))); @@ -158,7 +158,7 @@ public class ChallengesImportManager * @param challenge - challenge to be adjusted * @param string - string from YAML file */ - private void parseEntities(Challenges challenge, String string) { + private void parseEntities(Challenge challenge, String string) { Map req = new EnumMap<>(EntityType.class); Map blocks = new EnumMap<>(Material.class); if (!string.isEmpty()) { diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 40459b4..e5322e3 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -17,18 +17,18 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.util.Util; import world.bentobox.challenges.commands.admin.SurroundChallengeBuilder; -import world.bentobox.challenges.database.object.ChallengeLevels; -import world.bentobox.challenges.database.object.Challenges; -import world.bentobox.challenges.database.object.Challenges.ChallengeType; +import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.challenges.database.object.ChallengesPlayerData; import world.bentobox.challenges.panel.ChallengesPanels; public class ChallengesManager { public static final String FREE = "Free"; - private Map> challengeMap; - private Config chConfig; - private Config lvConfig; + private Map> challengeMap; + private Config chConfig; + private Config lvConfig; private Database players; private ChallengesPanels challengesPanels; private Map playerData; @@ -37,8 +37,8 @@ public class ChallengesManager { public ChallengesManager(ChallengesAddon addon) { this.addon = addon; // Set up the configs - chConfig = new Config<>(addon, Challenges.class); - lvConfig = new Config<>(addon, ChallengeLevels.class); + chConfig = new Config<>(addon, Challenge.class); + lvConfig = new Config<>(addon, ChallengeLevel.class); // Players is where all the player history will be stored players = new Database<>(addon, ChallengesPlayerData.class); // Cache of challenges @@ -78,7 +78,7 @@ public class ChallengesManager { * @param challenge - challenge * @return - number of times */ - public long checkChallengeTimes(User user, Challenges challenge, World world) { + public long checkChallengeTimes(User user, Challenge challenge, World world) { addPlayer(user); return playerData.get(user.getUniqueId()).getTimes(world, challenge.getUniqueId()); } @@ -109,7 +109,7 @@ public class ChallengesManager { if (inventory.getContents().length == 0) { return false; } - Challenges newChallenge = new Challenges(); + Challenge newChallenge = new Challenge(); newChallenge.setChallengeType(ChallengeType.INVENTORY); newChallenge.setFriendlyName(inventory.getTitle()); newChallenge.setDeployed(false); @@ -154,7 +154,7 @@ public class ChallengesManager { challengeInfo.getOwner().sendMessage("challenges.error.no-items-clicked"); return false; } - Challenges newChallenge = new Challenges(); + Challenge newChallenge = new Challenge(); newChallenge.setChallengeType(ChallengeType.ISLAND); newChallenge.setFriendlyName(challengeInfo.getName()); newChallenge.setDeployed(true); @@ -199,10 +199,10 @@ public class ChallengesManager { * @param world - world to check * @return - challenge or null if it does not exist */ - public Challenges getChallenge(String name, World world) { + public Challenge getChallenge(String name, World world) { String worldName = Util.getWorld(world).getName(); - for (Set ch : challengeMap.values()) { - Optional challenge = ch.stream().filter(c -> c.getUniqueId().equalsIgnoreCase(worldName + name)).findFirst(); + for (Set ch : challengeMap.values()) { + Optional challenge = ch.stream().filter(c -> c.getUniqueId().equalsIgnoreCase(worldName + name)).findFirst(); if (challenge.isPresent()) { return challenge.get(); } @@ -223,11 +223,11 @@ public class ChallengesManager { List result = new ArrayList<>(); // The first level is always unlocked - ChallengeLevels previousLevel = null; + ChallengeLevel previousLevel = null; int doneChallengeCount = Integer.MAX_VALUE; // For each challenge level, check how many the user has done - for (Entry> entry : this.challengeMap.entrySet()) + for (Entry> entry : this.challengeMap.entrySet()) { // Check how much challenges must be done in previous level. int challengesToDo = Math.max(0, entry.getKey().getWaiveramount() - doneChallengeCount); @@ -254,7 +254,7 @@ public class ChallengesManager { * Get the challenge list * @return the challengeList */ - public Map> getChallengeList() { + public Map> getChallengeList() { // TODO return the challenges for world return challengeMap; } @@ -265,9 +265,9 @@ public class ChallengesManager { * @param world * @return the set of challenges for this level, or the first set of challenges if level is blank, or a blank list if there are no challenges */ - public Set getChallenges(String level, World world) { + public Set getChallenges(String level, World world) { String worldName = Util.getWorld(world).getName(); - Optional lv = challengeMap.keySet().stream().filter(l -> l.getUniqueId().equalsIgnoreCase(level)).findFirst(); + Optional lv = challengeMap.keySet().stream().filter(l -> l.getUniqueId().equalsIgnoreCase(level)).findFirst(); // Get the challenges applicable to this world return lv.isPresent() ? challengeMap.get(lv.get()).stream() .filter(c -> c.getWorld().equalsIgnoreCase(worldName) || c.getWorld().isEmpty()).collect(Collectors.toSet()) @@ -286,9 +286,9 @@ public class ChallengesManager { * @param currentLevel - the current level * @return the previous level, or null if there is none */ - public ChallengeLevels getPreviousLevel(ChallengeLevels currentLevel) { - ChallengeLevels result = null; - for (ChallengeLevels level : challengeMap.keySet()) { + public ChallengeLevel getPreviousLevel(ChallengeLevel currentLevel) { + ChallengeLevel result = null; + for (ChallengeLevel level : challengeMap.keySet()) { if (level.equals(currentLevel)) { return result; } @@ -303,7 +303,7 @@ public class ChallengesManager { * @return true if it exists, otherwise false */ public boolean isChallenge(String name) { - for (Set ch : challengeMap.values()) { + for (Set ch : challengeMap.values()) { if (ch.stream().anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { return true; } @@ -318,7 +318,7 @@ public class ChallengesManager { * @return true if it exists, otherwise false */ public boolean isChallenge(World world, String name) { - for (Set ch : challengeMap.values()) { + for (Set ch : challengeMap.values()) { if (ch.stream().filter(c -> c.getWorld().equals(Util.getWorld(world).getName())).anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { return true; } @@ -417,7 +417,7 @@ public class ChallengesManager { /** * @param challengeList the challengeList to set */ - public void setChallengeList(Map> challengeList) { + public void setChallengeList(Map> challengeList) { this.challengeMap = challengeList; } @@ -435,7 +435,7 @@ public class ChallengesManager { * @param challenge * @return true if successful */ - private boolean storeChallenge(Challenges challenge) { + private boolean storeChallenge(Challenge challenge) { return storeChallenge(challenge, true, null, true); } @@ -447,15 +447,15 @@ public class ChallengesManager { * @param silent - if true, no messages are sent to user * @return - true if imported */ - public boolean storeChallenge(Challenges challenge, boolean overwrite, User user, boolean silent) { + public boolean storeChallenge(Challenge challenge, boolean overwrite, User user, boolean silent) { // See if we have this level already - ChallengeLevels level; + ChallengeLevel level; if (lvConfig.configObjectExists(challenge.getLevel())) { // Get it from the database level = lvConfig.loadConfigObject(challenge.getLevel()); } else { // Make it - level = new ChallengeLevels(); + level = new ChallengeLevel(); level.setUniqueId(challenge.getLevel()); lvConfig.saveConfigObject(level); } @@ -485,7 +485,7 @@ public class ChallengesManager { * Store a challenge level * @param level the challenge level */ - public void storeLevel(ChallengeLevels level) { + public void storeLevel(ChallengeLevel level) { lvConfig.saveConfigObject(level); } @@ -517,37 +517,37 @@ public class ChallengesManager { } - public Challenges createChallenge() + public Challenge createChallenge() { - return new Challenges(); + return new Challenge(); } - public List getChallenges(ChallengeLevels challengeLevel) + public List getChallenges(ChallengeLevel challengeLevel) { return new ArrayList<>(this.challengeMap.get(challengeLevel)); } - public List getChallengeLevelList() + public List getChallengeLevelList() { return new ArrayList<>(this.challengeMap.keySet()); } - public List getChallengesList() + public List getChallengesList() { return new ArrayList<>(); } - public void deleteChallenge(Challenges selectedChallenge) + public void deleteChallenge(Challenge selectedChallenge) { } - public void deleteChallengeLevel(ChallengeLevels valueObject) + public void deleteChallengeLevel(ChallengeLevel valueObject) { } @@ -558,9 +558,9 @@ public class ChallengesManager { } - public Challenges createChallenge(String reply) + public Challenge createChallenge(String reply) { - return new Challenges(); + return new Challenge(); } @@ -576,55 +576,55 @@ public class ChallengesManager { } - public ChallengeLevels createLevel(String reply) + public ChallengeLevel createLevel(String reply) { - return new ChallengeLevels(); + return new ChallengeLevel(); } - public void unlinkChallenge(ChallengeLevels challengeLevel, Challenges value) + public void unlinkChallenge(ChallengeLevel challengeLevel, Challenge value) { } - public void linkChallenge(ChallengeLevels challengeLevel, Challenges value) + public void linkChallenge(ChallengeLevel challengeLevel, Challenge value) { } - public void resetChallenge(UUID uniqueId, Challenges value) + public void resetChallenge(UUID uniqueId, Challenge value) { } - public void completeChallenge(UUID uniqueId, Challenges value) + public void completeChallenge(UUID uniqueId, Challenge value) { } - public List getFreeChallenges(User user, World world) + public List getFreeChallenges(User user, World world) { return Collections.emptyList(); } - public String getChallengesLevel(Challenges challenge) + public String getChallengesLevel(Challenge challenge) { return "HERE NEED LEVEL NAME"; } - public boolean isChallengeComplete(User user, Challenges challenge) + public boolean isChallengeComplete(User user, Challenge challenge) { return this.isChallengeComplete(user, challenge.getUniqueId(), user.getWorld()); } - public long checkChallengeTimes(User user, Challenges challenge) + public long checkChallengeTimes(User user, Challenge challenge) { return this.checkChallengeTimes(user, challenge, user.getWorld()); } diff --git a/src/main/java/world/bentobox/challenges/LevelStatus.java b/src/main/java/world/bentobox/challenges/LevelStatus.java index 3fb0c90..f00e9aa 100644 --- a/src/main/java/world/bentobox/challenges/LevelStatus.java +++ b/src/main/java/world/bentobox/challenges/LevelStatus.java @@ -1,6 +1,6 @@ package world.bentobox.challenges; -import world.bentobox.challenges.database.object.ChallengeLevels; +import world.bentobox.challenges.database.object.ChallengeLevel; /** * Level status class @@ -8,8 +8,8 @@ import world.bentobox.challenges.database.object.ChallengeLevels; * */ public class LevelStatus { - private final ChallengeLevels level; - private final ChallengeLevels previousLevel; + private final ChallengeLevel level; + private final ChallengeLevel previousLevel; private final int numberOfChallengesStillToDo; private final boolean complete; private final boolean isUnlocked; @@ -21,7 +21,7 @@ public class LevelStatus { * @param complete - whether complete or not * @param isUnlocked */ - public LevelStatus(ChallengeLevels level, ChallengeLevels previousLevel, int numberOfChallengesStillToDo, boolean complete, boolean isUnlocked) { + public LevelStatus(ChallengeLevel level, ChallengeLevel previousLevel, int numberOfChallengesStillToDo, boolean complete, boolean isUnlocked) { super(); this.level = level; this.previousLevel = previousLevel; @@ -32,7 +32,7 @@ public class LevelStatus { /** * @return the level */ - public ChallengeLevels getLevel() { + public ChallengeLevel getLevel() { return level; } /** @@ -44,7 +44,7 @@ public class LevelStatus { /** * @return the previousLevel */ - public ChallengeLevels getPreviousLevel() { + public ChallengeLevel getPreviousLevel() { return previousLevel; } /** diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenges.java b/src/main/java/world/bentobox/challenges/database/object/Challenge.java similarity index 98% rename from src/main/java/world/bentobox/challenges/database/object/Challenges.java rename to src/main/java/world/bentobox/challenges/database/object/Challenge.java index f717fe1..9d4c3e7 100644 --- a/src/main/java/world/bentobox/challenges/database/object/Challenges.java +++ b/src/main/java/world/bentobox/challenges/database/object/Challenge.java @@ -16,9 +16,9 @@ import world.bentobox.challenges.ChallengesManager; * @author tastybento * */ -public class Challenges implements DataObject { +public class Challenge implements DataObject { - public Challenges() {} + public Challenge() {} public boolean isRemoveEntities() @@ -649,10 +649,10 @@ public class Challenges implements DataObject { if (obj == null) { return false; } - if (!(obj instanceof Challenges)) { + if (!(obj instanceof Challenge)) { return false; } - Challenges other = (Challenges) obj; + Challenge other = (Challenge) obj; if (uniqueId == null) { if (other.uniqueId != null) { return false; diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java similarity index 95% rename from src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java rename to src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java index 304ac2c..70b5f74 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevels.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java @@ -14,9 +14,9 @@ import world.bentobox.challenges.ChallengesManager; * @author tastybento * */ -public class ChallengeLevels implements DataObject, Comparable { +public class ChallengeLevel implements DataObject, Comparable { - public ChallengeLevels() {} + public ChallengeLevel() {} @ConfigComment("A friendly name for the level. If blank, level name is used.") private String friendlyName = ""; @@ -98,7 +98,7 @@ public class ChallengeLevels implements DataObject, Comparable } @Override - public int compareTo(ChallengeLevels o) { + public int compareTo(ChallengeLevel o) { return Integer.compare(this.order, o.order); } @@ -208,10 +208,10 @@ public class ChallengeLevels implements DataObject, Comparable if (obj == null) { return false; } - if (!(obj instanceof ChallengeLevels)) { + if (!(obj instanceof ChallengeLevel)) { return false; } - ChallengeLevels other = (ChallengeLevels) obj; + ChallengeLevel other = (ChallengeLevel) obj; if (uniqueId == null) { if (other.uniqueId != null) { return false; diff --git a/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java b/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java index b6aa579..2b3fd09 100644 --- a/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/AdminEditGUI.java @@ -6,7 +6,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -22,7 +22,7 @@ public class AdminEditGUI implements ClickHandler { private ChallengesAddon addon; private User requester; - private Challenges challenge; + private Challenge challenge; private World world; private String permPrefix; private String label; @@ -38,7 +38,7 @@ public class AdminEditGUI implements ClickHandler { * @param permPrefix permission prefix for world * @param label command label */ - public AdminEditGUI(ChallengesAddon addon, User requester, User target, Challenges challenge, World world, + public AdminEditGUI(ChallengesAddon addon, User requester, User target, Challenge challenge, World world, String permPrefix, String label) { super(); this.addon = addon; diff --git a/src/main/java/world/bentobox/challenges/panel/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/AdminGUI.java index 8883820..2382d84 100644 --- a/src/main/java/world/bentobox/challenges/panel/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/AdminGUI.java @@ -6,7 +6,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -22,7 +22,7 @@ public class AdminGUI implements ClickHandler { private ChallengesAddon addon; private User player; - private Challenges challenge; + private Challenge challenge; private World world; private String permPrefix; private String label; @@ -36,7 +36,7 @@ public class AdminGUI implements ClickHandler { * @param permPrefix * @param label */ - public AdminGUI(ChallengesAddon addon, User player, Challenges challenge, World world, + public AdminGUI(ChallengesAddon addon, User player, Challenge challenge, World world, String permPrefix, String label) { super(); this.addon = addon; diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java index ed39f2b..ff58d80 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java @@ -13,8 +13,8 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.LevelStatus; import world.bentobox.challenges.commands.ChallengesCommand; -import world.bentobox.challenges.database.object.Challenges; -import world.bentobox.challenges.database.object.Challenges.ChallengeType; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -69,9 +69,9 @@ public class ChallengesPanels { } private void addChallengeItems(PanelBuilder panelBuilder) { - Set levelChallenges = manager.getChallenges(level, world); + Set levelChallenges = manager.getChallenges(level, world); // Only show a control panel for the level requested. - for (Challenges challenge : levelChallenges) { + for (Challenge challenge : levelChallenges) { createItem(panelBuilder, challenge); } } @@ -87,7 +87,7 @@ public class ChallengesPanels { * @param challenge * @param user */ - private void createItem(PanelBuilder panelBuilder, Challenges challenge) { + private void createItem(PanelBuilder panelBuilder, Challenge challenge) { // Check completion boolean completed = manager.isChallengeComplete(user, challenge.getUniqueId(), world); // If challenge is removed after completion, remove it @@ -164,7 +164,7 @@ public class ChallengesPanels { * @param player * @return List of strings splitting challenge string into 25 chars long */ - private List challengeDescription(Challenges challenge) { + private List challengeDescription(Challenge challenge) { List result = new ArrayList(); String level = challenge.getLevel(); if (!level.isEmpty()) { diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index 3dfe4c9..f52bf72 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -12,8 +12,8 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.LevelStatus; import world.bentobox.challenges.commands.ChallengesCommand; -import world.bentobox.challenges.database.object.Challenges; -import world.bentobox.challenges.database.object.Challenges.ChallengeType; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -93,7 +93,7 @@ public class ChallengesPanels2 { private void addChallengeItems(PanelBuilder panelBuilder) { // Only show a control panel for the level requested. - for (Challenges challenge : manager.getChallenges(level, world)) { + for (Challenge challenge : manager.getChallenges(level, world)) { createItem(panelBuilder, challenge); } } @@ -109,7 +109,7 @@ public class ChallengesPanels2 { * @param challenge * @param requester */ - private void createItem(PanelBuilder panelBuilder, Challenges challenge) { + private void createItem(PanelBuilder panelBuilder, Challenge challenge) { // For admin, glow means activated. For user, glow means done boolean glow = false; switch (mode) { @@ -219,7 +219,7 @@ public class ChallengesPanels2 { * @param player * @return List of strings splitting challenge string into 25 chars long */ - private List challengeDescription(Challenges challenge) { + private List challengeDescription(Challenge challenge) { List result = new ArrayList(); String level = challenge.getLevel(); if (!level.isEmpty()) { @@ -278,7 +278,7 @@ public class ChallengesPanels2 { return result; } - private List addRewards(Challenges challenge, boolean complete, boolean admin) { + private List addRewards(Challenge challenge, boolean complete, boolean admin) { List result = new ArrayList<>(); double moneyReward = 0; int expReward = 0; diff --git a/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java b/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java index 59221fc..9e69652 100644 --- a/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java @@ -12,7 +12,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.inventory.ItemStack; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem.ClickHandler; import world.bentobox.bentobox.api.panels.PanelListener; @@ -30,7 +30,7 @@ import world.bentobox.bentobox.util.Util; @Deprecated public class RequiredPanel implements ClickHandler, PanelListener { private static final int CONTROL_NUMBER = 4; - private Challenges challenge; + private Challenge challenge; private User user; private Panel panel; private Panel referringPanel; @@ -39,7 +39,7 @@ public class RequiredPanel implements ClickHandler, PanelListener { * @param challenge * @param user */ - public RequiredPanel(Challenges challenge, User user, Panel referringPanel) { + public RequiredPanel(Challenge challenge, User user, Panel referringPanel) { this.challenge = challenge; this.user = user; this.panel = openPanel(); diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index cb50e34..c5012f9 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -23,8 +23,8 @@ import org.bukkit.util.Vector; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.commands.ChallengesCommand; -import world.bentobox.challenges.database.object.Challenges; -import world.bentobox.challenges.database.object.Challenges.ChallengeType; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.hooks.VaultHook; @@ -43,7 +43,7 @@ public class TryToComplete { private String permPrefix; private User user; private ChallengesManager manager; - private Challenges challenge; + private Challenge challenge; private String label; public TryToComplete label(String label) { @@ -61,7 +61,7 @@ public class TryToComplete { return this; } - public TryToComplete challenge(Challenges challenge) { + public TryToComplete challenge(Challenge challenge) { this.challenge = challenge; return this; } @@ -138,7 +138,7 @@ public class TryToComplete { * @param world * @param permPrefix */ - public TryToComplete(ChallengesAddon addon, User user, ChallengesManager manager, Challenges challenge, World world, String permPrefix, String label) { + public TryToComplete(ChallengesAddon addon, User user, ChallengesManager manager, Challenge challenge, World world, String permPrefix, String label) { this.addon = addon; this.world = world; this.permPrefix = permPrefix; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 2635fef..5271864 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -13,7 +13,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; @@ -40,7 +40,7 @@ public class EditChallengeGUI extends CommonGUI public EditChallengeGUI(ChallengesAddon addon, World world, User user, - Challenges challenge, + Challenge challenge, String topLabel, String permissionPrefix) { @@ -55,7 +55,7 @@ public class EditChallengeGUI extends CommonGUI public EditChallengeGUI(ChallengesAddon addon, World world, User user, - Challenges challenge, + Challenge challenge, String topLabel, String permissionPrefix, CommonGUI parentGUI) @@ -301,9 +301,9 @@ public class EditChallengeGUI extends CommonGUI { case TYPE: { - List values = new ArrayList<>(Challenges.ChallengeType.values().length); + List values = new ArrayList<>(Challenge.ChallengeType.values().length); - for (Challenges.ChallengeType type : Challenges.ChallengeType.values()) + for (Challenge.ChallengeType type : Challenge.ChallengeType.values()) { values.add((this.challenge.getChallengeType().equals(type) ? "§2" : "§c") + this.user.getTranslation("challenges.gui.admin.descriptions." + type.name().toLowerCase())); @@ -312,15 +312,15 @@ public class EditChallengeGUI extends CommonGUI name = this.user.getTranslation("challenges.gui.admin.buttons.type"); description = values; - if (this.challenge.getChallengeType().equals(Challenges.ChallengeType.ISLAND)) + if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) { icon = new ItemStack(Material.GRASS_BLOCK); } - else if (this.challenge.getChallengeType().equals(Challenges.ChallengeType.INVENTORY)) + else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) { icon = new ItemStack(Material.CHEST); } - else if (this.challenge.getChallengeType().equals(Challenges.ChallengeType.LEVEL)) + else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.LEVEL)) { icon = new ItemStack(Material.EXPERIENCE_BOTTLE); } @@ -1108,9 +1108,9 @@ public class EditChallengeGUI extends CommonGUI * @param type Given challenge type. * @return Next Challenge Type. */ - private Challenges.ChallengeType getNextType(Challenges.ChallengeType type) + private Challenge.ChallengeType getNextType(Challenge.ChallengeType type) { - Challenges.ChallengeType[] values = Challenges.ChallengeType.values(); + Challenge.ChallengeType[] values = Challenge.ChallengeType.values(); for (int i = 0; i < values.length; i++) { @@ -1136,9 +1136,9 @@ public class EditChallengeGUI extends CommonGUI * @param type Given challenge type. * @return Previous Challenge Type. */ - private Challenges.ChallengeType getPreviousType(Challenges.ChallengeType type) + private Challenge.ChallengeType getPreviousType(Challenge.ChallengeType type) { - Challenges.ChallengeType[] values = Challenges.ChallengeType.values(); + Challenge.ChallengeType[] values = Challenge.ChallengeType.values(); for (int i = 0; i < values.length; i++) { @@ -1228,7 +1228,7 @@ public class EditChallengeGUI extends CommonGUI /** * Variable holds challenge thats needs editing. */ - private Challenges challenge; + private Challenge challenge; /** * Variable holds current active menu. diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 1bf87a5..912aa87 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -16,8 +16,8 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.database.object.ChallengeLevels; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; @@ -43,7 +43,7 @@ public class EditLevelGUI extends CommonGUI public EditLevelGUI(ChallengesAddon addon, World world, User user, - ChallengeLevels challengeLevel, + ChallengeLevel challengeLevel, String topLabel, String permissionPrefix) { @@ -58,7 +58,7 @@ public class EditLevelGUI extends CommonGUI public EditLevelGUI(ChallengesAddon addon, World world, User user, - ChallengeLevels challengeLevel, + ChallengeLevel challengeLevel, String topLabel, String permissionPrefix, CommonGUI parentGUI) @@ -145,7 +145,7 @@ public class EditLevelGUI extends CommonGUI */ private void buildChallengesPanel(PanelBuilder panelBuilder) { - List challengeList = this.addon.getChallengesManager().getChallenges(this.challengeLevel); + List challengeList = this.addon.getChallengesManager().getChallenges(this.challengeLevel); final int MAX_ELEMENTS = 21; @@ -262,7 +262,7 @@ public class EditLevelGUI extends CommonGUI * @param challenge Challenge which icon must be created. * @return PanelItem that represents given challenge. */ - private PanelItem createChallengeIcon(Challenges challenge) + private PanelItem createChallengeIcon(Challenge challenge) { return new PanelItemBuilder(). name(challenge.getFriendlyName()). @@ -538,7 +538,7 @@ public class EditLevelGUI extends CommonGUI ChallengesManager manager = this.addon.getChallengesManager(); // Get all challenge that is not in current challenge. - List challengeList = manager.getChallengesList(); + List challengeList = manager.getChallengesList(); challengeList.removeAll(manager.getChallenges(this.challengeLevel)); new SelectChallengeGUI(this.user, challengeList, (status, value) -> { @@ -630,7 +630,7 @@ public class EditLevelGUI extends CommonGUI /** * This variable holds current challenge level that is in editing GUI. */ - private ChallengeLevels challengeLevel; + private ChallengeLevel challengeLevel; /** * Variable holds current active menu. diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 4a50298..700efe6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -10,7 +10,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; import world.bentobox.challenges.utils.GuiUtils; @@ -82,7 +82,7 @@ public class ListChallengesGUI extends CommonGUI GuiUtils.fillBorder(panelBuilder); } - List challengeList = this.addon.getChallengesManager().getChallengesList(); + List challengeList = this.addon.getChallengesManager().getChallengesList(); final int MAX_ELEMENTS = 21; @@ -130,7 +130,7 @@ public class ListChallengesGUI extends CommonGUI * @param challenge Challenge which button must be created. * @return Challenge button. */ - private PanelItem createChallengeIcon(Challenges challenge) + private PanelItem createChallengeIcon(Challenge challenge) { PanelItemBuilder itemBuilder = new PanelItemBuilder(). name(challenge.getFriendlyName()). diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 2953f0b..3c33dd7 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -10,7 +10,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.database.object.ChallengeLevels; +import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ConfirmationGUI; import world.bentobox.challenges.utils.GuiUtils; @@ -82,7 +82,7 @@ public class ListLevelsGUI extends CommonGUI GuiUtils.fillBorder(panelBuilder); } - List levelList = this.addon.getChallengesManager().getChallengeLevelList(); + List levelList = this.addon.getChallengesManager().getChallengeLevelList(); final int MAX_ELEMENTS = 21; @@ -130,7 +130,7 @@ public class ListLevelsGUI extends CommonGUI * @param challengeLevel Level which button must be created. * @return Level button. */ - private PanelItem createLevelIcon(ChallengeLevels challengeLevel) + private PanelItem createLevelIcon(ChallengeLevel challengeLevel) { PanelItemBuilder itemBuilder = new PanelItemBuilder(). name(challengeLevel.getFriendlyName()). diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index 2501adf..098fe0a 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -15,7 +15,7 @@ import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.LevelStatus; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.TryToComplete; @@ -123,7 +123,7 @@ public class ChallengesGUI extends CommonGUI */ private void addFreeChallenges(PanelBuilder panelBuilder) { - List freeChallenges = this.challengesManager.getFreeChallenges(this.user, this.world); + List freeChallenges = this.challengesManager.getFreeChallenges(this.user, this.world); final int freeChallengesCount = freeChallenges.size(); if (freeChallengesCount > 18) @@ -168,7 +168,7 @@ public class ChallengesGUI extends CommonGUI } else { - for (Challenges challenge : freeChallenges) + for (Challenge challenge : freeChallenges) { // there are no limitations. Just bunch insert. panelBuilder.item(this.getChallengeButton(challenge)); @@ -185,7 +185,7 @@ public class ChallengesGUI extends CommonGUI { if (this.lastSelectedLevel != null) { - List challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel()); + List challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel()); final int challengesCount = challenges.size(); if (challengesCount > 18) @@ -230,7 +230,7 @@ public class ChallengesGUI extends CommonGUI } else { - for (Challenges challenge : challenges) + for (Challenge challenge : challenges) { // there are no limitations. Just bunch insert. panelBuilder.item(this.getChallengeButton(challenge)); @@ -315,7 +315,7 @@ public class ChallengesGUI extends CommonGUI * @param challenge which icon must be constructed. * @return PanelItem icon for challenge. */ - private PanelItem getChallengeButton(Challenges challenge) + private PanelItem getChallengeButton(Challenge challenge) { return new PanelItemBuilder(). icon(challenge.getIcon()). @@ -341,7 +341,7 @@ public class ChallengesGUI extends CommonGUI * @param challenge Which information must be retrieved. * @return List with strings that contains information about given challenge. */ - private List createChallengeDescription(Challenges challenge) + private List createChallengeDescription(Challenge challenge) { List result = new ArrayList<>(); @@ -392,14 +392,14 @@ public class ChallengesGUI extends CommonGUI { result.addAll(challenge.getDescription()); - if (challenge.getChallengeType().equals(Challenges.ChallengeType.INVENTORY)) + if (challenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) { if (challenge.isTakeItems()) { result.add(this.user.getTranslation("challenges.item-take-warning")); } } - else if (challenge.getChallengeType().equals(Challenges.ChallengeType.ISLAND)) + else if (challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) { result.add(this.user.getTranslation("challenges.items-closeby")); @@ -433,7 +433,7 @@ public class ChallengesGUI extends CommonGUI * @param challenge which reward message must be created. * @return list of strings that contains rewards message. */ - private List challengeRewards(Challenges challenge) + private List challengeRewards(Challenge challenge) { String rewardText; double rewardMoney; diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java index 2682d8f..aa01327 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java @@ -9,7 +9,7 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.challenges.database.object.Challenges; +import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.utils.GuiUtils; @@ -18,7 +18,7 @@ import world.bentobox.challenges.utils.GuiUtils; */ public class SelectChallengeGUI { - public SelectChallengeGUI(User user, List challengesList, BiConsumer consumer) + public SelectChallengeGUI(User user, List challengesList, BiConsumer consumer) { this.consumer = consumer; this.user = user; @@ -123,7 +123,7 @@ public class SelectChallengeGUI * @param challenge Challenge which PanelItem must be created. * @return new PanelItem for given Challenge. */ - private PanelItem createChallengeButton(Challenges challenge) + private PanelItem createChallengeButton(Challenge challenge) { return new PanelItemBuilder(). name(challenge.getFriendlyName()). @@ -144,7 +144,7 @@ public class SelectChallengeGUI /** * This variable stores consumer. */ - private BiConsumer consumer; + private BiConsumer consumer; /** * User who runs GUI. @@ -154,5 +154,5 @@ public class SelectChallengeGUI /** * Current value. */ - private List challengesList; + private List challengesList; } diff --git a/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java b/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java index df581e7..b0d8992 100644 --- a/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java +++ b/src/test/java/world/bentobox/challenges/ChallengesAddonTest.java @@ -35,8 +35,8 @@ import org.powermock.modules.junit4.PowerMockRunner; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import world.bentobox.challenges.database.object.Challenges; -import world.bentobox.challenges.database.object.Challenges.ChallengeType; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; /** * @author tastybento @@ -81,7 +81,7 @@ public class ChallengesAddonTest { public void test() { Gson gson = new GsonBuilder().setPrettyPrinting().create(); - Challenges challenges = new Challenges(); + Challenge challenges = new Challenge(); challenges.setChallengeType(ChallengeType.ISLAND); Map map = new HashMap<>(); map.put(Material.DIRT, 5); From f75e4e080ce8d69b1c844b81c6138519148b84b4 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 16:33:33 +0200 Subject: [PATCH 068/103] Rework Challenge, ChallengeLevel and ChallengesPlayerData classes. Challenge now will not know their world, as it is not necessary. Remove ICON type, as it is useless. Rename Level to Other, as under it will be not only level things. Rename slot to order, as it was weird that users could define slot but not order. Order is easier to understand and use. ChallengesLevel now knows all their levels. Each challenge level only will be for single world. Rename some variables. ChallengesPlayerData was just adapted with changes in challenges and level classes. --- .../challenges/ChallengesImportManager.java | 45 +- .../challenges/ChallengesManager.java | 32 +- .../challenges/database/object/Challenge.java | 1462 ++++++++++------- .../database/object/ChallengeLevel.java | 552 +++++-- .../database/object/ChallengesPlayerData.java | 405 +++-- .../challenges/panel/ChallengesPanels.java | 15 +- .../challenges/panel/ChallengesPanels2.java | 22 +- .../challenges/panel/RequiredPanel.java | 6 +- .../challenges/panel/TryToComplete.java | 31 +- .../panel/admin/EditChallengeGUI.java | 48 +- .../challenges/panel/admin/EditLevelGUI.java | 28 +- .../challenges/panel/user/ChallengesGUI.java | 4 +- 12 files changed, 1664 insertions(+), 986 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index 1b4b294..8f4df1f 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -16,10 +16,13 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.util.Util; +import world.bentobox.challenges.utils.GuiUtils; + /** * Imports challenges @@ -64,13 +67,13 @@ public class ChallengesImportManager user.sendMessage("challenges.admin.import.no-load","[message]", e.getMessage()); return false; } - makeLevels(user); + makeLevels(user, world, overwrite); makeChallenges(user, world, overwrite); addon.getChallengesManager().save(); return true; } - private void makeLevels(User user) { + private void makeLevels(User user, World world, boolean overwrite) { // Parse the levels String levels = chal.getString("challenges.levels", ""); if (!levels.isEmpty()) { @@ -82,15 +85,16 @@ public class ChallengesImportManager challengeLevel.setFriendlyName(level); challengeLevel.setUniqueId(level); challengeLevel.setOrder(order++); - challengeLevel.setWaiveramount(chal.getInt("challenges.waiveramount")); + challengeLevel.setWorld(Util.getWorld(world).getName()); + challengeLevel.setWaiverAmount(chal.getInt("challenges.waiveramount")); // Check if there is a level reward ConfigurationSection unlock = chal.getConfigurationSection("challenges.levelUnlock." + level); if (unlock != null) { challengeLevel.setUnlockMessage(unlock.getString("message")); - challengeLevel.setRewardDescription(unlock.getString("rewardDesc","")); + challengeLevel.setRewardText(unlock.getString("rewardDesc","")); challengeLevel.setRewardItems(parseItems(unlock.getString("itemReward",""))); - challengeLevel.setMoneyReward(unlock.getInt("moneyReward")); - challengeLevel.setExpReward(unlock.getInt("expReward")); + challengeLevel.setRewardMoney(unlock.getInt("moneyReward")); + challengeLevel.setRewardExperience(unlock.getInt("expReward")); challengeLevel.setRewardCommands(unlock.getStringList("commands")); } addon.getChallengesManager().storeLevel(challengeLevel); @@ -103,7 +107,6 @@ public class ChallengesImportManager /** * Imports challenges * @param overwrite - * @param args */ private void makeChallenges(User user, World world, boolean overwrite) { int size = 0; @@ -115,41 +118,42 @@ public class ChallengesImportManager newChallenge.setDeployed(true); ConfigurationSection details = chals.getConfigurationSection(challenge); newChallenge.setFriendlyName(details.getString("friendlyname", challenge)); - newChallenge.setWorld(Util.getWorld(world).getName()); newChallenge.setDescription(addon.getChallengesManager().stringSplit(details.getString("description", ""))); - newChallenge.setIcon(new ParseItem(addon, details.getString("icon") + ":1").getItem()); - newChallenge.setLevel(details.getString("level", ChallengesManager.FREE)); + newChallenge.setIcon(ItemParser.parse(details.getString("icon") + ":1")); newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); newChallenge.setTakeItems(details.getBoolean("takeItems",true)); newChallenge.setRewardText(details.getString("rewardText", "")); newChallenge.setRewardCommands(details.getStringList("rewardcommands")); newChallenge.setRewardMoney(details.getInt("moneyReward",0)); - newChallenge.setRewardExp(details.getInt("expReward")); + newChallenge.setRewardExperience(details.getInt("expReward")); newChallenge.setRepeatable(details.getBoolean("repeatable")); newChallenge.setRepeatRewardText(details.getString("repeatRewardText","")); newChallenge.setRepeatMoneyReward(details.getInt("repearMoneyReward")); - newChallenge.setRepeatExpReward(details.getInt("repeatExpReward")); + newChallenge.setRepeatExperienceReward(details.getInt("repeatExpReward")); newChallenge.setRepeatRewardCommands(details.getStringList("repeatrewardcommands")); newChallenge.setMaxTimes(details.getInt("maxtimes")); // TODO reset allowed - newChallenge.setReqMoney(details.getInt("requiredMoney")); - newChallenge.setReqExp(details.getInt("requiredExp")); + newChallenge.setRequiredMoney(details.getInt("requiredMoney")); + newChallenge.setRequiredExperience(details.getInt("requiredExp")); String reqItems = details.getString("requiredItems",""); if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.INVENTORY)) { newChallenge.setRequiredItems(parseItems(reqItems)); - } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.LEVEL)) { - newChallenge.setReqIslandlevel(Long.parseLong(reqItems)); + } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)) { + newChallenge.setRequiredIslandLevel(Long.parseLong(reqItems)); } else if (newChallenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) { parseEntities(newChallenge, reqItems); } newChallenge.setRewardItems(parseItems(details.getString("itemReward"))); newChallenge.setRepeatItemReward(parseItems(details.getString("repeatItemReward"))); // Save + this.addon.getChallengesManager().addChallengeToLevel(newChallenge, + addon.getChallengesManager().getLevel(Util.getWorld(world).getName() + "_" + details.getString("level"))); + if (addon.getChallengesManager().storeChallenge(newChallenge, overwrite, user, false)) { size++; } } - addon.getChallengesManager().sortChallenges(); + user.sendMessage("challenges.admin.import.number", "[number]", String.valueOf(size)); } @@ -180,7 +184,7 @@ public class ChallengesImportManager List result = new ArrayList<>(); if (!reqList.isEmpty()) { for (String s : reqList.split(" ")) { - ItemStack item = new ParseItem(addon,s).getItem(); + ItemStack item = ItemParser.parse(s); if (item != null) { result.add(item); } @@ -188,7 +192,4 @@ public class ChallengesImportManager } return result; } - - - -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index e5322e3..554faef 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -80,7 +80,7 @@ public class ChallengesManager { */ public long checkChallengeTimes(User user, Challenge challenge, World world) { addPlayer(user); - return playerData.get(user.getUniqueId()).getTimes(world, challenge.getUniqueId()); + return playerData.get(user.getUniqueId()).getTimes(challenge.getUniqueId()); } /** @@ -189,7 +189,7 @@ public class ChallengesManager { */ public List getAllChallengesList(World world) { List result = new ArrayList<>(); - challengeMap.values().forEach(ch -> ch.stream().filter(c -> c.getWorld().equals(Util.getWorld(world).getName())).forEach(c -> result.add(c.getUniqueId()))); + challengeMap.values().forEach(ch -> ch.stream().filter(c -> c.getUniqueId().startsWith(Util.getWorld(world).getName())).forEach(c -> result.add(c.getUniqueId()))); return result; } @@ -230,10 +230,10 @@ public class ChallengesManager { for (Entry> entry : this.challengeMap.entrySet()) { // Check how much challenges must be done in previous level. - int challengesToDo = Math.max(0, entry.getKey().getWaiveramount() - doneChallengeCount); + int challengesToDo = Math.max(0, entry.getKey().getWaiverAmount() - doneChallengeCount); doneChallengeCount = (int) entry.getValue().stream().filter( - ch -> playerData.isChallengeDone(world, ch.getUniqueId())).count(); + ch -> playerData.isChallengeDone(ch.getUniqueId())).count(); // Create result class with the data result.add(new LevelStatus( @@ -270,7 +270,7 @@ public class ChallengesManager { Optional lv = challengeMap.keySet().stream().filter(l -> l.getUniqueId().equalsIgnoreCase(level)).findFirst(); // Get the challenges applicable to this world return lv.isPresent() ? challengeMap.get(lv.get()).stream() - .filter(c -> c.getWorld().equalsIgnoreCase(worldName) || c.getWorld().isEmpty()).collect(Collectors.toSet()) + .filter(c -> c.getUniqueId().startsWith(worldName)).collect(Collectors.toSet()) : new HashSet<>(); } @@ -319,7 +319,7 @@ public class ChallengesManager { */ public boolean isChallenge(World world, String name) { for (Set ch : challengeMap.values()) { - if (ch.stream().filter(c -> c.getWorld().equals(Util.getWorld(world).getName())).anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { + if (ch.stream().filter(c -> c.getUniqueId().startsWith(Util.getWorld(world).getName())).anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { return true; } } @@ -328,13 +328,12 @@ public class ChallengesManager { /** * Checks if a challenge is complete or not - * @param uniqueId - unique ID - player's UUID * @param challengeName - Challenge uniqueId * @return - true if completed */ public boolean isChallengeComplete(User user, String challengeName, World world) { addPlayer(user); - return playerData.get(user.getUniqueId()).isChallengeDone(world, challengeName); + return playerData.get(user.getUniqueId()).isChallengeDone(challengeName); } /** @@ -396,7 +395,7 @@ public class ChallengesManager { */ public void setChallengeComplete(User user, String challengeUniqueId, World world) { addPlayer(user); - playerData.get(user.getUniqueId()).setChallengeDone(world, challengeUniqueId); + playerData.get(user.getUniqueId()).setChallengeDone(challengeUniqueId); // Save savePlayer(user.getUniqueId()); } @@ -409,7 +408,7 @@ public class ChallengesManager { */ public void setResetChallenge(User user, String challengeUniqueId, World world) { addPlayer(user); - playerData.get(user.getUniqueId()).setChallengeTimes(world, challengeUniqueId, 0); + playerData.get(user.getUniqueId()).setChallengeTimes(challengeUniqueId, 0); // Save savePlayer(user.getUniqueId()); } @@ -637,4 +636,17 @@ public class ChallengesManager { return playerList; } + + + + public ChallengeLevel getLevel(String level) + { + return null; + } + + + public void addChallengeToLevel(Challenge newChallenge, ChallengeLevel level) + { + + } } diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenge.java b/src/main/java/world/bentobox/challenges/database/object/Challenge.java index 9d4c3e7..6f6f829 100644 --- a/src/main/java/world/bentobox/challenges/database/object/Challenge.java +++ b/src/main/java/world/bentobox/challenges/database/object/Challenge.java @@ -1,6 +1,7 @@ package world.bentobox.challenges.database.object; +import com.google.gson.annotations.Expose; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -9,657 +10,1012 @@ import java.util.*; import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.database.objects.DataObject; -import world.bentobox.challenges.ChallengesManager; + /** * Data object for challenges * @author tastybento * */ -public class Challenge implements DataObject { - - public Challenge() {} - - - public boolean isRemoveEntities() +public class Challenge implements DataObject +{ + /** + * Empty constructor + */ + public Challenge() { - return false; } - public void setRemoveEntities(boolean b) + /** + * This enum holds all Challenge Types. + */ + public enum ChallengeType { - - } - - - public boolean isRemoveBlocks() - { - return false; - } - - - public void setRemoveBlocks(boolean b) - { - - } - - - public boolean isTakeExperience() - { - return false; - } - - - public void setTakeExperience(boolean b) - { - - } - - - public enum ChallengeType { - /** - * This challenge only shows and icon in the GUI and doesn't do anything. - */ - ICON, /** * The player must have the items on them. */ INVENTORY, - /** - * The island level has to be equal or over this amount. Only works if there's an island level plugin installed. - */ - LEVEL, + /** * Items or required entities have to be within x blocks of the player. */ - ISLAND + ISLAND, + + /** + * Other type, like required money / experience or island level. This my request + * other plugins to be setup before it could work. + */ + OTHER, } - // The order of the fields is the order shown in the YML files - @ConfigComment("Whether this challenge is deployed or not") - private boolean deployed; - - // Description - @ConfigComment("Name of the icon and challenge. May include color codes. Single line.") - private String friendlyName = ""; - @ConfigComment("Description of the challenge. Will become the lore on the icon. Can include & color codes. String List.") - private List description = new ArrayList<>(); - @ConfigComment("The icon in the GUI for this challenge. ItemStack.") - private ItemStack icon = new ItemStack(Material.PAPER); - @ConfigComment("Icon slot where this challenge should be placed. 0 to 49. A negative value means any slot") - private int slot = -1; - - // Definition - @ConfigComment("Challenge level. Default is Free") - private String level = ChallengesManager.FREE; - @ConfigComment("Challenge type can be ICON, INVENTORY, LEVEL or ISLAND.") - private ChallengeType challengeType = ChallengeType.INVENTORY; - @ConfigComment("World where this challenge operates. List only overworld. Nether and end are automatically covered.") - private String world = ""; - @ConfigComment("List of environments where this challenge will occur: NETHER, NORMAL, THE_END. Leave blank for all.") - private Set environment = new HashSet<>(); - @ConfigComment("The required permissions to see this challenge. String list.") - private Set reqPerms = new HashSet<>(); - @ConfigComment("The number of blocks around the player to search for items on an island") - private int searchRadius = 10; - @ConfigComment("If true, the challenge will disappear from the GUI when completed") - private boolean removeWhenCompleted; - @ConfigComment("Take the required items from the player") - private boolean takeItems = true; - @ConfigComment("Take the money from the player") - private boolean takeMoney = false; - - // Requirements - @ConfigComment("This is a map of the blocks required in a ISLAND challenge. Material, Integer") - private Map requiredBlocks = new EnumMap<>(Material.class); - @ConfigComment("The items that must be in the inventory to complete the challenge. ItemStack List.") - private List requiredItems = new ArrayList<>(); - @ConfigComment("Any entities that must be in the area for ISLAND type challenges. Map EntityType, Number") - private Map requiredEntities = new EnumMap<>(EntityType.class); - @ConfigComment("Required experience") - private int reqExp; - @ConfigComment("Required island level for this challenge. Only works if Level Addon is being used.") - private long reqIslandlevel; - @ConfigComment("Required money") - private int reqMoney; - - // Rewards - @ConfigComment("List of items the player will receive first time. ItemStack List.") - private List rewardItems = new ArrayList<>(); - @ConfigComment("If this is blank, the reward text will be auto-generated, otherwise this will be used.") - private String rewardText = ""; - @ConfigComment("Experience point reward") - private int rewardExp; - @ConfigComment("Money reward") - private int rewardMoney; - @ConfigComment("Commands to run when the player completes the challenge for the first time. String List") - private List rewardCommands = new ArrayList<>(); - - // Repeatable - @ConfigComment("True if the challenge is repeatable") - private boolean repeatable; - @ConfigComment("Maximum number of times the challenge can be repeated") - private int maxTimes = 1; - @ConfigComment("Repeat exp award") - private int repeatExpReward; - @ConfigComment("Reward items for repeating the challenge. List of ItemStacks.") - private List repeatItemReward = new ArrayList<>(); - @ConfigComment("Repeat money award") - private int repeatMoneyReward; - @ConfigComment("Commands to run when challenge is repeated. String List.") - private List repeatRewardCommands = new ArrayList<>(); - @ConfigComment("Description of the repeat rewards. If blank, it will be autogenerated.") - private String repeatRewardText = ""; +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + @ConfigComment("") @ConfigComment("Unique name of the challenge") + @Expose private String uniqueId = ""; - /* - * END OF SETTINGS - */ + @ConfigComment("") + @ConfigComment("The name of the challenge. May include color codes. Single line.") + @Expose + private String friendlyName = ""; - /** - * @return the challengeType - */ - public ChallengeType getChallengeType() { - return challengeType; - } + @ConfigComment("") + @ConfigComment("Whether this challenge is deployed or not.") + @Expose + private boolean deployed; - /** - * @param challengeType the challengeType to set - */ - public void setChallengeType(ChallengeType challengeType) { - this.challengeType = challengeType; - } + @ConfigComment("") + @ConfigComment("Description of the challenge. Will become the lore on the icon. Can ") + @ConfigComment("include & color codes. String List.") + @Expose + private List description = new ArrayList<>(); - /** - * @return the deployed - */ - public boolean isDeployed() { - return deployed; - } + @ConfigComment("") + @ConfigComment("The icon in the GUI for this challenge. ItemStack.") + @Expose + private ItemStack icon = new ItemStack(Material.PAPER); - /** - * @param deployed the deployed to set - */ - public void setDeployed(boolean deployed) { - this.deployed = deployed; - } + @ConfigComment("") + @ConfigComment("Order of this challenge. It allows define order for challenges in") + @ConfigComment("single level. If order for challenges are equal, it will order by") + @ConfigComment("challenge unique id.") + @Expose + private int order = -1; - /** - * @return the description - */ - public List getDescription() { - return description; - } + @ConfigComment("") + @ConfigComment("Challenge type can be INVENTORY, OTHER or ISLAND.") + @Expose + private ChallengeType challengeType = ChallengeType.INVENTORY; - /** - * @param description the description to set - */ - public void setDescription(List description) { - this.description = description; - } + @ConfigComment("") + @ConfigComment("List of environments where this challenge will occur: NETHER, NORMAL,") + @ConfigComment("THE_END. Leave blank for all.") + @Expose + private Set environment = new HashSet<>(); - /** - * @return the expReward - */ - public int getRewardExp() { - return rewardExp; - } + @ConfigComment("") + @ConfigComment("If true, the challenge will disappear from the GUI when completed") + @Expose + private boolean removeWhenCompleted; - /** - * @param expReward the expReward to set - */ - public void setRewardExp(int expReward) { - this.rewardExp = expReward; - } + @ConfigComment("") + @ConfigComment("Unique challenge ID. Empty means that challenge is in free challenge list.") + @Expose + private String level = ""; - /** - * @return the friendlyName - */ - public String getFriendlyName() { - return friendlyName; - } +// --------------------------------------------------------------------- +// Section: Requirement related +// --------------------------------------------------------------------- - /** - * @param friendlyName the friendlyName to set - */ - public void setFriendlyName(String friendlyName) { - this.friendlyName = friendlyName; - } + @ConfigComment("") + @ConfigComment("") + @ConfigComment("The required permissions to see this challenge. String list.") + @Expose + private Set requiredPermissions = new HashSet<>(); - /** - * @return the icon - */ - public ItemStack getIcon() { - return icon != null ? icon.clone() : new ItemStack(Material.MAP); - } + @ConfigComment("") + @ConfigComment("This is a map of the blocks required in a ISLAND challenge. Material,") + @ConfigComment("Integer") + @Expose + private Map requiredBlocks = new EnumMap<>(Material.class); - /** - * @param icon the icon to set - */ - public void setIcon(ItemStack icon) { - this.icon = icon; - } + @ConfigComment("") + @ConfigComment("Remove the required blocks from the island") + @Expose + private boolean removeBlocks; - /** - * @return the level - */ - public String getLevel() { - return level; - } + @ConfigComment("") + @ConfigComment("Any entities that must be in the area for ISLAND type challenges. ") + @ConfigComment("Map EntityType, Number") + @Expose + private Map requiredEntities = new EnumMap<>(EntityType.class); - /** - * @param level the level to set - */ - public void setLevel(String level) { - if (level.isEmpty()) { - level = ChallengesManager.FREE; - } - this.level = level; - } + @ConfigComment("") + @ConfigComment("Remove the entities from the island") + @Expose + private boolean removeEntities; - /** - * @return the maxTimes - */ - public int getMaxTimes() { - return maxTimes; - } + @ConfigComment("") + @ConfigComment("The items that must be in the inventory to complete the challenge. ") + @ConfigComment("ItemStack List.") + @Expose + private List requiredItems = new ArrayList<>(); - /** - * @param maxTimes the maxTimes to set - */ - public void setMaxTimes(int maxTimes) { - this.maxTimes = maxTimes; - } + @ConfigComment("") + @ConfigComment("Take the required items from the player") + @Expose + private boolean takeItems = true; - /** - * @return the moneyReward - */ - public int getRewardMoney() { - return rewardMoney; - } + @ConfigComment("") + @ConfigComment("Required experience for challenge completion.") + @Expose + private int requiredExperience = 0; - /** - * @param moneyReward the moneyReward to set - */ - public void setRewardMoney(int moneyReward) { - this.rewardMoney = moneyReward; - } + @ConfigComment("") + @ConfigComment("Take the experience from the player") + @Expose + private boolean takeExperience; - /** - * @return the removeWhenCompleted - */ - public boolean isRemoveWhenCompleted() { - return removeWhenCompleted; - } + @ConfigComment("") + @ConfigComment("Required money for challenge completion. Economy plugins or addons") + @ConfigComment("is required for this option.") + @Expose + private int requiredMoney = 0; - /** - * @param removeWhenCompleted the removeWhenCompleted to set - */ - public void setRemoveWhenCompleted(boolean removeWhenCompleted) { - this.removeWhenCompleted = removeWhenCompleted; - } + @ConfigComment("") + @ConfigComment("Take the money from the player") + @Expose + private boolean takeMoney; - /** - * @return the repeatable - */ - public boolean isRepeatable() { - return repeatable; - } + @ConfigComment("") + @ConfigComment("Required island level for challenge completion. Plugin or Addon that") + @ConfigComment("calculates island level is required for this option.") + @Expose + private long requiredIslandLevel; - /** - * @param repeatable the repeatable to set - */ - public void setRepeatable(boolean repeatable) { - this.repeatable = repeatable; - } + @ConfigComment("") + @ConfigComment("The number of blocks around the player to search for items on an island") + @Expose + private int searchRadius = 10; - /** - * @return the repeatExpReward - */ - public int getRepeatExpReward() { - return repeatExpReward; - } - /** - * @param repeatExpReward the repeatExpReward to set - */ - public void setRepeatExpReward(int repeatExpReward) { - this.repeatExpReward = repeatExpReward; - } +// --------------------------------------------------------------------- +// Section: Rewards +// --------------------------------------------------------------------- - /** - * @return the repeatItemReward - */ - public List getRepeatItemReward() { - return repeatItemReward; - } + @ConfigComment("") + @ConfigComment("") + @ConfigComment("If this is blank, the reward text will be auto-generated, otherwise") + @ConfigComment("this will be used.") + @Expose + private String rewardText = ""; - /** - * @param repeatItemReward the repeatItemReward to set - */ - public void setRepeatItemReward(List repeatItemReward) { - this.repeatItemReward = repeatItemReward; - } - /** - * @return the repeatMoneyReward - */ - public int getRepeatMoneyReward() { - return repeatMoneyReward; - } + @ConfigComment("") + @ConfigComment("List of items the player will receive first time. ItemStack List.") + @Expose + private List rewardItems = new ArrayList<>(); - /** - * @param repeatMoneyReward the repeatMoneyReward to set - */ - public void setRepeatMoneyReward(int repeatMoneyReward) { - this.repeatMoneyReward = repeatMoneyReward; - } + @ConfigComment("") + @ConfigComment("Experience point reward") + @Expose + private int rewardExperience = 0; - /** - * @return the repeatRewardCommands - */ - public List getRepeatRewardCommands() { - return repeatRewardCommands; - } + @ConfigComment("") + @ConfigComment("Money reward. Economy plugin or addon required for this option.") + @Expose + private int rewardMoney = 0; - /** - * @param repeatRewardCommands the repeatRewardCommands to set - */ - public void setRepeatRewardCommands(List repeatRewardCommands) { - this.repeatRewardCommands = repeatRewardCommands; - } + @ConfigComment("") + @ConfigComment("Commands to run when the player completes the challenge for the first") + @ConfigComment("time. String List") + @Expose + private List rewardCommands = new ArrayList<>(); - /** - * @return the repeatRewardText - */ - public String getRepeatRewardText() { - return repeatRewardText; - } - /** - * @param repeatRewardText the repeatRewardText to set - */ - public void setRepeatRewardText(String repeatRewardText) { - this.repeatRewardText = repeatRewardText; - } +// --------------------------------------------------------------------- +// Section: Repeat Rewards +// --------------------------------------------------------------------- - /** - * @return the reqExp - */ - public int getReqExp() { - return reqExp; - } - /** - * @param reqExp the reqExp to set - */ - public void setReqExp(int reqExp) { - this.reqExp = reqExp; - } + @ConfigComment("") + @ConfigComment("") + @ConfigComment("True if the challenge is repeatable") + @Expose + private boolean repeatable; - /** - * @return the reqIslandlevel - */ - public long getReqIslandlevel() { - return reqIslandlevel; - } + @ConfigComment("") + @ConfigComment("Description of the repeat rewards. If blank, it will be autogenerated.") + @Expose + private String repeatRewardText = ""; - /** - * @param reqIslandlevel the reqIslandlevel to set - */ - public void setReqIslandlevel(long reqIslandlevel) { - this.reqIslandlevel = reqIslandlevel; - } + @ConfigComment("") + @ConfigComment("Maximum number of times the challenge can be repeated. 0 or less") + @ConfigComment("will mean infinite times.") + @Expose + private int maxTimes = 1; - /** - * @return the reqMoney - */ - public int getReqMoney() { - return reqMoney; - } + @ConfigComment("") + @ConfigComment("Repeat experience reward") + @Expose + private int repeatExperienceReward = 0; - /** - * @param reqMoney the reqMoney to set - */ - public void setReqMoney(int reqMoney) { - this.reqMoney = reqMoney; - } + @ConfigComment("") + @ConfigComment("Reward items for repeating the challenge. List of ItemStacks.") + @Expose + private List repeatItemReward = new ArrayList<>(); - /** - * @return the reqPerms - */ - public Set getReqPerms() { - return reqPerms; - } + @ConfigComment("") + @ConfigComment("Repeat money reward. Economy plugin or addon required for this option.") + @Expose + private int repeatMoneyReward; - /** - * @param reqPerms the reqPerms to set - */ - public void setReqPerms(Set reqPerms) { - this.reqPerms = reqPerms; - } + @ConfigComment("") + @ConfigComment("Commands to run when challenge is repeated. String List.") + @Expose + private List repeatRewardCommands = new ArrayList<>(); - /** - * @return the requiredItems - */ - public List getRequiredItems() { - return requiredItems; - } - /** - * @param requiredItems the requiredItems to set - */ - public void setRequiredItems(List requiredItems) { - this.requiredItems = requiredItems; - } +// --------------------------------------------------------------------- +// Section: Getters +// --------------------------------------------------------------------- - /** - * @return requiredEntities - */ - public Map getRequiredEntities() { - return requiredEntities; - } - - /** - * @param requiredEntities the requiredEntities to set - */ - public void setRequiredEntities(Map requiredEntities) { - this.requiredEntities = requiredEntities; - } - - /** - * @return the requiredBlocks - */ - public Map getRequiredBlocks() { - return requiredBlocks; - } - - /** - * @param map the requiredBlocks to set - */ - public void setRequiredBlocks(Map map) { - this.requiredBlocks = map; - } - - /** - * @return the rewardCommands - */ - public List getRewardCommands() { - return rewardCommands; - } - - /** - * @param rewardCommands the rewardCommands to set - */ - public void setRewardCommands(List rewardCommands) { - this.rewardCommands = rewardCommands; - } - - /** - * @return the itemReward - */ - public List getRewardItems() { - return rewardItems; - } - - /** - * @param itemReward the itemReward to set - */ - public void setRewardItems(List itemReward) { - this.rewardItems = itemReward; - } - - /** - * @return the rewardText - */ - public String getRewardText() { - return rewardText; - } - - /** - * @param rewardText the rewardText to set - */ - public void setRewardText(String rewardText) { - this.rewardText = rewardText; - } - - /** - * @return the searchRadius - */ - public int getSearchRadius() { - return searchRadius; - } - - /** - * @param searchRadius the searchRadius to set - */ - public void setSearchRadius(int searchRadius) { - this.searchRadius = searchRadius; - } - - /** - * @return the slot - */ - public int getSlot() { - return slot; - } - - /** - * @param slot the slot to set - */ - public void setSlot(int slot) { - this.slot = slot; - } - - /** - * @return the takeItems - */ - public boolean isTakeItems() { - return takeItems; - } - - /** - * @param takeItems the takeItems to set - */ - public void setTakeItems(boolean takeItems) { - this.takeItems = takeItems; - } - - /** - * @return the takeMoney - */ - public boolean isTakeMoney() { - return takeMoney; - } - - /** - * @param takeMoney the takeMoney to set - */ - public void setTakeMoney(boolean takeMoney) { - this.takeMoney = takeMoney; - } - - /** - * @return the environment - */ - public Set getEnvironment() { - return environment; - } - - /** - * @param environment the environment to set - */ - public void setEnvironment(Set environment) { - this.environment = environment; - } - - /** - * @return the worlds - */ - public String getWorld() { - return world; - } - - /** - * @param worlds the worlds to set - */ - public void setWorld(String world) { - this.world = world; - } /** * @return the uniqueId */ @Override - public String getUniqueId() { + public String getUniqueId() + { return uniqueId; } + + /** + * @return the friendlyName + */ + public String getFriendlyName() + { + return friendlyName; + } + + + /** + * @return the deployed + */ + public boolean isDeployed() + { + return deployed; + } + + + /** + * @return the description + */ + public List getDescription() + { + return description; + } + + + /** + * @return the icon + */ + public ItemStack getIcon() + { + return icon; + } + + + /** + * @return the order + */ + public int getOrder() + { + return order; + } + + + /** + * @return the challengeType + */ + public ChallengeType getChallengeType() + { + return challengeType; + } + + + /** + * @return the environment + */ + public Set getEnvironment() + { + return environment; + } + + + /** + * @return the level + */ + public String getLevel() + { + return level; + } + + + /** + * @return the removeWhenCompleted + */ + public boolean isRemoveWhenCompleted() + { + return removeWhenCompleted; + } + + + /** + * @return the requiredPermissions + */ + public Set getRequiredPermissions() + { + return requiredPermissions; + } + + + /** + * @return the requiredBlocks + */ + public Map getRequiredBlocks() + { + return requiredBlocks; + } + + + /** + * @return the removeBlocks + */ + public boolean isRemoveBlocks() + { + return removeBlocks; + } + + + /** + * @return the requiredEntities + */ + public Map getRequiredEntities() + { + return requiredEntities; + } + + + /** + * @return the removeEntities + */ + public boolean isRemoveEntities() + { + return removeEntities; + } + + + /** + * @return the requiredItems + */ + public List getRequiredItems() + { + return requiredItems; + } + + + /** + * @return the takeItems + */ + public boolean isTakeItems() + { + return takeItems; + } + + + /** + * @return the requiredExperience + */ + public int getRequiredExperience() + { + return requiredExperience; + } + + + /** + * @return the takeExperience + */ + public boolean isTakeExperience() + { + return takeExperience; + } + + + /** + * @return the requiredMoney + */ + public int getRequiredMoney() + { + return requiredMoney; + } + + + /** + * @return the takeMoney + */ + public boolean isTakeMoney() + { + return takeMoney; + } + + + /** + * @return the requiredIslandLevel + */ + public long getRequiredIslandLevel() + { + return requiredIslandLevel; + } + + + /** + * @return the searchRadius + */ + public int getSearchRadius() + { + return searchRadius; + } + + + /** + * @return the rewardText + */ + public String getRewardText() + { + return rewardText; + } + + + /** + * @return the rewardItems + */ + public List getRewardItems() + { + return rewardItems; + } + + + /** + * @return the rewardExperience + */ + public int getRewardExperience() + { + return rewardExperience; + } + + + /** + * @return the rewardMoney + */ + public int getRewardMoney() + { + return rewardMoney; + } + + + /** + * @return the rewardCommands + */ + public List getRewardCommands() + { + return rewardCommands; + } + + + /** + * @return the repeatable + */ + public boolean isRepeatable() + { + return repeatable; + } + + + /** + * @return the repeatRewardText + */ + public String getRepeatRewardText() + { + return repeatRewardText; + } + + + /** + * @return the maxTimes + */ + public int getMaxTimes() + { + return maxTimes; + } + + + /** + * @return the repeatExperienceReward + */ + public int getRepeatExperienceReward() + { + return repeatExperienceReward; + } + + + /** + * @return the repeatItemReward + */ + public List getRepeatItemReward() + { + return repeatItemReward; + } + + + /** + * @return the repeatMoneyReward + */ + public int getRepeatMoneyReward() + { + return repeatMoneyReward; + } + + + /** + * @return the repeatRewardCommands + */ + public List getRepeatRewardCommands() + { + return repeatRewardCommands; + } + + +// --------------------------------------------------------------------- +// Section: Setters +// --------------------------------------------------------------------- + + /** * @param uniqueId the uniqueId to set */ @Override - public void setUniqueId(String uniqueId) { + public void setUniqueId(String uniqueId) + { this.uniqueId = uniqueId; } - /* (non-Javadoc) + + /** + * This method sets the friendlyName value. + * @param friendlyName the friendlyName new value. + * + */ + public void setFriendlyName(String friendlyName) + { + this.friendlyName = friendlyName; + } + + + /** + * This method sets the deployed value. + * @param deployed the deployed new value. + * + */ + public void setDeployed(boolean deployed) + { + this.deployed = deployed; + } + + + /** + * This method sets the description value. + * @param description the description new value. + * + */ + public void setDescription(List description) + { + this.description = description; + } + + + /** + * This method sets the icon value. + * @param icon the icon new value. + * + */ + public void setIcon(ItemStack icon) + { + this.icon = icon; + } + + + /** + * This method sets the order value. + * @param order the order new value. + * + */ + public void setOrder(int order) + { + this.order = order; + } + + + /** + * This method sets the challengeType value. + * @param challengeType the challengeType new value. + * + */ + public void setChallengeType(ChallengeType challengeType) + { + this.challengeType = challengeType; + } + + + /** + * This method sets the environment value. + * @param environment the environment new value. + * + */ + public void setEnvironment(Set environment) + { + this.environment = environment; + } + + + /** + * This method sets the level value. + * @param level the level new value. + */ + public void setLevel(String level) + { + this.level = level; + } + + + /** + * This method sets the removeWhenCompleted value. + * @param removeWhenCompleted the removeWhenCompleted new value. + * + */ + public void setRemoveWhenCompleted(boolean removeWhenCompleted) + { + this.removeWhenCompleted = removeWhenCompleted; + } + + + /** + * This method sets the requiredPermissions value. + * @param requiredPermissions the requiredPermissions new value. + * + */ + public void setRequiredPermissions(Set requiredPermissions) + { + this.requiredPermissions = requiredPermissions; + } + + + /** + * This method sets the requiredBlocks value. + * @param requiredBlocks the requiredBlocks new value. + * + */ + public void setRequiredBlocks(Map requiredBlocks) + { + this.requiredBlocks = requiredBlocks; + } + + + /** + * This method sets the removeBlocks value. + * @param removeBlocks the removeBlocks new value. + * + */ + public void setRemoveBlocks(boolean removeBlocks) + { + this.removeBlocks = removeBlocks; + } + + + /** + * This method sets the requiredEntities value. + * @param requiredEntities the requiredEntities new value. + * + */ + public void setRequiredEntities(Map requiredEntities) + { + this.requiredEntities = requiredEntities; + } + + + /** + * This method sets the removeEntities value. + * @param removeEntities the removeEntities new value. + * + */ + public void setRemoveEntities(boolean removeEntities) + { + this.removeEntities = removeEntities; + } + + + /** + * This method sets the requiredItems value. + * @param requiredItems the requiredItems new value. + * + */ + public void setRequiredItems(List requiredItems) + { + this.requiredItems = requiredItems; + } + + + /** + * This method sets the takeItems value. + * @param takeItems the takeItems new value. + * + */ + public void setTakeItems(boolean takeItems) + { + this.takeItems = takeItems; + } + + + /** + * This method sets the requiredExperience value. + * @param requiredExperience the requiredExperience new value. + * + */ + public void setRequiredExperience(int requiredExperience) + { + this.requiredExperience = requiredExperience; + } + + + /** + * This method sets the takeExperience value. + * @param takeExperience the takeExperience new value. + * + */ + public void setTakeExperience(boolean takeExperience) + { + this.takeExperience = takeExperience; + } + + + /** + * This method sets the requiredMoney value. + * @param requiredMoney the requiredMoney new value. + * + */ + public void setRequiredMoney(int requiredMoney) + { + this.requiredMoney = requiredMoney; + } + + + /** + * This method sets the takeMoney value. + * @param takeMoney the takeMoney new value. + * + */ + public void setTakeMoney(boolean takeMoney) + { + this.takeMoney = takeMoney; + } + + + /** + * This method sets the requiredIslandLevel value. + * @param requiredIslandLevel the requiredIslandLevel new value. + * + */ + public void setRequiredIslandLevel(long requiredIslandLevel) + { + this.requiredIslandLevel = requiredIslandLevel; + } + + + /** + * This method sets the searchRadius value. + * @param searchRadius the searchRadius new value. + * + */ + public void setSearchRadius(int searchRadius) + { + this.searchRadius = searchRadius; + } + + + /** + * This method sets the rewardText value. + * @param rewardText the rewardText new value. + * + */ + public void setRewardText(String rewardText) + { + this.rewardText = rewardText; + } + + + /** + * This method sets the rewardItems value. + * @param rewardItems the rewardItems new value. + * + */ + public void setRewardItems(List rewardItems) + { + this.rewardItems = rewardItems; + } + + + /** + * This method sets the rewardExperience value. + * @param rewardExperience the rewardExperience new value. + * + */ + public void setRewardExperience(int rewardExperience) + { + this.rewardExperience = rewardExperience; + } + + + /** + * This method sets the rewardMoney value. + * @param rewardMoney the rewardMoney new value. + * + */ + public void setRewardMoney(int rewardMoney) + { + this.rewardMoney = rewardMoney; + } + + + /** + * This method sets the rewardCommands value. + * @param rewardCommands the rewardCommands new value. + * + */ + public void setRewardCommands(List rewardCommands) + { + this.rewardCommands = rewardCommands; + } + + + /** + * This method sets the repeatable value. + * @param repeatable the repeatable new value. + * + */ + public void setRepeatable(boolean repeatable) + { + this.repeatable = repeatable; + } + + + /** + * This method sets the repeatRewardText value. + * @param repeatRewardText the repeatRewardText new value. + * + */ + public void setRepeatRewardText(String repeatRewardText) + { + this.repeatRewardText = repeatRewardText; + } + + + /** + * This method sets the maxTimes value. + * @param maxTimes the maxTimes new value. + * + */ + public void setMaxTimes(int maxTimes) + { + this.maxTimes = maxTimes; + } + + + /** + * This method sets the repeatExperienceReward value. + * @param repeatExperienceReward the repeatExperienceReward new value. + * + */ + public void setRepeatExperienceReward(int repeatExperienceReward) + { + this.repeatExperienceReward = repeatExperienceReward; + } + + + /** + * This method sets the repeatItemReward value. + * @param repeatItemReward the repeatItemReward new value. + * + */ + public void setRepeatItemReward(List repeatItemReward) + { + this.repeatItemReward = repeatItemReward; + } + + + /** + * This method sets the repeatMoneyReward value. + * @param repeatMoneyReward the repeatMoneyReward new value. + * + */ + public void setRepeatMoneyReward(int repeatMoneyReward) + { + this.repeatMoneyReward = repeatMoneyReward; + } + + + /** + * This method sets the repeatRewardCommands value. + * @param repeatRewardCommands the repeatRewardCommands new value. + * + */ + public void setRepeatRewardCommands(List repeatRewardCommands) + { + this.repeatRewardCommands = repeatRewardCommands; + } + + +// --------------------------------------------------------------------- +// Section: Other methods +// --------------------------------------------------------------------- + + + /** * @see java.lang.Object#hashCode() + * @return int */ @Override - public int hashCode() { + public int hashCode() + { final int prime = 31; int result = 1; result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) + + /** + * @see java.lang.Object#equals(Object) () + * @param obj of type Object + * @return boolean */ @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object obj) + { + if (this == obj) + { return true; } - if (obj == null) { - return false; - } - if (!(obj instanceof Challenge)) { + + if (!(obj instanceof Challenge)) + { return false; } + Challenge other = (Challenge) obj; - if (uniqueId == null) { - if (other.uniqueId != null) { - return false; - } - } else if (!uniqueId.equals(other.uniqueId)) { - return false; + + if (uniqueId == null) + { + return other.uniqueId == null; + } + else + { + return uniqueId.equals(other.uniqueId); } - return true; } -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java index 70b5f74..cae1976 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java @@ -1,9 +1,13 @@ package world.bentobox.challenges.database.object; +import com.google.gson.annotations.Expose; +import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import world.bentobox.bentobox.api.configuration.ConfigComment; import world.bentobox.bentobox.database.objects.DataObject; @@ -14,223 +18,455 @@ import world.bentobox.challenges.ChallengesManager; * @author tastybento * */ -public class ChallengeLevel implements DataObject, Comparable { +public class ChallengeLevel implements DataObject, Comparable +{ + /** + * Constructor ChallengeLevel creates a new ChallengeLevel instance. + */ + public ChallengeLevel() + { + } - public ChallengeLevel() {} - @ConfigComment("A friendly name for the level. If blank, level name is used.") - private String friendlyName = ""; - - @ConfigComment("Worlds that this level applies in. String list.") - private List worlds = new ArrayList<>(); +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- - @ConfigComment("Commands to run when this level is completed") - private List rewardCommands = new ArrayList<>(); - + @ConfigComment("") @ConfigComment("Level name") + @Expose private String uniqueId = ChallengesManager.FREE; - - @ConfigComment("The number of undone challenges that can be left on this level before unlocking next level") - private int waiveramount = 1; - - @ConfigComment("The ordering of the levels, lowest to highest") - private int order = 0; - - @ConfigComment("The message shown when unlocking this level") + + @ConfigComment("") + @ConfigComment("A friendly name for the level. If blank, level name is used.") + @Expose + private String friendlyName = ""; + + @ConfigComment("") + @ConfigComment("ItemStack that represents current level. Will be used as icon in GUIs.") + @Expose + private ItemStack icon = new ItemStack(Material.BOOK); + + @ConfigComment("") + @ConfigComment("World that this level applies in. String.") + @Expose + private String world = ""; + + @ConfigComment("") + @ConfigComment("The ordering of the level, lowest to highest") + @Expose + private int order; + + @ConfigComment("") + @ConfigComment("The number of undone challenges that can be left on this level before") + @ConfigComment("unlocking next level.") + @Expose + private int waiverAmount = 1; + + @ConfigComment("") + @ConfigComment("The message shown when unlocking this level. Single line string.") + @Expose private String unlockMessage = ""; - - @ConfigComment("Unlock reward description") - private String rewardDescription = ""; - - @ConfigComment("List of reward itemstacks") - private List rewardItems; - - @ConfigComment("Unlock experience reward") - private int expReward; - - @ConfigComment("Unlock money reward") - private int moneyReward; - - public String getFriendlyName() { - return friendlyName; - } - public List getRewardCommands() { - return rewardCommands = new ArrayList<>(); - } + @ConfigComment("") + @ConfigComment("") + @ConfigComment("If this is blank, the reward text will be auto-generated, otherwise") + @ConfigComment("this will be used.") + @Expose + private String rewardText = ""; + + @ConfigComment("") + @ConfigComment("List of items the player will receive on completing level.") + @ConfigComment("ItemStack List.") + @Expose + private List rewardItems = new ArrayList<>(); + + @ConfigComment("") + @ConfigComment("Experience point reward on completing level.") + @Expose + private int rewardExperience = 0; + + @ConfigComment("") + @ConfigComment("Money reward. Economy plugin or addon required for this option.") + @Expose + private int rewardMoney = 0; + + @ConfigComment("") + @ConfigComment("Commands to run when the player completes all challenges in current") + @ConfigComment("level. String List") + @Expose + private List rewardCommands = new ArrayList<>(); + + @ConfigComment("") + @ConfigComment("Set of all challenges that is linked with current level.") + @ConfigComment("String Set") + @Expose + private Set challenges = new HashSet<>(); + + +// --------------------------------------------------------------------- +// Section: Getters +// --------------------------------------------------------------------- + + + /** + * This method returns the uniqueId value. + * @return the value of uniqueId. + * @see DataObject#getUniqueId() + */ @Override - public String getUniqueId() { + public String getUniqueId() + { return uniqueId; } + /** - * Get the number of undone tasks that can be left on a level before unlocking next level - * @return + * This method returns the friendlyName value. + * @return the value of friendlyName. */ - public int getWaiveramount() { - return waiveramount; + public String getFriendlyName() + { + return friendlyName; } - public void setFriendlyName(String friendlyName) { - this.friendlyName = friendlyName; + + /** + * This method returns the icon value. + * @return the value of icon. + */ + public ItemStack getIcon() + { + return icon; } - public void setRewardCommands(List rewardCommands) { - this.rewardCommands = rewardCommands; + + /** + * This method returns the world value. + * @return the value of world. + */ + public String getWorld() + { + return world; } - @Override - public void setUniqueId(String uniqueId) { - this.uniqueId = uniqueId; - } - public void setWaiveramount(int waiveramount) { - this.waiveramount = waiveramount; - } - - public int getOrder() { + /** + * This method returns the order value. + * @return the value of order. + */ + public int getOrder() + { return order; } - public void setOrder(int order) { - this.order = order; - } - - @Override - public int compareTo(ChallengeLevel o) { - return Integer.compare(this.order, o.order); - } - - /** - * @return the rewardDescription - */ - public String getRewardDescription() { - return rewardDescription; - } /** - * @param rewardDescription the rewardDescription to set + * This method returns the waiverAmount value. + * @return the value of waiverAmount. */ - public void setRewardDescription(String rewardDescription) { - this.rewardDescription = rewardDescription; + public int getWaiverAmount() + { + return waiverAmount; } - /** - * @return the rewardItems - */ - public List getRewardItems() { - return rewardItems; - } /** - * @param rewardItems the rewardItems to set + * This method returns the unlockMessage value. + * @return the value of unlockMessage. */ - public void setRewardItems(List rewardItems) { - this.rewardItems = rewardItems; - } - - /** - * @return the expReward - */ - public int getExpReward() { - return expReward; - } - - /** - * @param expReward the expReward to set - */ - public void setExpReward(int expReward) { - this.expReward = expReward; - } - - /** - * @return the moneyReward - */ - public int getMoneyReward() { - return moneyReward; - } - - /** - * @param moneyReward the moneyReward to set - */ - public void setMoneyReward(int moneyReward) { - this.moneyReward = moneyReward; - } - - /** - * @return the unlockMessage - */ - public String getUnlockMessage() { + public String getUnlockMessage() + { return unlockMessage; } + /** - * @param unlockMessage the unlockMessage to set + * This method returns the rewardText value. + * @return the value of rewardText. */ - public void setUnlockMessage(String unlockMessage) { + public String getRewardText() + { + return rewardText; + } + + + /** + * This method returns the rewardItems value. + * @return the value of rewardItems. + */ + public List getRewardItems() + { + return rewardItems; + } + + + /** + * This method returns the rewardExperience value. + * @return the value of rewardExperience. + */ + public int getRewardExperience() + { + return rewardExperience; + } + + + /** + * This method returns the rewardMoney value. + * @return the value of rewardMoney. + */ + public int getRewardMoney() + { + return rewardMoney; + } + + + /** + * This method returns the rewardCommands value. + * @return the value of rewardCommands. + */ + public List getRewardCommands() + { + return rewardCommands; + } + + + /** + * This method returns the challenges value. + * @return the value of challenges. + */ + public Set getChallenges() + { + return challenges; + } + + +// --------------------------------------------------------------------- +// Section: Setters +// --------------------------------------------------------------------- + + + /** + * This method sets the uniqueId value. + * @param uniqueId the uniqueId new value. + * + * @see DataObject#setUniqueId(String) + */ + @Override + public void setUniqueId(String uniqueId) + { + this.uniqueId = uniqueId; + } + + + /** + * This method sets the friendlyName value. + * @param friendlyName the friendlyName new value. + * + */ + public void setFriendlyName(String friendlyName) + { + this.friendlyName = friendlyName; + } + + + /** + * This method sets the icon value. + * @param icon the icon new value. + * + */ + public void setIcon(ItemStack icon) + { + this.icon = icon; + } + + + /** + * This method sets the world value. + * @param world the world new value. + * + */ + public void setWorld(String world) + { + this.world = world; + } + + + /** + * This method sets the order value. + * @param order the order new value. + * + */ + public void setOrder(int order) + { + this.order = order; + } + + + /** + * This method sets the waiverAmount value. + * @param waiverAmount the waiverAmount new value. + * + */ + public void setWaiverAmount(int waiverAmount) + { + this.waiverAmount = waiverAmount; + } + + + /** + * This method sets the unlockMessage value. + * @param unlockMessage the unlockMessage new value. + * + */ + public void setUnlockMessage(String unlockMessage) + { this.unlockMessage = unlockMessage; } - /** - * @return the worlds - */ - public List getWorlds() { - return worlds; - } /** - * @param worlds the worlds to set + * This method sets the rewardText value. + * @param rewardText the rewardText new value. + * */ - public void setWorlds(List worlds) { - this.worlds = worlds; + public void setRewardText(String rewardText) + { + this.rewardText = rewardText; } - /* (non-Javadoc) - * @see java.lang.Object#hashCode() + + /** + * This method sets the rewardItems value. + * @param rewardItems the rewardItems new value. + * + */ + public void setRewardItems(List rewardItems) + { + this.rewardItems = rewardItems; + } + + + /** + * This method sets the rewardExperience value. + * @param rewardExperience the rewardExperience new value. + * + */ + public void setRewardExperience(int rewardExperience) + { + this.rewardExperience = rewardExperience; + } + + + /** + * This method sets the rewardMoney value. + * @param rewardMoney the rewardMoney new value. + * + */ + public void setRewardMoney(int rewardMoney) + { + this.rewardMoney = rewardMoney; + } + + + /** + * This method sets the rewardCommands value. + * @param rewardCommands the rewardCommands new value. + * + */ + public void setRewardCommands(List rewardCommands) + { + this.rewardCommands = rewardCommands; + } + + + /** + * This method sets the challenges value. + * @param challenges the challenges new value. + * + */ + public void setChallenges(Set challenges) + { + this.challenges = challenges; + } + + +// --------------------------------------------------------------------- +// Section: Other methods +// --------------------------------------------------------------------- + + + /** + * {@inheritDoc} */ @Override - public int hashCode() { + public int compareTo(ChallengeLevel o) + { + if (this.equals(o)) + { + return 0; + } + else + { + if (this.getWorld().equals(o.getWorld())) + { + if (this.order == o.getOrder()) + { + return this.getUniqueId().compareTo(o.getUniqueId()); + } + else + { + return Integer.compare(this.order, o.getOrder()); + } + } + else + { + return this.getWorld().compareTo(o.getWorld()); + } + } + } + + + /** + * {@inheritDoc} + */ + @Override + public int hashCode() + { final int prime = 31; int result = 1; result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); return result; } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) + + + /** + * {@inheritDoc} */ @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object obj) + { + if (this == obj) + { return true; } - if (obj == null) { - return false; - } - if (!(obj instanceof ChallengeLevel)) { + + if (!(obj instanceof ChallengeLevel)) + { return false; } + ChallengeLevel other = (ChallengeLevel) obj; - if (uniqueId == null) { - if (other.uniqueId != null) { - return false; - } - } else if (!uniqueId.equals(other.uniqueId)) { - return false; + + if (uniqueId == null) + { + return other.uniqueId == null; + } + else + { + return uniqueId.equals(other.uniqueId); } - return true; } - - - public ItemStack getIcon() - { - return null; - } - - - public void setIcon(ItemStack newIcon) - { - - } -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java b/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java index fd62f9f..afc84a0 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java @@ -1,6 +1,3 @@ -/** - * - */ package world.bentobox.challenges.database.object; import java.util.HashMap; @@ -20,173 +17,265 @@ import world.bentobox.bentobox.util.Util; * @author tastybento * */ -public class ChallengesPlayerData implements DataObject { +public class ChallengesPlayerData implements DataObject +{ + /** + * Constructor ChallengesPlayerData creates a new ChallengesPlayerData instance. + */ + public ChallengesPlayerData() + { + } - @Expose - private String uniqueId = ""; - /** - * Challenge map, where key = unique challenge name and Value = number of times completed - */ - @Expose - private Map challengeStatus = new HashMap<>(); - @Expose - private Map challengesTimestamp = new HashMap<>(); - @Expose - private Set levelsDone = new HashSet<>(); - // Required for bean instantiation - public ChallengesPlayerData() {} + /** + * Creates a player data entry + * + * @param uniqueId - the player's UUID in string format + */ + public ChallengesPlayerData(String uniqueId) + { + this.uniqueId = uniqueId; + } - /** - * Mark a challenge as having been completed. Will increment the number of times and timestamp - * @param world - world of challenge - * @param challengeName - unique challenge name - */ - public void setChallengeDone(World world, String challengeName) { - String name = Util.getWorld(world).getName() + challengeName; - int times = challengeStatus.getOrDefault(name, 0) + 1; - challengeStatus.put(name, times); - challengesTimestamp.put(name, System.currentTimeMillis()); - } - /** - * Set the number of times a challenge has been done - * @param world - world of challenge - * @param challengeName - unique challenge name - * @param times - the number of times to set - * - */ - public void setChallengeTimes(World world, String challengeName, int times) { - String name = Util.getWorld(world).getName() + challengeName; - challengeStatus.put(name, times); - challengesTimestamp.put(name, System.currentTimeMillis()); - } +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- - /** - * Check if a challenge has been done - * @param challengeName - unique challenge name - * @return true if done at least once - */ - public boolean isChallengeDone(World world, String challengeName) { - return getTimes(world, challengeName) > 0; - } - /** - * Check how many times a challenge has been done - * @param challengeName - unique challenge name - * @return - number of times - */ - public int getTimes(World world, String challengeName) { - return challengeStatus.getOrDefault(Util.getWorld(world).getName() + challengeName, 0); - } + /** + * This variable stores each player UUID as string. + */ + @Expose + private String uniqueId = ""; - /** - * Creates a player data entry - * @param uniqueId - the player's UUID in string format - */ - public ChallengesPlayerData(String uniqueId) { - this.uniqueId = uniqueId; - } + /** + * Challenge map, where key = unique challenge name and Value = number of times + * completed + */ + @Expose + private Map challengeStatus = new HashMap<>(); - /* (non-Javadoc) - * @see world.bentobox.bbox.database.objects.DataObject#getUniqueId() - */ - @Override - public String getUniqueId() { - return uniqueId; - } + /** + * Map of challenges completion time where key is challenges unique id and value is + * timestamp when challenge was completed last time. + */ + @Expose + private Map challengesTimestamp = new HashMap<>(); - /* (non-Javadoc) - * @see world.bentobox.bbox.database.objects.DataObject#setUniqueId(java.lang.String) - */ - @Override - public void setUniqueId(String uniqueId) { - this.uniqueId = uniqueId; - } + /** + * Set of Strings that contains all challenge levels that are completed. + */ + @Expose + private Set levelsDone = new HashSet<>(); - /** - * @return the challengeStatus - */ - public Map getChallengeStatus() { - return challengeStatus; - } - /** - * @param challengeStatus the challengeStatus to set - */ - public void setChallengeStatus(Map challengeStatus) { - this.challengeStatus = challengeStatus; - } - /** - * @return the challengesTimestamp - */ - public Map getChallengesTimestamp() { - return challengesTimestamp; - } - /** - * @param challengesTimestamp the challengesTimestamp to set - */ - public void setChallengesTimestamp(Map challengesTimestamp) { - this.challengesTimestamp = challengesTimestamp; - } - /** - * @return the levelsDone - */ - public Set getLevelsDone() { - return levelsDone; - } - /** - * @param levelsDone the levelsDone to set - */ - public void setLevelsDone(Set levelsDone) { - this.levelsDone = levelsDone; - } +// --------------------------------------------------------------------- +// Section: Getters +// --------------------------------------------------------------------- - /* (non-Javadoc) - * @see java.lang.Object#hashCode() - */ - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); - return result; - } - /* (non-Javadoc) - * @see java.lang.Object#equals(java.lang.Object) - */ - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof ChallengesPlayerData)) { - return false; - } - ChallengesPlayerData other = (ChallengesPlayerData) obj; - if (uniqueId == null) { - if (other.uniqueId != null) { - return false; - } - } else if (!uniqueId.equals(other.uniqueId)) { - return false; - } - return true; - } + /** + * @return uniqueID + * @see DataObject#getUniqueId() + */ + @Override + public String getUniqueId() + { + return uniqueId; + } - /** - * Resets all challenges and levels in world for this player - * @param world - */ - public void reset(World world) { - String worldName = Util.getWorld(world).getName(); - challengeStatus.keySet().removeIf(n -> n.startsWith(worldName)); - challengesTimestamp.keySet().removeIf(n -> n.startsWith(worldName)); - levelsDone.removeIf(n -> n.startsWith(worldName)); - } -} + /** + * This method returns the challengeStatus value. + * @return the value of challengeStatus. + */ + public Map getChallengeStatus() + { + return challengeStatus; + } + + + /** + * This method returns the challengesTimestamp value. + * @return the value of challengesTimestamp. + */ + public Map getChallengesTimestamp() + { + return challengesTimestamp; + } + + + /** + * This method returns the levelsDone value. + * @return the value of levelsDone. + */ + public Set getLevelsDone() + { + return levelsDone; + } + + +// --------------------------------------------------------------------- +// Section: Setters +// --------------------------------------------------------------------- + + + /** + * @param uniqueId - unique ID the uniqueId to set + * @see DataObject#setUniqueId(String) + */ + @Override + public void setUniqueId(String uniqueId) + { + this.uniqueId = uniqueId; + } + + + /** + * This method sets the challengeStatus value. + * @param challengeStatus the challengeStatus new value. + * + */ + public void setChallengeStatus(Map challengeStatus) + { + this.challengeStatus = challengeStatus; + } + + + /** + * This method sets the challengesTimestamp value. + * @param challengesTimestamp the challengesTimestamp new value. + * + */ + public void setChallengesTimestamp(Map challengesTimestamp) + { + this.challengesTimestamp = challengesTimestamp; + } + + + /** + * This method sets the levelsDone value. + * @param levelsDone the levelsDone new value. + * + */ + public void setLevelsDone(Set levelsDone) + { + this.levelsDone = levelsDone; + } + + +// --------------------------------------------------------------------- +// Section: Other Methods +// --------------------------------------------------------------------- + + + /** + * Resets all challenges and levels in world for this player + * + * @param world world which challenges must be reset. + */ + public void reset(World world) + { + String worldName = Util.getWorld(world).getName(); + challengeStatus.keySet().removeIf(n -> n.startsWith(worldName)); + challengesTimestamp.keySet().removeIf(n -> n.startsWith(worldName)); + levelsDone.removeIf(n -> n.startsWith(worldName)); + } + + + /** + * Mark a challenge as having been completed. Will increment the number of times and + * timestamp + * + * @param challengeName - unique challenge name + */ + public void setChallengeDone(String challengeName) + { + int times = challengeStatus.getOrDefault(challengeName, 0) + 1; + challengeStatus.put(challengeName, times); + challengesTimestamp.put(challengeName, System.currentTimeMillis()); + } + + + /** + * Set the number of times a challenge has been done + * + * @param challengeName - unique challenge name + * @param times - the number of times to set + */ + public void setChallengeTimes(String challengeName, int times) + { + challengeStatus.put(challengeName, times); + challengesTimestamp.put(challengeName, System.currentTimeMillis()); + } + + + /** + * Check if a challenge has been done + * + * @param challengeName - unique challenge name + * @return true if done at least once + */ + public boolean isChallengeDone(String challengeName) + { + return this.getTimes(challengeName) > 0; + } + + + /** + * Check how many times a challenge has been done + * + * @param challengeName - unique challenge name + * @return - number of times + */ + public int getTimes(String challengeName) + { + return challengeStatus.getOrDefault(challengeName, 0); + } + + + /** + * @see Object#hashCode() + * @return object hashCode value. + */ + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); + return result; + } + + + /** + * @see java.lang.Object#equals(java.lang.Object) + * @param obj Other object. + * @return boolean that indicate if objects are equals. + */ + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + + if (!(obj instanceof ChallengesPlayerData)) + { + return false; + } + + ChallengesPlayerData other = (ChallengesPlayerData) obj; + + if (uniqueId == null) + { + return other.uniqueId == null; + } + else + { + return uniqueId.equals(other.uniqueId); + } + } +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java index ff58d80..f021c74 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java @@ -85,7 +85,6 @@ public class ChallengesPanels { * Creates a panel item for challenge if appropriate and adds it to panelBuilder * @param panelBuilder * @param challenge - * @param user */ private void createItem(PanelBuilder panelBuilder, Challenge challenge) { // Check completion @@ -100,16 +99,13 @@ public class ChallengesPanels { .description(challengeDescription(challenge)) .glow(completed) .clickHandler((panel, player, c, s) -> { - if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { - new TryToComplete(addon).user(player).manager(manager).challenge(challenge) + new TryToComplete(addon).user(player).manager(manager).challenge(challenge) .world(world).permPrefix(permPrefix).label(label).build(); - //new TryToComplete(addon, player, manager, challenge, world, permPrefix, label); - } return true; }) .build(); - if (challenge.getSlot() >= 0) { - panelBuilder.item(challenge.getSlot(),item); + if (challenge.getOrder() >= 0) { + panelBuilder.item(challenge.getOrder(),item); } else { panelBuilder.item(item); } @@ -161,7 +157,6 @@ public class ChallengesPanels { * Creates the challenge description for the "item" in the inventory * * @param challenge - * @param player * @return List of strings splitting challenge string into 25 chars long */ private List challengeDescription(Challenge challenge) { @@ -210,7 +205,7 @@ public class ChallengesPanels { // First time moneyReward = challenge.getRewardMoney(); rewardText = challenge.getRewardText(); - expReward = challenge.getRewardExp(); + expReward = challenge.getRewardExperience(); if (!rewardText.isEmpty()) { result.addAll(splitTrans(user, "challenges.first-time-rewards")); } @@ -218,7 +213,7 @@ public class ChallengesPanels { // Repeat challenge moneyReward = challenge.getRepeatMoneyReward(); rewardText = challenge.getRepeatRewardText(); - expReward = challenge.getRepeatExpReward(); + expReward = challenge.getRepeatExperienceReward(); if (!rewardText.isEmpty()) { result.addAll(splitTrans(user, "challenges.repeat-rewards")); } diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index f52bf72..2f215c6 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -107,7 +107,6 @@ public class ChallengesPanels2 { * Creates a panel item for challenge if appropriate and adds it to panelBuilder * @param panelBuilder * @param challenge - * @param requester */ private void createItem(PanelBuilder panelBuilder, Challenge challenge) { // For admin, glow means activated. For user, glow means done @@ -138,33 +137,27 @@ public class ChallengesPanels2 { if (mode.equals(Mode.ADMIN)) { // Admin click itemBuilder.clickHandler((panel, player, c, s) -> { - if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { - new AdminGUI(addon, player, challenge, world, permPrefix, label); - } + new AdminGUI(addon, player, challenge, world, permPrefix, label); return true; }); } else if (mode.equals(Mode.EDIT)) { // Admin edit click itemBuilder.clickHandler((panel, player, c, s) -> { - if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { - new AdminEditGUI(addon, player, target, challenge, world, permPrefix, label); - } + new AdminEditGUI(addon, player, target, challenge, world, permPrefix, label); return true; }); } else { // Player click itemBuilder.clickHandler((panel, player, c, s) -> { - if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { - new TryToComplete(addon, player, manager, challenge, world, permPrefix, label); - } + new TryToComplete(addon, player, manager, challenge, world, permPrefix, label); return true; }); } // If the challenge has a specific slot allocated, use it - if (challenge.getSlot() >= 0) { - panelBuilder.item(challenge.getSlot(),itemBuilder.build()); + if (challenge.getOrder() >= 0) { + panelBuilder.item(challenge.getOrder(),itemBuilder.build()); } else { panelBuilder.item(itemBuilder.build()); } @@ -216,7 +209,6 @@ public class ChallengesPanels2 { * Creates the challenge description for the "item" in the inventory * * @param challenge - * @param player * @return List of strings splitting challenge string into 25 chars long */ private List challengeDescription(Challenge challenge) { @@ -287,7 +279,7 @@ public class ChallengesPanels2 { // First time moneyReward = challenge.getRewardMoney(); rewardText = challenge.getRewardText(); - expReward = challenge.getRewardExp(); + expReward = challenge.getRewardExperience(); if (!rewardText.isEmpty()) { result.addAll(splitTrans(requester, "challenges.first-time-rewards")); } @@ -296,7 +288,7 @@ public class ChallengesPanels2 { // Repeat challenge moneyReward = challenge.getRepeatMoneyReward(); rewardText = challenge.getRepeatRewardText(); - expReward = challenge.getRepeatExpReward(); + expReward = challenge.getRepeatExperienceReward(); if (!rewardText.isEmpty()) { result.addAll(splitTrans(requester, "challenges.repeat-rewards")); } diff --git a/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java b/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java index 9e69652..76ff526 100644 --- a/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java +++ b/src/main/java/world/bentobox/challenges/panel/RequiredPanel.java @@ -73,7 +73,7 @@ public class RequiredPanel implements ClickHandler, PanelListener { .clickHandler(this) .build()).forEach(pb::item); return pb.user(user).build(); - case LEVEL: + case OTHER: break; default: @@ -137,8 +137,6 @@ public class RequiredPanel implements ClickHandler, PanelListener { } // Save changes switch (challenge.getChallengeType()) { - case ICON: - break; case INVENTORY: List reqItems = new ArrayList<>(); // Skip first item @@ -154,7 +152,7 @@ public class RequiredPanel implements ClickHandler, PanelListener { break; case ISLAND: break; - case LEVEL: + case OTHER: break; default: break; diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index c5012f9..ffe8709 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -97,7 +97,7 @@ public class TryToComplete { vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney())); // Give exp - user.getPlayer().giveExp(challenge.getRewardExp()); + user.getPlayer().giveExp(challenge.getRewardExperience()); // Run commands runCommands(challenge.getRewardCommands()); user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); @@ -118,7 +118,7 @@ public class TryToComplete { vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward())); // Give exp - user.getPlayer().giveExp(challenge.getRepeatExpReward()); + user.getPlayer().giveExp(challenge.getRepeatExperienceReward()); // Run commands runCommands(challenge.getRepeatRewardCommands()); user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); @@ -162,7 +162,7 @@ public class TryToComplete { vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney())); // Give exp - user.getPlayer().giveExp(challenge.getRewardExp()); + user.getPlayer().giveExp(challenge.getRewardExperience()); // Run commands runCommands(challenge.getRewardCommands()); user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); @@ -183,7 +183,7 @@ public class TryToComplete { vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward())); // Give exp - user.getPlayer().giveExp(challenge.getRepeatExpReward()); + user.getPlayer().giveExp(challenge.getRepeatExperienceReward()); // Run commands runCommands(challenge.getRepeatRewardCommands()); user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); @@ -199,7 +199,7 @@ public class TryToComplete { */ private ChallengeResult checkIfCanCompleteChallenge() { // Check the world - if (!Util.getWorld(user.getWorld()).getName().equalsIgnoreCase(challenge.getWorld())) { + if (!challenge.getUniqueId().startsWith(Util.getWorld(world).getName())) { user.sendMessage("general.errors.wrong-world"); return new ChallengeResult(); } @@ -215,7 +215,7 @@ public class TryToComplete { } // Check repeatability if (manager.isChallengeComplete(user, challenge.getUniqueId(), world) - && (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.LEVEL) + && (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.OTHER) || challenge.getChallengeType().equals(ChallengeType.ISLAND))) { user.sendMessage("challenges.not-repeatable"); return new ChallengeResult(); @@ -226,24 +226,24 @@ public class TryToComplete { if (vaultHook.isPresent()) { - if (!vaultHook.get().has(this.user, this.challenge.getReqMoney())) + if (!vaultHook.get().has(this.user, this.challenge.getRequiredMoney())) { - this.user.sendMessage("challenges.not-enough-money", "[money]", Integer.toString(this.challenge.getReqMoney())); + this.user.sendMessage("challenges.not-enough-money", "[money]", Integer.toString(this.challenge.getRequiredMoney())); return new ChallengeResult(); } } // Check exp - if (this.user.getPlayer().getTotalExperience() < this.challenge.getReqExp()) + if (this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience()) { - this.user.sendMessage("challenges.not-enough-exp", "[xp]", Integer.toString(this.challenge.getReqExp())); + this.user.sendMessage("challenges.not-enough-exp", "[xp]", Integer.toString(this.challenge.getRequiredExperience())); return new ChallengeResult(); } switch (challenge.getChallengeType()) { case INVENTORY: return checkInventory(); - case LEVEL: + case OTHER: return checkLevel(); case ISLAND: return checkSurrounding(); @@ -303,9 +303,9 @@ public class TryToComplete { if (vaultHook.isPresent() && this.challenge.isTakeMoney() && - this.challenge.getReqMoney() > 0) + this.challenge.getRequiredMoney() > 0) { - vaultHook.get().withdraw(this.user, this.challenge.getReqMoney()); + vaultHook.get().withdraw(this.user, this.challenge.getRequiredMoney()); } } @@ -346,12 +346,12 @@ public class TryToComplete { // Check if the level addon is installed or not long level = addon.getAddonByName("Level") .map(l -> ((Level)l).getIslandLevel(world, user.getUniqueId())).orElse(0L); - if (level >= challenge.getReqIslandlevel()) { + if (level >= challenge.getRequiredIslandLevel()) { // process money removal this.removeMoney(); return new ChallengeResult().setMeetsRequirements(); } else { - user.sendMessage("challenges.error.island-level", TextVariables.NUMBER, String.valueOf(challenge.getReqIslandlevel())); + user.sendMessage("challenges.error.island-level", TextVariables.NUMBER, String.valueOf(challenge.getRequiredIslandLevel())); return new ChallengeResult(); } } @@ -428,7 +428,6 @@ public class TryToComplete { private boolean meetsRequirements; private boolean repeat; /** - * @param meetsRequirements the meetsRequirements to set */ public ChallengeResult setMeetsRequirements() { this.meetsRequirements = true; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 5271864..203b3c6 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -102,7 +102,7 @@ public class EditChallengeGUI extends CommonGUI case ISLAND: this.buildIslandRequirementsPanel(panelBuilder); break; - case LEVEL: + case OTHER: this.buildOtherRequirementsPanel(panelBuilder); break; } @@ -320,7 +320,7 @@ public class EditChallengeGUI extends CommonGUI { icon = new ItemStack(Material.CHEST); } - else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.LEVEL)) + else if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.OTHER)) { icon = new ItemStack(Material.EXPERIENCE_BOTTLE); } @@ -427,13 +427,13 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.order", "[value]", - Integer.toString(this.challenge.getSlot()))); + Integer.toString(this.challenge.getOrder()))); icon = new ItemStack(Material.DROPPER); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getSlot(), -1, 54, (status, value) -> { + new NumberGUI(this.user, this.challenge.getOrder(), -1, 54, (status, value) -> { if (status) { - this.challenge.setSlot(value); + this.challenge.setOrder(value); } this.build(); @@ -640,13 +640,13 @@ public class EditChallengeGUI extends CommonGUI case REQUIRED_PERMISSIONS: { name = this.user.getTranslation("challenges.gui.admin.buttons.permissions"); - description = new ArrayList<>(this.challenge.getReqPerms()); + description = new ArrayList<>(this.challenge.getRequiredPermissions()); icon = new ItemStack(Material.REDSTONE_LAMP); clickHandler = (panel, user, clickType, slot) -> { - new StringListGUI(this.user, this.challenge.getReqPerms(), (status, value) -> { + new StringListGUI(this.user, this.challenge.getRequiredPermissions(), (status, value) -> { if (status) { - this.challenge.setReqPerms(new HashSet<>(value)); + this.challenge.setRequiredPermissions(new HashSet<>(value)); } this.build(); @@ -713,13 +713,13 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.required-exp", "[value]", - Integer.toString(this.challenge.getMaxTimes()))); + Integer.toString(this.challenge.getRequiredExperience()))); icon = new ItemStack(Material.EXPERIENCE_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getReqExp(), 0, (status, value) -> { + new NumberGUI(this.user, this.challenge.getRequiredExperience(), 0, (status, value) -> { if (status) { - this.challenge.setReqExp(value); + this.challenge.setRequiredExperience(value); } this.build(); @@ -758,13 +758,13 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.required-level", "[value]", - Long.toString(this.challenge.getReqIslandlevel()))); + Long.toString(this.challenge.getRequiredIslandLevel()))); icon = new ItemStack(Material.BEACON); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, (int) this.challenge.getReqIslandlevel(), (status, value) -> { + new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> { if (status) { - this.challenge.setReqIslandlevel(value); + this.challenge.setRequiredIslandLevel(value); } this.build(); @@ -781,13 +781,13 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.required-money", "[value]", - Integer.toString(this.challenge.getReqMoney()))); + Integer.toString(this.challenge.getRequiredMoney()))); icon = new ItemStack(Material.GOLD_INGOT); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getReqMoney(), 0, (status, value) -> { + new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> { if (status) { - this.challenge.setReqMoney(value); + this.challenge.setRequiredMoney(value); } this.build(); @@ -874,13 +874,13 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp", "[value]", - Integer.toString(this.challenge.getRewardExp()))); + Integer.toString(this.challenge.getRewardExperience()))); icon = new ItemStack(Material.EXPERIENCE_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getReqExp(), 0, (status, value) -> { + new NumberGUI(this.user, this.challenge.getRewardExperience(), 0, (status, value) -> { if (status) { - this.challenge.setRewardExp(value); + this.challenge.setRewardExperience(value); } this.build(); @@ -1035,13 +1035,13 @@ public class EditChallengeGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-exp", "[value]", - Integer.toString(this.challenge.getRepeatExpReward()))); + Integer.toString(this.challenge.getRepeatExperienceReward()))); icon = new ItemStack(Material.GLASS_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRepeatExpReward(), 0, (status, value) -> { + new NumberGUI(this.user, this.challenge.getRepeatExperienceReward(), 0, (status, value) -> { if (status) { - this.challenge.setRepeatExpReward(value); + this.challenge.setRepeatExperienceReward(value); } this.build(); @@ -1234,4 +1234,4 @@ public class EditChallengeGUI extends CommonGUI * Variable holds current active menu. */ private MenuType currentMenuType; -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 912aa87..fbcf53c 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -398,13 +398,13 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.waiver-amount", "[value]", - Integer.toString(this.challengeLevel.getWaiveramount()))); + Integer.toString(this.challengeLevel.getWaiverAmount()))); icon = new ItemStack(Material.REDSTONE_TORCH); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getWaiveramount(), 0, (status, value) -> { + new NumberGUI(this.user, this.challengeLevel.getWaiverAmount(), 0, (status, value) -> { if (status) { - this.challengeLevel.setWaiveramount(value); + this.challengeLevel.setWaiverAmount(value); } this.build(); @@ -419,14 +419,14 @@ public class EditLevelGUI extends CommonGUI case REWARD_DESCRIPTION: { name = this.user.getTranslation("challenges.gui.admin.buttons.reward-text"); - description = Collections.singletonList(this.challengeLevel.getRewardDescription()); + description = Collections.singletonList(this.challengeLevel.getRewardText()); icon = new ItemStack(Material.WRITTEN_BOOK); clickHandler = (panel, user, clickType, slot) -> { new AnvilGUI(this.addon.getPlugin(), this.user.getPlayer(), - this.challengeLevel.getRewardDescription(), + this.challengeLevel.getRewardText(), (player, reply) -> { - this.challengeLevel.setRewardDescription(reply); + this.challengeLevel.setRewardText(reply); this.build(); return reply; }); @@ -468,13 +468,13 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.reward-exp", "[value]", - Integer.toString(this.challengeLevel.getExpReward()))); + Integer.toString(this.challengeLevel.getRewardExperience()))); icon = new ItemStack(Material.EXPERIENCE_BOTTLE); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getExpReward(), 0, (status, value) -> { + new NumberGUI(this.user, this.challengeLevel.getRewardExperience(), 0, (status, value) -> { if (status) { - this.challengeLevel.setExpReward(value); + this.challengeLevel.setRewardExperience(value); } this.build(); @@ -491,13 +491,13 @@ public class EditLevelGUI extends CommonGUI description = Collections.singletonList( this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", "[value]", - Integer.toString(this.challengeLevel.getMoneyReward()))); + Integer.toString(this.challengeLevel.getRewardMoney()))); icon = new ItemStack(Material.GOLD_INGOT); clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getMoneyReward(), 0, (status, value) -> { + new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> { if (status) { - this.challengeLevel.setMoneyReward(value); + this.challengeLevel.setRewardMoney(value); } this.build(); @@ -544,7 +544,7 @@ public class EditLevelGUI extends CommonGUI new SelectChallengeGUI(this.user, challengeList, (status, value) -> { if (status) { - manager.linkChallenge(this.challengeLevel, value); + manager.addChallengeToLevel(value, this.challengeLevel); } this.build(); @@ -636,4 +636,4 @@ public class EditLevelGUI extends CommonGUI * Variable holds current active menu. */ private MenuType currentMenuType; -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index 098fe0a..894bd75 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -443,13 +443,13 @@ public class ChallengesGUI extends CommonGUI { rewardText = challenge.getRewardText(); rewardMoney = challenge.getRewardMoney(); - rewardExperience = challenge.getRewardExp(); + rewardExperience = challenge.getRewardExperience(); } else { rewardText = challenge.getRepeatRewardText(); rewardMoney = challenge.getRepeatMoneyReward(); - rewardExperience = challenge.getRepeatExpReward(); + rewardExperience = challenge.getRepeatExperienceReward(); } List result = new ArrayList<>(); From 1bc6bb2b767ae39605d49a7fb66240eeb5dcba8a Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 16:34:37 +0200 Subject: [PATCH 069/103] Move LevelStatus to utils, as it is more Util then necessary class object. --- src/main/java/world/bentobox/challenges/ChallengesManager.java | 2 ++ .../java/world/bentobox/challenges/panel/ChallengesPanels.java | 2 +- .../java/world/bentobox/challenges/panel/ChallengesPanels2.java | 2 +- .../world/bentobox/challenges/panel/user/ChallengesGUI.java | 2 +- .../java/world/bentobox/challenges/{ => utils}/LevelStatus.java | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) rename src/main/java/world/bentobox/challenges/{ => utils}/LevelStatus.java (97%) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 554faef..8941337 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -22,6 +22,8 @@ import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.challenges.database.object.ChallengesPlayerData; import world.bentobox.challenges.panel.ChallengesPanels; +import world.bentobox.challenges.utils.LevelStatus; + public class ChallengesManager { diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java index f021c74..6e80a53 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java @@ -11,7 +11,7 @@ import org.bukkit.inventory.ItemStack; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.LevelStatus; +import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge.ChallengeType; diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index 2f215c6..c432ce6 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.LevelStatus; +import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge.ChallengeType; diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index 894bd75..d021247 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -14,7 +14,7 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.LevelStatus; +import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.TryToComplete; diff --git a/src/main/java/world/bentobox/challenges/LevelStatus.java b/src/main/java/world/bentobox/challenges/utils/LevelStatus.java similarity index 97% rename from src/main/java/world/bentobox/challenges/LevelStatus.java rename to src/main/java/world/bentobox/challenges/utils/LevelStatus.java index f00e9aa..5e99cf2 100644 --- a/src/main/java/world/bentobox/challenges/LevelStatus.java +++ b/src/main/java/world/bentobox/challenges/utils/LevelStatus.java @@ -1,4 +1,4 @@ -package world.bentobox.challenges; +package world.bentobox.challenges.utils; import world.bentobox.challenges.database.object.ChallengeLevel; From 590b3f114cbcf65c53503bf585a0caad48e77c72 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 17:30:30 +0200 Subject: [PATCH 070/103] Rework ChallengesManager. Implement all methods that were only placeholders. Remove all unnecessary old methods. Implement new methods in all classes. User and Admin command now opens new GUI. --- .../challenges/ChallengesImportManager.java | 6 +- .../challenges/ChallengesManager.java | 1437 ++++++++++------- .../commands/ChallengesCommand.java | 10 +- .../challenges/commands/admin/Challenges.java | 13 +- .../commands/admin/CompleteChallenge.java | 6 +- .../commands/admin/ResetChallenge.java | 6 +- .../commands/admin/ShowChallenges.java | 2 +- .../admin/SurroundChallengeBuilder.java | 2 +- .../challenges/listeners/ResetListener.java | 3 +- .../challenges/listeners/SaveListener.java | 2 +- .../challenges/panel/ChallengesPanels.java | 28 +- .../challenges/panel/ChallengesPanels2.java | 32 +- .../panel/CreateChallengeListener.java | 2 +- .../challenges/panel/TryToComplete.java | 12 +- .../challenges/panel/admin/AdminGUI.java | 41 +- .../challenges/panel/admin/EditLevelGUI.java | 10 +- .../panel/admin/ListChallengesGUI.java | 2 +- .../challenges/panel/admin/ListLevelsGUI.java | 2 +- .../challenges/panel/admin/ListUsersGUI.java | 10 +- .../challenges/panel/user/ChallengesGUI.java | 8 +- .../bentobox/challenges/utils/GuiUtils.java | 27 +- 21 files changed, 981 insertions(+), 680 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index 8f4df1f..8040590 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -97,7 +97,7 @@ public class ChallengesImportManager challengeLevel.setRewardExperience(unlock.getInt("expReward")); challengeLevel.setRewardCommands(unlock.getStringList("commands")); } - addon.getChallengesManager().storeLevel(challengeLevel); + addon.getChallengesManager().loadLevel(challengeLevel, overwrite, user, false); } } else { user.sendMessage("challenges.admin.import.no-levels"); @@ -118,7 +118,7 @@ public class ChallengesImportManager newChallenge.setDeployed(true); ConfigurationSection details = chals.getConfigurationSection(challenge); newChallenge.setFriendlyName(details.getString("friendlyname", challenge)); - newChallenge.setDescription(addon.getChallengesManager().stringSplit(details.getString("description", ""))); + newChallenge.setDescription(GuiUtils.stringSplit(details.getString("description", ""))); newChallenge.setIcon(ItemParser.parse(details.getString("icon") + ":1")); newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); newChallenge.setTakeItems(details.getBoolean("takeItems",true)); @@ -149,7 +149,7 @@ public class ChallengesImportManager this.addon.getChallengesManager().addChallengeToLevel(newChallenge, addon.getChallengesManager().getLevel(Util.getWorld(world).getName() + "_" + details.getString("level"))); - if (addon.getChallengesManager().storeChallenge(newChallenge, overwrite, user, false)) { + if (addon.getChallengesManager().loadChallenge(newChallenge, overwrite, user, false)) { size++; } } diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 8941337..4112609 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -1,654 +1,915 @@ package world.bentobox.challenges; -import org.apache.commons.lang.WordUtils; -import org.bukkit.ChatColor; -import org.bukkit.Material; +import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.Player; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.ItemStack; import java.util.*; -import java.util.Map.Entry; import java.util.stream.Collectors; import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.util.Util; -import world.bentobox.challenges.commands.admin.SurroundChallengeBuilder; import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.Challenge; -import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.challenges.database.object.ChallengesPlayerData; -import world.bentobox.challenges.panel.ChallengesPanels; import world.bentobox.challenges.utils.LevelStatus; -public class ChallengesManager { +/** + * This class manges challenges. It allows access to all data that is stored to database. + * It also provides information about challenge level status for each user. + */ +public class ChallengesManager +{ +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- - public static final String FREE = "Free"; - private Map> challengeMap; - private Config chConfig; - private Config lvConfig; - private Database players; - private ChallengesPanels challengesPanels; - private Map playerData; - private ChallengesAddon addon; + /** + * This config object stores structures for challenge objects. + */ + private Database challengeDatabase; - public ChallengesManager(ChallengesAddon addon) { - this.addon = addon; - // Set up the configs - chConfig = new Config<>(addon, Challenge.class); - lvConfig = new Config<>(addon, ChallengeLevel.class); - // Players is where all the player history will be stored - players = new Database<>(addon, ChallengesPlayerData.class); - // Cache of challenges - challengeMap = new LinkedHashMap<>(); - // Cache of player data - playerData = new HashMap<>(); - load(); - } + /** + * This config object stores structures for challenge level objects. + */ + private Database levelDatabase; - /** - * Load player from database into the cache or create new player data - * @param user - user to add - */ - private void addPlayer(User user) { - if (playerData.containsKey(user.getUniqueId())) { - return; - } - // The player is not in the cache - // Check if the player exists in the database - if (players.objectExists(user.getUniqueId().toString())) { - // Load player from database - ChallengesPlayerData data = players.loadObject(user.getUniqueId().toString()); - // Store in cache - playerData.put(user.getUniqueId(), data); - } else { - // Create the player data - ChallengesPlayerData pd = new ChallengesPlayerData(user.getUniqueId().toString()); - players.saveObject(pd); - // Add to cache - playerData.put(user.getUniqueId(), pd); - } - } + /** + * This database allows to access player challenge data. + */ + private Database playersDatabase; - /** - * Check how many times a player has done a challenge before - * @param user - user - * @param challenge - challenge - * @return - number of times - */ - public long checkChallengeTimes(User user, Challenge challenge, World world) { - addPlayer(user); - return playerData.get(user.getUniqueId()).getTimes(challenge.getUniqueId()); - } + /** + * This is local cache that links challenge unique id with challenge object. + */ + private Map challengeCacheData; - /** - * Creates a simple example description of the requirements - * @param user - user of this command - * @param requiredItems - list of items - * @return Description list - */ - private List createDescription(User user, List requiredItems) { - addPlayer(user); - List result = new ArrayList<>(); - result.add(user.getTranslation("challenges.admin.create.description")); - for (ItemStack item : requiredItems) { - result.add(user.getTranslation("challenges.admin.create.description-item-color") + item.getAmount() + " x " + Util.prettifyText(item.getType().toString())); - } - return result; - } + /** + * This is local cache that links level unique id with level object. + */ + private Map levelCacheData; - /** - * Creates an inventory challenge - * @param user - the user who is making the challenge - * @param inventory - the inventory that will be used to make the challenge - */ - public boolean createInvChallenge(User user, Inventory inventory) { - addPlayer(user); - if (inventory.getContents().length == 0) { - return false; - } - Challenge newChallenge = new Challenge(); - newChallenge.setChallengeType(ChallengeType.INVENTORY); - newChallenge.setFriendlyName(inventory.getTitle()); - newChallenge.setDeployed(false); - List requiredItems = new ArrayList<>(); - inventory.forEach(item -> { - if (item != null && !item.getType().equals(Material.AIR)) { - requiredItems.add(item); - } - }); - newChallenge.setRequiredItems(requiredItems); - newChallenge.setTakeItems(true); - newChallenge.setUniqueId(inventory.getTitle()); - newChallenge.setIcon(new ItemStack(Material.MAP)); - newChallenge.setLevel(FREE); - newChallenge.setDescription(createDescription(user, requiredItems)); + /** + * This is local cache that links UUID with corresponding player challenge data. + */ + private Map playerCacheData; - // Move all the items back to the player's inventory - inventory.forEach(item -> { - if (item != null) { - Map residual = user.getInventory().addItem(item); - // Drop any residual items at the foot of the player - residual.forEach((k, v) -> user.getWorld().dropItem(user.getLocation(), v)); - } - }); - - // Save the challenge - if (!chConfig.saveConfigObject(newChallenge)) { - user.sendRawMessage(ChatColor.RED + "Challenge creation failed!"); - return false; - } - user.sendRawMessage("Success"); - return true; - } - - /** - * Create a surrounding challenge - * @param challengeInfo - info on the challenge from the builder - * @return true if successful, false if not - */ - public boolean createSurroundingChallenge(SurroundChallengeBuilder challengeInfo) { - if (challengeInfo.getReqBlocks().isEmpty() && challengeInfo.getReqEntities().isEmpty()) { - challengeInfo.getOwner().sendMessage("challenges.error.no-items-clicked"); - return false; - } - Challenge newChallenge = new Challenge(); - newChallenge.setChallengeType(ChallengeType.ISLAND); - newChallenge.setFriendlyName(challengeInfo.getName()); - newChallenge.setDeployed(true); - newChallenge.setRequiredBlocks(challengeInfo.getReqBlocks()); - newChallenge.setRequiredEntities(challengeInfo.getReqEntities()); - newChallenge.setUniqueId(challengeInfo.getName()); - newChallenge.setIcon(new ItemStack(Material.ARMOR_STAND)); - newChallenge.setLevel(FREE); - - // Save the challenge - if (!chConfig.saveConfigObject(newChallenge)) { - challengeInfo.getOwner().sendMessage("challenges.error.could-not-save"); - return false; - } - return true; - } - - /** - * Get the list of all challenge unique names. - * @return List of challenge names - */ - public List getAllChallengesList() { - List result = new ArrayList<>(); - challengeMap.values().forEach(ch -> ch.forEach(c -> result.add(c.getUniqueId()))); - return result; - } - - /** - * Get the list of all challenge unique names for world. - * @param world - the world to check - * @return List of challenge names - */ - public List getAllChallengesList(World world) { - List result = new ArrayList<>(); - challengeMap.values().forEach(ch -> ch.stream().filter(c -> c.getUniqueId().startsWith(Util.getWorld(world).getName())).forEach(c -> result.add(c.getUniqueId()))); - return result; - } - - /** - * Get challenge by name - * @param name - unique name of challenge - * @param world - world to check - * @return - challenge or null if it does not exist - */ - public Challenge getChallenge(String name, World world) { - String worldName = Util.getWorld(world).getName(); - for (Set ch : challengeMap.values()) { - Optional challenge = ch.stream().filter(c -> c.getUniqueId().equalsIgnoreCase(worldName + name)).findFirst(); - if (challenge.isPresent()) { - return challenge.get(); - } - } - return null; - } - - /** - * Get the status on every level - * @param user - user - * @param world - world to check - * @return Level status - how many challenges still to do on which level - */ - public List getChallengeLevelStatus(User user, World world) - { - this.addPlayer(user); - ChallengesPlayerData playerData = this.playerData.get(user.getUniqueId()); - List result = new ArrayList<>(); - - // The first level is always unlocked - ChallengeLevel previousLevel = null; - int doneChallengeCount = Integer.MAX_VALUE; - - // For each challenge level, check how many the user has done - for (Entry> entry : this.challengeMap.entrySet()) - { - // Check how much challenges must be done in previous level. - int challengesToDo = Math.max(0, entry.getKey().getWaiverAmount() - doneChallengeCount); - - doneChallengeCount = (int) entry.getValue().stream().filter( - ch -> playerData.isChallengeDone(ch.getUniqueId())).count(); - - // Create result class with the data - result.add(new LevelStatus( - entry.getKey(), - previousLevel, - challengesToDo, - entry.getValue().size() == doneChallengeCount, - challengesToDo <= 0)); - - // Set up the next level for the next loop - previousLevel = entry.getKey(); - } - - return result; - } - - /** - * Get the challenge list - * @return the challengeList - */ - public Map> getChallengeList() { - // TODO return the challenges for world - return challengeMap; - } - - /** - * Get the set of challenges for this level for this world - * @param level - the level required - * @param world - * @return the set of challenges for this level, or the first set of challenges if level is blank, or a blank list if there are no challenges - */ - public Set getChallenges(String level, World world) { - String worldName = Util.getWorld(world).getName(); - Optional lv = challengeMap.keySet().stream().filter(l -> l.getUniqueId().equalsIgnoreCase(level)).findFirst(); - // Get the challenges applicable to this world - return lv.isPresent() ? challengeMap.get(lv.get()).stream() - .filter(c -> c.getUniqueId().startsWith(worldName)).collect(Collectors.toSet()) - : new HashSet<>(); - } - - /** - * @return the challengesPanels - */ - public ChallengesPanels getChallengesPanels() { - return challengesPanels; - } - - /** - * Get the previous level to the one supplied - * @param currentLevel - the current level - * @return the previous level, or null if there is none - */ - public ChallengeLevel getPreviousLevel(ChallengeLevel currentLevel) { - ChallengeLevel result = null; - for (ChallengeLevel level : challengeMap.keySet()) { - if (level.equals(currentLevel)) { - return result; - } - result = level; - } - return result; - } - - /** - * Check if a challenge exists - case insensitive - * @param name - name of challenge - * @return true if it exists, otherwise false - */ - public boolean isChallenge(String name) { - for (Set ch : challengeMap.values()) { - if (ch.stream().anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { - return true; - } - } - return false; - } - - /** - * Check if a challenge exists in world - case insensitive - * @param world - world to check - * @param name - name of challenge - * @return true if it exists, otherwise false - */ - public boolean isChallenge(World world, String name) { - for (Set ch : challengeMap.values()) { - if (ch.stream().filter(c -> c.getUniqueId().startsWith(Util.getWorld(world).getName())).anyMatch(c -> c.getUniqueId().equalsIgnoreCase(name))) { - return true; - } - } - return false; - } - - /** - * Checks if a challenge is complete or not - * @param challengeName - Challenge uniqueId - * @return - true if completed - */ - public boolean isChallengeComplete(User user, String challengeName, World world) { - addPlayer(user); - return playerData.get(user.getUniqueId()).isChallengeDone(challengeName); - } - - /** - * Check is user can see level - * @param user - user - * @param level - level unique id - * @return true if level is unlocked - */ - public boolean isLevelUnlocked(User user, String level, World world) { - addPlayer(user); - return getChallengeLevelStatus(user, world).stream().filter(LevelStatus::isUnlocked).anyMatch(lv -> lv.getLevel().getUniqueId().equalsIgnoreCase(level)); - } - - /** - * Clear and reload all challenges - */ - public void load() { - // Load the challenges - challengeMap.clear(); - addon.getLogger().info("Loading challenges..."); - chConfig.loadConfigObjects().forEach(this::storeChallenge); - sortChallenges(); - players.loadObjects().forEach(pd -> { - try { - UUID uuid = UUID.fromString(pd.getUniqueId()); - playerData.put(uuid,pd); - } catch (Exception e) { - addon.getLogger().severe("UUID for player in challenge data file is invalid!"); - } - }); - } - - /** - * Save configs and player data - */ - public void save() { - challengeMap.entrySet().forEach(en -> { - lvConfig.saveConfigObject(en.getKey()); - en.getValue().forEach(chConfig::saveConfigObject); - }); - savePlayers(); - } - - private void savePlayers() { - playerData.values().forEach(players :: saveObject); - } - - private void savePlayer(UUID playerUUID) { - if (playerData.containsKey(playerUUID)) { - players.saveObject(playerData.get(playerUUID)); - } - } - - /** - * Sets the challenge as complete and increments the number of times it has been completed - * @param user - user - * @param challengeUniqueId - unique challenge id - * @param world - world to set - */ - public void setChallengeComplete(User user, String challengeUniqueId, World world) { - addPlayer(user); - playerData.get(user.getUniqueId()).setChallengeDone(challengeUniqueId); - // Save - savePlayer(user.getUniqueId()); - } - - /** - * Reset the challenge to zero time / not done - * @param user - user - * @param challengeUniqueId - unique challenge id - * @param world - world to set - */ - public void setResetChallenge(User user, String challengeUniqueId, World world) { - addPlayer(user); - playerData.get(user.getUniqueId()).setChallengeTimes(challengeUniqueId, 0); - // Save - savePlayer(user.getUniqueId()); - } - - /** - * @param challengeList the challengeList to set - */ - public void setChallengeList(Map> challengeList) { - this.challengeMap = challengeList; - } - - public void sortChallenges() { - // Sort the challenge list into level order - challengeMap = challengeMap.entrySet().stream() - .sorted(Map.Entry.comparingByKey()) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, - (oldValue, newValue) -> oldValue, LinkedHashMap::new)); - } + /** + * This variable allows to access ChallengesAddon. + */ + private ChallengesAddon addon; - /** - * Store challenge silently. Used when loading. - * @param challenge - * @return true if successful - */ - private boolean storeChallenge(Challenge challenge) { - return storeChallenge(challenge, true, null, true); - } - - /** - * Stores the challenge. - * @param challenge - challenge - * @param overwrite - true if previous challenge should be overwritten - * @param user - user making the request - * @param silent - if true, no messages are sent to user - * @return - true if imported - */ - public boolean storeChallenge(Challenge challenge, boolean overwrite, User user, boolean silent) { - // See if we have this level already - ChallengeLevel level; - if (lvConfig.configObjectExists(challenge.getLevel())) { - // Get it from the database - level = lvConfig.loadConfigObject(challenge.getLevel()); - } else { - // Make it - level = new ChallengeLevel(); - level.setUniqueId(challenge.getLevel()); - lvConfig.saveConfigObject(level); - } - challengeMap.putIfAbsent(level, new HashSet<>()); - if (challengeMap.get(level).contains(challenge)) { - if (!overwrite) { - if (!silent) { - user.sendMessage("challenges.admin.import.skipping", "[challenge]", challenge.getFriendlyName()); - } - return false; - } else { - if (!silent) { - user.sendMessage("challenges.admin.import.overwriting", "[challenge]", challenge.getFriendlyName()); - } - challengeMap.get(level).add(challenge); - return true; - } - } - if (!silent) { - user.sendMessage("challenges.admin.import.imported", "[challenge]", challenge.getFriendlyName()); - } - challengeMap.get(level).add(challenge); - return true; - } - - /** - * Store a challenge level - * @param level the challenge level - */ - public void storeLevel(ChallengeLevel level) { - lvConfig.saveConfigObject(level); - } - - /** - * Simple splitter - * @param string - string to be split - * @return list of split strings - */ - public List stringSplit(String string) { - string = ChatColor.translateAlternateColorCodes('&', string); - // Check length of lines - List result = new ArrayList<>(); - Arrays.asList(string.split("\\|")).forEach(line -> result.addAll(Arrays.asList(WordUtils.wrap(line,25).split("\\n")))); - return result; - } - - /** - * Resets all the challenges for user in world - * @param uuid - island owner's UUID - * @param world - world - */ - public void resetAllChallenges(UUID uuid, World world) { - User user = User.getInstance(uuid); - addPlayer(user); - playerData.get(user.getUniqueId()).reset(world); - // Save - savePlayer(user.getUniqueId()); - - } +// --------------------------------------------------------------------- +// Section: Constants +// --------------------------------------------------------------------- - public Challenge createChallenge() - { - return new Challenge(); - } + /** + * String for free Challenge Level. + */ + public static final String FREE = ""; - public List getChallenges(ChallengeLevel challengeLevel) - { - return new ArrayList<>(this.challengeMap.get(challengeLevel)); - } +// --------------------------------------------------------------------- +// Section: Constructor +// --------------------------------------------------------------------- - public List getChallengeLevelList() - { - return new ArrayList<>(this.challengeMap.keySet()); - } - - - public List getChallengesList() - { - return new ArrayList<>(); - } - - - public void deleteChallenge(Challenge selectedChallenge) - { - - } - - - public void deleteChallengeLevel(ChallengeLevel valueObject) - { - - } - - public void resetAllChallenges(User uuid, World world) - { - - } - - - public Challenge createChallenge(String reply) + /** + * Initial constructor. Inits and loads all data. + * @param addon challenges addon. + */ + public ChallengesManager(ChallengesAddon addon) { - return new Challenge(); + this.addon = addon; + // Set up the configs + this.challengeDatabase = new Database<>(addon, Challenge.class); + this.levelDatabase = new Database<>(addon, ChallengeLevel.class); + // Players is where all the player history will be stored + this.playersDatabase = new Database<>(addon, ChallengesPlayerData.class); + + // Init all cache objects. + this.challengeCacheData = new HashMap<>(); + this.levelCacheData = new HashMap<>(); + this.playerCacheData = new HashMap<>(); + + this.load(); } - public boolean validateChallengeUniqueID(World world, String reply) +// --------------------------------------------------------------------- +// Section: Loading and storing methods +// --------------------------------------------------------------------- + + + /** + * Clear and reload all challenges + */ + public void load() { + this.challengeCacheData.clear(); + this.levelCacheData.clear(); + this.playerCacheData.clear(); + + this.addon.getLogger().info("Loading challenges..."); + + this.challengeDatabase.loadObjects().forEach(this::loadChallenge); + this.levelDatabase.loadObjects().forEach(this::loadLevel); + this.playersDatabase.loadObjects().forEach(this::loadPlayerData); + } + + + /** + * Load challenge silently. Used when loading. + * + * @param challenge Challenge that must be loaded. + * @return true if successful + */ + private void loadChallenge(Challenge challenge) + { + this.loadChallenge(challenge, true, null, true); + } + + + /** + * Load the challenge. + * + * @param challenge - challenge + * @param overwrite - true if previous challenge should be overwritten + * @param user - user making the request + * @param silent - if true, no messages are sent to user + * @return - true if imported + */ + public boolean loadChallenge(Challenge challenge, + boolean overwrite, + User user, + boolean silent) + { + if (this.challengeCacheData.containsKey(challenge.getUniqueId())) + { + if (!overwrite) + { + if (!silent) + { + user.sendMessage("challenges.admin.import.skip", + "[object]", challenge.getFriendlyName()); + } + + return false; + } + else + { + if (!silent) + { + user.sendMessage("challenges.admin.import.overwriting", + "[object]", challenge.getFriendlyName()); + } + } + } + else + { + if (!silent) + { + user.sendMessage("challenges.admin.import.add", + "[object]", challenge.getFriendlyName()); + } + } + + this.challengeCacheData.put(challenge.getUniqueId(), challenge); return true; } - public boolean validateLevelUniqueID(World world, String reply) + /** + * Store a challenge level + * + * @param level the challenge level + */ + private void loadLevel(ChallengeLevel level) { - return false; + this.loadLevel(level, true, null, true); } - public ChallengeLevel createLevel(String reply) + /** + * This method loads given level into local cache. It provides functionality to + * overwrite local value with new one, and send message to given user. + * @param level of type ChallengeLevel that must be loaded in local cache. + * @param overwrite of type boolean that indicate if local element must be overwritten. + * @param user of type User who will receive messages. + * @param silent of type boolean that indicate if message to user must be sent. + * @return boolean that indicate about load status. + */ + public boolean loadLevel(ChallengeLevel level, boolean overwrite, User user, boolean silent) { - return new ChallengeLevel(); + if (!this.isValidLevel(level)) + { + user.sendMessage("challenges.admin.import.error", + "[object]", level.getFriendlyName()); + + return false; + } + + if (this.levelCacheData.containsKey(level.getUniqueId())) + { + if (!overwrite) + { + if (!silent) + { + user.sendMessage("challenges.admin.import.skip", + "[object]", level.getFriendlyName()); + } + + return false; + } + else + { + if (!silent) + { + user.sendMessage("challenges.admin.import.overwriting", + "[object]", level.getFriendlyName()); + } + } + } + else + { + if (!silent) + { + user.sendMessage("challenges.admin.import.add", + "[object]", level.getFriendlyName()); + } + } + + this.levelCacheData.put(level.getUniqueId(), level); + return true; } - public void unlinkChallenge(ChallengeLevel challengeLevel, Challenge value) + /** + * This method stores PlayerData into local cache. + * @param playerData ChallengesPlayerData that must be loaded. + */ + private void loadPlayerData(ChallengesPlayerData playerData) { - + try + { + UUID uuid = UUID.fromString(playerData.getUniqueId()); + this.playerCacheData.put(uuid, playerData); + } + catch (Exception e) + { + this.addon.getLogger().severe("UUID for player in challenge data file is invalid!"); + } } - public void linkChallenge(ChallengeLevel challengeLevel, Challenge value) - { +// --------------------------------------------------------------------- +// Section: Other storing related methods +// --------------------------------------------------------------------- + + /** + * This method checks if given level all challenges exists in local cache or database. + * It also checks if world where level must operate exists. + * @param level that must be validated + * @return true ir level is valid, otherwise false. + */ + private boolean isValidLevel(ChallengeLevel level) + { + if (!this.addon.getPlugin().getIWM().inWorld(Bukkit.getWorld(level.getWorld()))) + { + return false; + } + + for (String uniqueID : level.getChallenges()) + { + if (!this.challengeCacheData.containsKey(uniqueID)) + { + if (this.challengeDatabase.objectExists(uniqueID)) + { + this.loadChallenge(this.challengeDatabase.loadObject(uniqueID)); + } + else + { + return false; + } + } + } + + return true; } - public void resetChallenge(UUID uniqueId, Challenge value) - { - - } - - - public void completeChallenge(UUID uniqueId, Challenge value) - { - - } - - - public List getFreeChallenges(User user, World world) - { - return Collections.emptyList(); - } - - - public String getChallengesLevel(Challenge challenge) - { - return "HERE NEED LEVEL NAME"; - } - - - public boolean isChallengeComplete(User user, Challenge challenge) - { - return this.isChallengeComplete(user, challenge.getUniqueId(), user.getWorld()); - } - - - public long checkChallengeTimes(User user, Challenge challenge) - { - return this.checkChallengeTimes(user, challenge, user.getWorld()); - } - - - public List getPlayers(World world) - { - List playerList = new ArrayList<>(); - - - return playerList; - } - - - - public ChallengeLevel getLevel(String level) + /** + * Load player from database into the cache or create new player data + * + * @param user - user to add + */ + private void addPlayer(User user) { + if (this.playerCacheData.containsKey(user.getUniqueId())) + { + return; + } + + // The player is not in the cache + // Check if the player exists in the database + + if (this.playersDatabase.objectExists(user.getUniqueId().toString())) + { + // Load player from database + ChallengesPlayerData data = this.playersDatabase.loadObject(user.getUniqueId().toString()); + // Store in cache + this.playerCacheData.put(user.getUniqueId(), data); + } + else + { + // Create the player data + ChallengesPlayerData pd = new ChallengesPlayerData(user.getUniqueId().toString()); + this.playersDatabase.saveObject(pd); + // Add to cache + this.playerCacheData.put(user.getUniqueId(), pd); + } + } + + +// --------------------------------------------------------------------- +// Section: Saving methods +// --------------------------------------------------------------------- + + + /** + * This method init all cached object saving to database. + */ + public void save() + { + this.saveChallenges(); + this.saveLevels(); + this.savePlayers(); + } + + + /** + * This method saves all challenges to database. + */ + private void saveChallenges() + { + this.challengeCacheData.values().forEach(this.challengeDatabase::saveObject); + } + + + /** + * This method saves given challenge object to database. + * @param challenge object that must be saved + */ + private void saveChallenge(Challenge challenge) + { + this.challengeDatabase.saveObject(challenge); + } + + + /** + * This method saves all levels to database. + */ + private void saveLevels() + { + this.levelCacheData.values().forEach(this.levelDatabase::saveObject); + } + + + /** + * This method saves given level into database. + * @param level object that must be saved + */ + private void saveLevel(ChallengeLevel level) + { + this.levelDatabase.saveObject(level); + } + + + /** + * This method saves all players to database. + */ + private void savePlayers() + { + this.playerCacheData.values().forEach(this.playersDatabase::saveObject); + } + + + /** + * This method saves player with given UUID. + * @param playerUUID users UUID. + */ + private void savePlayer(UUID playerUUID) + { + if (this.playerCacheData.containsKey(playerUUID)) + { + this.playersDatabase.saveObject(this.playerCacheData.get(playerUUID)); + } + } + + +// --------------------------------------------------------------------- +// Section: Player Data related methods +// --------------------------------------------------------------------- + + + /** + * This method returns all players who have done at least one challenge in given world. + * @param world World in which must search challenges. + * @return List with players who have done at least on challenge. + */ + public List getPlayers(World world) + { + List allChallengeList = this.getAllChallengesNames(world); + + // This is using Database, as some users may not be in the cache. + + return this.playersDatabase.loadObjects().stream().filter(playerData -> + allChallengeList.stream().anyMatch(playerData::isChallengeDone)). + map(playerData -> Bukkit.getPlayer(UUID.fromString(playerData.getUniqueId()))). + collect(Collectors.toList()); + } + + + /** + * This method returns how many times a player has done a challenge before + * @param user - user + * @param challenge - challenge + * @return - number of times + */ + public long getChallengeTimes(User user, Challenge challenge) + { + this.addPlayer(user); + return this.playerCacheData.get(user.getUniqueId()).getTimes(challenge.getUniqueId()); + } + + + /** + * Checks if a challenge is complete or not + * + * @param user - User who must be checked. + * @param challenge - Challenge + * @return - true if completed + */ + public boolean isChallengeComplete(User user, Challenge challenge) + { + this.addPlayer(user); + return this.playerCacheData.get(user.getUniqueId()).isChallengeDone(challenge.getUniqueId()); + } + + + /** + * Get the status on every level + * + * @param user - user + * @param world - world + * @return Level status - how many challenges still to do on which level + */ + public List getChallengeLevelStatus(User user, World world) + { + this.addPlayer(user); + ChallengesPlayerData playerData = this.playerCacheData.get(user.getUniqueId()); + + List challengeLevelList = this.getLevels(world); + + List result = new ArrayList<>(); + + // The first level is always unlocked and previous for it is null. + ChallengeLevel previousLevel = null; + int doneChallengeCount = 0; + + // For each challenge level, check how many the user has done + for (ChallengeLevel level : challengeLevelList) + { + // To find how many challenges user still must do in previous level, we must + // know how many challenges there were and how many has been done. Then + // from waiver amount remove calculated value and you get count. + + int challengesToDo = previousLevel == null ? 0 : + level.getWaiverAmount() - (previousLevel.getChallenges().size() - doneChallengeCount); + + // As level already contains unique ids of challenges, just iterate through them. + doneChallengeCount = (int) level.getChallenges().stream().filter(playerData::isChallengeDone).count(); + + result.add(new LevelStatus( + level, + previousLevel, + challengesToDo, + level.getChallenges().size() == doneChallengeCount, + challengesToDo <= 0)); + + previousLevel = level; + } + + return result; + } + + + /** + * Check is user can see given level. + * + * @param user - user + * @param world - world + * @param level - level + * @return true if level is unlocked + */ + public boolean isLevelUnlocked(User user, World world, ChallengeLevel level) + { + this.addPlayer(user); + + return this.getChallengeLevelStatus(user, world).stream(). + filter(LevelStatus::isUnlocked). + anyMatch(lv -> lv.getLevel().equals(level)); + } + + + /** + * Sets the challenge as complete and increments the number of times it has been + * completed + * + * @param user - user + * @param challenge - challenge + */ + public void setChallengeComplete(User user, Challenge challenge) + { + this.addPlayer(user); + this.playerCacheData.get(user.getUniqueId()).setChallengeDone(challenge.getUniqueId()); + // Save + this.savePlayer(user.getUniqueId()); + } + + + /** + * Reset the challenge to zero time / not done + * + * @param user - user + * @param challenge - challenge + */ + public void resetChallenge(User user, Challenge challenge) + { + this.addPlayer(user); + this.playerCacheData.get(user.getUniqueId()).setChallengeTimes(challenge.getUniqueId(), 0); + // Save + this.savePlayer(user.getUniqueId()); + } + + + + /** + * Resets all the challenges for user in world + * + * @param user - island owner's UUID + * @param world - world + */ + public void resetAllChallenges(User user, World world) + { + this.addPlayer(user); + this.playerCacheData.get(user.getUniqueId()).reset(world); + // Save + this.savePlayer(user.getUniqueId()); + } + + +// --------------------------------------------------------------------- +// Section: Challenges related methods +// --------------------------------------------------------------------- + + + /** + * Get the list of all challenge unique names for world. + * + * @param world - the world to check + * @return List of challenge names + */ + public List getAllChallengesNames(World world) + { + String worldName = Util.getWorld(world).getName(); + // TODO: Probably need to check also database. + return this.challengeCacheData.values().stream(). + sorted(Comparator.comparing(Challenge::getOrder)). + filter(challenge -> challenge.getUniqueId().startsWith(worldName)). + map(Challenge::getUniqueId). + collect(Collectors.toList()); + } + + + /** + * Get the list of all challenge for world. + * + * @param world - the world to check + * @return List of challenges + */ + public List getAllChallenges(World world) + { + String worldName = Util.getWorld(world).getName(); + // TODO: Probably need to check also database. + return this.challengeCacheData.values().stream(). + sorted(Comparator.comparing(Challenge::getOrder)). + filter(challenge -> challenge.getUniqueId().startsWith(worldName)). + collect(Collectors.toList()); + } + + + /** + * Free challenges... Challenges without a level. + * @param world World in which challenges must be searched. + * @return List with free challenges in given world. + */ + public List getFreeChallenges(World world) + { + // Free Challenges hides under FREE level. + return this.getAllChallenges(world).stream(). + filter(challenge -> challenge.getLevel().equals(FREE)). + collect(Collectors.toList()); + } + + + /** + * Level which challenges must be received + * @param level Challenge level. + * @return List with challenges in given level. + */ + public List getLevelChallenges(ChallengeLevel level) + { + return level.getChallenges().stream(). + map(this::getChallenge). + filter(Objects::nonNull). + collect(Collectors.toList()); + } + + + /** + * Get challenge by name. Case sensitive + * + * @param name - unique name of challenge + * @return - challenge or null if it does not exist + */ + public Challenge getChallenge(String name) + { + if (this.challengeCacheData.containsKey(name)) + { + return this.challengeCacheData.get(name); + } + else + { + // check database. + if (this.challengeDatabase.objectExists(name)) + { + Challenge challenge = this.challengeDatabase.loadObject(name); + this.challengeCacheData.put(name, challenge); + return challenge; + } + } + return null; } - public void addChallengeToLevel(Challenge newChallenge, ChallengeLevel level) + /** + * Check if a challenge exists - case insensitive + * + * @param name - name of challenge + * @return true if it exists, otherwise false + */ + public boolean containsChallenge(String name) { + if (this.challengeCacheData.containsKey(name)) + { + return true; + } + else + { + // check database. + if (this.challengeDatabase.objectExists(name)) + { + Challenge challenge = this.challengeDatabase.loadObject(name); + this.challengeCacheData.put(name, challenge); + return true; + } + } + return false; } -} + + + /** + * This method creates and returns new challenge with given uniqueID. + * @param uniqueID - new ID for challenge. + * @return Challenge that is currently created. + */ + public Challenge createChallenge(String uniqueID) + { + if (!this.containsChallenge(uniqueID)) + { + Challenge challenge = new Challenge(); + challenge.setUniqueId(uniqueID); + + this.saveChallenge(challenge); + this.loadChallenge(challenge); + + return challenge; + } + else + { + return null; + } + } + + + /** + * This method removes challenge from cache and memory. + * @param challenge that must be removed. + */ + public void deleteChallenge(Challenge challenge) + { + if (this.challengeCacheData.containsKey(challenge.getUniqueId())) + { + this.challengeCacheData.remove(challenge.getUniqueId()); + this.challengeDatabase.deleteObject(challenge); + } + } + + +// --------------------------------------------------------------------- +// Section: Level related methods +// --------------------------------------------------------------------- + + + /** + * This method returns list of challenge levels in given world. + * @param world for which levels must be searched. + * @return List with challenges in given world. + */ + public List getLevels(World world) + { + String worldName = Util.getWorld(world).getName(); + // TODO: Probably need to check also database. + return this.levelCacheData.values().stream(). + sorted(ChallengeLevel::compareTo). + filter(challenge -> challenge.getUniqueId().startsWith(worldName)). + collect(Collectors.toList()); + } + + + /** + * Get challenge level by its challenge. + * + * @param challenge - challenge which level must be returned. + * @return - challenge level or null if it does not exist + */ + public ChallengeLevel getLevel(Challenge challenge) + { + if (!challenge.getLevel().equals(FREE)) + { + return this.getLevel(challenge.getLevel()); + } + + return new ChallengeLevel(); + } + + + /** + * Get challenge level by name. Case sensitive + * + * @param name - unique name of challenge level + * @return - challenge level or null if it does not exist + */ + public ChallengeLevel getLevel(String name) + { + if (this.levelCacheData.containsKey(name)) + { + return this.levelCacheData.get(name); + } + else + { + // check database. + if (this.levelDatabase.objectExists(name)) + { + ChallengeLevel level = this.levelDatabase.loadObject(name); + this.levelCacheData.put(name, level); + return level; + } + } + + return null; + } + + + /** + * Check if a challenge level exists - case insensitive + * + * @param name - name of challenge level + * @return true if it exists, otherwise false + */ + public boolean containsLevel(String name) + { + if (this.levelCacheData.containsKey(name)) + { + return true; + } + else + { + // check database. + if (this.levelDatabase.objectExists(name)) + { + ChallengeLevel level = this.levelDatabase.loadObject(name); + this.levelCacheData.put(name, level); + return true; + } + } + + return false; + } + + + /** + * This method adds given challenge to given challenge level. + * @param newChallenge Challenge who must change owner. + * @param newLevel Level who must add new challenge + */ + public void addChallengeToLevel(Challenge newChallenge, ChallengeLevel newLevel) + { + if (newChallenge.getLevel().equals(FREE)) + { + newLevel.getChallenges().add(newChallenge.getUniqueId()); + newChallenge.setLevel(newLevel.getUniqueId()); + + this.saveLevel(newLevel); + this.saveChallenge(newChallenge); + } + else + { + ChallengeLevel oldLevel = this.getLevel(newChallenge.getLevel()); + + if (!oldLevel.equals(newLevel)) + { + this.removeChallengeFromLevel(newChallenge, newLevel); + newLevel.getChallenges().add(newChallenge.getUniqueId()); + newChallenge.setLevel(newLevel.getUniqueId()); + + this.saveLevel(newLevel); + this.saveChallenge(newChallenge); + } + } + } + + + /** + * This method removes given challenge from given challenge level. + * @param challenge Challenge which must leave level. + * @param level level which lost challenge + */ + public void removeChallengeFromLevel(Challenge challenge, ChallengeLevel level) + { + if (level.getChallenges().contains(challenge.getUniqueId())) + { + level.getChallenges().remove(challenge.getUniqueId()); + challenge.setLevel(FREE); + this.saveLevel(level); + this.saveChallenge(challenge); + } + } + + + /** + * This method creates and returns new challenges level with given uniqueID. + * @param uniqueID - new ID for challenge level. + * @return ChallengeLevel that is currently created. + */ + public ChallengeLevel createLevel(String uniqueID) + { + if (!this.containsLevel(uniqueID)) + { + ChallengeLevel level = new ChallengeLevel(); + level.setUniqueId(uniqueID); + + this.saveLevel(level); + this.loadLevel(level); + + return level; + } + else + { + return null; + } + } + + + /** + * This method removes challenge level from cache and memory. + * @param challengeLevel Level that must be removed. + */ + public void deleteChallengeLevel(ChallengeLevel challengeLevel) + { + if (this.levelCacheData.containsKey(challengeLevel.getUniqueId())) + { + this.levelCacheData.remove(challengeLevel.getUniqueId()); + this.levelDatabase.deleteObject(challengeLevel); + } + } +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java b/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java index bb2cc7a..67ddf60 100644 --- a/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java +++ b/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java @@ -3,10 +3,10 @@ package world.bentobox.challenges.commands; import java.util.List; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.panel.ChallengesPanels2; -import world.bentobox.challenges.panel.ChallengesPanels2.Mode; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.panel.user.ChallengesGUI; + public class ChallengesCommand extends CompositeCommand { public static final String CHALLENGE_COMMAND = "challenges"; @@ -19,7 +19,11 @@ public class ChallengesCommand extends CompositeCommand { public boolean execute(User user, String label, List args) { // Open up the challenges GUI if (user.isPlayer()) { - new ChallengesPanels2((ChallengesAddon) getAddon(), user, user, args.isEmpty() ? "" : args.get(0), getWorld(), getPermissionPrefix(), getTopLabel(), Mode.PLAYER); + new ChallengesGUI((ChallengesAddon) this.getAddon(), + this.getWorld(), + user, + this.getTopLabel(), + this.getPermissionPrefix()).build(); return true; } // Show help diff --git a/src/main/java/world/bentobox/challenges/commands/admin/Challenges.java b/src/main/java/world/bentobox/challenges/commands/admin/Challenges.java index 1115ff7..a73a127 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/Challenges.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/Challenges.java @@ -3,10 +3,10 @@ package world.bentobox.challenges.commands.admin; import java.util.List; import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.panel.ChallengesPanels2; -import world.bentobox.challenges.panel.ChallengesPanels2.Mode; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.panel.admin.AdminGUI; + public class Challenges extends CompositeCommand { @@ -25,7 +25,7 @@ public class Challenges extends CompositeCommand { this.setDescription("challenges.admin.description"); // Register sub commands new ImportCommand(getAddon(), this); - new CompleteChallenge(getAddon(), this); + // new CompleteChallenge(getAddon(), this); new ReloadChallenges(getAddon(), this); new ResetChallenge(getAddon(), this); //new ShowChallenges(getAddon(), this); @@ -37,7 +37,12 @@ public class Challenges extends CompositeCommand { public boolean execute(User user, String label, List args) { // Open up the admin challenges GUI if (user.isPlayer()) { - new ChallengesPanels2((ChallengesAddon) getAddon(), user, user, args.isEmpty() ? "" : args.get(0), getWorld(), getPermissionPrefix(), getTopLabel(), Mode.ADMIN); + new AdminGUI((ChallengesAddon) this.getAddon(), + this.getWorld(), + user, + this.getTopLabel(), + this.getPermissionPrefix()).build(); + return true; } return false; diff --git a/src/main/java/world/bentobox/challenges/commands/admin/CompleteChallenge.java b/src/main/java/world/bentobox/challenges/commands/admin/CompleteChallenge.java index 486662a..1a156fe 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/CompleteChallenge.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/CompleteChallenge.java @@ -51,13 +51,13 @@ public class CompleteChallenge extends CompositeCommand { return false; } // Check for valid challenge name - if (!manager.isChallenge(getWorld(), args.get(1))) { + if (!manager.containsChallenge(args.get(1))) { user.sendMessage("challenges.admin.complete.unknown-challenge"); return false; } // Complete challenge User target = User.getInstance(targetUUID); - manager.setChallengeComplete(target, args.get(1), getWorld()); + manager.setChallengeComplete(target, this.manager.getChallenge(args.get(1))); user.sendMessage("general.success"); return true; } @@ -70,7 +70,7 @@ public class CompleteChallenge extends CompositeCommand { return Optional.of(Util.tabLimit(new ArrayList<>(Util.getOnlinePlayerList(user)), lastArg)); } else if (args.size() == 4) { // Challenges in this world - return Optional.of(Util.tabLimit(manager.getAllChallengesList(getWorld()), lastArg)); + return Optional.of(Util.tabLimit(manager.getAllChallengesNames(getWorld()), lastArg)); } return Optional.empty(); } diff --git a/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java b/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java index 0774072..5e762d5 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java @@ -56,13 +56,13 @@ public class ResetChallenge extends CompositeCommand { return false; } // Check for valid challenge name - if (!manager.isChallenge(getWorld(), args.get(1))) { + if (!manager.containsChallenge(args.get(1))) { user.sendMessage("challenges.admin.complete.unknown-challenge"); return false; } // Complete challenge User target = User.getInstance(targetUUID); - manager.setResetChallenge(target, args.get(1), getWorld()); + manager.resetChallenge(target, manager.getChallenge(args.get(1))); user.sendMessage("general.success"); return true; } @@ -75,7 +75,7 @@ public class ResetChallenge extends CompositeCommand { return Optional.of(Util.tabLimit(new ArrayList<>(Util.getOnlinePlayerList(user)), lastArg)); } else if (args.size() == 4) { // Challenges in this world - return Optional.of(Util.tabLimit(manager.getAllChallengesList(getWorld()), lastArg)); + return Optional.of(Util.tabLimit(manager.getAllChallengesNames(getWorld()), lastArg)); } return Optional.empty(); } diff --git a/src/main/java/world/bentobox/challenges/commands/admin/ShowChallenges.java b/src/main/java/world/bentobox/challenges/commands/admin/ShowChallenges.java index 8842647..97eb1bb 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/ShowChallenges.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/ShowChallenges.java @@ -28,7 +28,7 @@ public class ShowChallenges extends CompositeCommand { @Override public boolean execute(User user, String label, List args) { - ((ChallengesAddon)getAddon()).getChallengesManager().getAllChallengesList().forEach(user::sendRawMessage); + ((ChallengesAddon)getAddon()).getChallengesManager().getAllChallengesNames(this.getWorld()).forEach(user::sendRawMessage); return true; } diff --git a/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java b/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java index ed4791c..037b0af 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/SurroundChallengeBuilder.java @@ -77,7 +77,7 @@ public class SurroundChallengeBuilder { } public boolean build() { - return addon.getChallengesManager().createSurroundingChallenge(this); + return false; //addon.getChallengesManager().createSurroundingChallenge(this); } diff --git a/src/main/java/world/bentobox/challenges/listeners/ResetListener.java b/src/main/java/world/bentobox/challenges/listeners/ResetListener.java index df0d401..4ee56a9 100644 --- a/src/main/java/world/bentobox/challenges/listeners/ResetListener.java +++ b/src/main/java/world/bentobox/challenges/listeners/ResetListener.java @@ -7,6 +7,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.bentobox.api.events.island.IslandEvent; import world.bentobox.bentobox.api.events.island.IslandEvent.Reason; @@ -27,7 +28,7 @@ public class ResetListener implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onIslandReset(IslandEvent e) { if (e.getReason().equals(Reason.CREATED) || (addon.getChallengesSettings().isResetChallenges() && e.getReason().equals(Reason.RESETTED))) { - addon.getChallengesManager().resetAllChallenges(e.getOwner(), e.getLocation().getWorld()); + addon.getChallengesManager().resetAllChallenges(User.getInstance(e.getOwner()), e.getLocation().getWorld()); } } } diff --git a/src/main/java/world/bentobox/challenges/listeners/SaveListener.java b/src/main/java/world/bentobox/challenges/listeners/SaveListener.java index 5f411ed..313d2ba 100644 --- a/src/main/java/world/bentobox/challenges/listeners/SaveListener.java +++ b/src/main/java/world/bentobox/challenges/listeners/SaveListener.java @@ -23,7 +23,7 @@ public class SaveListener implements Listener @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onWorldSave(WorldSaveEvent e) { - if (!this.addon.getChallengesManager().getAllChallengesList(e.getWorld()).isEmpty()) + if (!this.addon.getChallengesManager().getAllChallenges(e.getWorld()).isEmpty()) { this.addon.getChallengesManager().save(); } diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java index 6e80a53..c3d8f35 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels.java @@ -11,6 +11,8 @@ import org.bukkit.inventory.ItemStack; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; +import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.utils.GuiUtils; import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.database.object.Challenge; @@ -30,7 +32,7 @@ public class ChallengesPanels { private ChallengesAddon addon; private ChallengesManager manager; private User user; - private String level; + private ChallengeLevel level; private World world; private String permPrefix; private String label; @@ -43,17 +45,17 @@ public class ChallengesPanels { this.permPrefix = permPrefix; this.label = label; - if (manager.getChallengeList().isEmpty()) { + if (manager.getAllChallenges(world).isEmpty()) { addon.getLogger().severe("There are no challenges set up!"); user.sendMessage("general.errors.general"); return; } if (level.isEmpty()) { - level = manager.getChallengeList().keySet().iterator().next().getUniqueId(); + level = manager.getLevels(world).iterator().next().getUniqueId(); } - this.level = level; + this.level = this.manager.getLevel(level); // Check if level is valid - if (!manager.isLevelUnlocked(user, level, world)) { + if (!manager.isLevelUnlocked(user, world, this.level)) { return; } PanelBuilder panelBuilder = new PanelBuilder() @@ -69,7 +71,7 @@ public class ChallengesPanels { } private void addChallengeItems(PanelBuilder panelBuilder) { - Set levelChallenges = manager.getChallenges(level, world); + List levelChallenges = manager.getLevelChallenges(level); // Only show a control panel for the level requested. for (Challenge challenge : levelChallenges) { createItem(panelBuilder, challenge); @@ -77,7 +79,7 @@ public class ChallengesPanels { } private void addFreeChallanges(PanelBuilder panelBuilder) { - manager.getChallenges(ChallengesManager.FREE, world).forEach(challenge -> createItem(panelBuilder, challenge)); + manager.getFreeChallenges(world).forEach(challenge -> createItem(panelBuilder, challenge)); } @@ -88,7 +90,7 @@ public class ChallengesPanels { */ private void createItem(PanelBuilder panelBuilder, Challenge challenge) { // Check completion - boolean completed = manager.isChallengeComplete(user, challenge.getUniqueId(), world); + boolean completed = manager.isChallengeComplete(user, challenge); // If challenge is removed after completion, remove it if (completed && challenge.isRemoveWhenCompleted()) { return; @@ -130,7 +132,7 @@ public class ChallengesPanels { PanelItem item = new PanelItemBuilder() .icon(new ItemStack(Material.ENCHANTED_BOOK)) .name(name) - .description(manager.stringSplit(user.getTranslation("challenges.navigation","[level]",name))) + .description(GuiUtils.stringSplit(user.getTranslation("challenges.navigation","[level]",name))) .clickHandler((p, u, c, s) -> { u.closeInventory(); u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId()); @@ -144,7 +146,7 @@ public class ChallengesPanels { PanelItem item = new PanelItemBuilder() .icon(new ItemStack(Material.BOOK)) .name(name) - .description(manager.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName))) + .description(GuiUtils.stringSplit(user.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName))) .build(); panelBuilder.item(item); } @@ -167,9 +169,9 @@ public class ChallengesPanels { } // Check if completed or not - boolean complete = addon.getChallengesManager().isChallengeComplete(user, challenge.getUniqueId(), world); + boolean complete = addon.getChallengesManager().isChallengeComplete(user, challenge); int maxTimes = challenge.getMaxTimes(); - long doneTimes = addon.getChallengesManager().checkChallengeTimes(user, challenge, world); + long doneTimes = addon.getChallengesManager().getChallengeTimes(user, challenge); if (complete) { result.add(user.getTranslation("challenges.complete")); } @@ -234,6 +236,6 @@ public class ChallengesPanels { } private Collection splitTrans(User user, String string, String...strings) { - return addon.getChallengesManager().stringSplit(user.getTranslation(string, strings)); + return GuiUtils.stringSplit(user.getTranslation(string, strings)); } } diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index c432ce6..ea56420 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -10,6 +10,8 @@ import org.bukkit.inventory.ItemStack; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; +import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.utils.GuiUtils; import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.database.object.Challenge; @@ -35,7 +37,7 @@ public class ChallengesPanels2 { private ChallengesAddon addon; private ChallengesManager manager; private User requester; - private String level; + private ChallengeLevel level; private World world; private String permPrefix; private String label; @@ -52,18 +54,18 @@ public class ChallengesPanels2 { this.label = label; this.mode = mode; - if (manager.getChallengeList().isEmpty()) { + if (manager.getAllChallenges(world).isEmpty()) { addon.getLogger().severe("There are no challenges set up!"); requester.sendMessage("general.errors.general"); return; } if (level.isEmpty()) { // TODO: open the farthest challenge panel - level = manager.getChallengeList().keySet().iterator().next().getUniqueId(); + level = manager.getLevels(world).iterator().next().getUniqueId(); } - this.level = level; + this.level = manager.getLevel(level); // Check if level is valid - if (mode.equals(Mode.PLAYER) && !manager.isLevelUnlocked(requester, level, world)) { + if (mode.equals(Mode.PLAYER) && !manager.isLevelUnlocked(requester, world, this.level)) { return; } PanelBuilder panelBuilder = new PanelBuilder(); @@ -93,13 +95,13 @@ public class ChallengesPanels2 { private void addChallengeItems(PanelBuilder panelBuilder) { // Only show a control panel for the level requested. - for (Challenge challenge : manager.getChallenges(level, world)) { + for (Challenge challenge : manager.getLevelChallenges(level)) { createItem(panelBuilder, challenge); } } private void addFreeChallanges(PanelBuilder panelBuilder) { - manager.getChallenges(ChallengesManager.FREE, world).forEach(challenge -> createItem(panelBuilder, challenge)); + manager.getFreeChallenges(world).forEach(challenge -> createItem(panelBuilder, challenge)); } @@ -116,10 +118,10 @@ public class ChallengesPanels2 { glow = challenge.isDeployed(); break; case EDIT: - glow = manager.isChallengeComplete(requester, challenge.getUniqueId(), world); + glow = manager.isChallengeComplete(requester, challenge); break; case PLAYER: - glow = manager.isChallengeComplete(requester, challenge.getUniqueId(), world); + glow = manager.isChallengeComplete(requester, challenge); break; default: break; @@ -169,7 +171,7 @@ public class ChallengesPanels2 { // Add navigation to other levels for (LevelStatus status: manager.getChallengeLevelStatus(requester, world)) { - if (status.getLevel().getUniqueId().equalsIgnoreCase(level)) { + if (status.getLevel().getUniqueId().equalsIgnoreCase(level.getUniqueId())) { // Skip if this is the current level previousStatus = status; continue; @@ -182,7 +184,7 @@ public class ChallengesPanels2 { PanelItem item = new PanelItemBuilder() .icon(new ItemStack(Material.ENCHANTED_BOOK)) .name(name) - .description(manager.stringSplit(requester.getTranslation("challenges.navigation","[level]",name))) + .description(GuiUtils.stringSplit(requester.getTranslation("challenges.navigation","[level]",name))) .clickHandler((p, u, c, s) -> { u.closeInventory(); u.performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + status.getLevel().getUniqueId()); @@ -196,7 +198,7 @@ public class ChallengesPanels2 { PanelItem item = new PanelItemBuilder() .icon(new ItemStack(Material.BOOK)) .name(name) - .description(manager.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName))) + .description(GuiUtils.stringSplit(requester.getTranslation("challenges.to-complete", "[challengesToDo]",String.valueOf(previousStatus != null ? previousStatus.getNumberOfChallengesStillToDo() : ""), "[thisLevel]", previousLevelName))) .build(); panelBuilder.item(item); } @@ -230,9 +232,9 @@ public class ChallengesPanels2 { result.addAll(addRewards(challenge, true, true)); } else { // Check if completed or not - boolean complete = addon.getChallengesManager().isChallengeComplete(requester, challenge.getUniqueId(), world); + boolean complete = addon.getChallengesManager().isChallengeComplete(requester, challenge); int maxTimes = challenge.getMaxTimes(); - long doneTimes = addon.getChallengesManager().checkChallengeTimes(requester, challenge, world); + long doneTimes = addon.getChallengesManager().getChallengeTimes(requester, challenge); if (complete) { result.add(requester.getTranslation("challenges.complete")); } @@ -307,6 +309,6 @@ public class ChallengesPanels2 { } private Collection splitTrans(User user, String string, String...strings) { - return addon.getChallengesManager().stringSplit(user.getTranslation(string, strings)); + return GuiUtils.stringSplit(user.getTranslation(string, strings)); } } diff --git a/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java b/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java index 978b64b..d0b63ee 100644 --- a/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java +++ b/src/main/java/world/bentobox/challenges/panel/CreateChallengeListener.java @@ -29,7 +29,7 @@ public class CreateChallengeListener implements PanelListener { @Override public void onInventoryClose(InventoryCloseEvent event) { - addon.getChallengesManager().createInvChallenge(user, event.getInventory()); + addon.getChallengesManager().createChallenge("uniqueID"); } @Override diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index ffe8709..aadbc38 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -124,7 +124,7 @@ public class TryToComplete { user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); } // Mark as complete - manager.setChallengeComplete(user, challenge.getUniqueId(), world); + manager.setChallengeComplete(user, challenge); user.closeInventory(); user.getPlayer().performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + challenge.getLevel()); return result; @@ -189,7 +189,7 @@ public class TryToComplete { user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); } // Mark as complete - manager.setChallengeComplete(user, challenge.getUniqueId(), world); + manager.setChallengeComplete(user, challenge); user.closeInventory(); user.getPlayer().performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + challenge.getLevel()); } @@ -204,17 +204,17 @@ public class TryToComplete { return new ChallengeResult(); } // Check if user has the - if (!challenge.getLevel().equals(ChallengesManager.FREE) && !manager.isLevelUnlocked(user, challenge.getLevel(), world)) { + if (!challenge.getLevel().equals(ChallengesManager.FREE) && !manager.isLevelUnlocked(user, world, manager.getLevel(challenge.getLevel()))) { user.sendMessage("challenges.errors.challenge-level-not-available"); return new ChallengeResult(); } // Check max times - if (challenge.isRepeatable() && challenge.getMaxTimes() > 0 && manager.checkChallengeTimes(user, challenge, world) >= challenge.getMaxTimes()) { + if (challenge.isRepeatable() && challenge.getMaxTimes() > 0 && manager.getChallengeTimes(user, challenge) >= challenge.getMaxTimes()) { user.sendMessage("challenges.not-repeatable"); return new ChallengeResult(); } // Check repeatability - if (manager.isChallengeComplete(user, challenge.getUniqueId(), world) + if (manager.isChallengeComplete(user, challenge) && (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.OTHER) || challenge.getChallengeType().equals(ChallengeType.ISLAND))) { user.sendMessage("challenges.not-repeatable"); @@ -288,7 +288,7 @@ public class TryToComplete { this.removeMoney(); // Return the result - return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge.getUniqueId(), world)); + return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge)); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 97ae16e..d93d5b5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -11,6 +11,7 @@ import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.util.Util; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.utils.GuiUtils; @@ -198,25 +199,25 @@ public class AdminGUI extends CommonGUI this.user.getPlayer(), "unique_id", (player, reply) -> { + String newName = Util.getWorld(this.world).getName() + "_" + reply; - if (this.addon.getChallengesManager().validateChallengeUniqueID(this.world, reply)) - { - new EditChallengeGUI(this.addon, - this.world, - this.user, - this.addon.getChallengesManager().createChallenge(reply), - this.topLabel, - this.permissionPrefix, - this).build(); - } - else - { - this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); - this.build(); - } + if (this.addon.getChallengesManager().containsChallenge(newName)) + { + new EditChallengeGUI(this.addon, + this.world, + this.user, + this.addon.getChallengesManager().createChallenge(reply), + this.topLabel, + this.permissionPrefix, + this).build(); + } + else + { + this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); + } - return reply; - }); + return reply; + }); return true; }; @@ -234,8 +235,9 @@ public class AdminGUI extends CommonGUI this.user.getPlayer(), "unique_id", (player, reply) -> { + String newName = Util.getWorld(this.world).getName() + "_" + reply; - if (this.addon.getChallengesManager().validateLevelUniqueID(this.world, reply)) + if (this.addon.getChallengesManager().containsLevel(newName)) { new EditLevelGUI(this.addon, this.world, @@ -248,7 +250,6 @@ public class AdminGUI extends CommonGUI else { this.user.sendMessage("challenges.errors.unique-id", "[id]", reply); - this.build(); } return reply; @@ -410,4 +411,4 @@ public class AdminGUI extends CommonGUI return new PanelItem(icon, name, description, glow, clickHandler, false); } -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index fbcf53c..41517a7 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -145,7 +145,7 @@ public class EditLevelGUI extends CommonGUI */ private void buildChallengesPanel(PanelBuilder panelBuilder) { - List challengeList = this.addon.getChallengesManager().getChallenges(this.challengeLevel); + List challengeList = this.addon.getChallengesManager().getLevelChallenges(this.challengeLevel); final int MAX_ELEMENTS = 21; @@ -538,8 +538,8 @@ public class EditLevelGUI extends CommonGUI ChallengesManager manager = this.addon.getChallengesManager(); // Get all challenge that is not in current challenge. - List challengeList = manager.getChallengesList(); - challengeList.removeAll(manager.getChallenges(this.challengeLevel)); + List challengeList = manager.getAllChallenges(this.world); + challengeList.removeAll(manager.getLevelChallenges(this.challengeLevel)); new SelectChallengeGUI(this.user, challengeList, (status, value) -> { if (status) @@ -563,10 +563,10 @@ public class EditLevelGUI extends CommonGUI clickHandler = (panel, user, clickType, slot) -> { ChallengesManager manager = this.addon.getChallengesManager(); - new SelectChallengeGUI(this.user, manager.getChallenges(this.challengeLevel), (status, value) -> { + new SelectChallengeGUI(this.user, manager.getLevelChallenges(this.challengeLevel), (status, value) -> { if (status) { - manager.unlinkChallenge(this.challengeLevel, value); + manager.removeChallengeFromLevel(value, this.challengeLevel); } this.build(); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 700efe6..77e98f8 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -82,7 +82,7 @@ public class ListChallengesGUI extends CommonGUI GuiUtils.fillBorder(panelBuilder); } - List challengeList = this.addon.getChallengesManager().getChallengesList(); + List challengeList = this.addon.getChallengesManager().getAllChallenges(this.world); final int MAX_ELEMENTS = 21; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 3c33dd7..6a9b967 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -82,7 +82,7 @@ public class ListLevelsGUI extends CommonGUI GuiUtils.fillBorder(panelBuilder); } - List levelList = this.addon.getChallengesManager().getChallengeLevelList(); + List levelList = this.addon.getChallengesManager().getLevels(this.world); final int MAX_ELEMENTS = 21; diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index b6c9d99..284c8cd 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -178,20 +178,20 @@ public class ListUsersGUI extends CommonGUI switch (this.operationMode) { case COMPLETE: - new SelectChallengeGUI(this.user, manager.getChallengesList(), (status, value) -> { + new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), (status, value) -> { if (status) { - manager.completeChallenge(player.getUniqueId(), value); + manager.setChallengeComplete(User.getInstance(player), value); } this.build(); }); break; case RESET: - new SelectChallengeGUI(this.user, manager.getChallengesList(), (status, value) -> { + new SelectChallengeGUI(this.user, manager.getAllChallenges(this.world), (status, value) -> { if (status) { - manager.resetChallenge(player.getUniqueId(), value); + manager.resetChallenge(User.getInstance(player), value); } this.build(); @@ -292,4 +292,4 @@ public class ListUsersGUI extends CommonGUI return true; }).build(); } -} +} \ No newline at end of file diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index d021247..d9c54e6 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -123,7 +123,7 @@ public class ChallengesGUI extends CommonGUI */ private void addFreeChallenges(PanelBuilder panelBuilder) { - List freeChallenges = this.challengesManager.getFreeChallenges(this.user, this.world); + List freeChallenges = this.challengesManager.getFreeChallenges(this.world); final int freeChallengesCount = freeChallenges.size(); if (freeChallengesCount > 18) @@ -185,7 +185,7 @@ public class ChallengesGUI extends CommonGUI { if (this.lastSelectedLevel != null) { - List challenges = this.challengesManager.getChallenges(this.lastSelectedLevel.getLevel()); + List challenges = this.challengesManager.getLevelChallenges(this.lastSelectedLevel.getLevel()); final int challengesCount = challenges.size(); if (challengesCount > 18) @@ -346,7 +346,7 @@ public class ChallengesGUI extends CommonGUI List result = new ArrayList<>(); result.add(this.user.getTranslation("challenges.level", - "[level]", this.challengesManager.getChallengesLevel(challenge))); + "[level]", this.challengesManager.getLevel(challenge).getFriendlyName())); boolean completed = this.challengesManager.isChallengeComplete(this.user, challenge); @@ -358,7 +358,7 @@ public class ChallengesGUI extends CommonGUI if (challenge.isRepeatable()) { int maxTimes = challenge.getMaxTimes(); - long doneTimes = this.challengesManager.checkChallengeTimes(this.user, challenge); + long doneTimes = this.challengesManager.getChallengeTimes(this.user, challenge); if (maxTimes > 0) { diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index 34b6107..ecde0d0 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -1,11 +1,16 @@ package world.bentobox.challenges.utils; +import org.apache.commons.lang.WordUtils; +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; @@ -360,4 +365,24 @@ public class GuiUtils return new BorderBlock(itemStack); } } -} + + + /** + * Simple splitter + * + * @param string - string to be split + * @return list of split strings + */ + public static List stringSplit(String string) + { + string = ChatColor.translateAlternateColorCodes('&', string); + // Check length of lines + List result = new ArrayList<>(); + + Arrays.asList(string.split("\\|")). + forEach(line -> result.addAll( + Arrays.asList(WordUtils.wrap(line, 25).split("\\n")))); + + return result; + } +} \ No newline at end of file From bf22a50124e4ef239a65c0ccde5ac8f83276bc52 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 17:33:51 +0200 Subject: [PATCH 071/103] Add ToDoes about Economy. --- .../bentobox/challenges/panel/admin/EditChallengeGUI.java | 3 +++ .../world/bentobox/challenges/panel/admin/EditLevelGUI.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 203b3c6..4800f62 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -25,6 +25,9 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary methods that creates GUI and allow to edit challenges * properties. + * + * TODO: In current class set that MONEY are availabe only if ECONOMY exist. + * TODO: In current class set that ISLAND LEVEL are availabe only if LEVEL ADDON exist. */ public class EditChallengeGUI extends CommonGUI { diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 41517a7..e50bff5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -28,7 +28,8 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary elements to create Levels Edit GUI. - */ + * TODO: In current class set that MONEY are availabe only if ECONOMY exist. +*/ public class EditLevelGUI extends CommonGUI { // --------------------------------------------------------------------- From 9c4c5b7d86a818bf4f67eed56316a640751c94d2 Mon Sep 17 00:00:00 2001 From: BONNe1704 Date: Wed, 23 Jan 2019 18:01:19 +0200 Subject: [PATCH 072/103] Fix issue when Levels were not loaded with world name in unique ID. Fix crash that appears after renaming Level to Other challenge type. --- .../challenges/ChallengesImportManager.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java index 8040590..c16ab32 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesImportManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesImportManager.java @@ -83,7 +83,7 @@ public class ChallengesImportManager for (String level : lvs) { ChallengeLevel challengeLevel = new ChallengeLevel(); challengeLevel.setFriendlyName(level); - challengeLevel.setUniqueId(level); + challengeLevel.setUniqueId(Util.getWorld(world).getName() + "_" + level); challengeLevel.setOrder(order++); challengeLevel.setWorld(Util.getWorld(world).getName()); challengeLevel.setWaiverAmount(chal.getInt("challenges.waiveramount")); @@ -120,7 +120,17 @@ public class ChallengesImportManager newChallenge.setFriendlyName(details.getString("friendlyname", challenge)); newChallenge.setDescription(GuiUtils.stringSplit(details.getString("description", ""))); newChallenge.setIcon(ItemParser.parse(details.getString("icon") + ":1")); - newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); + + if (details.getString("type").equalsIgnoreCase("level")) + { + // Fix for older version config + newChallenge.setChallengeType(Challenge.ChallengeType.OTHER); + } + else + { + newChallenge.setChallengeType(Challenge.ChallengeType.valueOf(details.getString("type","INVENTORY").toUpperCase())); + } + newChallenge.setTakeItems(details.getBoolean("takeItems",true)); newChallenge.setRewardText(details.getString("rewardText", "")); newChallenge.setRewardCommands(details.getStringList("rewardcommands")); From 38fce9a4b07459ffc54d839ae4cb72ea0990309e Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 19:49:13 +0200 Subject: [PATCH 073/103] Fix issue when Challenge and ChallengeLevel icons were stored with glowing effect and lore from admin panel. This issue happened because PanelItem overwrites ItemStack metaData. It is fixed by returning clone of icon element instead of returning actual icon. --- .../world/bentobox/challenges/database/object/Challenge.java | 2 +- .../bentobox/challenges/database/object/ChallengeLevel.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/database/object/Challenge.java b/src/main/java/world/bentobox/challenges/database/object/Challenge.java index 6f6f829..6d73716 100644 --- a/src/main/java/world/bentobox/challenges/database/object/Challenge.java +++ b/src/main/java/world/bentobox/challenges/database/object/Challenge.java @@ -308,7 +308,7 @@ public class Challenge implements DataObject */ public ItemStack getIcon() { - return icon; + return icon.clone(); } diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java index cae1976..de4c71b 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengeLevel.java @@ -138,7 +138,7 @@ public class ChallengeLevel implements DataObject, Comparable */ public ItemStack getIcon() { - return icon; + return icon.clone(); } From 53da2d67c78787168fe2e4d7f732f3703f980121 Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 19:50:15 +0200 Subject: [PATCH 074/103] Fix logical error that opens all levels instead of locking them. WaiverAmount should be reducer, not from whom reduces. --- .../java/world/bentobox/challenges/ChallengesManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 4112609..7cd09b9 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -488,10 +488,10 @@ public class ChallengesManager { // To find how many challenges user still must do in previous level, we must // know how many challenges there were and how many has been done. Then - // from waiver amount remove calculated value and you get count. + // remove waiver amount to get count of challenges that still necessary to do. int challengesToDo = previousLevel == null ? 0 : - level.getWaiverAmount() - (previousLevel.getChallenges().size() - doneChallengeCount); + (previousLevel.getChallenges().size() - doneChallengeCount - level.getWaiverAmount()); // As level already contains unique ids of challenges, just iterate through them. doneChallengeCount = (int) level.getChallenges().stream().filter(playerData::isChallengeDone).count(); From ca32c535104b792a08ec90c052c0cb97456b930b Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 20:19:18 +0200 Subject: [PATCH 075/103] Update To BentoBox 1.1 Use new approach to hooking addons into game-mode. --- pom.xml | 14 +---- .../bentobox/challenges/ChallengesAddon.java | 54 ++++++------------- 2 files changed, 16 insertions(+), 52 deletions(-) diff --git a/pom.xml b/pom.xml index e9e4c9c..7acf7f0 100644 --- a/pom.xml +++ b/pom.xml @@ -100,19 +100,7 @@ world.bentobox bentobox - 1.1-SNAPSHOT - provided - - - world.bentobox - bskyblock - 1.0 - provided - - - world.bentobox - acidisland - 1.0 + 1.1 provided diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 68923a2..157588f 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -2,7 +2,6 @@ package world.bentobox.challenges; import org.bukkit.Bukkit; -import world.bentobox.acidisland.AcidIsland; import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.commands.admin.Challenges; @@ -75,45 +74,22 @@ public class ChallengesAddon extends Addon { // Challenge import setup this.importManager = new ChallengesImportManager(this); + this.getPlugin().getAddonsManager().getGameModeAddons().forEach(gameModeAddon -> { + if (!this.settings.getDisabledGameModes().contains(gameModeAddon.getDescription().getName())) + { + if (gameModeAddon.getPlayerCommand().isPresent()) + { + new ChallengesCommand(this, gameModeAddon.getPlayerCommand().get()); + this.hooked = true; + } - // Integrate into AcidIsland. - if (this.settings.getDisabledGameModes().isEmpty() || - !this.settings.getDisabledGameModes().contains("AcidIsland")) - { - this.getPlugin().getAddonsManager().getAddonByName("AcidIsland").ifPresent( - addon -> { - AcidIsland acidIsland = (AcidIsland) addon; - - new Challenges(this, - this.getPlugin().getCommandsManager().getCommand( - acidIsland.getSettings().getAdminCommand())); - - new ChallengesCommand(this, - this.getPlugin().getCommandsManager().getCommand( - acidIsland.getSettings().getIslandCommand())); - - this.hooked = true; - }); - } - - // Integrate into BSkyBlock. - if (this.settings.getDisabledGameModes().isEmpty() || - !this.settings.getDisabledGameModes().contains("BSkyBlock")) - { - this.getPlugin().getAddonsManager().getAddonByName("BSkyBlock").ifPresent( - addon -> { -// BSkyBlock skyBlock = (BSkyBlock) addon; -// SkyBlock addon cannot change commands ;( - - new Challenges(this, - this.getPlugin().getCommandsManager().getCommand("bsbadmin")); - - new ChallengesCommand(this, - this.getPlugin().getCommandsManager().getCommand("island")); - - this.hooked = true; - }); - } + if (gameModeAddon.getAdminCommand().isPresent()) + { + new Challenges(this, gameModeAddon.getAdminCommand().get()); + this.hooked = true; + } + } + }); if (this.hooked) { // Try to find Level addon and if it does not exist, display a warning From 3d0f01f2ddd87e7540a0fcf17dcabd3b0f9a825b Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 20:31:26 +0200 Subject: [PATCH 076/103] Fix issue when icons cannot be changed via parse. Parser does not work with materials. Use materials directly instead. --- .../bentobox/challenges/panel/admin/EditChallengeGUI.java | 8 ++++---- .../bentobox/challenges/panel/admin/EditLevelGUI.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 4800f62..61cbb74 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -384,18 +384,18 @@ public class EditChallengeGUI extends CommonGUI this.user.getPlayer(), this.challenge.getIcon().getType().name(), (player, reply) -> { - ItemStack newIcon = ItemParser.parse(reply); + Material material = Material.getMaterial(reply); - if (newIcon != null) + if (material != null) { - this.challenge.setIcon(newIcon); + this.challenge.setIcon(new ItemStack(material)); + this.build(); } else { this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); } - this.build(); return reply; }); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index e50bff5..23deeb5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -331,18 +331,18 @@ public class EditLevelGUI extends CommonGUI this.user.getPlayer(), this.challengeLevel.getIcon().getType().name(), (player, reply) -> { - ItemStack newIcon = ItemParser.parse(reply); + Material material = Material.getMaterial(reply); - if (newIcon != null) + if (material != null) { - this.challengeLevel.setIcon(newIcon); + this.challengeLevel.setIcon(new ItemStack(material)); + this.build(); } else { this.user.sendMessage("challenges.errors.wrong-icon", "[value]", reply); } - this.build(); return reply; }); From 22205265f610e85cf8bbd59e122977d955e26fca Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 20:36:50 +0200 Subject: [PATCH 077/103] Fix issue when UniqueID was not accepted. Logical error. --- .../java/world/bentobox/challenges/panel/admin/AdminGUI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index d93d5b5..0140aea 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -201,7 +201,7 @@ public class AdminGUI extends CommonGUI (player, reply) -> { String newName = Util.getWorld(this.world).getName() + "_" + reply; - if (this.addon.getChallengesManager().containsChallenge(newName)) + if (!this.addon.getChallengesManager().containsChallenge(newName)) { new EditChallengeGUI(this.addon, this.world, @@ -237,7 +237,7 @@ public class AdminGUI extends CommonGUI (player, reply) -> { String newName = Util.getWorld(this.world).getName() + "_" + reply; - if (this.addon.getChallengesManager().containsLevel(newName)) + if (!this.addon.getChallengesManager().containsLevel(newName)) { new EditLevelGUI(this.addon, this.world, From d3bf5a157f45d766f4e7fd8b368e80f42c507b6f Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 20:46:04 +0200 Subject: [PATCH 078/103] Fix issue when Has_Island option in UserList did not show players if they have not done any challenge. --- .../bentobox/challenges/panel/admin/ListUsersGUI.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index 284c8cd..d00503c 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -3,16 +3,17 @@ package world.bentobox.challenges.panel.admin; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.OfflinePlayer; import org.bukkit.World; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.database.objects.Players; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.panel.CommonGUI; @@ -235,7 +236,10 @@ public class ListUsersGUI extends CommonGUI } else if (mode.equals(ViewMode.WITH_ISLAND)) { - return this.addon.getChallengesManager().getPlayers(this.world); + return this.addon.getPlayers().getPlayers().stream(). + filter(player -> this.addon.getIslands().getIsland(this.world, player.getPlayerUUID()) != null). + map(Players::getPlayer). + collect(Collectors.toList()); } else { From c3b87da88ee4a4bc6b016ffedbd2ae74097b9abf Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 21:34:40 +0200 Subject: [PATCH 079/103] Add 2 new variables in ChallengesAddon: - economyProvided that indicate if there exist any EconomyPlugin. - levelProvided that indicate if level addon is enabled. --- .../bentobox/challenges/ChallengesAddon.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 157588f..ce799a7 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -28,6 +28,15 @@ public class ChallengesAddon extends Addon { private boolean hooked; + /** + * This indicate if economy plugin exists. + */ + private boolean economyProvided; + + /** + * This indicate if level addon exists. + */ + private boolean levelProvided; // --------------------------------------------------------------------- // Section: Constants @@ -93,10 +102,19 @@ public class ChallengesAddon extends Addon { if (this.hooked) { // Try to find Level addon and if it does not exist, display a warning - if (!this.getAddonByName("Level").isPresent()) { + + this.levelProvided = this.getAddonByName("Level").isPresent(); + + if (!this.levelProvided) { this.logWarning("Level add-on not found so level challenges will not work!"); } + this.economyProvided = this.getPlugin().getVault().isPresent() && this.getPlugin().getVault().get().hook(); + + if (!this.economyProvided) { + this.logWarning("Economy plugin not found so money options will not work!"); + } + // Register the reset listener this.registerListener(new ResetListener(this)); // Register the autosave listener. @@ -185,4 +203,24 @@ public class ChallengesAddon extends Addon { { return this.settings; } + + + /** + * + * @return economyProvided variable. + */ + public boolean isEconomyProvided() + { + return economyProvided; + } + + + /** + * + * @return levelProvided variable. + */ + public boolean isLevelProvided() + { + return levelProvided; + } } From 96cb4488c384dd5e6b1fa066c70048f77d17a82a Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 21:44:33 +0200 Subject: [PATCH 080/103] Disable Money and Level buttons in admin panel, if EconomyPlugin or Level addon is missing. --- .../panel/admin/EditChallengeGUI.java | 162 ++++++++++++------ .../challenges/panel/admin/EditLevelGUI.java | 33 ++-- 2 files changed, 127 insertions(+), 68 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 61cbb74..523a652 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -11,7 +11,6 @@ import net.wesjd.anvilgui.AnvilGUI; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; @@ -25,9 +24,6 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary methods that creates GUI and allow to edit challenges * properties. - * - * TODO: In current class set that MONEY are availabe only if ECONOMY exist. - * TODO: In current class set that ISLAND LEVEL are availabe only if LEVEL ADDON exist. */ public class EditChallengeGUI extends CommonGUI { @@ -762,19 +758,29 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.required-level", "[value]", Long.toString(this.challenge.getRequiredIslandLevel()))); - icon = new ItemStack(Material.BEACON); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> { - if (status) - { - this.challenge.setRequiredIslandLevel(value); - } - this.build(); - }); + if (this.addon.isLevelProvided()) + { + icon = new ItemStack(Material.BEACON); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, (int) this.challenge.getRequiredIslandLevel(), (status, value) -> { + if (status) + { + this.challenge.setRequiredIslandLevel(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } @@ -785,18 +791,28 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.required-money", "[value]", Integer.toString(this.challenge.getRequiredMoney()))); - icon = new ItemStack(Material.GOLD_INGOT); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> { - if (status) - { - this.challenge.setRequiredMoney(value); - } - this.build(); - }); - return true; - }; + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRequiredMoney(), 0, (status, value) -> { + if (status) + { + this.challenge.setRequiredMoney(value); + } + + this.build(); + }); + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } + glow = false; break; } @@ -806,20 +822,31 @@ public class EditChallengeGUI extends CommonGUI if (this.challenge.isTakeMoney()) { - description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.enabled")); + description = Collections.singletonList(this.user + .getTranslation("challenges.gui.admin.descriptions.enabled")); } else { - description = Collections.singletonList(this.user.getTranslation("challenges.gui.admin.descriptions.disabled")); + description = Collections.singletonList(this.user + .getTranslation("challenges.gui.admin.descriptions.disabled")); } - icon = new ItemStack(Material.LEVER); - clickHandler = (panel, user, clickType, slot) -> { - this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.LEVER); + clickHandler = (panel, user, clickType, slot) -> { + this.challenge.setTakeMoney(!this.challenge.isTakeMoney()); + + this.build(); + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - this.build(); - return true; - }; glow = this.challenge.isTakeMoney(); break; } @@ -901,19 +928,29 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", "[value]", Integer.toString(this.challenge.getRewardMoney()))); - icon = new ItemStack(Material.GOLD_INGOT); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> { - if (status) - { - this.challenge.setRewardMoney(value); - } - this.build(); - }); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challenge.getRewardMoney(), 0, (status, value) -> { + if (status) + { + this.challenge.setRewardMoney(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } @@ -1062,19 +1099,32 @@ public class EditChallengeGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.repeat-reward-money", "[value]", Integer.toString(this.challenge.getRepeatMoneyReward()))); - icon = new ItemStack(Material.GOLD_NUGGET); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challenge.getRepeatMoneyReward(), 0, (status, value) -> { - if (status) - { - this.challenge.setRepeatMoneyReward(value); - } - this.build(); - }); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_NUGGET); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, + this.challenge.getRepeatMoneyReward(), + 0, + (status, value) -> { + if (status) + { + this.challenge.setRepeatMoneyReward(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index 23deeb5..e3113a5 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -28,7 +28,6 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary elements to create Levels Edit GUI. - * TODO: In current class set that MONEY are availabe only if ECONOMY exist. */ public class EditLevelGUI extends CommonGUI { @@ -493,19 +492,29 @@ public class EditLevelGUI extends CommonGUI this.user.getTranslation("challenges.gui.admin.descriptions.reward-money", "[value]", Integer.toString(this.challengeLevel.getRewardMoney()))); - icon = new ItemStack(Material.GOLD_INGOT); - clickHandler = (panel, user, clickType, slot) -> { - new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> { - if (status) - { - this.challengeLevel.setRewardMoney(value); - } - this.build(); - }); + if (this.addon.isEconomyProvided()) + { + icon = new ItemStack(Material.GOLD_INGOT); + clickHandler = (panel, user, clickType, slot) -> { + new NumberGUI(this.user, this.challengeLevel.getRewardMoney(), 0, (status, value) -> { + if (status) + { + this.challengeLevel.setRewardMoney(value); + } + + this.build(); + }); + + return true; + }; + } + else + { + icon = new ItemStack(Material.BARRIER); + clickHandler = null; + } - return true; - }; glow = false; break; } From e68c5b27731e9c37b62e44f484ba99b203551cb5 Mon Sep 17 00:00:00 2001 From: BONNe Date: Wed, 23 Jan 2019 21:50:10 +0200 Subject: [PATCH 081/103] Fix issue, when top command was not displayed in Description. --- .../world/bentobox/challenges/panel/user/ChallengesGUI.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index d9c54e6..575fe8d 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -424,6 +424,8 @@ public class ChallengesGUI extends CommonGUI result.addAll(this.challengeRewards(challenge)); } + result.replaceAll(x -> x.replace("[label]", this.topLabel)); + return result; } From 2734c70fc559506e8ac29cf47c6f783c3c6565bf Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 24 Jan 2019 23:28:25 +0200 Subject: [PATCH 082/103] Add direct access to vaultHook and Level addon. --- .../bentobox/challenges/ChallengesAddon.java | 60 +++++++++++++++++-- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index ce799a7..0160b4a 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -2,12 +2,17 @@ package world.bentobox.challenges; import org.bukkit.Bukkit; +import java.util.Optional; + import world.bentobox.bentobox.api.configuration.Config; +import world.bentobox.bentobox.hooks.VaultHook; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.commands.admin.Challenges; import world.bentobox.challenges.listeners.ResetListener; import world.bentobox.challenges.listeners.SaveListener; import world.bentobox.bentobox.api.addons.Addon; +import world.bentobox.level.Level; + /** * Add-on to BSkyBlock that enables challenges @@ -29,10 +34,20 @@ public class ChallengesAddon extends Addon { private boolean hooked; /** - * This indicate if economy plugin exists. + * This boolean indicate if economy is enabled. */ private boolean economyProvided; + /** + * VaultHook that process economy. + */ + private VaultHook vaultHook; + + /** + * Level addon. + */ + private Level levelAddon; + /** * This indicate if level addon exists. */ @@ -103,17 +118,31 @@ public class ChallengesAddon extends Addon { if (this.hooked) { // Try to find Level addon and if it does not exist, display a warning - this.levelProvided = this.getAddonByName("Level").isPresent(); + Optional level = this.getAddonByName("Level"); - if (!this.levelProvided) { + if (!level.isPresent()) + { this.logWarning("Level add-on not found so level challenges will not work!"); + this.levelAddon = null; + } + else + { + this.levelProvided = true; + this.levelAddon = (Level) level.get(); } - this.economyProvided = this.getPlugin().getVault().isPresent() && this.getPlugin().getVault().get().hook(); + Optional vault = this.getPlugin().getVault(); - if (!this.economyProvided) { + if (!vault.isPresent() || !vault.get().hook()) + { + this.vaultHook = null; this.logWarning("Economy plugin not found so money options will not work!"); } + else + { + this.economyProvided = true; + this.vaultHook = vault.get(); + } // Register the reset listener this.registerListener(new ResetListener(this)); @@ -215,6 +244,17 @@ public class ChallengesAddon extends Addon { } + /** + * Returns VaultHook. Used to get easier access to Economy. NEVER USE WITHOUT isEconomyProvided or null + * check. + * @return VaultHook or null. + */ + public VaultHook getEconomyProvider() + { + return vaultHook; + } + + /** * * @return levelProvided variable. @@ -223,4 +263,14 @@ public class ChallengesAddon extends Addon { { return levelProvided; } + + + /** + * This method returns Level addon. Used to easier access to Level. NEVER USE WITHOUT isLevelProvided or null + * @return LevelAddon or null. + */ + public Level getLevelAddon() + { + return levelAddon; + } } From 1375d13ae47f9cfeb4e6acac43bf2290ce21e243 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 24 Jan 2019 23:28:54 +0200 Subject: [PATCH 083/103] Remove unused import. --- src/main/java/world/bentobox/challenges/ChallengesManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 7cd09b9..9278ba1 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -7,12 +7,11 @@ import org.bukkit.entity.Player; import java.util.*; import java.util.stream.Collectors; -import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.api.user.User; import world.bentobox.bentobox.database.Database; import world.bentobox.bentobox.util.Util; -import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.ChallengesPlayerData; import world.bentobox.challenges.utils.LevelStatus; From 52b02e06bf921d57cdf00b3e43597b6f50e40612 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 24 Jan 2019 23:29:56 +0200 Subject: [PATCH 084/103] Rework TryToComplete class. Remove unnecessary code. --- .../challenges/panel/ChallengesPanels2.java | 24 +- .../challenges/panel/TryToComplete.java | 894 +++++++++++------- .../panel/admin/EditChallengeGUI.java | 1 + .../challenges/panel/user/ChallengesGUI.java | 7 +- 4 files changed, 584 insertions(+), 342 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java index ea56420..2006f46 100644 --- a/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java +++ b/src/main/java/world/bentobox/challenges/panel/ChallengesPanels2.java @@ -1,26 +1,26 @@ package world.bentobox.challenges.panel; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; -import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.database.object.ChallengeLevel; -import world.bentobox.challenges.utils.GuiUtils; -import world.bentobox.challenges.utils.LevelStatus; -import world.bentobox.challenges.commands.ChallengesCommand; -import world.bentobox.challenges.database.object.Challenge; -import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.bentobox.api.panels.Panel; import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.ChallengesManager; +import world.bentobox.challenges.commands.ChallengesCommand; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; +import world.bentobox.challenges.database.object.ChallengeLevel; +import world.bentobox.challenges.utils.GuiUtils; +import world.bentobox.challenges.utils.LevelStatus; /** @@ -152,7 +152,7 @@ public class ChallengesPanels2 { } else { // Player click itemBuilder.clickHandler((panel, player, c, s) -> { - new TryToComplete(addon, player, manager, challenge, world, permPrefix, label); + new TryToComplete(addon, player, challenge, world, label, permPrefix); return true; }); } diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index aadbc38..92b558a 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -3,387 +3,532 @@ */ package world.bentobox.challenges.panel; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.util.Vector; +import java.util.*; +import java.util.stream.Collectors; -import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.commands.ChallengesCommand; -import world.bentobox.challenges.database.object.Challenge; -import world.bentobox.challenges.database.object.Challenge.ChallengeType; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.hooks.VaultHook; import world.bentobox.bentobox.util.Util; -import world.bentobox.level.Level; +import world.bentobox.challenges.ChallengesAddon; +import world.bentobox.challenges.ChallengesManager; +import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.Challenge.ChallengeType; + /** * Run when a user tries to complete a challenge * @author tastybento * */ -public class TryToComplete { +public class TryToComplete +{ +// --------------------------------------------------------------------- +// Section: Variables +// --------------------------------------------------------------------- + /** + * Challenges addon variable. + */ private ChallengesAddon addon; - private World world; - private String permPrefix; - private User user; - private ChallengesManager manager; - private Challenge challenge; - private String label; - public TryToComplete label(String label) { - this.label = label; + /** + * Challenges manager for addon. + */ + private ChallengesManager manager; + + /** + * World where all checks are necessary. + */ + private World world; + + /** + * User who is completing challenge. + */ + private User user; + + /** + * Permission prefix string. + */ + private String permissionPrefix; + + /** + * Top command first label. + */ + private String topLabel; + + /** + * Challenge that should be completed. + */ + private Challenge challenge; + + +// --------------------------------------------------------------------- +// Section: Builder +// --------------------------------------------------------------------- + + @Deprecated + public TryToComplete label(String label) + { + this.topLabel = label; return this; } - public TryToComplete user(User user) { + + @Deprecated + public TryToComplete user(User user) + { this.user = user; return this; } - public TryToComplete manager(ChallengesManager manager) { + + @Deprecated + public TryToComplete manager(ChallengesManager manager) + { this.manager = manager; return this; } - public TryToComplete challenge(Challenge challenge) { + + @Deprecated + public TryToComplete challenge(Challenge challenge) + { this.challenge = challenge; return this; } - public TryToComplete world(World world) { + + @Deprecated + public TryToComplete world(World world) + { this.world = world; return this; } - public TryToComplete permPrefix(String prefix) { - this.permPrefix = prefix; + + @Deprecated + public TryToComplete permPrefix(String prefix) + { + this.permissionPrefix = prefix; return this; } - public TryToComplete(ChallengesAddon addon) { + + @Deprecated + public TryToComplete(ChallengesAddon addon) + { this.addon = addon; } - public ChallengeResult build() { + +// --------------------------------------------------------------------- +// Section: Constructor +// --------------------------------------------------------------------- + + + /** + * @param addon - Challenges Addon. + * @param user - User who performs challenge. + * @param challenge - Challenge that should be completed. + * @param world - World where completion may occur. + * @param topLabel - Label of the top command. + * @param permissionPrefix - Permission prefix for GameMode addon. + */ + public TryToComplete(ChallengesAddon addon, + User user, + Challenge challenge, + World world, + String topLabel, + String permissionPrefix) + { + this.addon = addon; + this.world = world; + this.permissionPrefix = permissionPrefix; + this.user = user; + this.manager = addon.getChallengesManager(); + this.challenge = challenge; + this.topLabel = topLabel; + + this.build(); + } + + +// --------------------------------------------------------------------- +// Section: Methods +// --------------------------------------------------------------------- + + + /** + * This method checks if challenge can be done, and complete it, if it is possible. + * @return ChallengeResult object, that contains completion status. + */ + public ChallengeResult build() + { // Check if can complete challenge - ChallengeResult result = checkIfCanCompleteChallenge(); - if (!result.meetsRequirements) { + ChallengeResult result = this.checkIfCanCompleteChallenge(); + + if (!result.meetsRequirements) + { return result; } - if (!result.repeat) { - // Give rewards - for (ItemStack reward : challenge.getRewardItems()) { - user.getInventory().addItem(reward).forEach((k,v) -> user.getWorld().dropItem(user.getLocation(), v)); + + if (!result.repeat) + { + // Item rewards + for (ItemStack reward : this.challenge.getRewardItems()) + { + this.user.getInventory().addItem(reward).forEach((k, v) -> + this.user.getWorld().dropItem(this.user.getLocation(), v)); } - // Give money - this.addon.getPlugin().getVault().ifPresent( - vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney())); + // Money Reward + if (this.addon.isEconomyProvided()) + { + this.addon.getEconomyProvider().deposit(this.user, this.challenge.getRewardMoney()); + } + + // Experience Reward + this.user.getPlayer().giveExp(this.challenge.getRewardExperience()); - // Give exp - user.getPlayer().giveExp(challenge.getRewardExperience()); // Run commands - runCommands(challenge.getRewardCommands()); - user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); - if (addon.getChallengesSettings().isBroadcastMessages()) { - for (Player p : addon.getServer().getOnlinePlayers()) { + this.runCommands(this.challenge.getRewardCommands()); + + this.user.sendMessage("challenges.you-completed", "[challenge]", this.challenge.getFriendlyName()); + + if (this.addon.getChallengesSettings().isBroadcastMessages()) + { + for (Player p : this.addon.getServer().getOnlinePlayers()) + { User.getInstance(p).sendMessage("challenges.name-has-completed", - "[name]", user.getName(), "[challenge]", challenge.getFriendlyName()); + "[name]", this.user.getName(), "[challenge]", this.challenge.getFriendlyName()); } } - } else { - // Give rewards - for (ItemStack reward : challenge.getRepeatItemReward()) { - user.getInventory().addItem(reward).forEach((k,v) -> user.getWorld().dropItem(user.getLocation(), v)); + } + else + { + // Item Repeat Rewards + for (ItemStack reward : this.challenge.getRepeatItemReward()) + { + this.user.getInventory().addItem(reward).forEach((k, v) -> + this.user.getWorld().dropItem(this.user.getLocation(), v)); } - // Give money - this.addon.getPlugin().getVault().ifPresent( - vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward())); + // Money Repeat Reward + if (this.addon.isEconomyProvided()) + { + this.addon.getEconomyProvider().deposit(this.user, this.challenge.getRepeatMoneyReward()); + } + + // Experience Repeat Reward + this.user.getPlayer().giveExp(this.challenge.getRepeatExperienceReward()); - // Give exp - user.getPlayer().giveExp(challenge.getRepeatExperienceReward()); // Run commands - runCommands(challenge.getRepeatRewardCommands()); - user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); + this.runCommands(this.challenge.getRepeatRewardCommands()); + + this.user.sendMessage("challenges.you-repeated", "[challenge]", this.challenge.getFriendlyName()); } + // Mark as complete - manager.setChallengeComplete(user, challenge); - user.closeInventory(); - user.getPlayer().performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + challenge.getLevel()); + this.manager.setChallengeComplete(this.user, this.challenge); + return result; } - /** - * @param addon - * @param user - * @param manager - * @param challenge - * @param world - * @param permPrefix - */ - public TryToComplete(ChallengesAddon addon, User user, ChallengesManager manager, Challenge challenge, World world, String permPrefix, String label) { - this.addon = addon; - this.world = world; - this.permPrefix = permPrefix; - this.user = user; - this.manager = manager; - this.challenge = challenge; - - // Check if can complete challenge - ChallengeResult result = checkIfCanCompleteChallenge(); - if (!result.meetsRequirements) { - return; - } - if (!result.repeat) { - // Give rewards - for (ItemStack reward : challenge.getRewardItems()) { - user.getInventory().addItem(reward).forEach((k,v) -> user.getWorld().dropItem(user.getLocation(), v)); - } - - // Give money - this.addon.getPlugin().getVault().ifPresent( - vaultHook -> vaultHook.deposit(this.user, this.challenge.getRewardMoney())); - - // Give exp - user.getPlayer().giveExp(challenge.getRewardExperience()); - // Run commands - runCommands(challenge.getRewardCommands()); - user.sendMessage("challenges.you-completed", "[challenge]", challenge.getFriendlyName()); - if (addon.getChallengesSettings().isBroadcastMessages()) { - for (Player p : addon.getServer().getOnlinePlayers()) { - User.getInstance(p).sendMessage("challenges.name-has-completed", - "[name]", user.getName(), "[challenge]", challenge.getFriendlyName()); - } - } - } else { - // Give rewards - for (ItemStack reward : challenge.getRepeatItemReward()) { - user.getInventory().addItem(reward).forEach((k,v) -> user.getWorld().dropItem(user.getLocation(), v)); - } - - // Give money - this.addon.getPlugin().getVault().ifPresent( - vaultHook -> vaultHook.deposit(this.user, this.challenge.getRepeatMoneyReward())); - - // Give exp - user.getPlayer().giveExp(challenge.getRepeatExperienceReward()); - // Run commands - runCommands(challenge.getRepeatRewardCommands()); - user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); - } - // Mark as complete - manager.setChallengeComplete(user, challenge); - user.closeInventory(); - user.getPlayer().performCommand(label + " " + ChallengesCommand.CHALLENGE_COMMAND + " " + challenge.getLevel()); - } /** * Checks if a challenge can be completed or not + * It returns ChallengeResult. */ - private ChallengeResult checkIfCanCompleteChallenge() { + private ChallengeResult checkIfCanCompleteChallenge() + { + ChallengeType type = this.challenge.getChallengeType(); + // Check the world - if (!challenge.getUniqueId().startsWith(Util.getWorld(world).getName())) { - user.sendMessage("general.errors.wrong-world"); - return new ChallengeResult(); + if (!this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName())) + { + this.user.sendMessage("general.errors.wrong-world"); } - // Check if user has the - if (!challenge.getLevel().equals(ChallengesManager.FREE) && !manager.isLevelUnlocked(user, world, manager.getLevel(challenge.getLevel()))) { - user.sendMessage("challenges.errors.challenge-level-not-available"); - return new ChallengeResult(); + // Check if user has unlocked challenges level. + else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) && + !this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel()))) + { + this.user.sendMessage("challenges.errors.challenge-level-not-available"); } // Check max times - if (challenge.isRepeatable() && challenge.getMaxTimes() > 0 && manager.getChallengeTimes(user, challenge) >= challenge.getMaxTimes()) { - user.sendMessage("challenges.not-repeatable"); - return new ChallengeResult(); + else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 && + this.manager.getChallengeTimes(this.user, this.challenge) >= this.challenge.getMaxTimes()) + { + this.user.sendMessage("challenges.not-repeatable"); } // Check repeatability - if (manager.isChallengeComplete(user, challenge) - && (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.OTHER) - || challenge.getChallengeType().equals(ChallengeType.ISLAND))) { - user.sendMessage("challenges.not-repeatable"); - return new ChallengeResult(); - } - - // Check money - Optional vaultHook = this.addon.getPlugin().getVault(); - - if (vaultHook.isPresent()) + else if (this.manager.isChallengeComplete(this.user, this.challenge) + && (!this.challenge.isRepeatable() || type.equals(ChallengeType.ISLAND))) { - if (!vaultHook.get().has(this.user, this.challenge.getRequiredMoney())) - { - this.user.sendMessage("challenges.not-enough-money", "[money]", Integer.toString(this.challenge.getRequiredMoney())); - return new ChallengeResult(); - } + this.user.sendMessage("challenges.not-repeatable"); } - - // Check exp - if (this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience()) + else if (type.equals(ChallengeType.INVENTORY)) { - this.user.sendMessage("challenges.not-enough-exp", "[xp]", Integer.toString(this.challenge.getRequiredExperience())); - return new ChallengeResult(); + return this.checkInventory(); + } + else if (type.equals(ChallengeType.ISLAND)) + { + return this.checkSurrounding(); + } + else if (type.equals(ChallengeType.OTHER)) + { + return this.checkOthers(); } - switch (challenge.getChallengeType()) { - case INVENTORY: - return checkInventory(); - case OTHER: - return checkLevel(); - case ISLAND: - return checkSurrounding(); - default: - return new ChallengeResult(); - } - } - - private ChallengeResult checkInventory() { - // Run through inventory - List required = new ArrayList<>(challenge.getRequiredItems()); - for (ItemStack req : required) { - // Check for FIREWORK_ROCKET, ENCHANTED_BOOK, WRITTEN_BOOK, POTION and FILLED_MAP because these have unique meta when created - switch (req.getType()) { - case FIREWORK_ROCKET: - case ENCHANTED_BOOK: - case WRITTEN_BOOK: - case FILLED_MAP: - // Get how many items are in the inventory. Item stacks amounts need to be summed - int numInInventory = Arrays.stream(user.getInventory().getContents()).filter(Objects::nonNull).filter(i -> i.getType().equals(req.getType())).mapToInt(i -> i.getAmount()).sum(); - if (numInInventory < req.getAmount()) { - user.sendMessage("challenges.error.not-enough-items", "[items]", Util.prettifyText(req.getType().toString())); - return new ChallengeResult(); - } - break; - default: - // General checking - if (!user.getInventory().containsAtLeast(req, req.getAmount())) { - user.sendMessage("challenges.error.not-enough-items", "[items]", Util.prettifyText(req.getType().toString())); - return new ChallengeResult(); - } - } - - } - // If remove items, then remove them - if (challenge.isTakeItems()) { - removeItems(required); - - } - - // process money removal - this.removeMoney(); - - // Return the result - return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge)); + // Everything fails till this point. + return new ChallengeResult(); } /** - * This method withdraw user money, if challenge Required Money is larger then 0, and - * it is set to removal. - * This works only if vaultHook is enabled. - */ - private void removeMoney() + * This method runs all commands from command list. + * @param commands List of commands that must be performed. + */ + private void runCommands(List commands) { - Optional vaultHook = this.addon.getPlugin().getVault(); - - if (vaultHook.isPresent() && - this.challenge.isTakeMoney() && - this.challenge.getRequiredMoney() > 0) + // Ignore commands with this perm + if (user.hasPermission(this.permissionPrefix + "command.challengeexempt") && !user.isOp()) { - vaultHook.get().withdraw(this.user, this.challenge.getRequiredMoney()); + return; } + for (String cmd : commands) + { + if (cmd.startsWith("[SELF]")) + { + String alert = "Running command '" + cmd + "' as " + this.user.getName(); + this.addon.getLogger().info(alert); + cmd = cmd.substring(6, cmd.length()).replace("[player]", this.user.getName()).trim(); + try + { + if (!user.performCommand(cmd)) + { + this.showError(cmd); + } + } + catch (Exception e) + { + this.showError(cmd); + } + + continue; + } + // Substitute in any references to player + try + { + if (!this.addon.getServer().dispatchCommand(this.addon.getServer().getConsoleSender(), + cmd.replace("[player]", this.user.getName()))) + { + this.showError(cmd); + } + } + catch (Exception e) + { + this.showError(cmd); + } + } + } + + + /** + * Throws error message. + * @param cmd Error message that appear after failing some command. + */ + private void showError(final String cmd) + { + this.addon.getLogger().severe("Problem executing command executed by player - skipping!"); + this.addon.getLogger().severe(() -> "Command was : " + cmd); + } + + +// --------------------------------------------------------------------- +// Section: Inventory Challenge +// --------------------------------------------------------------------- + + + /** + * Checks if a inventory challenge can be completed or not + * It returns ChallengeResult. + */ + private ChallengeResult checkInventory() + { + // Run through inventory + List required = new ArrayList<>(this.challenge.getRequiredItems()); + for (ItemStack req : required) + { + // Check for FIREWORK_ROCKET, ENCHANTED_BOOK, WRITTEN_BOOK, POTION and FILLED_MAP because these have unique meta when created + switch (req.getType()) + { + case FIREWORK_ROCKET: + case ENCHANTED_BOOK: + case WRITTEN_BOOK: + case FILLED_MAP: + // Get how many items are in the inventory. Item stacks amounts need to be summed + int numInInventory = + Arrays.stream(this.user.getInventory().getContents()).filter(Objects::nonNull). + filter(i -> i.getType().equals(req.getType())). + mapToInt(ItemStack::getAmount). + sum(); + + if (numInInventory < req.getAmount()) + { + this.user.sendMessage("challenges.error.not-enough-items", + "[items]", + Util.prettifyText(req.getType().toString())); + return new ChallengeResult(); + } + break; + default: + // General checking + if (!this.user.getInventory().containsAtLeast(req, req.getAmount())) + { + this.user.sendMessage("challenges.error.not-enough-items", + "[items]", + Util.prettifyText(req.getType().toString())); + return new ChallengeResult(); + } + } + } + + // If remove items, then remove them + + if (this.challenge.isTakeItems()) + { + this.removeItems(required); + } + + + // Return the result + return new ChallengeResult().setMeetsRequirements().setRepeat( + this.manager.isChallengeComplete(this.user, this.challenge)); } /** * Removes items from a user's inventory * @param required - a list of item stacks to be removed - * @return Map of item type and quantity that were successfully removed from the user's inventory */ - public Map removeItems(List required) { + Map removeItems(List required) + { Map removed = new HashMap<>(); - for (ItemStack req : required) { + + for (ItemStack req : required) + { int amountToBeRemoved = req.getAmount(); - List itemsInInv = Arrays.stream(user.getInventory().getContents()).filter(Objects::nonNull).filter(i -> i.getType().equals(req.getType())).collect(Collectors.toList()); - for (ItemStack i : itemsInInv) { - if (amountToBeRemoved > 0) { + List itemsInInv = Arrays.stream(user.getInventory().getContents()). + filter(Objects::nonNull). + filter(i -> i.getType().equals(req.getType())). + collect(Collectors.toList()); + + for (ItemStack i : itemsInInv) + { + if (amountToBeRemoved > 0) + { // Remove either the full amount or the remaining amount - if (i.getAmount() >= amountToBeRemoved) { + if (i.getAmount() >= amountToBeRemoved) + { i.setAmount(i.getAmount() - amountToBeRemoved); removed.merge(i.getType(), amountToBeRemoved, Integer::sum); amountToBeRemoved = 0; - } else { + } + else + { removed.merge(i.getType(), i.getAmount(), Integer::sum); amountToBeRemoved -= i.getAmount(); i.setAmount(0); - } } } - if (amountToBeRemoved > 0) { - addon.logError("Could not remove " + amountToBeRemoved + " of " + req.getType() + " from player's inventory!"); + + if (amountToBeRemoved > 0) + { + this.addon.logError("Could not remove " + amountToBeRemoved + " of " + req.getType() + + " from player's inventory!"); } } + return removed; } - private ChallengeResult checkLevel() { - // Check if the level addon is installed or not - long level = addon.getAddonByName("Level") - .map(l -> ((Level)l).getIslandLevel(world, user.getUniqueId())).orElse(0L); - if (level >= challenge.getRequiredIslandLevel()) { - // process money removal - this.removeMoney(); - return new ChallengeResult().setMeetsRequirements(); - } else { - user.sendMessage("challenges.error.island-level", TextVariables.NUMBER, String.valueOf(challenge.getRequiredIslandLevel())); - return new ChallengeResult(); - } - } - private ChallengeResult checkSurrounding() { - if (!addon.getIslands().userIsOnIsland(world, user)) { - // Player is not on island - user.sendMessage("challenges.error.not-on-island"); - return new ChallengeResult(); - } - // Check for items or entities in the area - ChallengeResult result = searchForEntities(challenge.getRequiredEntities(), challenge.getSearchRadius()); - if (result.meetsRequirements && !challenge.getRequiredBlocks().isEmpty()) { - // Search for items only if entities found - result = searchForBlocks(challenge.getRequiredBlocks(), challenge.getSearchRadius()); - } +// --------------------------------------------------------------------- +// Section: Island Challenge +// --------------------------------------------------------------------- - if (result.meetsRequirements && this.challenge.isTakeMoney()) + + /** + * Checks if a island challenge can be completed or not + * It returns ChallengeResult. + */ + private ChallengeResult checkSurrounding() + { + ChallengeResult result; + + if (!this.addon.getIslands().userIsOnIsland(this.world, this.user)) { - // process money removal - this.removeMoney(); + // Player is not on island + this.user.sendMessage("challenges.error.not-on-island"); + result = new ChallengeResult(); + } + else + { + // Check for items or entities in the area + + result = this.searchForEntities(this.challenge.getRequiredEntities(), this.challenge.getSearchRadius()); + + if (result.meetsRequirements && !this.challenge.getRequiredBlocks().isEmpty()) + { + // Search for items only if entities found + result = this.searchForBlocks(this.challenge.getRequiredBlocks(), this.challenge.getSearchRadius()); + } + + if (result.meetsRequirements && + this.challenge.isRemoveEntities() && + !this.challenge.getRequiredEntities().isEmpty()) + { + this.removeEntities(); + } + + if (result.meetsRequirements && + this.challenge.isRemoveBlocks() && + !this.challenge.getRequiredBlocks().isEmpty()) + { + this.removeBlocks(); + } } return result; } - private ChallengeResult searchForBlocks(Map map, int searchRadius) { + + /** + * This method search required blocks in given radius from user position. + * @param map RequiredBlock Map. + * @param searchRadius Search distance + * @return ChallengeResult + */ + private ChallengeResult searchForBlocks(Map map, int searchRadius) + { Map blocks = new EnumMap<>(map); - for (int x = -searchRadius; x <= searchRadius; x++) { - for (int y = -searchRadius; y <= searchRadius; y++) { - for (int z = -searchRadius; z <= searchRadius; z++) { - Material mat = user.getWorld().getBlockAt(user.getLocation().add(new Vector(x,y,z))).getType(); + + for (int x = -searchRadius; x <= searchRadius; x++) + { + for (int y = -searchRadius; y <= searchRadius; y++) + { + for (int z = -searchRadius; z <= searchRadius; z++) + { + Material mat = this.user.getWorld().getBlockAt(this.user.getLocation().add(new Vector(x, y, z))).getType(); // Remove one blocks.computeIfPresent(mat, (b, amount) -> amount - 1); // Remove any that have an amount of 0 @@ -391,92 +536,189 @@ public class TryToComplete { } } } - if (blocks.isEmpty()) { + + if (blocks.isEmpty()) + { return new ChallengeResult().setMeetsRequirements(); } - user.sendMessage("challenges.error.not-close-enough", "[number]", String.valueOf(searchRadius)); - blocks.forEach((k,v) -> user.sendMessage("challenges.error.you-still-need", - "[amount]", String.valueOf(v), - "[item]", Util.prettifyText(k.toString()))); - return new ChallengeResult(); - } + this.user.sendMessage("challenges.error.not-close-enough", "[number]", String.valueOf(searchRadius)); + + blocks.forEach((k, v) -> user.sendMessage("challenges.error.you-still-need", + "[amount]", String.valueOf(v), + "[item]", Util.prettifyText(k.toString()))); - private ChallengeResult searchForEntities(Map map, int searchRadius) { - Map entities = map.isEmpty() ? new EnumMap<>(EntityType.class) : new EnumMap<>(map); - user.getPlayer().getNearbyEntities(searchRadius, searchRadius, searchRadius).forEach(entity -> { - // Look through all the nearby Entities, filtering by type - entities.computeIfPresent(entity.getType(), (reqEntity, amount) -> amount - 1); - entities.entrySet().removeIf(e -> e.getValue() == 0); - }); - if (entities.isEmpty()) { - return new ChallengeResult().setMeetsRequirements(); - } - entities.forEach((reqEnt, amount) -> user.sendMessage("challenges.error.you-still-need", - "[amount]", String.valueOf(amount), - "[item]", Util.prettifyText(reqEnt.toString()))); return new ChallengeResult(); } /** - * Contains flags on completion of challenge - * @author tastybento - * + * This method search required entities in given radius from user position. + * @param map RequiredEntities Map. + * @param searchRadius Search distance + * @return ChallengeResult */ - public class ChallengeResult { + private ChallengeResult searchForEntities(Map map, int searchRadius) + { + Map entities = map.isEmpty() ? new EnumMap<>(EntityType.class) : new EnumMap<>(map); + + this.user.getPlayer().getNearbyEntities(searchRadius, searchRadius, searchRadius).forEach(entity -> { + // Look through all the nearby Entities, filtering by type + entities.computeIfPresent(entity.getType(), (reqEntity, amount) -> amount - 1); + entities.entrySet().removeIf(e -> e.getValue() == 0); + }); + + if (entities.isEmpty()) + { + return new ChallengeResult().setMeetsRequirements(); + } + + entities.forEach((reqEnt, amount) -> this.user.sendMessage("challenges.error.you-still-need", + "[amount]", String.valueOf(amount), + "[item]", Util.prettifyText(reqEnt.toString()))); + + return new ChallengeResult(); + } + + + /** + * This method removes required block and set air instead of it. + */ + private void removeBlocks() + { + Map blocks = new EnumMap<>(this.challenge.getRequiredBlocks()); + int searchRadius = this.challenge.getSearchRadius(); + + for (int x = -searchRadius; x <= searchRadius; x++) + { + for (int y = -searchRadius; y <= searchRadius; y++) + { + for (int z = -searchRadius; z <= searchRadius; z++) + { + Block block = this.user.getWorld().getBlockAt(this.user.getLocation().add(new Vector(x, y, z))); + + if (blocks.containsKey(block.getType())) + { + blocks.computeIfPresent(block.getType(), (b, amount) -> amount - 1); + blocks.entrySet().removeIf(en -> en.getValue() <= 0); + + block.setType(Material.AIR); + } + } + } + } + } + + + /** + * This method removes required entities. + */ + private void removeEntities() + { + Map entities = this.challenge.getRequiredEntities().isEmpty() ? + new EnumMap<>(EntityType.class) : new EnumMap<>(this.challenge.getRequiredEntities()); + + int searchRadius = this.challenge.getSearchRadius(); + + this.user.getPlayer().getNearbyEntities(searchRadius, searchRadius, searchRadius).forEach(entity -> { + // Look through all the nearby Entities, filtering by type + + if (entities.containsKey(entity.getType())) + { + entities.computeIfPresent(entity.getType(), (reqEntity, amount) -> amount - 1); + entities.entrySet().removeIf(e -> e.getValue() == 0); + entity.remove(); + } + }); + } + + +// --------------------------------------------------------------------- +// Section: Other challenge +// --------------------------------------------------------------------- + + + /** + * Checks if a other challenge can be completed or not + * It returns ChallengeResult. + */ + private ChallengeResult checkOthers() + { + if (!this.addon.isEconomyProvided() || + this.challenge.getRequiredMoney() <= 0 || + !this.addon.getEconomyProvider().has(this.user, this.challenge.getRequiredMoney())) + { + this.user.sendMessage("challenges.not-enough-money", + "[money]", + Integer.toString(this.challenge.getRequiredMoney())); + } + else if (this.challenge.getRequiredExperience() <= 0 || + this.user.getPlayer().getTotalExperience() < this.challenge.getRequiredExperience()) + { + this.user.sendMessage("challenges.not-enough-exp", + "[xp]", + Integer.toString(this.challenge.getRequiredExperience())); + } + else if (!this.addon.isLevelProvided() || + this.addon.getLevelAddon().getIslandLevel(this.world, this.user.getUniqueId()) < this.challenge.getRequiredIslandLevel()) + { + this.user.sendMessage("challenges.error.island-level", + TextVariables.NUMBER, + String.valueOf(this.challenge.getRequiredIslandLevel())); + } + else + { + if (this.addon.isEconomyProvided() && this.challenge.isTakeMoney()) + { + this.addon.getEconomyProvider().withdraw(this.user, this.challenge.getRequiredMoney()); + } + + if (this.challenge.isTakeExperience()) + { + this.user.getPlayer().setTotalExperience( + this.user.getPlayer().getTotalExperience() - this.challenge.getRequiredExperience()); + } + + return new ChallengeResult().setMeetsRequirements(); + } + + return new ChallengeResult(); + } + + +// --------------------------------------------------------------------- +// Section: Private classes +// --------------------------------------------------------------------- + + + /** + * Contains flags on completion of challenge + * + * @author tastybento + */ + private class ChallengeResult + { private boolean meetsRequirements; + private boolean repeat; + + /** */ - public ChallengeResult setMeetsRequirements() { + ChallengeResult setMeetsRequirements() + { this.meetsRequirements = true; return this; } + + /** * @param repeat the repeat to set */ - public ChallengeResult setRepeat(boolean repeat) { + ChallengeResult setRepeat(boolean repeat) + { this.repeat = repeat; return this; } - - } - - private void runCommands(List commands) { - // Ignore commands with this perm - if (user.hasPermission(permPrefix + "command.challengeexempt") && !user.isOp()) { - return; - } - for (String cmd : commands) { - if (cmd.startsWith("[SELF]")) { - String alert = "Running command '" + cmd + "' as " + user.getName(); - addon.getLogger().info(alert); - cmd = cmd.substring(6,cmd.length()).replace("[player]", user.getName()).trim(); - try { - if (!user.performCommand(cmd)) { - showError(cmd); - } - } catch (Exception e) { - showError(cmd); - } - - continue; - } - // Substitute in any references to player - try { - if (!addon.getServer().dispatchCommand(addon.getServer().getConsoleSender(), cmd.replace("[player]", user.getName()))) { - showError(cmd); - } - } catch (Exception e) { - showError(cmd); - } - } - } - - private void showError(final String cmd) { - addon.getLogger().severe("Problem executing command executed by player - skipping!"); - addon.getLogger().severe(() -> "Command was : " + cmd); - } } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 523a652..33d7653 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -24,6 +24,7 @@ import world.bentobox.challenges.utils.GuiUtils; /** * This class contains all necessary methods that creates GUI and allow to edit challenges * properties. + * TODO: ISLAND is not repeatable. */ public class EditChallengeGUI extends CommonGUI { diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index 575fe8d..b4f0775 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -14,10 +14,10 @@ import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.TryToComplete; +import world.bentobox.challenges.utils.LevelStatus; /** @@ -324,11 +324,10 @@ public class ChallengesGUI extends CommonGUI clickHandler((panel, user1, clickType, slot) -> { new TryToComplete(this.addon, this.user, - this.challengesManager, challenge, this.world, - this.permissionPrefix, - this.topLabel); + this.topLabel, + this.permissionPrefix); return true; }). glow(this.challengesManager.isChallengeComplete(this.user, challenge)). From 0943a48c3c70e8f7a9676fe9830646ae2cdac21e Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 24 Jan 2019 23:57:50 +0200 Subject: [PATCH 085/103] Add Environment check when completing challenge. --- .../java/world/bentobox/challenges/panel/TryToComplete.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 92b558a..2fc3a43 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -274,6 +274,12 @@ public class TryToComplete { this.user.sendMessage("challenges.not-repeatable"); } + // Check environment + else if (!this.challenge.getEnvironment().isEmpty() && + !this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment())) + { + this.user.sendMessage("general.errors.wrong-environment"); + } else if (type.equals(ChallengeType.INVENTORY)) { return this.checkInventory(); From e0f38206aa6e5fbac3e5f1a6ecf3e8f40b8a5b3b Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 25 Jan 2019 00:20:33 +0200 Subject: [PATCH 086/103] Add check on permission. --- .../challenges/panel/TryToComplete.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 2fc3a43..2c09577 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -278,7 +278,12 @@ public class TryToComplete else if (!this.challenge.getEnvironment().isEmpty() && !this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment())) { - this.user.sendMessage("general.errors.wrong-environment"); + this.user.sendMessage("challenges.errors.wrong-environment"); + } + // Check permission + else if (!this.checkPermissions()) + { + this.user.sendMessage("general.errors.no-permission"); } else if (type.equals(ChallengeType.INVENTORY)) { @@ -298,6 +303,16 @@ public class TryToComplete } + /** + * This method checks if user has all required permissions. + * @return true if user has all required permissions, otherwise false. + */ + private boolean checkPermissions() + { + return this.challenge.getRequiredPermissions().isEmpty() || + this.challenge.getRequiredPermissions().stream().allMatch(s -> this.user.hasPermission(s)); + } + /** * This method runs all commands from command list. * @param commands List of commands that must be performed. From 2a4b892ed72d81639c51e8bc35dc66c4cf7bb323 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 25 Jan 2019 00:28:12 +0200 Subject: [PATCH 087/103] Create EMPTY_RESULT variable to avoid so many new ChallengeResult object initializations. --- .../challenges/panel/TryToComplete.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 2c09577..64ffb63 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -69,6 +69,10 @@ public class TryToComplete */ private Challenge challenge; + /** + * Variable that will be used to avoid multiple empty object generation. + */ + private final ChallengeResult EMPTY_RESULT = new ChallengeResult(); // --------------------------------------------------------------------- // Section: Builder @@ -249,57 +253,69 @@ public class TryToComplete */ private ChallengeResult checkIfCanCompleteChallenge() { + ChallengeResult result; + ChallengeType type = this.challenge.getChallengeType(); // Check the world if (!this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName())) { this.user.sendMessage("general.errors.wrong-world"); + result = EMPTY_RESULT; } // Check if user has unlocked challenges level. else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) && !this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel()))) { this.user.sendMessage("challenges.errors.challenge-level-not-available"); + result = EMPTY_RESULT; } // Check max times else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 && this.manager.getChallengeTimes(this.user, this.challenge) >= this.challenge.getMaxTimes()) { this.user.sendMessage("challenges.not-repeatable"); + result = EMPTY_RESULT; } // Check repeatability else if (this.manager.isChallengeComplete(this.user, this.challenge) && (!this.challenge.isRepeatable() || type.equals(ChallengeType.ISLAND))) { this.user.sendMessage("challenges.not-repeatable"); + result = EMPTY_RESULT; } // Check environment else if (!this.challenge.getEnvironment().isEmpty() && !this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment())) { this.user.sendMessage("challenges.errors.wrong-environment"); + result = EMPTY_RESULT; } // Check permission else if (!this.checkPermissions()) { this.user.sendMessage("general.errors.no-permission"); + result = EMPTY_RESULT; } else if (type.equals(ChallengeType.INVENTORY)) { - return this.checkInventory(); + result = this.checkInventory(); } else if (type.equals(ChallengeType.ISLAND)) { - return this.checkSurrounding(); + result = this.checkSurrounding(); } else if (type.equals(ChallengeType.OTHER)) { - return this.checkOthers(); + result = this.checkOthers(); + } + else + { + result = EMPTY_RESULT; } // Everything fails till this point. - return new ChallengeResult(); + return result; } @@ -407,7 +423,7 @@ public class TryToComplete this.user.sendMessage("challenges.error.not-enough-items", "[items]", Util.prettifyText(req.getType().toString())); - return new ChallengeResult(); + return EMPTY_RESULT; } break; default: @@ -417,7 +433,7 @@ public class TryToComplete this.user.sendMessage("challenges.error.not-enough-items", "[items]", Util.prettifyText(req.getType().toString())); - return new ChallengeResult(); + return EMPTY_RESULT; } } } @@ -500,7 +516,7 @@ public class TryToComplete { // Player is not on island this.user.sendMessage("challenges.error.not-on-island"); - result = new ChallengeResult(); + result = EMPTY_RESULT; } else { @@ -569,7 +585,7 @@ public class TryToComplete "[amount]", String.valueOf(v), "[item]", Util.prettifyText(k.toString()))); - return new ChallengeResult(); + return EMPTY_RESULT; } @@ -598,7 +614,7 @@ public class TryToComplete "[amount]", String.valueOf(amount), "[item]", Util.prettifyText(reqEnt.toString()))); - return new ChallengeResult(); + return EMPTY_RESULT; } @@ -703,7 +719,7 @@ public class TryToComplete return new ChallengeResult().setMeetsRequirements(); } - return new ChallengeResult(); + return EMPTY_RESULT; } From 089f09dd4595ef42ba8ea95b175280fd369a9b70 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 25 Jan 2019 00:54:21 +0200 Subject: [PATCH 088/103] Implement ChallengeLevel completion rewards. Add methods isLevelDone() and addCompletedLevel() to ChallengesPlayerData object. Add isLevelCompleted(), validateLevelCompletion() and setLevelComplete() to ChallengesManager. Add check in TryToComplete after completing challenges first time. --- .../challenges/ChallengesManager.java | 43 ++++++++++++++++++ .../database/object/ChallengesPlayerData.java | 28 ++++++++++-- .../challenges/panel/TryToComplete.java | 44 +++++++++++++++++++ 3 files changed, 111 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 9278ba1..9b6e40a 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -574,6 +574,49 @@ public class ChallengesManager } + /** + * This method returns if given user has been already completed given level. + * @param level Level that must be checked. + * @param user User who need to be checked. + * @return true, if level is already completed. + */ + public boolean isLevelCompleted(User user, ChallengeLevel level) + { + this.addPlayer(user); + return this.playerCacheData.get(user.getUniqueId()).isLevelDone(level.getUniqueId()); + } + + + /** + * This method checks all level challenges and checks if all challenges are done. + * @param level Level that must be checked. + * @param user User who need to be checked. + * @return true, if all challenges are done, otherwise false. + */ + public boolean validateLevelCompletion(User user, ChallengeLevel level) + { + this.addPlayer(user); + ChallengesPlayerData playerData = this.playerCacheData.get(user.getUniqueId()); + long doneChallengeCount = level.getChallenges().stream().filter(playerData::isChallengeDone).count(); + + return level.getChallenges().size() == doneChallengeCount; + } + + + /** + * This method sets given level as completed. + * @param level Level that must be completed. + * @param user User who complete level. + */ + public void setLevelComplete(User user, ChallengeLevel level) + { + this.addPlayer(user); + this.playerCacheData.get(user.getUniqueId()).addCompletedLevel(level.getUniqueId()); + // Save + this.savePlayer(user.getUniqueId()); + } + + // --------------------------------------------------------------------- // Section: Challenges related methods // --------------------------------------------------------------------- diff --git a/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java b/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java index afc84a0..9907099 100644 --- a/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java +++ b/src/main/java/world/bentobox/challenges/database/object/ChallengesPlayerData.java @@ -1,14 +1,13 @@ package world.bentobox.challenges.database.object; + +import com.google.gson.annotations.Expose; +import org.bukkit.World; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.bukkit.World; - -import com.google.gson.annotations.Expose; - import world.bentobox.bentobox.database.objects.DataObject; import world.bentobox.bentobox.util.Util; @@ -235,6 +234,27 @@ public class ChallengesPlayerData implements DataObject } + /** + * This method adds given level id to completed level set. + * @param uniqueId from ChallengeLevel object. + */ + public void addCompletedLevel(String uniqueId) + { + this.levelsDone.add(uniqueId); + } + + + /** + * This method returns if given level is done. + * @param uniqueId of ChallengeLevel object. + * @return true if level is completed, otherwise false + */ + public boolean isLevelDone(String uniqueId) + { + return !this.levelsDone.isEmpty() && this.levelsDone.contains(uniqueId); + } + + /** * @see Object#hashCode() * @return object hashCode value. diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 64ffb63..0a19811 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -21,6 +21,7 @@ import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge.ChallengeType; +import world.bentobox.challenges.database.object.ChallengeLevel; /** @@ -243,6 +244,49 @@ public class TryToComplete // Mark as complete this.manager.setChallengeComplete(this.user, this.challenge); + if (!result.repeat) + { + ChallengeLevel level = this.manager.getLevel(this.challenge); + + if (!this.manager.isLevelCompleted(this.user, level)) + { + if (this.manager.validateLevelCompletion(this.user, level)) + { + // Item rewards + for (ItemStack reward : level.getRewardItems()) + { + this.user.getInventory().addItem(reward).forEach((k, v) -> + this.user.getWorld().dropItem(this.user.getLocation(), v)); + } + + // Money Reward + if (this.addon.isEconomyProvided()) + { + this.addon.getEconomyProvider().deposit(this.user, level.getRewardMoney()); + } + + // Experience Reward + this.user.getPlayer().giveExp(level.getRewardExperience()); + + // Run commands + this.runCommands(level.getRewardCommands()); + + this.user.sendMessage("challenges.you-completed-level", "[level]", level.getFriendlyName()); + + if (this.addon.getChallengesSettings().isBroadcastMessages()) + { + for (Player p : this.addon.getServer().getOnlinePlayers()) + { + User.getInstance(p).sendMessage("challenges.name-has-completed-level", + "[name]", this.user.getName(), "[level]", level.getFriendlyName()); + } + } + + this.manager.setLevelComplete(this.user, level); + } + } + } + return result; } From 087ee07f45816735a48cff613f939550cb7864d0 Mon Sep 17 00:00:00 2001 From: BONNe Date: Fri, 25 Jan 2019 00:59:06 +0200 Subject: [PATCH 089/103] Add glowing effect on challenge level icons that are completed. --- .../bentobox/challenges/panel/user/ChallengesGUI.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index b4f0775..df6e328 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -49,11 +49,11 @@ public class ChallengesGUI extends CommonGUI this.levelStatusList = this.challengesManager.getChallengeLevelStatus(this.user, this.world); - for (int i = 0; i < this.levelStatusList.size(); i++) + for (LevelStatus levelStatus : this.levelStatusList) { - if (this.levelStatusList.get(i).isUnlocked()) + if (levelStatus.isUnlocked()) { - this.lastSelectedLevel = this.levelStatusList.get(i); + this.lastSelectedLevel = levelStatus; } else { @@ -491,6 +491,7 @@ public class ChallengesGUI extends CommonGUI ItemStack icon; List description; PanelItem.ClickHandler clickHandler; + boolean glow; if (level.isUnlocked()) { @@ -507,6 +508,7 @@ public class ChallengesGUI extends CommonGUI this.build(); return true; }; + glow = this.challengesManager.isLevelCompleted(this.user, level.getLevel()); } else { @@ -518,9 +520,10 @@ public class ChallengesGUI extends CommonGUI "[thisLevel]", level.getPreviousLevel().getFriendlyName())); clickHandler = null; + glow = false; } - return new PanelItem(icon, name, description, false, clickHandler, false); + return new PanelItem(icon, name, description, glow, clickHandler, false); } From 4b2f974b56b27cae415363de39de9f997657ba6e Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 00:12:42 +0200 Subject: [PATCH 090/103] Add correct language references. --- .../world/bentobox/challenges/ChallengesManager.java | 4 ++-- .../challenges/panel/admin/EditChallengeGUI.java | 2 +- .../challenges/panel/user/ChallengesGUI.java | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 9b6e40a..007de11 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -154,7 +154,7 @@ public class ChallengesManager { if (!silent) { - user.sendMessage("challenges.admin.import.skip", + user.sendMessage("challenges.admin.import.skipping", "[object]", challenge.getFriendlyName()); } @@ -219,7 +219,7 @@ public class ChallengesManager { if (!silent) { - user.sendMessage("challenges.admin.import.skip", + user.sendMessage("challenges.admin.import.skipping", "[object]", level.getFriendlyName()); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 33d7653..7d896c7 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -451,7 +451,7 @@ public class EditChallengeGUI extends CommonGUI for (World.Environment environment : World.Environment.values()) { values.add((this.challenge.getEnvironment().contains(environment.name()) ? "§2" : "§c") + - this.user.getTranslation("challenges.gui.admin.descriptions." + environment.name())); + this.user.getTranslation("challenges.gui.admin.descriptions." + environment.name().toLowerCase())); } name = this.user.getTranslation("challenges.gui.admin.buttons.environment"); diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index df6e328..b5f2a51 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -134,7 +134,7 @@ public class ChallengesGUI extends CommonGUI { panelBuilder.item(new PanelItemBuilder(). icon(Material.SIGN). - name("Previous"). + name(this.user.getTranslation("challenges.gui.buttons.previous")). clickHandler((panel, user1, clickType, slot) -> { this.freeChallengeIndex--; this.build(); @@ -158,7 +158,7 @@ public class ChallengesGUI extends CommonGUI { panelBuilder.item(new PanelItemBuilder(). icon(Material.SIGN). - name("Next"). + name(this.user.getTranslation("challenges.gui.buttons.next")). clickHandler((panel, user1, clickType, slot) -> { this.freeChallengeIndex++; this.build(); @@ -196,7 +196,7 @@ public class ChallengesGUI extends CommonGUI { panelBuilder.item(new PanelItemBuilder(). icon(Material.SIGN). - name("Previous"). + name(this.user.getTranslation("challenges.gui.buttons.previous")). clickHandler((panel, user1, clickType, slot) -> { this.pageIndex--; this.build(); @@ -220,7 +220,7 @@ public class ChallengesGUI extends CommonGUI { panelBuilder.item(new PanelItemBuilder(). icon(Material.SIGN). - name("Next"). + name(this.user.getTranslation("challenges.gui.buttons.next")). clickHandler((panel, user1, clickType, slot) -> { this.pageIndex++; this.build(); @@ -262,7 +262,7 @@ public class ChallengesGUI extends CommonGUI { panelBuilder.item(new PanelItemBuilder(). icon(Material.SIGN). - name("Previous"). + name(this.user.getTranslation("challenges.gui.buttons.previous")). clickHandler((panel, user1, clickType, slot) -> { this.levelIndex--; this.build(); @@ -286,7 +286,7 @@ public class ChallengesGUI extends CommonGUI { panelBuilder.item(new PanelItemBuilder(). icon(Material.SIGN). - name("Next"). + name(this.user.getTranslation("challenges.gui.buttons.next")). clickHandler((panel, user1, clickType, slot) -> { this.levelIndex++; this.build(); From ca26fa0d8f565b27cf95bbf4d138aebc5a5f9d1b Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 00:12:58 +0200 Subject: [PATCH 091/103] Add missing Language references. --- src/main/resources/locales/en-US.yml | 303 ++++++++++++++++++--------- 1 file changed, 208 insertions(+), 95 deletions(-) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index cfbd361..99c95c9 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -6,98 +6,211 @@ ### Credits ### # Tastybento: maintainer -challenges: - admin: - challenge-created: "[challenge] created!" - complete: - description: "Mark challenge complete" - parameters: " " - unknown-challenge: "&cUnknown challenge" - create: - description: "&6Collect:" - description-item-color: "&B" - inventory: - description: "create an inventory challenge" - parameters: "[challenge name]" - surrounding: - description: "create a surrounding challenge" - hit-things: "Hit things to add them to the list of things required. Right click when done." - parameters: "[challenge name]" - description: "challenges admin" - error: - no-name: "You must include a challenge name" - gui-title: "&aChallenges Admin" - import: - description: "import challenges from challenges.yml" - imported: "Imported '[challenge]'" - levels: "Importing levels: [levels]" - no-file: "&cCould not find challenges.yml file to import!" - no-levels: "Warning: No levels defined in challenges.yml" - no-load: "&cError: Could not load challenges.yml. [message]" - number: "Imported [number] challenges" - overwriting: "Overwriting '[challenge]'" - parameters: "[overwrite]" - skipping: "'[challenge]' already exists - skipping" - parameters: "" - reload: - description: "reload challenges from the database" - parameters: "" - reset: - description: "Reset challenge to 0 times / incomplete" - parameters: " " - seticon: - description: "sets the challenge icon to inhand item" - error: - no-such-challenge: "&cNo such challenge name" - parameters: "[challenge name]" - you-added: "You added one [thing] to the challenge" - challenge: - format: "[description]" - complete: "&BComplete" - completechallenge: - challange-completed: "Challenge: [challengename] has been completed for [name]" - completed-times: "Completed [donetimes] out of [maxtimes]" - description: "Open the challenges menu" - error: - could-not-save: "&cCould not save the challenge!" - island-level: "&cYour island must be level [number] to complete this challenge!" - items-not-there: "&cAll required items must be close to you on your island!" - no-items-clicked: "&cYou did not click on anything. Cancelling." - not-close-enough: "&cYou must be standing within [number] blocks of all required items." - not-enough-items: "&cYou do not have enough [items] to complete this challenge!" - not-on-island: "&cYou must be on your island to do that!" - reward-problem: "&cThere was a problem giving your reward. Ask Admin to check log!" - you-still-need: "&cYou still need [amount] x [item]" - exp-reward: "&6Exp reward: [reward]" - first-time-rewards: "&6First time reward(s)" - gui-title: "&aChallenges" - help: - command: "/challenges: &fshow challenges" - config-reloaded: "Configuration reloaded from file." - reset-all-challenges: "resets all of the player's challenges" - reset-challenge: "marks a challenge as incomplete" - reset-challenge-for-all: "globally resets a challenge for every player with an optional repetition" - incomplete: Incomplete - item-take-warning: "&cAll required items are|&ctaken when you complete|&cthis challenge!" - items-closeby: "&cAll required items|&cmust be close to you|&con your island!" - level: "&FLevel: [level]" - max-reached: "Max reached [donetimes] out of [maxtimes]" - money-reward: "&6Money reward: $[reward]" - name: "Challenge Name" - name-has-completed: "[name] has completed the [challenge] challenge!" - navigation: "Click to see [level] challenges!" - not-repeatable: "This challenge is not repeatable!" - parameters: "[Level]" - repeat-rewards: "&6Repeat reward(s)" - repeatable: "This challenge can be repeated [maxtimes] times" - resetallchallenges: - success: "[name] has had all challenges reset." - resetchallenge: - challenge-reset: "Challenge: [challengename] has been reset for [name]" - error-challenge-does-not-exist: "Challenge doesn't exist or isn't yet completed" - rewards: "&FReward(s)" - to-complete: "Complete [challengesToDo] more [thisLevel] challenges to unlock this level!" - you-completed: "You completed the [challenge] challenge!" - you-repeated: "You repeated the [challenge] challenge!" - not-enough-money: "It is necessary to have [money] on your account to complete the challenge." - not-enough-exp: "It is necessary to have [xp] EXP to complete challenge." \ No newline at end of file +challenges: + admin: + challenge-created: '[challenge] created!' + complete: + description: Mark challenge complete + parameters: + unknown-challenge: '&cUnknown challenge' + create: + description: '&6Collect:' + description-item-color: '&B' + inventory: + description: create an inventory challenge + parameters: '[challenge name]' + surrounding: + description: create a surrounding challenge + hit-things: Hit things to add them to the list of things required. Right click when done. + parameters: '[challenge name]' + description: challenges admin + error: + no-name: You must include a challenge name + gui-title: '&aChallenges Admin' + import: + add: 'Adding new challenge: [object]' + description: import challenges from challenges.yml + imported: Imported '[challenge]' + levels: 'Importing levels: [levels]' + no-file: '&cCould not find challenges.yml file to import!' + no-levels: 'Warning: No levels defined in challenges.yml' + no-load: '&cError: Could not load challenges.yml. [message]' + number: Imported [number] challenges + overwriting: Overwriting '[challenge]' + parameters: '[overwrite]' + skipping: '''[challenge]'' already exists - skipping' + parameters: '' + reload: + description: reload challenges from the database + parameters: '' + reset: + description: Reset challenge to 0 times / incomplete + parameters: + seticon: + description: sets the challenge icon to inhand item + error: + no-such-challenge: '&cNo such challenge name' + parameters: '[challenge name]' + you-added: You added one [thing] to the challenge + blocks-take-warning: Blocks will be removed. + challenge: + format: '[description]' + complete: '&BComplete' + completechallenge: + challange-completed: 'Challenge: [challengename] has been completed for [name]' + completed-times: Completed [donetimes] out of [maxtimes] + description: Open the challenges menu + entities-kill-warning: Entities will be killed. + error: + could-not-save: '&cCould not save the challenge!' + island-level: '&cYour island must be level [number] to complete this challenge!' + items-not-there: '&cAll required items must be close to you on your island!' + no-items-clicked: '&cYou did not click on anything. Cancelling.' + not-close-enough: '&cYou must be standing within [number] blocks of all required + items.' + not-enough-items: '&cYou do not have enough [items] to complete this challenge!' + not-on-island: '&cYou must be on your island to do that!' + reward-problem: '&cThere was a problem giving your reward. Ask Admin to check + log!' + you-still-need: '&cYou still need [amount] x [item]' + errors: + challenge-level-not-available: You have not unlocked level to complete this challenge. + unique-id: Unique ID [id] is already taken. Choose different. + wrong-environment: You are in wrong environment! + wrong-icon: Material [icon] is not recognized + exp-reward: '&6Exp reward: [reward]' + first-time-rewards: '&6First time reward(s)' + gui: + admin: + buttons: + add-challenge: Create Challenge + add-level: Create Level + blocks: Blocks + broadcast: Broadcast Messages + challenges: Challenges + complete: Complete + delete-challenge: Delete Challenge + delete-level: Delete Level + deployed: Deployment status + description: Description + edit-challenge: Edit Challenge + edit-level: Edit Level + entities: Entities + environment: Environment + free-challenges: Free Challenges Position + glow: Completion Glowing + icon: Icon + name: Name + order: Order Number + permissions: Permissions + properties: Properties + remove-blocks: Remove Blocks + remove-challenge: Remove Challenge + remove-entities: Remove Entities + remove-exp: Take Experience + remove-items: Remove items + remove-money: Remove Money + remove-on-complete: Remove on completion + repeat-count: Repeat Count + repeat-reward-command: Repeat Reward Command + repeat-reward-exp: Repeat Reward Experience + repeat-reward-items: Repeat Reward Items + repeat-reward-money: Repeat Reward Money + repeat-reward-text: Repeat Reward Text + repeatable: Repeatable + required-exp: Required Experience + required-items: Required items + required-level: Required Island Level + required-money: Required Money + requirements: Requirements + reset: Reset + reward-command: Reward Command + reward-exp: Reward Experience + reward-items: Reward Items + reward-money: Reward Money + reward-text: Reward Text + rewards: Rewards + search-radius: Search radius + settings: Settings + toggle-users: Choose players + type: Challenge Type + waiver-amount: Waiver Amount + choose-challenge-title: Challenges List + choose-level-title: Levels List + choose-user-title: Users List + descriptions: + broadcast: Broadcast 1st time challenge completion messages to all players. + disabled: disabled + enabled: enabled + free-challenges: This indicate if free challenges must be at the start (true) or at the end (false) of list. + glow: Add enchanted glow to completed challenges + in_world: In World + inventory: This type of challenges allows to define blocks and entities on island requirements. + island: This type of challenges allows to define inventory item requirements. + nether: Nether + normal: Normal + online: Online + order: Current order [value] + other: This type of challenges allows to define Money, Experience or island level requirements. + remove-on-complete: Remove non-repeatable challenges from the challenge GUI when complete. + repeat-count: 'Current value: [value]' + repeat-reward-exp: 'Current value: [value]' + repeat-reward-money: 'Current value: [value]' + required-exp: Current necessary [value] + required-level: 'Current value: [value]' + required-money: 'Current value: [value]' + reset: Reset Challenges - if this is true, player's challenges will reset when they reset an island or if they are kicked or leave a team + reward-exp: 'Current value: [value]' + reward-money: 'Current value: [value]' + search-radius: Current radius [value] + the_end: The End + waiver-amount: 'Current value: [value]' + with_island: With Island + edit-challenge-title: Edit Challenge + edit-entities: Manage Entities + edit-level-title: Edit Levels + manage-blocks: Manage Blocks + settings-title: Edit Settings + button: + add: Add + remove-selected: Remove Selected + buttons: + back: Return + next: Next + previous: Previous + title: '"Challenges GUI"' + gui-title: '&aChallenges' + help: + command: '/challenges: &fshow challenges' + config-reloaded: Configuration reloaded from file. + reset-all-challenges: resets all of the player's challenges + reset-challenge: marks a challenge as incomplete + reset-challenge-for-all: globally resets a challenge for every player with an optional repetition + incomplete: Incomplete + item-take-warning: '&cAll required items are|&ctaken when you complete|&cthis + challenge!' + items-closeby: '&cAll required items|&cmust be close to you|&con your island!' + level: '&FLevel: [level]' + max-reached: Max reached [donetimes] out of [maxtimes] + maxed-reached: Completed [donetimes] out of [maxtimes] + money-reward: '&6Money reward: $[reward]' + name: Challenge Name + name-has-completed: '[name] has completed the [challenge] challenge!' + name-has-completed-level: '[name] completed all challenges in [level]!' + navigation: Click to see [level] challenges! + not-enough-exp: It is necessary to have [xp] EXP to complete challenge. + not-enough-money: It is necessary to have [money] on your account to complete the challenge. + not-repeatable: This challenge is not repeatable! + parameters: '[Level]' + repeat-rewards: '&6Repeat reward(s)' + repeatable: This challenge can be repeated [maxtimes] times + resetallchallenges: + success: '[name] has had all challenges reset.' + resetchallenge: + challenge-reset: 'Challenge: [challengename] has been reset for [name]' + error-challenge-does-not-exist: Challenge doesn't exist or isn't yet completed + rewards: '&FReward(s)' + to-complete: Complete [challengesToDo] more [thisLevel] challenges to unlock this level! + you-completed: You completed the [challenge] challenge! + you-completed-level: Congratulations, you complete [level]! + you-repeated: You repeated the [challenge] challenge! From 01482b926b41a330b197b34a55edbeba29432b21 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 13:17:38 +0200 Subject: [PATCH 092/103] Fix issue, when new challenges and levels were without world name. --- .../java/world/bentobox/challenges/panel/admin/AdminGUI.java | 4 ++-- .../bentobox/challenges/panel/admin/EditChallengeGUI.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java index 0140aea..644e0d0 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/AdminGUI.java @@ -206,7 +206,7 @@ public class AdminGUI extends CommonGUI new EditChallengeGUI(this.addon, this.world, this.user, - this.addon.getChallengesManager().createChallenge(reply), + this.addon.getChallengesManager().createChallenge(newName), this.topLabel, this.permissionPrefix, this).build(); @@ -242,7 +242,7 @@ public class AdminGUI extends CommonGUI new EditLevelGUI(this.addon, this.world, this.user, - this.addon.getChallengesManager().createLevel(reply), + this.addon.getChallengesManager().createLevel(newName), this.topLabel, this.permissionPrefix, this).build(); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index 7d896c7..f77951f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -147,7 +147,7 @@ public class EditChallengeGUI extends CommonGUI panelBuilder.item(28, this.createButton(Button.REMOVE_ENTITIES)); panelBuilder.item(21, this.createButton(Button.REQUIRED_BLOCKS)); - panelBuilder.item(29, this.createButton(Button.REMOVE_BLOCKS)); + panelBuilder.item(30, this.createButton(Button.REMOVE_BLOCKS)); panelBuilder.item(23, this.createButton(Button.SEARCH_RADIUS)); panelBuilder.item(25, this.createButton(Button.REQUIRED_PERMISSIONS)); From a55a2f536e914e652019986c85d03a15793fbc12 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 13:17:59 +0200 Subject: [PATCH 093/103] Add Import Button --- src/main/resources/locales/en-US.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 99c95c9..832c005 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -135,6 +135,7 @@ challenges: toggle-users: Choose players type: Challenge Type waiver-amount: Waiver Amount + import: Import choose-challenge-title: Challenges List choose-level-title: Levels List choose-user-title: Users List From ab22651425f80288d474cb44ad320eb1973cc7c7 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 13:47:56 +0200 Subject: [PATCH 094/103] Fix an issue when users could do challenges in other gamemodes. Fix an issue when users could complete challenges outside their island. --- .../bentobox/challenges/panel/TryToComplete.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 0a19811..d7d2944 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -302,11 +302,18 @@ public class TryToComplete ChallengeType type = this.challenge.getChallengeType(); // Check the world - if (!this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName())) + if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) || + !this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName())) { this.user.sendMessage("general.errors.wrong-world"); result = EMPTY_RESULT; } + // Player is not on island + else if (!this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user)) + { + this.user.sendMessage("challenges.error.not-on-island"); + result = EMPTY_RESULT; + } // Check if user has unlocked challenges level. else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) && !this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel()))) @@ -556,7 +563,7 @@ public class TryToComplete { ChallengeResult result; - if (!this.addon.getIslands().userIsOnIsland(this.world, this.user)) + if (!this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user)) { // Player is not on island this.user.sendMessage("challenges.error.not-on-island"); From 2a6127b0f63844f2a65a93eb21dfea8876003b03 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 13:53:49 +0200 Subject: [PATCH 095/103] Remove repeating blockage for Island Challenge type. --- .../java/world/bentobox/challenges/panel/TryToComplete.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index d7d2944..2ae9d48 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -329,8 +329,7 @@ public class TryToComplete result = EMPTY_RESULT; } // Check repeatability - else if (this.manager.isChallengeComplete(this.user, this.challenge) - && (!this.challenge.isRepeatable() || type.equals(ChallengeType.ISLAND))) + else if (!this.challenge.isRepeatable() && this.manager.isChallengeComplete(this.user, this.challenge)) { this.user.sendMessage("challenges.not-repeatable"); result = EMPTY_RESULT; From d6a39b2600b83a915f791d40046f397fe1f3e338 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 13:58:00 +0200 Subject: [PATCH 096/103] Add completion blockage for un-deployed challenges. --- .../world/bentobox/challenges/panel/TryToComplete.java | 7 ++++++- src/main/resources/locales/en-US.yml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 2ae9d48..3e32318 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -302,7 +302,12 @@ public class TryToComplete ChallengeType type = this.challenge.getChallengeType(); // Check the world - if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) || + if (!this.challenge.isDeployed()) + { + this.user.sendMessage("challenges.error.not-deployed"); + result = EMPTY_RESULT; + } + else if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) || !this.challenge.getUniqueId().startsWith(Util.getWorld(this.world).getName())) { this.user.sendMessage("general.errors.wrong-world"); diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 832c005..95631ef 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -73,6 +73,7 @@ challenges: reward-problem: '&cThere was a problem giving your reward. Ask Admin to check log!' you-still-need: '&cYou still need [amount] x [item]' + not-deployed: '&cChallenge is not deployed.' errors: challenge-level-not-available: You have not unlocked level to complete this challenge. unique-id: Unique ID [id] is already taken. Choose different. From 586b07686023482642d3635fc276a803e4983d84 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 14:46:03 +0200 Subject: [PATCH 097/103] Fix issues when Description were to long to fit in window. --- .../panel/admin/EditChallengeGUI.java | 11 ++++++----- .../challenges/panel/admin/EditLevelGUI.java | 9 ++++----- .../panel/admin/EditSettingsGUI.java | 10 +++++----- .../panel/admin/ListChallengesGUI.java | 2 +- .../challenges/panel/admin/ListLevelsGUI.java | 2 +- .../challenges/panel/admin/ListUsersGUI.java | 6 +++--- .../challenges/panel/user/ChallengesGUI.java | 9 ++++----- .../challenges/panel/util/ItemSwitchGUI.java | 3 ++- .../challenges/panel/util/NumberGUI.java | 2 +- .../panel/util/SelectChallengeGUI.java | 2 +- .../challenges/panel/util/StringListGUI.java | 7 +++++-- .../bentobox/challenges/utils/GuiUtils.java | 19 ++++++++++++++++++- src/main/resources/locales/en-US.yml | 2 +- 13 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java index f77951f..812b58f 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditChallengeGUI.java @@ -280,7 +280,7 @@ public class EditChallengeGUI extends CommonGUI return null; } - return new PanelItem(icon, name, description, glow, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false); } @@ -305,11 +305,12 @@ public class EditChallengeGUI extends CommonGUI for (Challenge.ChallengeType type : Challenge.ChallengeType.values()) { - values.add((this.challenge.getChallengeType().equals(type) ? "§2" : "§c") + + values.add((this.challenge.getChallengeType().equals(type) ? "&2" : "&c") + this.user.getTranslation("challenges.gui.admin.descriptions." + type.name().toLowerCase())); } - name = this.user.getTranslation("challenges.gui.admin.buttons.type"); + name = this.user.getTranslation("challenges.gui.admin.buttons.type", + "[value]", this.challenge.getChallengeType().name()); description = values; if (this.challenge.getChallengeType().equals(Challenge.ChallengeType.ISLAND)) @@ -450,7 +451,7 @@ public class EditChallengeGUI extends CommonGUI for (World.Environment environment : World.Environment.values()) { - values.add((this.challenge.getEnvironment().contains(environment.name()) ? "§2" : "§c") + + values.add((this.challenge.getEnvironment().contains(environment.name()) ? "&2" : "&c") + this.user.getTranslation("challenges.gui.admin.descriptions." + environment.name().toLowerCase())); } @@ -1153,7 +1154,7 @@ public class EditChallengeGUI extends CommonGUI return null; } - return new PanelItem(icon, name, description, glow, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java index e3113a5..75c7159 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditLevelGUI.java @@ -13,11 +13,10 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.util.ItemParser; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesManager; -import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.database.object.Challenge; +import world.bentobox.challenges.database.object.ChallengeLevel; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.util.ItemSwitchGUI; import world.bentobox.challenges.panel.util.NumberGUI; @@ -253,7 +252,7 @@ public class EditLevelGUI extends CommonGUI return null; } - return new PanelItem(icon, name, description, glow, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false); } @@ -266,7 +265,7 @@ public class EditLevelGUI extends CommonGUI { return new PanelItemBuilder(). name(challenge.getFriendlyName()). - description(challenge.getDescription()). + description(GuiUtils.stringSplit(challenge.getDescription())). icon(challenge.getIcon()). clickHandler((panel, user1, clickType, slot) -> { // Open challenges edit screen. @@ -591,7 +590,7 @@ public class EditLevelGUI extends CommonGUI return null; } - return new PanelItem(icon, name, description, glow, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false); } diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java index 16625d6..1617f76 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java @@ -66,7 +66,7 @@ public class EditSettingsGUI extends CommonGUI // resetChallenges panelBuilder.item(19, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.reset")). - description(this.user.getTranslation("challenges.gui.admin.descriptions.reset")). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.reset"))). icon(Material.LAVA_BUCKET). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setResetChallenges( @@ -79,7 +79,7 @@ public class EditSettingsGUI extends CommonGUI // broadcastMessages panelBuilder.item(20, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.broadcast")). - description(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast")). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.broadcast"))). icon(Material.JUKEBOX). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setBroadcastMessages( @@ -92,7 +92,7 @@ public class EditSettingsGUI extends CommonGUI // removeCompleteOneTimeChallenges panelBuilder.item(21, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.remove-on-complete")). - description(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete")). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.remove-on-complete"))). icon(Material.MAGMA_BLOCK). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setRemoveCompleteOneTimeChallenges( @@ -105,7 +105,7 @@ public class EditSettingsGUI extends CommonGUI // addCompletedGlow panelBuilder.item(22, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.glow")). - description(this.user.getTranslation("challenges.gui.admin.descriptions.glow")). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.glow"))). icon(Material.GLOWSTONE). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setAddCompletedGlow( @@ -118,7 +118,7 @@ public class EditSettingsGUI extends CommonGUI // freeChallengesAtTheTop panelBuilder.item(23, new PanelItemBuilder(). name(this.user.getTranslation("challenges.gui.admin.buttons.free-challenges")). - description(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges")). + description(GuiUtils.stringSplit(this.user.getTranslation("challenges.gui.admin.descriptions.free-challenges"))). icon(Material.FILLED_MAP). clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setFreeChallengesFirst( diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java index 77e98f8..ad76912 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListChallengesGUI.java @@ -134,7 +134,7 @@ public class ListChallengesGUI extends CommonGUI { PanelItemBuilder itemBuilder = new PanelItemBuilder(). name(challenge.getFriendlyName()). - description(challenge.getDescription()). + description(GuiUtils.stringSplit(challenge.getDescription())). icon(challenge.getIcon()). glow(challenge.isDeployed()); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java index 6a9b967..5267d10 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListLevelsGUI.java @@ -134,7 +134,7 @@ public class ListLevelsGUI extends CommonGUI { PanelItemBuilder itemBuilder = new PanelItemBuilder(). name(challengeLevel.getFriendlyName()). - description(challengeLevel.getUnlockMessage()). + description(GuiUtils.stringSplit(challengeLevel.getUnlockMessage())). icon(challengeLevel.getIcon()). glow(false); diff --git a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java index d00503c..c7c5461 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/ListUsersGUI.java @@ -216,7 +216,7 @@ public class ListUsersGUI extends CommonGUI return new PanelItemBuilder(). name(player.getName()). icon(Material.BARRIER). - description(this.user.getTranslation("general.errors.player-has-no-island")). + description(GuiUtils.stringSplit(this.user.getTranslation("general.errors.player-has-no-island"))). clickHandler((panel, user1, clickType, slot) -> false). build(); } @@ -258,7 +258,7 @@ public class ListUsersGUI extends CommonGUI for (int i = 0; i < ViewMode.values().length; i++) { - values.add((this.modeIndex == i ? "§2" : "§c") + + values.add((this.modeIndex == i ? "&2" : "&c") + this.user.getTranslation("challenges.gui.admin.descriptions." + ViewMode.values()[i].name().toLowerCase())); } @@ -267,7 +267,7 @@ public class ListUsersGUI extends CommonGUI name(this.user.getTranslation("challenges.gui.admin.buttons.toggle-users", "[value]", this.user.getTranslation("challenges.gui.admin.descriptions." + ViewMode.values()[this.modeIndex].name().toLowerCase()))). - description(values). + description(GuiUtils.stringSplit(values)). icon(Material.STONE_BUTTON). clickHandler( (panel, user1, clickType, slot) -> { diff --git a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java index b5f2a51..a1913f5 100644 --- a/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/user/ChallengesGUI.java @@ -5,7 +5,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import world.bentobox.bentobox.api.panels.PanelItem; @@ -17,6 +16,7 @@ import world.bentobox.challenges.ChallengesManager; import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.panel.CommonGUI; import world.bentobox.challenges.panel.TryToComplete; +import world.bentobox.challenges.utils.GuiUtils; import world.bentobox.challenges.utils.LevelStatus; @@ -320,7 +320,7 @@ public class ChallengesGUI extends CommonGUI return new PanelItemBuilder(). icon(challenge.getIcon()). name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()). - description(this.createChallengeDescription(challenge)). + description(GuiUtils.stringSplit(this.createChallengeDescription(challenge))). clickHandler((panel, user1, clickType, slot) -> { new TryToComplete(this.addon, this.user, @@ -496,8 +496,7 @@ public class ChallengesGUI extends CommonGUI if (level.isUnlocked()) { icon = level.getLevel().getIcon(); - description = Collections.singletonList( - this.user.getTranslation("challenges.navigation", "[level]", name)); + description = GuiUtils.stringSplit(this.user.getTranslation("challenges.navigation", "[level]", name)); clickHandler = (panel, user1, clickType, slot) -> { this.lastSelectedLevel = level; @@ -514,7 +513,7 @@ public class ChallengesGUI extends CommonGUI { icon = new ItemStack(Material.BOOK); - description = Collections.singletonList( + description = GuiUtils.stringSplit( this.user.getTranslation("challenges.to-complete", "[challengesToDo]", Integer.toString(level.getNumberOfChallengesStillToDo()), "[thisLevel]", level.getPreviousLevel().getFriendlyName())); diff --git a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java index 1188ec5..2d44739 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/ItemSwitchGUI.java @@ -14,6 +14,7 @@ import world.bentobox.bentobox.api.panels.PanelItem; import world.bentobox.bentobox.api.panels.PanelListener; import world.bentobox.bentobox.api.panels.builders.PanelBuilder; import world.bentobox.bentobox.api.user.User; +import world.bentobox.challenges.utils.GuiUtils; /** @@ -123,7 +124,7 @@ public class ItemSwitchGUI return null; } - return new PanelItem(icon, name, description, false, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), false, clickHandler, false); } diff --git a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java index 8917303..6eb0376 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/NumberGUI.java @@ -238,7 +238,7 @@ public class NumberGUI return null; } - return new PanelItem(icon, name, description, glow, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), glow, clickHandler, false); } diff --git a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java index aa01327..ab6bdab 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/SelectChallengeGUI.java @@ -127,7 +127,7 @@ public class SelectChallengeGUI { return new PanelItemBuilder(). name(challenge.getFriendlyName()). - description(challenge.getDescription()). + description(GuiUtils.stringSplit(challenge.getDescription())). icon(challenge.getIcon()). clickHandler((panel, user1, clickType, slot) -> { this.consumer.accept(true, challenge); diff --git a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java index 2a7c169..964d531 100644 --- a/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/util/StringListGUI.java @@ -3,7 +3,10 @@ package world.bentobox.challenges.panel.util; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.function.BiConsumer; import net.wesjd.anvilgui.AnvilGUI; @@ -174,7 +177,7 @@ public class StringListGUI return null; } - return new PanelItem(icon, name, description, false, clickHandler, false); + return new PanelItem(icon, name, GuiUtils.stringSplit(description), false, clickHandler, false); } diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index ecde0d0..da5eebe 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -6,7 +6,6 @@ import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.inventory.ItemStack; - import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -385,4 +384,22 @@ public class GuiUtils return result; } + + + /** + * Simple splitter for all strings in list. + * @param stringList - list of string to be split + * @return list of split strings + */ + public static List stringSplit(List stringList) + { + if (stringList.isEmpty()) + { + return stringList; + } + + List newList = new ArrayList<>(stringList.size()); + stringList.stream().map(GuiUtils::stringSplit).forEach(newList::addAll); + return newList; + } } \ No newline at end of file diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 95631ef..fff97b6 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -134,7 +134,7 @@ challenges: search-radius: Search radius settings: Settings toggle-users: Choose players - type: Challenge Type + type: 'Challenge Type: [value]' waiver-amount: Waiver Amount import: Import choose-challenge-title: Challenges List From d3ae24271606e402da6209c99fa5d096f7774ebe Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 15:19:09 +0200 Subject: [PATCH 098/103] Remove "CR" at the end of strings. --- .../java/world/bentobox/challenges/utils/GuiUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java index da5eebe..737f735 100644 --- a/src/main/java/world/bentobox/challenges/utils/GuiUtils.java +++ b/src/main/java/world/bentobox/challenges/utils/GuiUtils.java @@ -374,13 +374,15 @@ public class GuiUtils */ public static List stringSplit(String string) { + // Remove all ending lines from string. + string = string.replaceAll("([\\r\\n])", "\\|"); string = ChatColor.translateAlternateColorCodes('&', string); // Check length of lines List result = new ArrayList<>(); - Arrays.asList(string.split("\\|")). - forEach(line -> result.addAll( - Arrays.asList(WordUtils.wrap(line, 25).split("\\n")))); + Arrays.stream(string.split("\\|")). + map(line -> Arrays.asList(WordUtils.wrap(line, 25).split("\\r\\n"))). + forEach(result::addAll); return result; } From f3fe85ab2efd17d692d1b3f78252ce025f292cd0 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 15:36:21 +0200 Subject: [PATCH 099/103] Fix issue when SettingsGUI did not display updated values. --- .../bentobox/challenges/panel/admin/EditSettingsGUI.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java index 1617f76..984e9ce 100644 --- a/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java +++ b/src/main/java/world/bentobox/challenges/panel/admin/EditSettingsGUI.java @@ -71,6 +71,7 @@ public class EditSettingsGUI extends CommonGUI clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setResetChallenges( !this.addon.getChallengesSettings().isResetChallenges()); + this.build(); return true; }). glow(this.addon.getChallengesSettings().isResetChallenges()). @@ -84,6 +85,7 @@ public class EditSettingsGUI extends CommonGUI clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setBroadcastMessages( !this.addon.getChallengesSettings().isBroadcastMessages()); + this.build(); return true; }). glow(this.addon.getChallengesSettings().isBroadcastMessages()). @@ -97,6 +99,7 @@ public class EditSettingsGUI extends CommonGUI clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setRemoveCompleteOneTimeChallenges( !this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges()); + this.build(); return true; }). glow(this.addon.getChallengesSettings().isRemoveCompleteOneTimeChallenges()). @@ -110,6 +113,7 @@ public class EditSettingsGUI extends CommonGUI clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setAddCompletedGlow( !this.addon.getChallengesSettings().isAddCompletedGlow()); + this.build(); return true; }). glow(this.addon.getChallengesSettings().isAddCompletedGlow()). @@ -123,6 +127,7 @@ public class EditSettingsGUI extends CommonGUI clickHandler((panel, user1, clickType, i) -> { this.addon.getChallengesSettings().setFreeChallengesFirst( !this.addon.getChallengesSettings().isFreeChallengesFirst()); + this.build(); return true; }). glow(this.addon.getChallengesSettings().isFreeChallengesFirst()). From 6d1f4999e4a87ae2d92845c2109cdd4c0e683678 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 15:36:48 +0200 Subject: [PATCH 100/103] Fix issue when Settings object were not saved on server shutdown. --- .../java/world/bentobox/challenges/ChallengesAddon.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 0160b4a..63c8b89 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -1,16 +1,16 @@ package world.bentobox.challenges; -import org.bukkit.Bukkit; +import org.bukkit.Bukkit; import java.util.Optional; +import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.configuration.Config; import world.bentobox.bentobox.hooks.VaultHook; import world.bentobox.challenges.commands.ChallengesCommand; import world.bentobox.challenges.commands.admin.Challenges; import world.bentobox.challenges.listeners.ResetListener; import world.bentobox.challenges.listeners.SaveListener; -import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.level.Level; @@ -178,6 +178,11 @@ public class ChallengesAddon extends Addon { if (this.hooked) { this.challengesManager.save(); } + + if (this.settings != null) + { + new Config<>(this, Settings.class).saveConfigObject(this.settings); + } } From 0050a83d1a63c1aec31a085c64078ec41fa7e64b Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 16:14:43 +0200 Subject: [PATCH 101/103] Fix crash while enabling addon. This crash happened because BentoBox hookManager is not initialized when addons are enabled. --- .../bentobox/challenges/ChallengesAddon.java | 38 +++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 63c8b89..6f4cc94 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -40,8 +40,9 @@ public class ChallengesAddon extends Addon { /** * VaultHook that process economy. + * todo: because of BentoBox limitations. */ - private VaultHook vaultHook; + private Optional vaultHook = null; /** * Level addon. @@ -131,18 +132,19 @@ public class ChallengesAddon extends Addon { this.levelAddon = (Level) level.get(); } - Optional vault = this.getPlugin().getVault(); - - if (!vault.isPresent() || !vault.get().hook()) - { - this.vaultHook = null; - this.logWarning("Economy plugin not found so money options will not work!"); - } - else - { - this.economyProvided = true; - this.vaultHook = vault.get(); - } + // BentoBox limitation. Cannot check hooks, as HookManager is created after loading addons. +// Optional vault = this.getPlugin().getVault(); +// +// if (!vault.isPresent() || !vault.get().hook()) +// { +// this.vaultHook = null; +// this.logWarning("Economy plugin not found so money options will not work!"); +// } +// else +// { +// this.economyProvided = true; +// this.vaultHook = vault.get(); +// } // Register the reset listener this.registerListener(new ResetListener(this)); @@ -245,7 +247,13 @@ public class ChallengesAddon extends Addon { */ public boolean isEconomyProvided() { - return economyProvided; + if (!this.economyProvided && this.getPlugin().getVault().isPresent() && this.vaultHook == null) + { + this.vaultHook = this.getPlugin().getVault(); + this.economyProvided = this.vaultHook.get().hook(); + } + + return this.economyProvided; } @@ -256,7 +264,7 @@ public class ChallengesAddon extends Addon { */ public VaultHook getEconomyProvider() { - return vaultHook; + return vaultHook.orElseGet(null); } From 3f42af1c497190fade27e319c60c316a853fc5fb Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 16:14:57 +0200 Subject: [PATCH 102/103] Update Config file. --- src/main/resources/config.yml | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 9760fcd..c1a030c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,16 +1,31 @@ -# Challenges Config - +# Challenges Configuration ${project.version} +# This config file is dynamic and saved when the server is shutdown. +# You cannot edit it while the server is running because changes will +# be lost! Use in-game settings GUI or edit when server is offline. +# +# # Reset Challenges - if this is true, player's challenges will reset when they # reset an island or if they are kicked or leave a team. Prevents exploiting the # challenges by doing them repeatedly. -resetchallenges: true - +resetChallenges: true +# # Broadcast 1st time challenge completion messages to all players. # Change to false if the spam becomes too much. -broadcastmessages: true - -# Remove non-repeatable challenges from the challenge GUI when complete -removecompleteonetimechallenges: false - +broadcastMessages: true +# +# Remove non-repeatable challenges from the challenge GUI when complete. +removeCompleteOneTimeChallenges: false +# # Add enchanted glow to completed challenges -addcompletedglow: true +addCompletedGlow: true +# +# This indicate if free challenges must be at the start (true) or at the end (false) of list. +freeChallengesFirst: false +# +# This list stores GameModes in which Challenges addon should not work. +# To disable addon it is necessary to write its name in new line that starts with -. Example: +# disabled-gamemodes: +# - BSkyBlock +disabled-gamemodes: [] +# +uniqueId: config From 752ea5b4351964609305b4037c948391638c44e9 Mon Sep 17 00:00:00 2001 From: BONNe Date: Sat, 26 Jan 2019 16:15:24 +0200 Subject: [PATCH 103/103] Update To 0.5.0 - version. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7acf7f0..5df5469 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ world.bentobox challenges - 0.3.1-SNAPSHOT + 0.5.0-SNAPSHOT Challenges Challenges is an add-on for BentoBox, an expandable Minecraft Bukkit plugin for island-type games like ASkyBlock or AcidIsland.