diff --git a/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java b/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java index f14a4c3..d094bdc 100644 --- a/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java +++ b/src/main/java/world/bentobox/challenges/commands/ChallengesCommand.java @@ -1,7 +1,9 @@ package world.bentobox.challenges.commands; import java.util.List; +import java.util.Optional; +import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.challenges.ChallengesAddon; import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.user.User; @@ -19,26 +21,64 @@ public class ChallengesCommand extends CompositeCommand } + /** + * {@inheritDoc} + */ + @Override + public boolean canExecute(User user, String label, List args) + { + Optional optionalAddon = this.getAddon().getPlugin().getIWM().getAddon(this.getWorld()); + + if (!optionalAddon.isPresent()) + { + // Not a GameMode world. + user.sendMessage("general.errors.wrong-world"); + return false; + } + + if (!((ChallengesAddon) this.getAddon()).getChallengesManager().hasAnyChallengeData(this.getWorld())) + { + // Do not open gui if there is no challenges. + + this.getAddon().getLogger().severe("There are no challenges set up in " + this.getWorld() + "!"); + + // Show admin better explanation. + if (user.isOp() || user.hasPermission(this.getPermissionPrefix() + ".admin.challenges")) + { + String topLabel = optionalAddon.get().getAdminCommand().orElseGet(this::getParent).getTopLabel(); + user.sendMessage("challenges.errors.no-challenges-admin", "[label]", topLabel); + } + else + { + user.sendMessage("challenges.errors.no-challenges"); + } + + return false; + } + + if (this.getPlugin().getIslands().getIsland(this.getWorld(), user.getUniqueId()) == null) + { + // Do not open gui if there is no island for this player. + user.sendMessage("general.errors.no-island"); + return false; + } + + return true; + } + + @Override public boolean execute(User user, String label, List args) { // Open up the challenges GUI if (user.isPlayer()) { - if (this.getPlugin().getIslands().getIsland(this.getWorld(), user.getUniqueId()) != null) - { - new ChallengesGUI((ChallengesAddon) this.getAddon(), - this.getWorld(), - user, - this.getTopLabel(), - this.getPermissionPrefix()).build(); - return true; - } - else - { - user.sendMessage("general.errors.no-island"); - return false; - } + new ChallengesGUI((ChallengesAddon) this.getAddon(), + this.getWorld(), + user, + this.getTopLabel(), + this.getPermissionPrefix()).build(); + return true; } // Show help showHelp(this, user); @@ -54,5 +94,6 @@ public class ChallengesCommand extends CompositeCommand this.setDescription("challenges.commands.user.main.description"); new CompleteChallengeCommand(this.getAddon(), this); + this.setOnlyPlayer(true); } } diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index bd49e2f..ca2748c 100755 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -353,6 +353,7 @@ challenges: defaults-file-exist: '&cdefaults.json already exists. Use overwrite mode to replace it!' defaults-file-error: '&cThere was an error while creating defaults.json file! Check console!' no-challenges: '&cChallenges are not implemented in current world!' + no-challenges-admin: '&cChallenges are not implemented in current world! You should use &5/[label] challenges &cto adding them!' missing-level: '&cChallenge Level [level] is not defined in database. It may case some errors!' protection: flags: diff --git a/src/main/resources/locales/lv-LV.yml b/src/main/resources/locales/lv-LV.yml index aa85683..8c0faaf 100755 --- a/src/main/resources/locales/lv-LV.yml +++ b/src/main/resources/locales/lv-LV.yml @@ -351,6 +351,7 @@ challenges: defaults-file-exist: '&cdefaults.json jau eksistē. Lieto overwrite, lai to pārrakstītu!' defaults-file-error: '&cRadās kļūda veidojot defaults.json failu! Pārbaudi konsoli!' no-challenges: '&cŠajā pasaulē nav izveidoti uzdevumi!' + no-challenges-admin: '&cŠajā pasaulē nav izveidoti uzdevumi! Izmanot komandu &5/[label] challenges&c, lai tos pievienotu!' missing-level: '&cLīmenis [level] nav definēts datubāzē. Tas var radīt problēmas!' protection: flags: