mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-27 05:01:43 +08:00
Require plan.command permission to execute /plan or /planproxy commands
Affects issues: - Fixed #3526
This commit is contained in:
parent
ac3bffb484
commit
ac74d3cd4e
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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"),
|
||||
|
@ -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));
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user