From 9927cde616833675885ea5da5d9bf63bac109ef8 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 22 Aug 2018 17:12:41 +1000 Subject: [PATCH] JS command perms --- .../sk89q/minecraft/util/commands/CommandLocals.java | 4 ++++ .../com/sk89q/worldedit/command/BrushProcessor.java | 11 ++++++++++- .../parametric/FunctionParametricCallable.java | 1 + .../util/command/parametric/ParametricCallable.java | 1 + worldedit-core/src/main/resources/cs_adv.js | 3 ++- 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java index 0bc2992a5..40441aa09 100644 --- a/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java +++ b/worldedit-core/src/main/java/com/sk89q/minecraft/util/commands/CommandLocals.java @@ -47,4 +47,8 @@ public class CommandLocals { return locals.put(key, value); } + public Object putIfAbsent(Object key, Object value) { + return locals.putIfAbsent(key, value); + } + } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushProcessor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushProcessor.java index 06fa14594..3504bc352 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushProcessor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushProcessor.java @@ -13,6 +13,8 @@ import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.util.command.CallableProcessor; +import com.sk89q.worldedit.util.command.CommandCallable; +import com.sk89q.worldedit.util.command.parametric.AParametricCallable; public class BrushProcessor extends MethodCommands implements CallableProcessor { private final WorldEdit worldEdit; @@ -55,7 +57,14 @@ public class BrushProcessor extends MethodCommands implements CallableProcessor< } } - bs.addPermissions(getPermissions()); + CommandCallable callable = locals.get(CommandCallable.class); + String[] perms; + if (callable != null && callable instanceof AParametricCallable) { + perms = ((AParametricCallable) callable).getPermissions(); + } else { + perms = getPermissions(); + } + bs.addPermissions(perms); if (locals != null) { String args = (String) locals.get("arguments"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java index f6489b629..4ab9de23f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/FunctionParametricCallable.java @@ -211,6 +211,7 @@ public class FunctionParametricCallable extends AParametricCallable { if (!testPermission(locals)) { throw new CommandPermissionsException(); } + locals.putIfAbsent(CommandCallable.class, this); String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_"; String[] split = (calledCommand + " " + stringArguments).split(" ", -1); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java index daae175e1..d603d005c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/command/parametric/ParametricCallable.java @@ -197,6 +197,7 @@ public class ParametricCallable extends AParametricCallable { if (!testPermission(locals)) { throw new CommandPermissionsException(); } + locals.putIfAbsent(CommandCallable.class, this); String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_"; String[] split = (calledCommand + " " + stringArguments).split(" ", -1); diff --git a/worldedit-core/src/main/resources/cs_adv.js b/worldedit-core/src/main/resources/cs_adv.js index 1ca0de167..e82583e8d 100644 --- a/worldedit-core/src/main/resources/cs_adv.js +++ b/worldedit-core/src/main/resources/cs_adv.js @@ -29,6 +29,7 @@ var f = functions[i]; if (f.hasOwnProperty('desc')) { + if (!f.hasOwnProperty('permission')) f.permission = "fawe.use"; if (!f.hasOwnProperty('aliases')) f.aliases = [f.name]; var cmd = com.boydti.fawe.config.Commands.fromArgs(f.aliases, f.usage, f.desc, f.min, f.max, f.flags, f.help); var man = com.sk89q.worldedit.extension.platform.CommandManager.getInstance(); @@ -41,7 +42,7 @@ } }); var w2 = new wrap(); - var callable = new com.sk89q.worldedit.util.command.parametric.FunctionParametricCallable(builder, "", cmd, "fawe.use", args, w2); + var callable = new com.sk89q.worldedit.util.command.parametric.FunctionParametricCallable(builder, "", cmd, f.permission, args, w2); commands.add(callable); } }