From 51422108c68d01612b58f81bab0a2c4403496637 Mon Sep 17 00:00:00 2001 From: Tastybento Date: Thu, 22 Feb 2018 23:52:39 -0800 Subject: [PATCH] WIP - challenges Admin command cadmin to create and manage challenges in-game. Challenges are saved as yml files. Note that admins cannot edit yml files directly if server is running because they will be overwritten. User UI sort of works if challenge files are hand tailored. More to do! --- locales/en-US.yml | 70 ++- pom.xml | 16 + .../addon/challenges/Challenges.java | 2 + .../addon/challenges/ChallengesManager.java | 30 +- .../commands/ChallengesCommand.java | 3 +- .../admin/ChallengesAdminCommand.java | 41 ++ .../commands/{ => admin}/CreateChallenge.java | 4 +- .../challenges/commands/admin/MakeLevel.java | 65 +++ .../commands/admin/SetDeployed.java | 65 +++ .../commands/admin/SetDescription.java | 65 +++ .../challenges/commands/admin/SetExp.java | 65 +++ .../commands/admin/SetFriendlyName.java | 65 +++ .../challenges/commands/admin/SetLevel.java | 65 +++ .../commands/admin/SetMaxTimes.java | 65 +++ .../challenges/commands/admin/SetPerm.java | 65 +++ .../commands/admin/SetRepeatable.java | 65 +++ .../challenges/commands/admin/SetReward.java | 65 +++ .../challenges/commands/admin/SetType.java | 65 +++ .../challenges/commands/admin/TakeItems.java | 65 +++ .../database/object/ChallengesData.java | 510 ++++++++++++------ .../challenges/database/object/LevelsDO.java | 38 +- .../challenges/panel/ChallengesPanels.java | 86 +-- .../addon/challenges/panel/TryToComplete.java | 209 +++++++ 23 files changed, 1546 insertions(+), 243 deletions(-) create mode 100644 src/bskyblock/addon/challenges/commands/admin/ChallengesAdminCommand.java rename src/bskyblock/addon/challenges/commands/{ => admin}/CreateChallenge.java (91%) create mode 100644 src/bskyblock/addon/challenges/commands/admin/MakeLevel.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetDeployed.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetDescription.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetExp.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetFriendlyName.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetLevel.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetMaxTimes.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetPerm.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetRepeatable.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetReward.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/SetType.java create mode 100644 src/bskyblock/addon/challenges/commands/admin/TakeItems.java create mode 100644 src/bskyblock/addon/challenges/panel/TryToComplete.java diff --git a/locales/en-US.yml b/locales/en-US.yml index 90522a1..4991aaa 100755 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -8,49 +8,41 @@ challenges: complete: "Complete" - expReward: "Exp reward" - firstTimeRewards: "First time reward(s)" - guititle: "BSkyBlock Challenges" - help1: "Use /c to view information about a challenge." - help2: "Use /c complete to attempt to complete that challenge." + exp-reward: "Exp reward" + first-time-rewards: "First time reward(s)" + gui-title: "BSkyBlock Challenges" incomplete: "Incomplete" - invalidChallengeName: "Invalid challenge name! Use /c help for more information" itemTakeWarning: "All required items are taken when you complete this challenge!" level: "Level" - maxreached: "Max reached [donetimes] out of [maxtimes]" - moneyReward: "Money reward" + max-reached: "Max reached [donetimes] out of [maxtimes]" + money-reward: "Money reward" name: "Challenge Name" - nameHasCompleted: "[name] has completed the [challenge] challenge!" + name-has-completed: "[name] has completed the [challenge] challenge!" navigation: "Click to see [level] challenges!" - notRepeatable: "This Challenge is not repeatable!" - repeatRewards: "Repeat reward(s)" + not-repeatable: "This Challenge is not repeatable!" + repeat-rewards: "Repeat reward(s)" rewards: "Reward(s)" - toComplete: "Complete [challengesToDo] more [thisLevel] challenges to unlock this level!" - toCompleteUse: "To complete this challenge, use" - unknownChallenge: "Unknown challenge name (check spelling)!" - youHaveCompleted: "You have completed the [challenge] challenge!" - youHaveNotUnlocked: "You have not unlocked this challenge yet!" - youRepeated: "You repeated the [challenge] challenge!" -completechallenge: - challangeCompleted: "Challenge: [challengename] has been completed for [name]" - errorChallengeDoesNotExist: "Challenge doesn't exist or is already completed" -error: - IslandLevel: "Your island must be level [level] to complete this challenge!" - ItemsNotThere: "All required items must be close to you on your island!" - NotCloseEnough: "You must be standing within [number] blocks of all required items." - NotEnoughItems: "You do not have enough required item(s)" - NotOnIsland: "You must be on your island to do that!" - RewardProblem: "There was a problem giving your reward. Ask Admin to check log!" - YouAreMissing: "You are missing" -help: - command: "/challenges: &fshow challenges" - configReloaded: "Configuration reloaded from file." - resetAllChallenges: "resets all of the player's challenges" - resetChallenge: "marks a challenge as incomplete" - resetChallengeForAll: "globally resets a challenge for every player with an optional repetition" -resetallchallenges: - success: "[name] has had all challenges reset." -resetchallenge: - challengeReset: "Challenge: [challengename] has been reset for [name]" - errorChallengeDoesNotExist: "Challenge doesn't exist or isn't yet completed" + 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!" + completechallenge: + challange-completed: "Challenge: [challengename] has been completed for [name]" + error: + island-level: "Your island must be level [level] to complete this challenge!" + items-not-there: "All required items must be close to you on your island!" + not-close-enough: "You 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: "You must be on your island to do that!" + reward-problem: "There was a problem giving your reward. Ask Admin to check log!" + 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" + 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" diff --git a/pom.xml b/pom.xml index 22781bf..153d5b4 100644 --- a/pom.xml +++ b/pom.xml @@ -50,6 +50,13 @@ us.tastybento bskyblock LATEST + provided + + + bskyblock.addon + Level + 0.0.1-SNAPSHOT + provided @@ -60,4 +67,13 @@ Challenges bskyblock.addons + + + + bskyblock.addon + Level + 0.0.1-SNAPSHOT + + + \ No newline at end of file diff --git a/src/bskyblock/addon/challenges/Challenges.java b/src/bskyblock/addon/challenges/Challenges.java index 4b50925..2dda74f 100644 --- a/src/bskyblock/addon/challenges/Challenges.java +++ b/src/bskyblock/addon/challenges/Challenges.java @@ -3,6 +3,7 @@ package bskyblock.addon.challenges; import org.bukkit.Bukkit; import bskyblock.addon.challenges.commands.ChallengesCommand; +import bskyblock.addon.challenges.commands.admin.ChallengesAdminCommand; import bskyblock.addon.challenges.config.PluginConfig; import us.tastybento.bskyblock.api.addons.Addon; @@ -30,6 +31,7 @@ public class Challenges extends Addon { challengesManager = new ChallengesManager(this); // Register commands new ChallengesCommand(this); + new ChallengesAdminCommand(this); // Done } diff --git a/src/bskyblock/addon/challenges/ChallengesManager.java b/src/bskyblock/addon/challenges/ChallengesManager.java index d29f24d..2845a41 100644 --- a/src/bskyblock/addon/challenges/ChallengesManager.java +++ b/src/bskyblock/addon/challenges/ChallengesManager.java @@ -9,9 +9,9 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.UUID; import java.util.stream.Collectors; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.inventory.Inventory; @@ -69,20 +69,26 @@ public class ChallengesManager { challengeList.clear(); try { for (ChallengesData challenge : chHandler.loadObjects()) { + Bukkit.getLogger().info("DEBUG: Loading challenge " + challenge.getFriendlyName() + " level " + challenge.getLevel()); // See if we have this level already LevelsDO level; if (lvHandler.objectExists(challenge.getLevel())) { + Bukkit.getLogger().info("DEBUG: Level contains level " + challenge.getLevel()); // Get it from the database level = lvHandler.loadObject(challenge.getLevel()); } else { + Bukkit.getLogger().info("DEBUG: Level does not contains level " + challenge.getLevel()); // Make it level = new LevelsDO(); level.setUniqueId(challenge.getLevel()); + Bukkit.getLogger().info("DEBUG: Level unique Id set to " + level.getUniqueId()); lvHandler.saveObject(level); } if (challengeList.containsKey(level)) { + Bukkit.getLogger().info("DEBUG: Challenge contains level " + level.getUniqueId()); challengeList.get(level).add(challenge); } else { + Bukkit.getLogger().info("DEBUG: No key found"); // First challenge of this level type List challenges = new ArrayList<>(); challenges.add(challenge); @@ -95,11 +101,13 @@ public class ChallengesManager { // TODO Auto-generated catch block e.printStackTrace(); } + Bukkit.getLogger().info("DEBUG: " + challengeList.size()); // Sort the challenge list into level order challengeList = challengeList.entrySet().stream() .sorted(Map.Entry.comparingByKey()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new)); + Bukkit.getLogger().info("DEBUG: " + challengeList.size()); } /** @@ -228,12 +236,12 @@ public class ChallengesManager { * @param uniqueId2 - Challenge id * @return - true if completed */ - public boolean isChallengeComplete(UUID uniqueId, String uniqueId2) { + public boolean isChallengeComplete(User user, String uniqueId2) { // TODO Auto-generated method stub return false; } - public boolean isLevelComplete(UUID uniqueId, LevelsDO otherLevel) { + public boolean isLevelComplete(User user, LevelsDO otherLevel) { // TODO Auto-generated method stub return false; } @@ -330,6 +338,8 @@ public class ChallengesManager { newChallenge.setTakeItems(true); newChallenge.setUniqueId(inventory.getTitle()); newChallenge.setIcon(new ItemStack(Material.EMPTY_MAP)); + newChallenge.setFreeChallenge(true); + newChallenge.setLevel(""); // Move all the items back to the player's inventory inventory.forEach(item -> { @@ -355,5 +365,19 @@ public class ChallengesManager { user.sendRawMessage("Success"); } + + public boolean isLevelAvailable(User user, String level) { + // TODO + return false; + } + + public long checkChallengeTimes(User user, ChallengesData challenge) { + // TODO Auto-generated method stub + return 0; + } + + public Challenges getAddon() { + return addon; + } } diff --git a/src/bskyblock/addon/challenges/commands/ChallengesCommand.java b/src/bskyblock/addon/challenges/commands/ChallengesCommand.java index b577352..5cb7c07 100644 --- a/src/bskyblock/addon/challenges/commands/ChallengesCommand.java +++ b/src/bskyblock/addon/challenges/commands/ChallengesCommand.java @@ -14,8 +14,7 @@ public class ChallengesCommand extends CompositeCommand { public ChallengesCommand(Challenges addon) { super(CHALLENGE_COMMAND, "c", "challenge"); this.addon = addon; - // Set up create command - new CreateChallenge(addon, this); + // Set up commands } @Override diff --git a/src/bskyblock/addon/challenges/commands/admin/ChallengesAdminCommand.java b/src/bskyblock/addon/challenges/commands/admin/ChallengesAdminCommand.java new file mode 100644 index 0000000..c9d38d0 --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/ChallengesAdminCommand.java @@ -0,0 +1,41 @@ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import bskyblock.addon.challenges.Challenges; +import us.tastybento.bskyblock.Constants; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +public class ChallengesAdminCommand extends CompositeCommand { + private static final String CHALLENGE_ADMIN_COMMAND = "cadmin"; + private Challenges addon; + + public ChallengesAdminCommand(Challenges addon) { + super(CHALLENGE_ADMIN_COMMAND); + this.addon = addon; + // Set up create command + new CreateChallenge(addon, this); + } + + @Override + public boolean execute(User user, List args) { + // Open up the challenges GUI + if (user.isPlayer()) { + addon.getChallengesManager().getChallengesPanels().getChallenges(user); + return true; + } + return false; + } + + @Override + public void setup() { + this.setOnlyPlayer(true); + this.setPermission(Constants.PERMPREFIX + "challenges.admin"); + this.setParameters("challaneges.admin.parameters"); + this.setDescription("challenges.admin.description"); + this.setOnlyPlayer(true); + } + + +} diff --git a/src/bskyblock/addon/challenges/commands/CreateChallenge.java b/src/bskyblock/addon/challenges/commands/admin/CreateChallenge.java similarity index 91% rename from src/bskyblock/addon/challenges/commands/CreateChallenge.java rename to src/bskyblock/addon/challenges/commands/admin/CreateChallenge.java index 66c9a6c..daf7dde 100644 --- a/src/bskyblock/addon/challenges/commands/CreateChallenge.java +++ b/src/bskyblock/addon/challenges/commands/admin/CreateChallenge.java @@ -1,4 +1,4 @@ -package bskyblock.addon.challenges.commands; +package bskyblock.addon.challenges.commands.admin; import java.util.List; @@ -18,7 +18,7 @@ public class CreateChallenge extends CompositeCommand { * Admin command to make challenges * @param parent */ - public CreateChallenge(Challenges addon, ChallengesCommand parent) { + public CreateChallenge(Challenges addon, CompositeCommand parent) { super(parent, "create"); this.addon = addon; } diff --git a/src/bskyblock/addon/challenges/commands/admin/MakeLevel.java b/src/bskyblock/addon/challenges/commands/admin/MakeLevel.java new file mode 100644 index 0000000..c9866de --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/MakeLevel.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class MakeLevel extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public MakeLevel(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public MakeLevel(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public MakeLevel(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetDeployed.java b/src/bskyblock/addon/challenges/commands/admin/SetDeployed.java new file mode 100644 index 0000000..699c3d2 --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetDeployed.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetDeployed extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetDeployed(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetDeployed(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetDeployed(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetDescription.java b/src/bskyblock/addon/challenges/commands/admin/SetDescription.java new file mode 100644 index 0000000..8b2539a --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetDescription.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetDescription extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetDescription(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetDescription(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetDescription(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetExp.java b/src/bskyblock/addon/challenges/commands/admin/SetExp.java new file mode 100644 index 0000000..593f500 --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetExp.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetExp extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetExp(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetExp(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetExp(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetFriendlyName.java b/src/bskyblock/addon/challenges/commands/admin/SetFriendlyName.java new file mode 100644 index 0000000..6d7cffd --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetFriendlyName.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetFriendlyName extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetFriendlyName(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetFriendlyName(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetFriendlyName(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetLevel.java b/src/bskyblock/addon/challenges/commands/admin/SetLevel.java new file mode 100644 index 0000000..159e54b --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetLevel.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetLevel extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetLevel(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetLevel(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetLevel(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetMaxTimes.java b/src/bskyblock/addon/challenges/commands/admin/SetMaxTimes.java new file mode 100644 index 0000000..4f7644c --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetMaxTimes.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetMaxTimes extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetMaxTimes(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetMaxTimes(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetMaxTimes(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetPerm.java b/src/bskyblock/addon/challenges/commands/admin/SetPerm.java new file mode 100644 index 0000000..9f65c36 --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetPerm.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetPerm extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetPerm(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetPerm(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetPerm(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetRepeatable.java b/src/bskyblock/addon/challenges/commands/admin/SetRepeatable.java new file mode 100644 index 0000000..83e85bd --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetRepeatable.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetRepeatable extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetRepeatable(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetRepeatable(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetRepeatable(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetReward.java b/src/bskyblock/addon/challenges/commands/admin/SetReward.java new file mode 100644 index 0000000..2cd33d0 --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetReward.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetReward extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetReward(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetReward(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetReward(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/SetType.java b/src/bskyblock/addon/challenges/commands/admin/SetType.java new file mode 100644 index 0000000..883e87e --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/SetType.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class SetType extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public SetType(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public SetType(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public SetType(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/commands/admin/TakeItems.java b/src/bskyblock/addon/challenges/commands/admin/TakeItems.java new file mode 100644 index 0000000..bb65589 --- /dev/null +++ b/src/bskyblock/addon/challenges/commands/admin/TakeItems.java @@ -0,0 +1,65 @@ +/** + * + */ +package bskyblock.addon.challenges.commands.admin; + +import java.util.List; + +import us.tastybento.bskyblock.BSkyBlock; +import us.tastybento.bskyblock.api.commands.CompositeCommand; +import us.tastybento.bskyblock.api.commands.User; + +/** + * @author tastybento + * + */ +public class TakeItems extends CompositeCommand { + + /** + * @param plugin + * @param label + * @param string + */ + public TakeItems(BSkyBlock plugin, String label, String... string) { + super(plugin, label, string); + // TODO Auto-generated constructor stub + } + + /** + * @param parent + * @param label + * @param aliases + */ + public TakeItems(CompositeCommand parent, String label, String... aliases) { + super(parent, label, aliases); + // TODO Auto-generated constructor stub + } + + /** + * @param label + * @param aliases + */ + public TakeItems(String label, String... aliases) { + super(label, aliases); + // TODO Auto-generated constructor stub + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#setup() + */ + @Override + public void setup() { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see us.tastybento.bskyblock.api.commands.BSBCommand#execute(us.tastybento.bskyblock.api.commands.User, java.util.List) + */ + @Override + public boolean execute(User user, List args) { + // TODO Auto-generated method stub + return false; + } + +} diff --git a/src/bskyblock/addon/challenges/database/object/ChallengesData.java b/src/bskyblock/addon/challenges/database/object/ChallengesData.java index 9f4d9e9..391eea0 100644 --- a/src/bskyblock/addon/challenges/database/object/ChallengesData.java +++ b/src/bskyblock/addon/challenges/database/object/ChallengesData.java @@ -42,11 +42,11 @@ public class ChallengesData implements DataObject { /** * Description of the challenge. Will become the lore on the icon. Can include color codes. */ - private String description = ""; + private List description = new ArrayList<>(); /** * Experience point reward */ - private long expReward; + private int expReward; /** * This challenge can be completed at any time */ @@ -60,18 +60,17 @@ public class ChallengesData implements DataObject { */ private ItemStack icon = new ItemStack(Material.PAPER); /** - * The challenge level, e.g. Novice, Expert, etc. - * Levels are completed in order + * The challenge level. Default is Free */ - private String level = "Novice"; + private String level = "Free"; /** * Maximum number of times the challenge can be repeated */ - private long maxTimes = 1; + private int maxTimes = 1; /** * Money reward */ - private long moneyReward; + private int moneyReward; /** * If true, the challenge will disappear from the GUI when completed */ @@ -83,7 +82,7 @@ public class ChallengesData implements DataObject { /** * Repeat exp award */ - private long repeatExpReward; + private int repeatExpReward; /** * Reward items for repeating the challenge */ @@ -91,11 +90,11 @@ public class ChallengesData implements DataObject { /** * Repeat money award */ - private long repeatMoneyReward; + private int repeatMoneyReward; /** * Commands to run when challenge is repeated */ - private List repeatrewardcommands = new ArrayList<>(); + private List repeatRewardCommands = new ArrayList<>(); /** * Description of the repeat rewards. If blank, it will be autogenerated. */ @@ -103,7 +102,7 @@ public class ChallengesData implements DataObject { /** * Minimum amount of player experience */ - private long reqExp; + private int reqExp; /** * Require level for this challenge. */ @@ -111,7 +110,7 @@ public class ChallengesData implements DataObject { /** * Minimum amount of money required */ - private long reqMoney; + private int reqMoney; /** * The required permissions to see this challenge */ @@ -127,7 +126,7 @@ public class ChallengesData implements DataObject { /** * List of items the player will receive first time */ - private List rewardItems = new ArrayList<>(); + private List itemReward = new ArrayList<>(); /** * If this is blank, the reward text will be auto-generated, otherwise this will be used. */ @@ -154,243 +153,424 @@ public class ChallengesData implements DataObject { */ private String uniqueId = ""; + + /** + * @return the challengeType + */ public ChallengeType getChallengeType() { return challengeType; } - public String getDescription() { + /** + * @param challengeType the challengeType to set + */ + public void setChallengeType(ChallengeType challengeType) { + this.challengeType = challengeType; + } + + /** + * @return the deployed + */ + public boolean isDeployed() { + return deployed; + } + + /** + * @param deployed the deployed to set + */ + public void setDeployed(boolean deployed) { + this.deployed = deployed; + } + + /** + * @return the description + */ + public List getDescription() { return description; } - public long getExpReward() { + /** + * @param description the description to set + */ + public void setDescription(List description) { + this.description = description; + } + + /** + * @return the expReward + */ + public int getExpReward() { return expReward; } + /** + * @param expReward the expReward to set + */ + public void setExpReward(int expReward) { + this.expReward = expReward; + } + + /** + * @return the freeChallenge + */ + public boolean isFreeChallenge() { + return freeChallenge; + } + + /** + * @param freeChallenge the freeChallenge to set + */ + public void setFreeChallenge(boolean freeChallenge) { + this.freeChallenge = freeChallenge; + } + + /** + * @return the friendlyName + */ public String getFriendlyName() { return friendlyName; } + /** + * @param friendlyName the friendlyName to set + */ + public void setFriendlyName(String friendlyName) { + this.friendlyName = friendlyName; + } + + /** + * @return the icon + */ public ItemStack getIcon() { return icon; } + /** + * @param icon the icon to set + */ + public void setIcon(ItemStack icon) { + this.icon = icon; + } + + /** + * @return the level + */ public String getLevel() { return level; } - public long getMaxTimes() { + /** + * @param level the level to set + */ + public void setLevel(String level) { + this.level = level; + } + + /** + * @return the maxTimes + */ + public int getMaxTimes() { return maxTimes; } - public long getMoneyReward() { + /** + * @param maxTimes the maxTimes to set + */ + public void setMaxTimes(int maxTimes) { + this.maxTimes = maxTimes; + } + + /** + * @return the moneyReward + */ + public int getMoneyReward() { return moneyReward; } - public long getRepeatExpReward() { + /** + * @param moneyReward the moneyReward to set + */ + public void setMoneyReward(int moneyReward) { + this.moneyReward = moneyReward; + } + + /** + * @return the removeWhenCompleted + */ + public boolean isRemoveWhenCompleted() { + return removeWhenCompleted; + } + + /** + * @param removeWhenCompleted the removeWhenCompleted to set + */ + public void setRemoveWhenCompleted(boolean removeWhenCompleted) { + this.removeWhenCompleted = removeWhenCompleted; + } + + /** + * @return the repeatable + */ + public boolean isRepeatable() { + return repeatable; + } + + /** + * @param repeatable the repeatable to set + */ + public void setRepeatable(boolean repeatable) { + this.repeatable = repeatable; + } + + /** + * @return the repeatExpReward + */ + public int getRepeatExpReward() { return repeatExpReward; } + /** + * @param repeatExpReward the repeatExpReward to set + */ + public void setRepeatExpReward(int repeatExpReward) { + this.repeatExpReward = repeatExpReward; + } + + /** + * @return the repeatItemReward + */ public List getRepeatItemReward() { return repeatItemReward; } - public long getRepeatMoneyReward() { + /** + * @param repeatItemReward the repeatItemReward to set + */ + public void setRepeatItemReward(List repeatItemReward) { + this.repeatItemReward = repeatItemReward; + } + + /** + * @return the repeatMoneyReward + */ + public int getRepeatMoneyReward() { return repeatMoneyReward; } - public List getRepeatrewardcommands() { - return repeatrewardcommands; + /** + * @param repeatMoneyReward the repeatMoneyReward to set + */ + public void setRepeatMoneyReward(int repeatMoneyReward) { + this.repeatMoneyReward = repeatMoneyReward; } + /** + * @return the repeatRewardCommands + */ + public List getRepeatRewardCommands() { + return repeatRewardCommands; + } + + /** + * @param repeatRewardCommands the repeatRewardCommands to set + */ + public void setRepeatRewardCommands(List repeatRewardCommands) { + this.repeatRewardCommands = repeatRewardCommands; + } + + /** + * @return the repeatRewardText + */ public String getRepeatRewardText() { return repeatRewardText; } - public long getReqExp() { + /** + * @param repeatRewardText the repeatRewardText to set + */ + public void setRepeatRewardText(String repeatRewardText) { + this.repeatRewardText = repeatRewardText; + } + + /** + * @return the reqExp + */ + public int getReqExp() { return reqExp; } + /** + * @param reqExp the reqExp to set + */ + public void setReqExp(int reqExp) { + this.reqExp = reqExp; + } + + /** + * @return the reqIslandlevel + */ public long getReqIslandlevel() { return reqIslandlevel; } - public long getReqMoney() { + /** + * @param reqIslandlevel the reqIslandlevel to set + */ + public void setReqIslandlevel(long reqIslandlevel) { + this.reqIslandlevel = reqIslandlevel; + } + + /** + * @return the reqMoney + */ + public int getReqMoney() { return reqMoney; } + /** + * @param reqMoney the reqMoney to set + */ + public void setReqMoney(int reqMoney) { + this.reqMoney = reqMoney; + } + + /** + * @return the reqPerms + */ public Set getReqPerms() { return reqPerms; } + /** + * @param reqPerms the reqPerms to set + */ + public void setReqPerms(Set reqPerms) { + this.reqPerms = reqPerms; + } + + /** + * @return the requiredItems + */ public List getRequiredItems() { return requiredItems; } + /** + * @param requiredItems the requiredItems to set + */ + public void setRequiredItems(List requiredItems) { + this.requiredItems = requiredItems; + } + + /** + * @return the rewardCommands + */ public List getRewardCommands() { return rewardCommands; } - public List getRewardItems() { - return rewardItems; + /** + * @param rewardCommands the rewardCommands to set + */ + public void setRewardCommands(List rewardCommands) { + this.rewardCommands = rewardCommands; } + /** + * @return the itemReward + */ + public List getItemReward() { + return itemReward; + } + + /** + * @param itemReward the itemReward to set + */ + public void setItemReward(List itemReward) { + this.itemReward = 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 uniqueId + */ @Override public String getUniqueId() { return uniqueId; } - public boolean isDeployed() { - return deployed; - } - - public boolean isFreeChallenge() { - return freeChallenge; - } - - public boolean isRemoveWhenCompleted() { - return removeWhenCompleted; - } - - public boolean isRepeatable() { - return repeatable; - } - - public boolean isTakeItems() { - return takeItems; - } - - public boolean isTakeMoney() { - return takeMoney; - } - - public void setChallengeType(ChallengeType challengeType) { - this.challengeType = challengeType; - } - - public void setDeployed(boolean deployed) { - this.deployed = deployed; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setExpReward(long expReward) { - this.expReward = expReward; - } - - public void setFreeChallenge(boolean freeChallenge) { - this.freeChallenge = freeChallenge; - } - - public void setFriendlyName(String friendlyName) { - this.friendlyName = friendlyName; - } - - public void setIcon(ItemStack icon) { - this.icon = icon; - } - - public void setLevel(String level) { - this.level = level; - } - - public void setMaxTimes(long maxTimes) { - this.maxTimes = maxTimes; - } - - public void setMoneyReward(long moneyReward) { - this.moneyReward = moneyReward; - } - - public void setRemoveWhenCompleted(boolean removeWhenCompleted) { - this.removeWhenCompleted = removeWhenCompleted; - } - - public void setRepeatable(boolean repeatable) { - this.repeatable = repeatable; - } - - public void setRepeatExpReward(long repeatExpReward) { - this.repeatExpReward = repeatExpReward; - } - - public void setRepeatItemReward(List repeatItemReward) { - this.repeatItemReward = repeatItemReward; - } - - public void setRepeatMoneyReward(long repeatMoneyReward) { - this.repeatMoneyReward = repeatMoneyReward; - } - - public void setRepeatrewardcommands(List repeatrewardcommands) { - this.repeatrewardcommands = repeatrewardcommands; - } - - public void setRepeatRewardText(String repeatRewardText) { - this.repeatRewardText = repeatRewardText; - } - - public void setReqExp(long reqExp) { - this.reqExp = reqExp; - } - - public void setReqIslandlevel(long reqIslandlevel) { - this.reqIslandlevel = reqIslandlevel; - } - - public void setReqMoney(long reqMoney) { - this.reqMoney = reqMoney; - } - - public void setReqPerms(Set reqPerms) { - this.reqPerms = reqPerms; - } - - public void setRequiredItems(List requiredItems) { - this.requiredItems = requiredItems; - } - - public void setRewardCommands(List rewardCommands) { - this.rewardCommands = rewardCommands; - } - - public void setRewardItems(List rewardItems) { - this.rewardItems = rewardItems; - } - - public void setRewardText(String rewardText) { - this.rewardText = rewardText; - } - - public void setSearchRadius(int searchRadius) { - this.searchRadius = searchRadius; - } - - public void setSlot(int slot) { - this.slot = slot; - } - - public void setTakeItems(boolean takeItems) { - this.takeItems = takeItems; - } - - public void setTakeMoney(boolean takeMoney) { - this.takeMoney = takeMoney; - } - + /** + * @param uniqueId the uniqueId to set + */ @Override public void setUniqueId(String uniqueId) { this.uniqueId = uniqueId; diff --git a/src/bskyblock/addon/challenges/database/object/LevelsDO.java b/src/bskyblock/addon/challenges/database/object/LevelsDO.java index b5d9026..338d0f6 100644 --- a/src/bskyblock/addon/challenges/database/object/LevelsDO.java +++ b/src/bskyblock/addon/challenges/database/object/LevelsDO.java @@ -18,7 +18,7 @@ public class LevelsDO implements DataObject, Comparable { /** * Level name */ - private String uniqueId = ""; + private String uniqueId = "Free"; /** * The number of undone challenges that can be left on this level before unlocking next level */ @@ -75,5 +75,41 @@ public class LevelsDO implements DataObject, Comparable { public int compareTo(LevelsDO o) { return Integer.compare(this.order, o.order); } + + /* (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 LevelsDO)) { + return false; + } + LevelsDO other = (LevelsDO) obj; + if (uniqueId == null) { + if (other.uniqueId != null) { + return false; + } + } else if (!uniqueId.equals(other.uniqueId)) { + return false; + } + return true; + } } diff --git a/src/bskyblock/addon/challenges/panel/ChallengesPanels.java b/src/bskyblock/addon/challenges/panel/ChallengesPanels.java index 4e7e55e..ec1481d 100644 --- a/src/bskyblock/addon/challenges/panel/ChallengesPanels.java +++ b/src/bskyblock/addon/challenges/panel/ChallengesPanels.java @@ -11,6 +11,7 @@ import bskyblock.addon.challenges.Challenges; import bskyblock.addon.challenges.ChallengesManager; import bskyblock.addon.challenges.ChallengesManager.LevelStatus; import bskyblock.addon.challenges.database.object.ChallengesData; +import bskyblock.addon.challenges.database.object.ChallengesData.ChallengeType; import us.tastybento.bskyblock.api.commands.User; import us.tastybento.bskyblock.api.panels.ClickType; import us.tastybento.bskyblock.api.panels.Panel; @@ -20,13 +21,12 @@ import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder; public class ChallengesPanels { - private static final boolean DEBUG = false; - //private static final String CHALLENGE_COMMAND = "challenges"; - private Challenges plugin; + private static final boolean DEBUG = true; + private Challenges addon; private ChallengesManager manager; public ChallengesPanels(Challenges plugin, ChallengesManager manager){ - this.plugin = plugin; + this.addon = plugin; this.manager = manager; } @@ -41,24 +41,54 @@ public class ChallengesPanels { /** * Dynamically creates an inventory of challenges for the player showing the * level - * - * @param user - * @return inventory */ public void getChallenges(User user, String level) { - plugin.getLogger().info("DEBUG: level requested = " + level); + addon.getLogger().info("DEBUG: level requested = " + level); PanelBuilder panelBuilder = new PanelBuilder() .setName(user.getTranslation("challenges.guiTitle")); + + addChallengeItems(panelBuilder, user, level); + addFreeChallanges(panelBuilder); + addNavigation(panelBuilder, user); + + // Create the panel + addon.getLogger().info("DEBUG: panel created"); + Panel panel = panelBuilder.build(); + panel.open(user); + } + + private void addFreeChallanges(PanelBuilder panelBuilder) { + /* + // Add the free challenges if not already shown (which can happen if all of the challenges are done!) + if (!level.equals("") && challengeList.containsKey("")) { + for (String freeChallenges: challengeList.get("")) { + CPItem item = createItem(freeChallenges, player); + if (item != null) { + cp.add(item); + } + } + }*/ + + } + + private void addChallengeItems(PanelBuilder panelBuilder, User user, String level) { + List levelChallenges = manager.getChallenges(level); // Do some checking if (DEBUG) - plugin.getLogger().info("DEBUG: Opening level " + level); + addon.getLogger().info("DEBUG: Opening level " + level + " with " + levelChallenges.size() + " challenges"); + // Only show a control panel for the level requested. for (ChallengesData challenge : levelChallenges) { - plugin.getLogger().info("Adding challenge " + challenge.getUniqueId()); - boolean completed = manager.isChallengeComplete(user.getUniqueId(), challenge.getUniqueId()); - if (completed && challenge.isRemoveWhenCompleted()) + addon.getLogger().info("DEBUG: Adding challenge " + challenge.getUniqueId()); + // Check completion + boolean completed = manager.isChallengeComplete(user, challenge.getUniqueId()); + addon.getLogger().info("DEBUG: challenge completed = " + completed); + // If challenge is removed after completion, remove it + if (completed && challenge.isRemoveWhenCompleted()) { + addon.getLogger().info("DEBUG: ignored completed"); continue; + } PanelItem item = new PanelItemBuilder() .icon(challenge.getIcon()) .name(challenge.getFriendlyName().isEmpty() ? challenge.getUniqueId() : challenge.getFriendlyName()) @@ -67,15 +97,22 @@ public class ChallengesPanels { .clickHandler(new PanelItem.ClickHandler() { @Override public boolean onClick(User user, ClickType click) { - user.sendMessage("Hi!"); - return false; + if (!challenge.getChallengeType().equals(ChallengeType.ICON)) { + new TryToComplete(addon, user, manager, challenge); + } + return true; } }) - //.setCommand(CHALLENGE_COMMAND + " c " + challenge.getUniqueId()) .build(); - plugin.getLogger().info("requested slot" + challenge.getSlot()); + addon.getLogger().info("requested slot" + challenge.getSlot()); panelBuilder.addItem(challenge.getSlot(),item); } + + + } + + private void addNavigation(PanelBuilder panelBuilder, User user) { + // TODO Auto-generated method stub // Add navigation to other levels for (LevelStatus status: manager.getChallengeLevelStatus(user)) { String name = ChatColor.GOLD + (status.getLevel().getFriendlyName().isEmpty() ? status.getLevel().getUniqueId() : status.getLevel().getFriendlyName()); @@ -86,7 +123,7 @@ public class ChallengesPanels { .name(name) .description(Arrays.asList(user.getTranslation("challenges.navigation","[level]",name))) .clickHandler(new PanelItem.ClickHandler() { - + @Override public boolean onClick(User user, ClickType click) { // TODO Auto-generated method stub @@ -107,19 +144,6 @@ public class ChallengesPanels { panelBuilder.addItem(item); } } - /* - // Add the free challenges if not already shown (which can happen if all of the challenges are done!) - if (!level.equals("") && challengeList.containsKey("")) { - for (String freeChallenges: challengeList.get("")) { - CPItem item = createItem(freeChallenges, player); - if (item != null) { - cp.add(item); - } - } - }*/ - // Create the panel - Panel panel = panelBuilder.build(); - panel.open(user); } /* @@ -178,5 +202,5 @@ public class ChallengesPanels { challengePanels.remove(event.getPlayer().getUniqueId()); plugin.getLogger().info("DEBUG: removing inv " + challengePanels.size()); } -*/ + */ } diff --git a/src/bskyblock/addon/challenges/panel/TryToComplete.java b/src/bskyblock/addon/challenges/panel/TryToComplete.java new file mode 100644 index 0000000..eae4dc1 --- /dev/null +++ b/src/bskyblock/addon/challenges/panel/TryToComplete.java @@ -0,0 +1,209 @@ +/** + * + */ +package bskyblock.addon.challenges.panel; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.inventory.ItemStack; + +import bskyblock.addon.challenges.Challenges; +import bskyblock.addon.challenges.ChallengesManager; +import bskyblock.addon.challenges.database.object.ChallengesData; +import bskyblock.addon.challenges.database.object.ChallengesData.ChallengeType; +import bskyblock.addon.level.Level; +import us.tastybento.bskyblock.Constants; +import us.tastybento.bskyblock.api.commands.User; +import us.tastybento.bskyblock.util.Util; + +/** + * Run when a user tries to complete a challenge + * @author tastybento + * + */ +public class TryToComplete { + + private Challenges addon; + + public TryToComplete(Challenges addon, User user, ChallengesManager manager, ChallengesData challenge) { + this.addon = addon; + Bukkit.getLogger().info("DEBUG: try to complete"); + // Check if user is in the worlds + if (!Util.inWorld(user.getLocation())) { + user.sendMessage("general.errors.wrong-world"); + return; + } + Bukkit.getLogger().info("DEBUG: right world"); + // Check if can complete challenge + ChallengeResult result = checkIfCanCompleteChallenge(user, manager, challenge); + if (!result.meetsRequirements) { + Bukkit.getLogger().info("DEBUG: could not complete"); + return; + } + Bukkit.getLogger().info("DEBUG: Can complete!"); + if (!result.repeat) { + // Give rewards + for (ItemStack reward : challenge.getItemReward()) { + user.getInventory().addItem(reward).forEach((k,v) -> user.getWorld().dropItem(user.getLocation(), v)); + } + // Give money + challenge.getMoneyReward(); + // Give exp + user.getPlayer().giveExp(challenge.getExpReward()); + // Run commands + runCommands(user, challenge.getRewardCommands()); + user.sendMessage("challenges.you-completed", "[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 + challenge.getRepeatMoneyReward(); + // Give exp + user.getPlayer().giveExp(challenge.getRepeatExpReward()); + // Run commands + runCommands(user, challenge.getRepeatRewardCommands()); + user.sendMessage("challenges.you-repeated", "[challenge]", challenge.getFriendlyName()); + } + + } + + /** + * Checks if a challenge can be completed or not + */ + private ChallengeResult checkIfCanCompleteChallenge(User user, ChallengesManager manager, ChallengesData challenge) { + // Check if user has the + if (!challenge.isFreeChallenge() && !manager.isLevelAvailable(user, challenge.getLevel())) { + user.sendMessage("challenges.errors.challenge-level-not-available"); + return new ChallengeResult(); + } + Bukkit.getLogger().info("DEBUG: Level is available or challenge is free"); + // Check max times + if (challenge.isRepeatable() && challenge.getMaxTimes() > 0) { + Bukkit.getLogger().info("DEBUG: repeatable and max times > 0"); + if (manager.checkChallengeTimes(user, challenge) >= challenge.getMaxTimes()) { + user.sendMessage("challenges.errors.cannot-repeat"); + return new ChallengeResult(); + } + } + // Check repeatability + if (manager.isChallengeComplete(user, challenge.getUniqueId()) + && (!challenge.isRepeatable() || challenge.getChallengeType().equals(ChallengeType.LEVEL) + || challenge.getChallengeType().equals(ChallengeType.SURROUNDING))) { + user.sendMessage("challenges.errors.cannot-repeat"); + return new ChallengeResult(); + } + Bukkit.getLogger().info("DEBUG: switch " + challenge.getChallengeType()); + switch (challenge.getChallengeType()) { + case INVENTORY: + return checkInventory(user, manager, challenge); + case LEVEL: + return checkLevel(user, manager, challenge); + case SURROUNDING: + return checkSurrounding(user, manager, challenge); + default: + return new ChallengeResult(); + } + } + + private ChallengeResult checkInventory(User user, ChallengesManager manager, ChallengesData challenge) { + Bukkit.getLogger().info("DEBUG: Checking inventory"); + // Run through inventory + List required = new ArrayList<>(challenge.getRequiredItems()); + for (ItemStack req : required) { + // I wonder how well this works + if (!user.getInventory().containsAtLeast(req, req.getAmount())) { + Bukkit.getLogger().info("DEBUG: insufficient items " + req); + 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()) { + for (ItemStack items : required) { + user.getInventory().removeItem(items); + } + } + Bukkit.getLogger().info("DEBUG: Everything there!"); + return new ChallengeResult().setMeetsRequirements().setRepeat(manager.isChallengeComplete(user, challenge.getUniqueId())); + } + + private ChallengeResult checkLevel(User user, ChallengesManager manager, ChallengesData challenge) { + // Check if the level addon is installed or not + return addon.getAddonByName("BSkyBlock-Level").map(l -> { + return ((Level)l).getIslandLevel(user.getUniqueId()) >= challenge.getReqIslandlevel() ? + new ChallengeResult().setMeetsRequirements() : new ChallengeResult(); + }).orElse(new ChallengeResult()); + } + + private ChallengeResult checkSurrounding(User user, ChallengesManager manager, ChallengesData challenge) { + // TODO Auto-generated method stub + return new ChallengeResult(); + } + + /** + * Contains flags on completion of challenge + * @author tastybento + * + */ + public class ChallengeResult { + private boolean meetsRequirements; + private boolean repeat; + /** + * @param meetsRequirements the meetsRequirements to set + */ + public ChallengeResult setMeetsRequirements() { + this.meetsRequirements = true; + return this; + } + /** + * @param repeat the repeat to set + */ + public ChallengeResult setRepeat(boolean repeat) { + this.repeat = repeat; + return this; + } + + } + + private void runCommands(User player, List commands) { + // Ignore commands with this perm + if (player.hasPermission(Constants.PERMPREFIX + "command.challengeexempt") && !player.isOp()) { + return; + } + for (String cmd : commands) { + if (cmd.startsWith("[SELF]")) { + addon.getLogger().info("Running command '" + cmd + "' as " + player.getName()); + cmd = cmd.substring(6,cmd.length()).replace("[player]", player.getName()).trim(); + try { + if (!player.performCommand(cmd)) { + addon.getLogger().severe("Problem executing island command executed by player - skipping!"); + addon.getLogger().severe("Command was : " + cmd); + } + } catch (Exception e) { + addon.getLogger().severe("Problem executing island command executed by player - skipping!"); + addon.getLogger().severe("Command was : " + cmd); + addon.getLogger().severe("Error was: " + e.getMessage()); + e.printStackTrace(); + } + + continue; + } + // Substitute in any references to player + try { + if (!addon.getServer().dispatchCommand(addon.getServer().getConsoleSender(), cmd.replace("[player]", player.getName()))) { + addon.getLogger().severe("Problem executing challenge reward commands - skipping!"); + addon.getLogger().severe("Command was : " + cmd); + } + } catch (Exception e) { + addon.getLogger().severe("Problem executing challenge reward commands - skipping!"); + addon.getLogger().severe("Command was : " + cmd); + addon.getLogger().severe("Error was: " + e.getMessage()); + e.printStackTrace(); + } + } + } +}