Skip to content

Commit

Permalink
Fixes #264
Browse files Browse the repository at this point in the history
Challenges Menu will be opened only if player is in correct world.
  • Loading branch information
BONNe committed Sep 19, 2021
1 parent 220cc20 commit 99c920f
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.ChallengesPanel;
import world.bentobox.challenges.utils.Utils;


public class ChallengesPlayerCommand extends CompositeCommand
Expand All @@ -26,9 +28,10 @@ public ChallengesPlayerCommand(ChallengesAddon addon, CompositeCommand cmd)
@Override
public boolean canExecute(User user, String label, List<String> args)
{
if (!getIWM().inWorld(getWorld())) {
if (!this.getIWM().inWorld(user.getWorld()) ||
Util.getWorld(this.getWorld()) != Util.getWorld(user.getWorld())) {
// Not a GameMode world.
user.sendMessage("general.errors.wrong-world");
Utils.sendMessage(user, user.getTranslation("general.errors.wrong-world"));
return false;
}

Expand Down Expand Up @@ -57,7 +60,14 @@ public boolean canExecute(User user, String label, List<String> args)
if (this.getIslands().getIsland(this.getWorld(), user) == null)
{
// Do not open gui if there is no island for this player.
user.sendMessage("general.errors.no-island");
Utils.sendMessage(user, user.getTranslation("general.errors.no-island"));
return false;
} else if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.getWorld()) &&
!this.getIslands().locationIsOnIsland(user.getPlayer(), user.getLocation()))
{
// Do not open gui if player is not on the island, but challenges requires island for
// completion.
Utils.sendMessage(user, user.getTranslation("challenges.errors.not-on-island"));
return false;
}

Expand Down

0 comments on commit 99c920f

Please sign in to comment.