JS command perms

This commit is contained in:
Jesse Boyd 2018-08-22 17:12:41 +10:00
parent 4651d5e36b
commit 9927cde616
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 18 additions and 2 deletions

View File

@ -47,4 +47,8 @@ public class CommandLocals {
return locals.put(key, value); return locals.put(key, value);
} }
public Object putIfAbsent(Object key, Object value) {
return locals.putIfAbsent(key, value);
}
} }

View File

@ -13,6 +13,8 @@ import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.command.CallableProcessor; 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<BrushSettings> { public class BrushProcessor extends MethodCommands implements CallableProcessor<BrushSettings> {
private final WorldEdit worldEdit; 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) { if (locals != null) {
String args = (String) locals.get("arguments"); String args = (String) locals.get("arguments");

View File

@ -211,6 +211,7 @@ public class FunctionParametricCallable extends AParametricCallable {
if (!testPermission(locals)) { if (!testPermission(locals)) {
throw new CommandPermissionsException(); throw new CommandPermissionsException();
} }
locals.putIfAbsent(CommandCallable.class, this);
String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_"; String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_";
String[] split = (calledCommand + " " + stringArguments).split(" ", -1); String[] split = (calledCommand + " " + stringArguments).split(" ", -1);

View File

@ -197,6 +197,7 @@ public class ParametricCallable extends AParametricCallable {
if (!testPermission(locals)) { if (!testPermission(locals)) {
throw new CommandPermissionsException(); throw new CommandPermissionsException();
} }
locals.putIfAbsent(CommandCallable.class, this);
String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_"; String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_";
String[] split = (calledCommand + " " + stringArguments).split(" ", -1); String[] split = (calledCommand + " " + stringArguments).split(" ", -1);

View File

@ -29,6 +29,7 @@
var f = functions[i]; var f = functions[i];
if (f.hasOwnProperty('desc')) if (f.hasOwnProperty('desc'))
{ {
if (!f.hasOwnProperty('permission')) f.permission = "fawe.use";
if (!f.hasOwnProperty('aliases')) f.aliases = [f.name]; 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 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(); var man = com.sk89q.worldedit.extension.platform.CommandManager.getInstance();
@ -41,7 +42,7 @@
} }
}); });
var w2 = new wrap(); 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); commands.add(callable);
} }
} }