Skip to content

Commit

Permalink
Add check on permission.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Jan 24, 2019
1 parent 0943a48 commit e0f3820
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/java/world/bentobox/challenges/panel/TryToComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,12 @@ else if (this.manager.isChallengeComplete(this.user, this.challenge)
else if (!this.challenge.getEnvironment().isEmpty() &&
!this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment()))
{
this.user.sendMessage("general.errors.wrong-environment");
this.user.sendMessage("challenges.errors.wrong-environment");
}
// Check permission
else if (!this.checkPermissions())
{
this.user.sendMessage("general.errors.no-permission");
}
else if (type.equals(ChallengeType.INVENTORY))
{
Expand All @@ -298,6 +303,16 @@ else if (type.equals(ChallengeType.OTHER))
}


/**
* This method checks if user has all required permissions.
* @return true if user has all required permissions, otherwise false.
*/
private boolean checkPermissions()
{
return this.challenge.getRequiredPermissions().isEmpty() ||
this.challenge.getRequiredPermissions().stream().allMatch(s -> this.user.hasPermission(s));
}

/**
* This method runs all commands from command list.
* @param commands List of commands that must be performed.
Expand Down

0 comments on commit e0f3820

Please sign in to comment.