mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-02 22:47:37 +01: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
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (command.getRequiredPermissions().stream().anyMatch(permission -> !sender.hasPermission(permission))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
runnableFactory.create(() -> {
|
runnableFactory.create(() -> {
|
||||||
try {
|
try {
|
||||||
command.getExecutor().accept(getSender(sender), new Arguments(args));
|
command.getExecutor().accept(getSender(sender), new Arguments(args));
|
||||||
@ -70,6 +73,9 @@ public class BukkitCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
|
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 {
|
try {
|
||||||
return command.getArgumentResolver().apply(getSender(sender), new Arguments(args));
|
return command.getArgumentResolver().apply(getSender(sender), new Arguments(args));
|
||||||
} catch (Exception e) {
|
} 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.Arguments;
|
||||||
import com.djrapitops.plan.commands.use.CMDSender;
|
import com.djrapitops.plan.commands.use.CMDSender;
|
||||||
import com.djrapitops.plan.commands.use.Subcommand;
|
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.ErrorContext;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
import net.md_5.bungee.api.CommandSender;
|
import net.md_5.bungee.api.CommandSender;
|
||||||
@ -42,7 +43,7 @@ public class BungeeCommand extends Command implements TabExecutor {
|
|||||||
ErrorLogger errorLogger,
|
ErrorLogger errorLogger,
|
||||||
Subcommand command, String name
|
Subcommand command, String name
|
||||||
) {
|
) {
|
||||||
super(name);
|
super(name, Permissions.USE_COMMAND.getPermission());
|
||||||
this.runnableFactory = runnableFactory;
|
this.runnableFactory = runnableFactory;
|
||||||
this.errorLogger = errorLogger;
|
this.errorLogger = errorLogger;
|
||||||
|
|
||||||
|
@ -102,6 +102,7 @@ public class PlanCommand {
|
|||||||
CommandWithSubcommands command = CommandWithSubcommands.builder(locale)
|
CommandWithSubcommands command = CommandWithSubcommands.builder(locale)
|
||||||
.alias(commandName)
|
.alias(commandName)
|
||||||
.colorScheme(colors)
|
.colorScheme(colors)
|
||||||
|
.requirePermission(Permissions.USE_COMMAND.getPermission())
|
||||||
.subcommand(serverCommand())
|
.subcommand(serverCommand())
|
||||||
.subcommand(serversCommand())
|
.subcommand(serversCommand())
|
||||||
.subcommand(networkCommand())
|
.subcommand(networkCommand())
|
||||||
|
@ -22,6 +22,7 @@ package com.djrapitops.plan.settings;
|
|||||||
* @author AuroraLS3
|
* @author AuroraLS3
|
||||||
*/
|
*/
|
||||||
public enum Permissions {
|
public enum Permissions {
|
||||||
|
USE_COMMAND("plan.command"),
|
||||||
SERVER("plan.server"),
|
SERVER("plan.server"),
|
||||||
SERVERS("plan.servers"),
|
SERVERS("plan.servers"),
|
||||||
NETWORK("plan.network"),
|
NETWORK("plan.network"),
|
||||||
|
@ -158,6 +158,9 @@ public class PlanNukkit extends PluginBase implements PlanPlugin {
|
|||||||
sender = new NukkitCMDSender(actualSender);
|
sender = new NukkitCMDSender(actualSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command.getRequiredPermissions().stream().anyMatch(permission -> !sender.hasPermission(permission))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
runnableFactory.create(() -> {
|
runnableFactory.create(() -> {
|
||||||
try {
|
try {
|
||||||
command.getExecutor().accept(sender, new Arguments(args));
|
command.getExecutor().accept(sender, new Arguments(args));
|
||||||
|
@ -43,6 +43,9 @@ public class VelocityCommand implements SimpleCommand {
|
|||||||
public void execute(final Invocation invocation) {
|
public void execute(final Invocation invocation) {
|
||||||
CommandSource source = invocation.source();
|
CommandSource source = invocation.source();
|
||||||
String[] args = invocation.arguments();
|
String[] args = invocation.arguments();
|
||||||
|
if (command.getRequiredPermissions().stream().anyMatch(permission -> !source.hasPermission(permission))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
runnableFactory.create(() -> {
|
runnableFactory.create(() -> {
|
||||||
try {
|
try {
|
||||||
command.getExecutor().accept(getSender(source), new Arguments(args));
|
command.getExecutor().accept(getSender(source), new Arguments(args));
|
||||||
@ -67,6 +70,9 @@ public class VelocityCommand implements SimpleCommand {
|
|||||||
public List<String> suggest(final Invocation invocation) {
|
public List<String> suggest(final Invocation invocation) {
|
||||||
CommandSource source = invocation.source();
|
CommandSource source = invocation.source();
|
||||||
String[] currentArgs = invocation.arguments();
|
String[] currentArgs = invocation.arguments();
|
||||||
|
if (command.getRequiredPermissions().stream().anyMatch(permission -> !source.hasPermission(permission))) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return command.getArgumentResolver().apply(getSender(source), new Arguments(currentArgs));
|
return command.getArgumentResolver().apply(getSender(source), new Arguments(currentArgs));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user