Require plan.command permission to execute /plan or /planproxy commands

Affects issues:
- Fixed #3526
This commit is contained in:
Aurora Lahtela 2024-06-16 10:08:36 +03:00
parent ac3bffb484
commit ac74d3cd4e
6 changed files with 19 additions and 1 deletions

View File

@ -55,6 +55,9 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (command.getRequiredPermissions().stream().anyMatch(permission -> !sender.hasPermission(permission))) {
return true;
}
runnableFactory.create(() -> {
try {
command.getExecutor().accept(getSender(sender), new Arguments(args));
@ -70,6 +73,9 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
if (command.getRequiredPermissions().stream().anyMatch(permission -> !sender.hasPermission(permission))) {
return Collections.emptyList();
}
try {
return command.getArgumentResolver().apply(getSender(sender), new Arguments(args));
} catch (Exception e) {

View File

@ -19,6 +19,7 @@ package com.djrapitops.plan.command.use;
import com.djrapitops.plan.commands.use.Arguments;
import com.djrapitops.plan.commands.use.CMDSender;
import com.djrapitops.plan.commands.use.Subcommand;
import com.djrapitops.plan.settings.Permissions;
import com.djrapitops.plan.utilities.logging.ErrorContext;
import com.djrapitops.plan.utilities.logging.ErrorLogger;
import net.md_5.bungee.api.CommandSender;
@ -42,7 +43,7 @@ public class BungeeCommand extends Command implements TabExecutor {
ErrorLogger errorLogger,
Subcommand command, String name
) {
super(name);
super(name, Permissions.USE_COMMAND.getPermission());
this.runnableFactory = runnableFactory;
this.errorLogger = errorLogger;

View File

@ -102,6 +102,7 @@ public class PlanCommand {
CommandWithSubcommands command = CommandWithSubcommands.builder(locale)
.alias(commandName)
.colorScheme(colors)
.requirePermission(Permissions.USE_COMMAND.getPermission())
.subcommand(serverCommand())
.subcommand(serversCommand())
.subcommand(networkCommand())

View File

@ -22,6 +22,7 @@ package com.djrapitops.plan.settings;
* @author AuroraLS3
*/
public enum Permissions {
USE_COMMAND("plan.command"),
SERVER("plan.server"),
SERVERS("plan.servers"),
NETWORK("plan.network"),

View File

@ -158,6 +158,9 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
sender = new NukkitCMDSender(actualSender);
}
if (command.getRequiredPermissions().stream().anyMatch(permission -> !sender.hasPermission(permission))) {
return true;
}
runnableFactory.create(() -> {
try {
command.getExecutor().accept(sender, new Arguments(args));

View File

@ -43,6 +43,9 @@ public class VelocityCommand implements SimpleCommand {
public void execute(final Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if (command.getRequiredPermissions().stream().anyMatch(permission -> !source.hasPermission(permission))) {
return;
}
runnableFactory.create(() -> {
try {
command.getExecutor().accept(getSender(source), new Arguments(args));
@ -67,6 +70,9 @@ public class VelocityCommand implements SimpleCommand {
public List<String> suggest(final Invocation invocation) {
CommandSource source = invocation.source();
String[] currentArgs = invocation.arguments();
if (command.getRequiredPermissions().stream().anyMatch(permission -> !source.hasPermission(permission))) {
return Collections.emptyList();
}
try {
return command.getArgumentResolver().apply(getSender(source), new Arguments(currentArgs));
} catch (Exception e) {