Add custom admin message that informs about non-existing challenges in current world.

This commit is contained in:
BONNe 2019-05-19 13:29:02 +03:00
parent c3f93fd797
commit 7e04f592ad
3 changed files with 57 additions and 14 deletions

View File

@ -1,7 +1,9 @@
package world.bentobox.challenges.commands; package world.bentobox.challenges.commands;
import java.util.List; import java.util.List;
import java.util.Optional;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User; 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<String> args)
{
Optional<GameModeAddon> 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 @Override
public boolean execute(User user, String label, List<String> args) public boolean execute(User user, String label, List<String> args)
{ {
// Open up the challenges GUI // Open up the challenges GUI
if (user.isPlayer()) if (user.isPlayer())
{ {
if (this.getPlugin().getIslands().getIsland(this.getWorld(), user.getUniqueId()) != null) new ChallengesGUI((ChallengesAddon) this.getAddon(),
{ this.getWorld(),
new ChallengesGUI((ChallengesAddon) this.getAddon(), user,
this.getWorld(), this.getTopLabel(),
user, this.getPermissionPrefix()).build();
this.getTopLabel(), return true;
this.getPermissionPrefix()).build();
return true;
}
else
{
user.sendMessage("general.errors.no-island");
return false;
}
} }
// Show help // Show help
showHelp(this, user); showHelp(this, user);
@ -54,5 +94,6 @@ public class ChallengesCommand extends CompositeCommand
this.setDescription("challenges.commands.user.main.description"); this.setDescription("challenges.commands.user.main.description");
new CompleteChallengeCommand(this.getAddon(), this); new CompleteChallengeCommand(this.getAddon(), this);
this.setOnlyPlayer(true);
} }
} }

View File

@ -353,6 +353,7 @@ challenges:
defaults-file-exist: '&cdefaults.json already exists. Use overwrite mode to replace it!' 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!' 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: '&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!' missing-level: '&cChallenge Level [level] is not defined in database. It may case some errors!'
protection: protection:
flags: flags:

View File

@ -351,6 +351,7 @@ challenges:
defaults-file-exist: '&cdefaults.json jau eksistē. Lieto overwrite, lai to pārrakstītu!' 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!' defaults-file-error: '&cRadās kļūda veidojot defaults.json failu! Pārbaudi konsoli!'
no-challenges: '&cŠajā pasaulē nav izveidoti uzdevumi!' 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!' missing-level: '&cLīmenis [level] nav definēts datubāzē. Tas var radīt problēmas!'
protection: protection:
flags: flags: