added commandScriptACE setting and custom permissions for scarpet.

This commit is contained in:
gnembon committed 2020-03-11 02:39:39 -03:00
1 parent 8f32354606
commit 493cea2c13
4 files changed
+27 -10

No files matched your search

+18 -3
View File
@@ -28,6 +28,7 @@ import static carpet.settings.RuleCategory.OPTIMIZATION;
import static carpet.settings.RuleCategory.SURVIVAL;
import static carpet.settings.RuleCategory.TNT;
import static carpet.settings.RuleCategory.DISPENSER;
import static carpet.settings.RuleCategory.SCARPET;
@SuppressWarnings("CanBeFinal")
public class CarpetSettings
@@ -303,13 +304,27 @@ public class CarpetSettings
@Rule(desc = "Enables /draw commands", extra = "... allows for drawing simple shapes", category = COMMAND)
public static String commandDraw = "true";
@Rule(desc = "Enables /script command", extra = "An in-game scripting API for Scarpet programming language", category = COMMAND)
public static boolean commandScript = true;
@Rule(
desc = "Enables /script command",
extra = "An in-game scripting API for Scarpet programming language",
category = {COMMAND, SCARPET}
)
public static String commandScript = "true";
@Rule(
desc = "Enables restrictions for arbitrary code execution with scarpet",
extra = {
"Users that don't have this permission level",
"won't be able to load apps or /script run"
},
category = {COMMAND, SCARPET}
)
public static String commandScriptACE = "ops";
@Rule(
desc = "Scarpet script from world files will autoload on server/world start ",
extra = "if /script is enabled",
category = CREATIVE
category = SCARPET
)
public static boolean scriptsAutoload = false;
@@ -11,6 +11,7 @@ import carpet.script.LazyValue;
import carpet.script.Tokenizer;
import carpet.script.exception.CarpetExpressionException;
import carpet.script.value.FunctionValue;
import carpet.settings.SettingsManager;
import carpet.utils.Messenger;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
@@ -79,7 +80,7 @@ public class ScriptCommand
LiteralArgumentBuilder<ServerCommandSource> u = literal("resume").
executes( (cc) -> { CarpetServer.scriptServer.stopAll = false; return 1;});
LiteralArgumentBuilder<ServerCommandSource> l = literal("run").
requires((player) -> player.hasPermissionLevel(2)).
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE)).
then(argument("expr", StringArgumentType.greedyString()).suggests(ScriptCommand::suggestCode).
executes((cc) -> compute(
cc,
@@ -205,7 +206,7 @@ public class ScriptCommand
BlockPredicateArgumentType.getBlockPredicate(cc, "filter"),
"outline"
)))))))));
LiteralArgumentBuilder<ServerCommandSource> a = literal("load").requires( (player) -> player.hasPermissionLevel(2) ).
LiteralArgumentBuilder<ServerCommandSource> a = literal("load").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(true),bb)).
executes((cc) ->
@@ -222,7 +223,7 @@ public class ScriptCommand
)
)
);
LiteralArgumentBuilder<ServerCommandSource> f = literal("unload").requires( (player) -> player.hasPermissionLevel(2) ).
LiteralArgumentBuilder<ServerCommandSource> f = literal("unload").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.modules.keySet(),bb)).
executes((cc) ->
@@ -231,7 +232,7 @@ public class ScriptCommand
return success?1:0;
}));
LiteralArgumentBuilder<ServerCommandSource> q = literal("event").requires( (player) -> player.hasPermissionLevel(2) ).
LiteralArgumentBuilder<ServerCommandSource> q = literal("event").requires( (player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScriptACE) ).
executes( (cc) -> listEvents(cc.getSource())).
then(literal("add_to").
then(argument("event", StringArgumentType.word()).
@@ -268,10 +269,10 @@ public class ScriptCommand
dispatcher.register(literal("script").
requires((player) -> CarpetSettings.commandScript).
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
then(b).then(u).then(o).then(l).then(s).then(c).then(h).then(i).then(e).then(t).then(a).then(f).then(q));
dispatcher.register(literal("script").
requires((player) -> CarpetSettings.commandScript).
requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandScript)).
then(literal("in").
then(argument("app", StringArgumentType.word()).
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.modules.keySet(), bb)).
@@ -30,7 +30,7 @@ public abstract class ArmorStandEntity_scarpetMarkerMixin extends LivingEntity
@Inject(method = "readCustomDataFromTag", at = @At("HEAD"))
private void checkScarpetMarkerUnloaded(CallbackInfo ci)
{
if ((CarpetSettings.scriptsAutoload || CarpetSettings.commandScript) && !world.isClient)
if ((CarpetSettings.scriptsAutoload || !CarpetSettings.commandScript.equals("false")) && !world.isClient)
{
if (getScoreboardTags().contains(ExpressionInspector.MARKER_STRING))
{
@@ -11,5 +11,6 @@ public class RuleCategory
public static final String COMMAND = "command";
public static final String TNT = "tnt";
public static final String DISPENSER = "dispenser";
public static final String SCARPET = "scarpet";
}