diff --git a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java index 2fc3a43..2c09577 100644 --- a/src/main/java/world/bentobox/challenges/panel/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/panel/TryToComplete.java @@ -278,7 +278,12 @@ public class TryToComplete 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)) { @@ -298,6 +303,16 @@ public class TryToComplete } + /** + * 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.