diff --git a/src/main/java/world/bentobox/challenges/ChallengesAddon.java b/src/main/java/world/bentobox/challenges/ChallengesAddon.java index 0f28e44..e3b7a71 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesAddon.java +++ b/src/main/java/world/bentobox/challenges/ChallengesAddon.java @@ -225,10 +225,12 @@ public class ChallengesAddon extends Addon { @Override public void onReload() { - if (this.hooked) { - this.challengesManager.save(); + super.onReload(); + if (this.hooked) + { this.loadSettings(); + this.challengesManager.reload(); this.getLogger().info("Challenges addon reloaded."); } } diff --git a/src/main/java/world/bentobox/challenges/ChallengesManager.java b/src/main/java/world/bentobox/challenges/ChallengesManager.java index 3430fb3..3677c76 100644 --- a/src/main/java/world/bentobox/challenges/ChallengesManager.java +++ b/src/main/java/world/bentobox/challenges/ChallengesManager.java @@ -127,6 +127,13 @@ public class ChallengesManager { this.challengeCacheData.clear(); this.levelCacheData.clear(); + + if (!this.playerCacheData.isEmpty()) + { + // store player data before cleaning. + this.savePlayersData(); + } + this.playerCacheData.clear(); this.addon.getLogger().info("Loading challenges..."); @@ -143,6 +150,12 @@ public class ChallengesManager */ public void reload() { + if (!this.playerCacheData.isEmpty()) + { + // store player data before cleaning. + this.savePlayersData(); + } + this.addon.getLogger().info("Reloading challenges..."); this.challengeDatabase = new Database<>(addon, Challenge.class); diff --git a/src/main/java/world/bentobox/challenges/commands/admin/ReloadChallenges.java b/src/main/java/world/bentobox/challenges/commands/admin/ReloadChallenges.java index 72b751e..05be3fb 100644 --- a/src/main/java/world/bentobox/challenges/commands/admin/ReloadChallenges.java +++ b/src/main/java/world/bentobox/challenges/commands/admin/ReloadChallenges.java @@ -8,36 +8,65 @@ import world.bentobox.bentobox.api.addons.Addon; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; -public class ReloadChallenges extends CompositeCommand { - - private ChallengesManager manager; +/** + * This class allows to reload challenges addon. + */ +public class ReloadChallenges extends CompositeCommand +{ /** - * Admin command to complete user challenges + * Admin command to reloads challenges addon. * @param parent */ - public ReloadChallenges(Addon addon, CompositeCommand parent) { + public ReloadChallenges(Addon addon, CompositeCommand parent) + { super(addon, parent, "reload"); + this.manager = ((ChallengesAddon) getAddon()).getChallengesManager(); } + + /** + * {@inheritDoc} + */ @Override - public void setup() { + public void setup() + { this.setPermission("admin.challenges"); this.setParametersHelp("challenges.commands.admin.reload.parameters"); this.setDescription("challenges.commands.admin.reload.description"); - manager = ((ChallengesAddon)getAddon()).getChallengesManager(); } + + /** + * {@inheritDoc} + */ @Override - public boolean execute(User user, String label, List args) { - if (!args.isEmpty()) { - // Show help - showHelp(this, user); + public boolean execute(User user, String label, List args) + { + if (args.isEmpty()) + { + this.manager.load(); + user.sendMessage("general.success"); + return true; + } + else if (args.get(0).equalsIgnoreCase("hard")) + { + this.manager.reload(); + user.sendMessage("general.success"); + return true; + } + else + { + this.showHelp(this, user); return false; } - manager.load(); - user.sendMessage("general.success"); - return true; } + + // --------------------------------------------------------------------- + // Section: Variables + // --------------------------------------------------------------------- + + + private ChallengesManager manager; } diff --git a/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java b/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java deleted file mode 100644 index b23038c..0000000 --- a/src/main/java/world/bentobox/challenges/commands/admin/ResetChallenge.java +++ /dev/null @@ -1,81 +0,0 @@ -package world.bentobox.challenges.commands.admin; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -import world.bentobox.challenges.ChallengesAddon; -import world.bentobox.challenges.ChallengesManager; -import world.bentobox.bentobox.api.addons.Addon; -import world.bentobox.bentobox.api.commands.CompositeCommand; -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; - - /** - * Admin command to complete user challenges - * @param parent - */ - public ResetChallenge(Addon addon, CompositeCommand parent) { - super(addon, parent, "reset"); - } - - @Override - public void setup() { - this.setPermission("admin.challenges"); - this.setParametersHelp("challenges.commands.admin.reset.parameters"); - this.setDescription("challenges.commands.admin.reset.description"); - manager = ((ChallengesAddon)getAddon()).getChallengesManager(); - } - - @Override - public boolean execute(User user, String label, List args) { - if (args.size() != 2) { - // Show help - showHelp(this, user); - return false; - } - // Get target player - UUID targetUUID = getPlayers().getUUID(args.get(0)); - if (targetUUID == null) { - user.sendMessage("general.errors.unknown-player", TextVariables.NAME, args.get(0)); - return false; - } - if (!getPlugin().getIslands().hasIsland(getWorld(), targetUUID)) { - user.sendMessage("general.errors.player-has-no-island"); - return false; - } - // Check for valid challenge name - if (!manager.containsChallenge(args.get(1))) { - user.sendMessage("challenges.errors.unknown-challenge"); - return false; - } - // Complete challenge - manager.resetChallenge(targetUUID, this.getWorld(), manager.getChallenge(args.get(1)), user.getUniqueId()); - user.sendMessage("general.success"); - return true; - } - - @Override - public Optional> tabComplete(User user, String alias, List args) { - String lastArg = !args.isEmpty() ? args.get(args.size()-1) : ""; - if (args.size() == 3) { - // Online players - 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.getAllChallengesNames(getWorld()), lastArg)); - } - return Optional.empty(); - } -}