three things:
- logger is carpet, fixes #522 - fixed fancy commands to functions - so could be used later with lambdas and functions that use different argument names - moved a few builtin apps to commands via /carpet
This commit is contained in:
1 parent
68cd896376
commit
741edf1465
7 files changed
+67
-30
No files matched your search
@@ -37,7 +37,7 @@ import static carpet.settings.RuleCategory.CLIENT;
|
|||||||
public class CarpetSettings
|
public class CarpetSettings
|
||||||
{
|
{
|
||||||
public static final String carpetVersion = "1.4.15+v201102";
|
public static final String carpetVersion = "1.4.15+v201102";
|
||||||
public static final Logger LOG = LogManager.getLogger();
|
public static final Logger LOG = LogManager.getLogger("carpet");
|
||||||
public static boolean skipGenerationChecks = false;
|
public static boolean skipGenerationChecks = false;
|
||||||
public static boolean impendingFillSkipUpdates = false;
|
public static boolean impendingFillSkipUpdates = false;
|
||||||
public static Box currentTelepotingEntityBox = null;
|
public static Box currentTelepotingEntityBox = null;
|
||||||
@@ -71,6 +71,32 @@ public class CarpetSettings
|
|||||||
)
|
)
|
||||||
public static String language = "none";
|
public static String language = "none";
|
||||||
|
|
||||||
|
@Rule(
|
||||||
|
desc = "Turns on internal camera path tracing app",
|
||||||
|
extra = "Controlled via 'camera' command",
|
||||||
|
category = {COMMAND, SCARPET},
|
||||||
|
appSource = "camera"
|
||||||
|
)
|
||||||
|
public static boolean commandCamera = true;
|
||||||
|
|
||||||
|
@Rule(
|
||||||
|
desc = "Allows to add extra graphical debug information",
|
||||||
|
extra = "Controlled via 'overlay' command",
|
||||||
|
category = {COMMAND, SCARPET},
|
||||||
|
appSource = "overlay"
|
||||||
|
)
|
||||||
|
public static boolean commandOverlay = true;
|
||||||
|
|
||||||
|
@Rule(
|
||||||
|
desc = "Turns on extra information about mobs above and around them",
|
||||||
|
extra = "Controlled via 'ai_tracker' command",
|
||||||
|
category = {COMMAND, SCARPET},
|
||||||
|
appSource = "ai_tracker"
|
||||||
|
)
|
||||||
|
public static boolean commandAITracker = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Rule(desc = "Gbhs sgnf sadsgras fhskdpri!", category = EXPERIMENTAL)
|
@Rule(desc = "Gbhs sgnf sadsgras fhskdpri!", category = EXPERIMENTAL)
|
||||||
public static boolean superSecretSetting = false;
|
public static boolean superSecretSetting = false;
|
||||||
|
|
||||||
|
|||||||
@@ -210,11 +210,11 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value handleCommand(ServerCommandSource source, String call, List<Value> args)
|
public Value handleCommand(ServerCommandSource source, FunctionValue function, List<Value> args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return call(source, call, args);
|
return call(source, function, args);
|
||||||
}
|
}
|
||||||
catch (CarpetExpressionException exc)
|
catch (CarpetExpressionException exc)
|
||||||
{
|
{
|
||||||
@@ -330,20 +330,17 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value call(ServerCommandSource source, String call, List<Value> suppliedArgs)
|
public Value call(ServerCommandSource source, FunctionValue function, List<Value> suppliedArgs)
|
||||||
{
|
{
|
||||||
if (CarpetServer.scriptServer.stopAll)
|
if (CarpetServer.scriptServer.stopAll)
|
||||||
throw new CarpetExpressionException("SCARPET PAUSED", null);
|
throw new CarpetExpressionException("SCARPET PAUSED", null);
|
||||||
FunctionValue function = getFunction(call);
|
|
||||||
if (function == null)
|
|
||||||
throw new CarpetExpressionException("UNDEFINED", null);
|
|
||||||
|
|
||||||
List<LazyValue> argv = FunctionValue.lazify(suppliedArgs);
|
List<LazyValue> argv = FunctionValue.lazify(suppliedArgs);
|
||||||
|
|
||||||
List<String> args = function.getArguments();
|
List<String> args = function.getArguments();
|
||||||
if (argv.size() != args.size())
|
if (argv.size() != args.size())
|
||||||
{
|
{
|
||||||
String error = "Fail: stored function "+call+" takes "+args.size()+" arguments, not "+argv.size()+ ":\n";
|
String error = "Fail: stored function "+function.getPrettyString()+" takes "+args.size()+" arguments, not "+argv.size()+ ":\n";
|
||||||
for (int i = 0; i < max(argv.size(), args.size()); i++)
|
for (int i = 0; i < max(argv.size(), args.size()); i++)
|
||||||
{
|
{
|
||||||
error += (i<args.size()?args.get(i):"??")+" => "+(i<argv.size()?argv.get(i).evalValue(null).getString():"??")+"\n";
|
error += (i<args.size()?args.get(i):"??")+" => "+(i<argv.size()?argv.get(i).evalValue(null).getString():"??")+"\n";
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
|||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
|
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.util.WorldSavePath;
|
import net.minecraft.util.WorldSavePath;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
|
||||||
@@ -63,19 +65,19 @@ public class CarpetScriptServer
|
|||||||
* @param app is the BundledModule of an app. Libraries
|
* @param app is the BundledModule of an app. Libraries
|
||||||
* should be registered as builtInScripts instead
|
* should be registered as builtInScripts instead
|
||||||
*/
|
*/
|
||||||
public static void registerRuleScript(BundledModule app) {
|
public static void registerSettingsApp(BundledModule app) {
|
||||||
ruleModuleData.add(app);
|
ruleModuleData.add(app);
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
registerBuiltInScript(BundledModule.carpetNative("camera", false));
|
registerSettingsApp (BundledModule.carpetNative("camera", false));
|
||||||
registerBuiltInScript(BundledModule.carpetNative("overlay", false));
|
registerSettingsApp (BundledModule.carpetNative("overlay", false));
|
||||||
registerBuiltInScript(BundledModule.carpetNative("event_test", false));
|
registerBuiltInScript(BundledModule.carpetNative("event_test", false));
|
||||||
registerBuiltInScript(BundledModule.carpetNative("stats_test", false));
|
registerBuiltInScript(BundledModule.carpetNative("stats_test", false));
|
||||||
registerBuiltInScript(BundledModule.carpetNative("math", true));
|
registerBuiltInScript(BundledModule.carpetNative("math", true));
|
||||||
registerBuiltInScript(BundledModule.carpetNative("chunk_display", false));
|
registerBuiltInScript(BundledModule.carpetNative("chunk_display", false));
|
||||||
registerBuiltInScript(BundledModule.carpetNative("ai_tracker", false));
|
registerSettingsApp (BundledModule.carpetNative("ai_tracker", false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CarpetScriptServer(MinecraftServer server)
|
public CarpetScriptServer(MinecraftServer server)
|
||||||
@@ -188,6 +190,7 @@ public class CarpetScriptServer
|
|||||||
public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer, boolean autoload, boolean isRuleApp)
|
public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer, boolean autoload, boolean isRuleApp)
|
||||||
{
|
{
|
||||||
//TODO add per player modules to support player actions better on a server
|
//TODO add per player modules to support player actions better on a server
|
||||||
|
long start = System.nanoTime();
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
name = name.toLowerCase(Locale.ROOT);
|
||||||
boolean reload = false;
|
boolean reload = false;
|
||||||
if (modules.containsKey(name))
|
if (modules.containsKey(name))
|
||||||
@@ -237,6 +240,8 @@ public class CarpetScriptServer
|
|||||||
}
|
}
|
||||||
//addEvents(source, name);
|
//addEvents(source, name);
|
||||||
addLegacyCommand(source, name, reload, !isRuleApp); // this needs to be moved to config reader, only supporting legacy command here
|
addLegacyCommand(source, name, reload, !isRuleApp); // this needs to be moved to config reader, only supporting legacy command here
|
||||||
|
long end = System.nanoTime();
|
||||||
|
CarpetSettings.LOG.info("App "+name+" loaded in "+(end-start)/1000000+" ms");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,7 +279,7 @@ public class CarpetScriptServer
|
|||||||
{
|
{
|
||||||
if (host.appConfig.containsKey(StringValue.of("legacy_command_type_support"))) // temporary stuff for testing
|
if (host.appConfig.containsKey(StringValue.of("legacy_command_type_support"))) // temporary stuff for testing
|
||||||
{
|
{
|
||||||
command = getFancyCommand(command, host, function);
|
command = getFancyCommand(command, host, host.getFunction(function));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -301,41 +306,43 @@ public class CarpetScriptServer
|
|||||||
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
|
CarpetServer.settingsManager.notifyPlayersCommandsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int execute(CommandContext<ServerCommandSource> ctx, String hostName, String funName) throws CommandSyntaxException
|
private int execute(CommandContext<ServerCommandSource> ctx, String hostName, FunctionValue function, List<String> paramNames) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
CarpetScriptHost cHost = modules.get(hostName).retrieveForExecution(ctx.getSource());
|
CarpetScriptHost cHost = modules.get(hostName).retrieveForExecution(ctx.getSource());
|
||||||
List<String> argNames = cHost.getFunction(funName).getArguments();
|
List<String> argNames = function.getArguments();
|
||||||
|
if (argNames.size() != paramNames.size())
|
||||||
|
throw new SimpleCommandExceptionType(new LiteralText("Target function "+function.getPrettyString()+" as wrong number of arguments, required "+paramNames.size()+", found "+argNames.size())).create();
|
||||||
List<Value> args = new ArrayList<>(argNames.size());
|
List<Value> args = new ArrayList<>(argNames.size());
|
||||||
for (String s : argNames)
|
for (String s : paramNames)
|
||||||
{
|
{
|
||||||
args.add(CommandArgument.getValue(ctx, s));
|
args.add(CommandArgument.getValue(ctx, s));
|
||||||
}
|
}
|
||||||
Value response = cHost.handleCommand(ctx.getSource(), funName, args);
|
Value response = cHost.handleCommand(ctx.getSource(), function, args);
|
||||||
if (!response.isNull()) Messenger.m(ctx.getSource(), "gi " + response.getString());
|
if (!response.isNull()) Messenger.m(ctx.getSource(), "gi " + response.getString());
|
||||||
return (int) response.readInteger();
|
return (int) response.readInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
private LiteralArgumentBuilder<ServerCommandSource> getFancyCommand(LiteralArgumentBuilder<ServerCommandSource> command, ScriptHost host, String funName )
|
private LiteralArgumentBuilder<ServerCommandSource> getFancyCommand(LiteralArgumentBuilder<ServerCommandSource> command, ScriptHost host, FunctionValue function )
|
||||||
{
|
{
|
||||||
List<String> argNames = host.getFunction(funName).getArguments();
|
List<String> argNames = function.getArguments();
|
||||||
String hostName = host.getName();
|
String hostName = host.getName();
|
||||||
if (argNames.size() == 0)
|
if (argNames.size() == 0)
|
||||||
{
|
{
|
||||||
return command.then(literal(funName).
|
return command.then(literal(function.getString()).
|
||||||
requires((player) -> modules.containsKey(hostName) && modules.get(hostName).getFunction(funName) != null).
|
requires((player) -> modules.containsKey(hostName)).
|
||||||
executes((c) -> execute(c, hostName, funName)));
|
executes((c) -> execute(c, hostName, function, Collections.emptyList())));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<String> reversedArgs = new ArrayList<>(argNames);
|
List<String> reversedArgs = new ArrayList<>(argNames);
|
||||||
Collections.reverse(reversedArgs);
|
Collections.reverse(reversedArgs);
|
||||||
RequiredArgumentBuilder<ServerCommandSource, ?> argChain = CommandArgument.argumentNode(reversedArgs.get(0)).executes(c -> execute(c, hostName, funName));
|
RequiredArgumentBuilder<ServerCommandSource, ?> argChain = CommandArgument.argumentNode(reversedArgs.get(0)).executes(c -> execute(c, hostName, function, argNames));
|
||||||
for (int i = 1; i < reversedArgs.size(); i++)
|
for (int i = 1; i < reversedArgs.size(); i++)
|
||||||
{
|
{
|
||||||
argChain = CommandArgument.argumentNode(reversedArgs.get(i)).then(argChain);
|
argChain = CommandArgument.argumentNode(reversedArgs.get(i)).then(argChain);
|
||||||
}
|
}
|
||||||
return command.then(literal(funName).
|
return command.then(literal(function.getString()).
|
||||||
requires((player) -> modules.containsKey(hostName) && modules.get(hostName).getFunction(funName) != null).
|
requires((player) -> modules.containsKey(hostName)).
|
||||||
then(argChain)
|
then(argChain)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ public abstract class CommandArgument
|
|||||||
if (!caseSensitive) choseValue = choseValue.toLowerCase(Locale.ROOT);
|
if (!caseSensitive) choseValue = choseValue.toLowerCase(Locale.ROOT);
|
||||||
if (!validOptions.isEmpty() && !validOptions.contains(choseValue))
|
if (!validOptions.isEmpty() && !validOptions.contains(choseValue))
|
||||||
{
|
{
|
||||||
throw new SimpleCommandExceptionType(new LiteralText("")).create();
|
throw new SimpleCommandExceptionType(new LiteralText("Incorrect value for "+param+": "+choseValue)).create();
|
||||||
}
|
}
|
||||||
return StringValue.of(choseValue);
|
return StringValue.of(choseValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package carpet.settings;
|
package carpet.settings;
|
||||||
|
|
||||||
import carpet.CarpetServer;
|
|
||||||
import carpet.utils.Translations;
|
import carpet.utils.Translations;
|
||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
@@ -43,7 +42,7 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
|||||||
this.isStrict = rule.strict();
|
this.isStrict = rule.strict();
|
||||||
this.extraInfo = ImmutableList.copyOf(rule.extra());
|
this.extraInfo = ImmutableList.copyOf(rule.extra());
|
||||||
this.categories = ImmutableList.copyOf(rule.category());
|
this.categories = ImmutableList.copyOf(rule.category());
|
||||||
this.scarpetApp = rule.scarpetApp();
|
this.scarpetApp = rule.appSource();
|
||||||
this.settingsManager = settingsManager;
|
this.settingsManager = settingsManager;
|
||||||
this.validators = new ArrayList<>();
|
this.validators = new ArrayList<>();
|
||||||
for (Class v : rule.validate())
|
for (Class v : rule.validate())
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public @interface Rule
|
|||||||
* Consider telling the rule name so users can edit globals
|
* Consider telling the rule name so users can edit globals
|
||||||
* (in case there are relevant globals to edit ofc)
|
* (in case there are relevant globals to edit ofc)
|
||||||
*/
|
*/
|
||||||
String scarpetApp() default "";
|
String appSource() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class of the validator checked when the rule is changed.
|
* The class of the validator checked when the rule is changed.
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ public class SettingsManager
|
|||||||
private final String fancyName;
|
private final String fancyName;
|
||||||
private MinecraftServer server;
|
private MinecraftServer server;
|
||||||
private List<TriConsumer<ServerCommandSource, ParsedRule<?>, String>> observers = new ArrayList<>();
|
private List<TriConsumer<ServerCommandSource, ParsedRule<?>, String>> observers = new ArrayList<>();
|
||||||
|
private static List<TriConsumer<ServerCommandSource, ParsedRule<?>, String>> staticObservers = new ArrayList<>();
|
||||||
|
|
||||||
|
|
||||||
public SettingsManager(String version, String identifier)
|
public SettingsManager(String version, String identifier)
|
||||||
{
|
{
|
||||||
@@ -103,13 +105,19 @@ public class SettingsManager
|
|||||||
{
|
{
|
||||||
observers.add(observer);
|
observers.add(observer);
|
||||||
}
|
}
|
||||||
|
public static void addGlobalRuleObserver(TriConsumer<ServerCommandSource, ParsedRule<?>, String> observer)
|
||||||
|
{
|
||||||
|
staticObservers.add(observer);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void notifyRuleChanged(ServerCommandSource source, ParsedRule<?> rule, String userTypedValue)
|
void notifyRuleChanged(ServerCommandSource source, ParsedRule<?> rule, String userTypedValue)
|
||||||
{
|
{
|
||||||
observers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
observers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
||||||
|
staticObservers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
||||||
ServerNetworkHandler.updateRuleWithConnectedClients(rule);
|
ServerNetworkHandler.updateRuleWithConnectedClients(rule);
|
||||||
switchScarpetRule(source, rule);
|
switchScarpetRule(source, rule);
|
||||||
CARPET_RULE_CHANGES.onCarpetRuleChanges(rule, source);
|
if (CARPET_RULE_CHANGES.isNeeded()) CARPET_RULE_CHANGES.onCarpetRuleChanges(rule, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchScarpetRule(ServerCommandSource source, ParsedRule<?> rule)
|
void switchScarpetRule(ServerCommandSource source, ParsedRule<?> rule)
|
||||||
|
|||||||
Reference in new issue
Block a user