Merge branch 'master' into 1.17
This commit is contained in:
commit
f67d50d3d3
5 files changed
+22
-22
No files matched your search
@@ -281,7 +281,7 @@ public class HopperCounter
|
|||||||
{
|
{
|
||||||
block = ((BlockItem) item).getBlock();
|
block = ((BlockItem) item).getBlock();
|
||||||
}
|
}
|
||||||
else if (Registry.BLOCK.containsId(id))
|
else if (Registry.BLOCK.getOrEmpty(id).isPresent())
|
||||||
{
|
{
|
||||||
block = Registry.BLOCK.get(id);
|
block = Registry.BLOCK.get(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.function.BiPredicate;
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@@ -76,10 +76,10 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
public Map<Value, Value> appConfig;
|
public Map<Value, Value> appConfig;
|
||||||
public Map<String, CommandArgument> appArgTypes;
|
public Map<String, CommandArgument> appArgTypes;
|
||||||
|
|
||||||
Function<ServerCommandSource, Boolean> commandValidator;
|
Predicate<ServerCommandSource> commandValidator;
|
||||||
boolean isRuleApp;
|
boolean isRuleApp;
|
||||||
|
|
||||||
private CarpetScriptHost(CarpetScriptServer server, Module code, boolean perUser, ScriptHost parent, Map<Value, Value> config, Map<String, CommandArgument> argTypes, Function<ServerCommandSource, Boolean> commandValidator, boolean isRuleApp)
|
private CarpetScriptHost(CarpetScriptServer server, Module code, boolean perUser, ScriptHost parent, Map<Value, Value> config, Map<String, CommandArgument> argTypes, Predicate<ServerCommandSource> commandValidator, boolean isRuleApp)
|
||||||
{
|
{
|
||||||
super(code, perUser, parent);
|
super(code, perUser, parent);
|
||||||
this.saveTimeout = 0;
|
this.saveTimeout = 0;
|
||||||
@@ -100,7 +100,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
this.isRuleApp = isRuleApp;
|
this.isRuleApp = isRuleApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CarpetScriptHost create(CarpetScriptServer scriptServer, Module module, boolean perPlayer, ServerCommandSource source, Function<ServerCommandSource, Boolean> commandValidator, boolean isRuleApp)
|
public static CarpetScriptHost create(CarpetScriptServer scriptServer, Module module, boolean perPlayer, ServerCommandSource source, Predicate<ServerCommandSource> commandValidator, boolean isRuleApp)
|
||||||
{
|
{
|
||||||
CarpetScriptHost host = new CarpetScriptHost(scriptServer, module, perPlayer, null, Collections.emptyMap(), new HashMap<>(), commandValidator, isRuleApp);
|
CarpetScriptHost host = new CarpetScriptHost(scriptServer, module, perPlayer, null, Collections.emptyMap(), new HashMap<>(), commandValidator, isRuleApp);
|
||||||
// parse code and convert to expression
|
// parse code and convert to expression
|
||||||
@@ -180,13 +180,13 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
|
|
||||||
public LiteralArgumentBuilder<ServerCommandSource> getNewCommandTree(
|
public LiteralArgumentBuilder<ServerCommandSource> getNewCommandTree(
|
||||||
List<Pair<List<CommandToken>,FunctionArgument>> entries, Function<ServerCommandSource, Boolean> useValidator
|
List<Pair<List<CommandToken>,FunctionArgument>> entries, Predicate<ServerCommandSource> useValidator
|
||||||
) throws CommandSyntaxException
|
) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
String hostName = main.getName();
|
String hostName = main.getName();
|
||||||
Function<ServerCommandSource, Boolean> configValidator = getCommandConfigPermissions();
|
Predicate<ServerCommandSource> configValidator = getCommandConfigPermissions();
|
||||||
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
||||||
requires((player) -> CarpetServer.scriptServer.modules.containsKey(hostName) && useValidator.apply(player) && configValidator.apply(player));
|
requires((player) -> CarpetServer.scriptServer.modules.containsKey(hostName) && useValidator.test(player) && configValidator.test(player));
|
||||||
for (Pair<List<CommandToken>,FunctionArgument> commandData : entries)
|
for (Pair<List<CommandToken>,FunctionArgument> commandData : entries)
|
||||||
{
|
{
|
||||||
command = this.addPathToCommand(command, commandData.getKey(), commandData.getValue());
|
command = this.addPathToCommand(command, commandData.getKey(), commandData.getValue());
|
||||||
@@ -194,7 +194,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Function<ServerCommandSource, Boolean> getCommandConfigPermissions() throws CommandSyntaxException
|
public Predicate<ServerCommandSource> getCommandConfigPermissions() throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
Value confValue = appConfig.get(StringValue.of("command_permission"));
|
Value confValue = appConfig.get(StringValue.of("command_permission"));
|
||||||
if (confValue == null) return s -> true;
|
if (confValue == null) return s -> true;
|
||||||
@@ -475,7 +475,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Function<ServerCommandSource, Boolean> configValidator;
|
Predicate<ServerCommandSource> configValidator;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
configValidator = getCommandConfigPermissions();
|
configValidator = getCommandConfigPermissions();
|
||||||
@@ -487,7 +487,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
String hostName = getName();
|
String hostName = getName();
|
||||||
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
||||||
requires((player) -> scriptServer.modules.containsKey(hostName) && commandValidator.apply(player) && configValidator.apply(player)).
|
requires((player) -> scriptServer.modules.containsKey(hostName) && commandValidator.test(player) && configValidator.test(player)).
|
||||||
executes( (c) ->
|
executes( (c) ->
|
||||||
{
|
{
|
||||||
CarpetScriptHost targetHost = scriptServer.modules.get(hostName).retrieveOwnForExecution(c.getSource());
|
CarpetScriptHost targetHost = scriptServer.modules.get(hostName).retrieveOwnForExecution(c.getSource());
|
||||||
@@ -540,7 +540,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiteralArgumentBuilder<ServerCommandSource> readCommands(Function<ServerCommandSource, Boolean> useValidator) throws CommandSyntaxException
|
public LiteralArgumentBuilder<ServerCommandSource> readCommands(Predicate<ServerCommandSource> useValidator) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
Value commands = appConfig.get(StringValue.of("commands"));
|
Value commands = appConfig.get(StringValue.of("commands"));
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
@@ -226,7 +226,7 @@ public class CarpetScriptServer
|
|||||||
return modules.get(name);
|
return modules.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addScriptHost(ServerCommandSource source, String name, Function<ServerCommandSource, Boolean> commandValidator,
|
public boolean addScriptHost(ServerCommandSource source, String name, Predicate<ServerCommandSource> commandValidator,
|
||||||
boolean perPlayer, boolean autoload, boolean isRuleApp)
|
boolean perPlayer, boolean autoload, boolean isRuleApp)
|
||||||
{
|
{
|
||||||
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet load", CarpetProfiler.TYPE.GENERAL);
|
CarpetProfiler.ProfilerToken currentSection = CarpetProfiler.start_section(null, "Scarpet load", CarpetProfiler.TYPE.GENERAL);
|
||||||
@@ -457,7 +457,7 @@ public class CarpetScriptServer
|
|||||||
static class TransferData
|
static class TransferData
|
||||||
{
|
{
|
||||||
boolean perUser;
|
boolean perUser;
|
||||||
Function<ServerCommandSource, Boolean> commandValidator;
|
Predicate<ServerCommandSource> commandValidator;
|
||||||
boolean isRuleApp;
|
boolean isRuleApp;
|
||||||
private TransferData(CarpetScriptHost host)
|
private TransferData(CarpetScriptHost host)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.BiPredicate;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -133,7 +134,7 @@ public class WorldAccess {
|
|||||||
Context c,
|
Context c,
|
||||||
String name,
|
String name,
|
||||||
List<Value> params,
|
List<Value> params,
|
||||||
BiFunction<BlockState, BlockPos, Boolean> test
|
BiPredicate<BlockState, BlockPos> test
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
CarpetContext cc = (CarpetContext) c;
|
CarpetContext cc = (CarpetContext) c;
|
||||||
@@ -141,9 +142,9 @@ public class WorldAccess {
|
|||||||
throw new InternalExpressionException("'" + name + "' requires at least one parameter");
|
throw new InternalExpressionException("'" + name + "' requires at least one parameter");
|
||||||
Value v0 = params.get(0);
|
Value v0 = params.get(0);
|
||||||
if (v0 instanceof BlockValue)
|
if (v0 instanceof BlockValue)
|
||||||
return BooleanValue.of(test.apply(((BlockValue) v0).getBlockState(), ((BlockValue) v0).getPos()));
|
return BooleanValue.of(test.test(((BlockValue) v0).getBlockState(), ((BlockValue) v0).getPos()));
|
||||||
BlockValue block = BlockArgument.findIn(cc, params, 0).block;
|
BlockValue block = BlockArgument.findIn(cc, params, 0).block;
|
||||||
return BooleanValue.of(test.apply(block.getBlockState(), block.getPos()));
|
return BooleanValue.of(test.test(block.getBlockState(), block.getPos()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Value stateStringQuery(
|
private static Value stateStringQuery(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package carpet.settings;
|
|||||||
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;
|
||||||
import com.google.common.collect.Sets;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
@@ -12,7 +11,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
|
||||||
|
import org.apache.commons.lang3.ClassUtils;
|
||||||
|
|
||||||
import static carpet.utils.Translations.tr;
|
import static carpet.utils.Translations.tr;
|
||||||
|
|
||||||
@@ -39,7 +39,6 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
|||||||
public final T defaultValue;
|
public final T defaultValue;
|
||||||
public final String defaultAsString;
|
public final String defaultAsString;
|
||||||
public final SettingsManager settingsManager;
|
public final SettingsManager settingsManager;
|
||||||
private static final Set<Class<?>> NUMBER_CLASSES = Sets.newHashSet(byte.class, short.class, int.class, long.class, float.class, double.class);
|
|
||||||
|
|
||||||
ParsedRule(Field field, Rule rule, SettingsManager settingsManager)
|
ParsedRule(Field field, Rule rule, SettingsManager settingsManager)
|
||||||
{
|
{
|
||||||
@@ -216,7 +215,7 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
|||||||
public boolean getBoolValue()
|
public boolean getBoolValue()
|
||||||
{
|
{
|
||||||
if (type == boolean.class) return (Boolean) get();
|
if (type == boolean.class) return (Boolean) get();
|
||||||
if (NUMBER_CLASSES.contains(type)) return ((Number) get()).doubleValue() > 0;
|
if (ClassUtils.primitiveToWrapper(type).isAssignableFrom(Number.class)) return ((Number) get()).doubleValue() > 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user