23w44a and some cleanups

This commit is contained in:
gnembon committed 2023-11-01 22:13:35 +01:00
1 parent 5b8e61c1bd
commit 7392f16785
7 files changed
+42 -32

No files matched your search

@@ -40,6 +40,7 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import org.apache.commons.lang3.tuple.Pair;
import javax.annotation.Nullable;
import java.math.BigInteger;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -77,7 +78,7 @@ public class CarpetScriptHost extends ScriptHost
public AppStoreManager.StoreNode storeSource;
boolean hasCommand;
private CarpetScriptHost(CarpetScriptServer server, Module code, boolean perUser, ScriptHost parent, Map<Value, Value> config, Map<String, CommandArgument> argTypes, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp)
private CarpetScriptHost(CarpetScriptServer server, @Nullable Module code, boolean perUser, ScriptHost parent, Map<Value, Value> config, Map<String, CommandArgument> argTypes, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp)
{
super(code, server, perUser, parent);
this.saveTimeout = 0;
@@ -98,7 +99,7 @@ public class CarpetScriptHost extends ScriptHost
storeSource = null;
}
public static CarpetScriptHost create(CarpetScriptServer scriptServer, Module module, boolean perPlayer, CommandSourceStack source, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp, AppStoreManager.StoreNode storeSource)
public static CarpetScriptHost create(CarpetScriptServer scriptServer, @Nullable Module module, boolean perPlayer, CommandSourceStack source, Predicate<CommandSourceStack> commandValidator, boolean isRuleApp, AppStoreManager.StoreNode storeSource)
{
CarpetScriptHost host = new CarpetScriptHost(scriptServer, module, perPlayer, null, Collections.emptyMap(), new HashMap<>(), commandValidator, isRuleApp);
// parse code and convert to expression
@@ -742,7 +743,7 @@ public class CarpetScriptHost extends ScriptHost
FunctionValue function = getFunction(call);
if (function == null)
{
throw new CarpetExpressionException("Couldn't find function '" + call + "' in app '" + this.getName() + "'", null);
throw new CarpetExpressionException("Couldn't find function '" + call + "' in app '" + this.getVisualName() + "'", null);
}
List<LazyValue> argv = new ArrayList<>();
if (coords != null)
@@ -968,7 +969,7 @@ public class CarpetScriptHost extends ScriptHost
public Tag readFileTag(FileArgument fdesc)
{
if (getName() == null && !fdesc.isShared)
if (isDefaultApp() && !fdesc.isShared)
{
return null;
}
@@ -985,7 +986,7 @@ public class CarpetScriptHost extends ScriptHost
public boolean writeTagFile(Tag tag, FileArgument fdesc)
{
if (getName() == null && !fdesc.isShared)
if (isDefaultApp() && !fdesc.isShared)
{
return false; // if belongs to an app, cannot be default host.
}
@@ -1007,27 +1008,27 @@ public class CarpetScriptHost extends ScriptHost
public boolean removeResourceFile(FileArgument fdesc)
{
return (getName() != null || fdesc.isShared) && fdesc.dropExistingFile(main); //
return (!isDefaultApp() || fdesc.isShared) && fdesc.dropExistingFile(main); //
}
public boolean appendLogFile(FileArgument fdesc, List<String> data)
{
return (getName() != null || fdesc.isShared) && fdesc.appendToTextFile(main, data); // if belongs to an app, cannot be default host.
return (!isDefaultApp() || fdesc.isShared) && fdesc.appendToTextFile(main, data); // if belongs to an app, cannot be default host.
}
public List<String> readTextResource(FileArgument fdesc)
{
return getName() == null && !fdesc.isShared ? null : fdesc.listFile(main);
return isDefaultApp() && !fdesc.isShared ? null : fdesc.listFile(main);
}
public JsonElement readJsonFile(FileArgument fdesc)
{
return getName() == null && !fdesc.isShared ? null : fdesc.readJsonFile(main);
return isDefaultApp() && !fdesc.isShared ? null : fdesc.readJsonFile(main);
}
public Stream<String> listFolder(FileArgument fdesc)
{
return getName() == null && !fdesc.isShared ? null : fdesc.listFolder(main);
return isDefaultApp() && !fdesc.isShared ? null : fdesc.listFolder(main);
}
public boolean applyActionForResource(String path, boolean shared, Consumer<Path> action)
@@ -1202,7 +1203,7 @@ public class CarpetScriptHost extends ScriptHost
{
if (super.issueDeprecation(feature))
{
Carpet.Messenger_message(responsibleSource, "rb App '" +getName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement");
Carpet.Messenger_message(responsibleSource, "rb App '" +getVisualName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement");
return true;
}
return false;
@@ -421,7 +421,7 @@ public class ScriptCommand
CommandSourceStack source = context.getSource();
CarpetScriptServer scriptServer = ss(context);
Carpet.Messenger_message(source, "lb Stored functions" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getName() + ":"));
Carpet.Messenger_message(source, "lb Stored functions" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getVisualName() + ":"));
host.globalFunctionNames(host.main, (str) -> all || !str.startsWith("__")).sorted().forEach((s) -> {
FunctionValue fun = host.getFunction(s);
if (fun == null)
@@ -442,7 +442,7 @@ public class ScriptCommand
});
//Messenger.m(source, "w "+code);
Carpet.Messenger_message(source, "w ");
Carpet.Messenger_message(source, "lb Global variables" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getName() + ":"));
Carpet.Messenger_message(source, "lb Global variables" + ((host == scriptServer.globalHost) ? ":" : " in " + host.getVisualName() + ":"));
host.globalVariableNames(host.main, (s) -> s.startsWith("global_")).sorted().forEach((s) -> {
LazyValue variable = host.getGlobalVariable(s);
if (variable == null)
+14 -2
View File
@@ -10,6 +10,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.HashSet;
@@ -121,6 +122,17 @@ public abstract class ScriptHost
return main == null ? null : main.name();
}
public String getVisualName()
{
return main == null ? "built-in default app" : main.name();
}
public boolean isDefaultApp()
{
return main == null;
}
@Nullable
public final Module main;
@FunctionalInterface
@@ -131,7 +143,7 @@ public abstract class ScriptHost
public ErrorSnooper errorSnooper = null;
protected ScriptHost(Module code, ScriptServer scriptServer, boolean perUser, ScriptHost parent)
protected ScriptHost(@Nullable Module code, ScriptServer scriptServer, boolean perUser, ScriptHost parent)
{
this.parent = parent;
this.main = code;
@@ -551,7 +563,7 @@ public abstract class ScriptHost
return false;
}
deprecations.add(feature);
DEPRECATION_LOG.warn("App '" + getName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement");
DEPRECATION_LOG.warn("App '" + getVisualName() + "' uses '" + feature + "', which is deprecated for removal. Check the docs for a replacement");
return true;
}
+1 -1
View File
@@ -205,7 +205,7 @@ public class Carpet
return;
}
}
throw new LoadException(String.format("%s requires a version of mod '%s' matching '%s', which is missing!", host.getName(), requiredModId, stringPredicate));
throw new LoadException(String.format("%s requires a version of mod '%s' matching '%s', which is missing!", host.getVisualName(), requiredModId, stringPredicate));
}
// to be ran once during CarpetEventServer.Event static init
@@ -1,7 +1,7 @@
package carpet.script.utils;
import carpet.script.external.Vanilla;
import net.minecraft.commands.CommandResultConsumer;
import net.minecraft.commands.CommandResultCallback;
import net.minecraft.commands.CommandSigningContext;
import net.minecraft.commands.CommandSource;
import net.minecraft.commands.CommandSourceStack;
@@ -33,7 +33,7 @@ public class SnoopyCommandSource extends CommandSourceStack
private final MinecraftServer server;
// skipping silent since snooper is never silent
private final Entity entity;
private final CommandResultConsumer<CommandSourceStack> resultConsumer;
private final CommandResultCallback resultConsumer;
private final EntityAnchorArgument.Anchor entityAnchor;
private final Vec2 rotation;
// good stuff
@@ -47,8 +47,7 @@ public class SnoopyCommandSource extends CommandSourceStack
{
super(CommandSource.NULL, original.getPosition(), original.getRotation(), original.getLevel(), Vanilla.MinecraftServer_getRunPermissionLevel(original.getServer()),
original.getTextName(), original.getDisplayName(), original.getServer(), original.getEntity(), false,
(ctx, succ, res) -> {
}, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()), i -> {});
CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(original.getServer()));
this.output = CommandSource.NULL;
this.position = original.getPosition();
this.world = original.getLevel();
@@ -57,8 +56,7 @@ public class SnoopyCommandSource extends CommandSourceStack
this.name = original.getDisplayName();
this.server = original.getServer();
this.entity = original.getEntity();
this.resultConsumer = (ctx, succ, res) -> {
};
this.resultConsumer = CommandResultCallback.EMPTY;
this.entityAnchor = original.getAnchor();
this.rotation = original.getRotation();
this.error = error;
@@ -81,8 +79,7 @@ public class SnoopyCommandSource extends CommandSourceStack
this.name = player.getDisplayName();
this.server = player.level().getServer();
this.entity = player;
this.resultConsumer = (ctx, succ, res) -> {
};
this.resultConsumer = CommandResultCallback.EMPTY;
this.entityAnchor = EntityAnchorArgument.Anchor.FEET;
this.rotation = player.getRotationVector(); // not a client call really
this.error = error;
@@ -91,13 +88,13 @@ public class SnoopyCommandSource extends CommandSourceStack
this.taskChainer = TaskChainer.immediate(player.server);
}
private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultConsumer<CommandSourceStack> consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer,
private SnoopyCommandSource(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String simpleName, Component name, MinecraftServer server, @Nullable Entity entity, CommandResultCallback consumer, EntityAnchorArgument.Anchor entityAnchor, CommandSigningContext context, TaskChainer chainer,
Component[] error, List<Component> chatOutput
)
{
super(output, pos, rot, world, level,
simpleName, name, server, entity, false,
consumer, entityAnchor, context, chainer, i -> {});
consumer, entityAnchor, context, chainer);
this.output = output;
this.position = pos;
this.rotation = rot;
@@ -134,15 +131,15 @@ public class SnoopyCommandSource extends CommandSourceStack
}
@Override
public CommandSourceStack withCallback(CommandResultConsumer<CommandSourceStack> consumer)
public CommandSourceStack withCallback(CommandResultCallback consumer)
{
return new SnoopyCommandSource(output, position, rotation, world, level, simpleName, name, server, entity, consumer, entityAnchor, signingContext, taskChainer, error, chatOutput);
}
@Override
public CommandSourceStack withCallback(CommandResultConsumer<CommandSourceStack> consumer, BinaryOperator<CommandResultConsumer<CommandSourceStack>> binaryOperator)
public CommandSourceStack withCallback(CommandResultCallback consumer, BinaryOperator<CommandResultCallback> binaryOperator)
{
CommandResultConsumer<CommandSourceStack> resultConsumer = binaryOperator.apply(this.resultConsumer, consumer);
CommandResultCallback resultConsumer = binaryOperator.apply(this.resultConsumer, consumer);
return this.withCallback(resultConsumer);
}