Skip to content

Commit

Permalink
Add custom admin message that informs about non-existing challenges i…
Browse files Browse the repository at this point in the history
…n current world.
  • Loading branch information
BONNe committed May 19, 2019
1 parent c3f93fd commit 7e04f59
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,26 +21,64 @@ public ChallengesCommand(ChallengesAddon addon, CompositeCommand cmd)
}


/**
* {@inheritDoc}
*/
@Override
public boolean execute(User user, String label, List<String> args)
public boolean canExecute(User user, String label, List<String> args)
{
// Open up the challenges GUI
if (user.isPlayer())
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()))
{
if (this.getPlugin().getIslands().getIsland(this.getWorld(), user.getUniqueId()) != null)
// 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"))
{
new ChallengesGUI((ChallengesAddon) this.getAddon(),
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix()).build();
return true;
String topLabel = optionalAddon.get().getAdminCommand().orElseGet(this::getParent).getTopLabel();
user.sendMessage("challenges.errors.no-challenges-admin", "[label]", topLabel);
}
else
{
user.sendMessage("general.errors.no-island");
return false;
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<String> args)
{
// Open up the challenges GUI
if (user.isPlayer())
{
new ChallengesGUI((ChallengesAddon) this.getAddon(),
this.getWorld(),
user,
this.getTopLabel(),
this.getPermissionPrefix()).build();
return true;
}
// Show help
showHelp(this, user);
Expand All @@ -54,5 +94,6 @@ public void setup()
this.setDescription("challenges.commands.user.main.description");

new CompleteChallengeCommand(this.getAddon(), this);
this.setOnlyPlayer(true);
}
}
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/lv-LV.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7e04f59

Please sign in to comment.