Merge branch 'master' into 1.17
This commit is contained in:
commit
c8d3f01f78
6 files changed
+31
-27
No files matched your search
@@ -244,13 +244,13 @@ public class ScriptCommand
|
|||||||
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(true),bb)).
|
suggests( (cc, bb) -> suggestMatching(CarpetServer.scriptServer.listAvailableModules(true),bb)).
|
||||||
executes((cc) ->
|
executes((cc) ->
|
||||||
{
|
{
|
||||||
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "app"), true, false, false);
|
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "app"), true, false, null);
|
||||||
return success?1:0;
|
return success?1:0;
|
||||||
}).
|
}).
|
||||||
then(literal("global").
|
then(literal("global").
|
||||||
executes((cc) ->
|
executes((cc) ->
|
||||||
{
|
{
|
||||||
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "app"), false, false, false);
|
boolean success = CarpetServer.scriptServer.addScriptHost(cc.getSource(), StringArgumentType.getString(cc, "app"), false, false, null);
|
||||||
return success?1:0;
|
return success?1:0;
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import java.util.Comparator;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
@@ -152,12 +153,12 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
|
|
||||||
public LiteralArgumentBuilder<ServerCommandSource> getNewCommandTree(
|
public LiteralArgumentBuilder<ServerCommandSource> getNewCommandTree(
|
||||||
List<Pair<List<CommandToken>,FunctionArgument<Value>>> entries
|
List<Pair<List<CommandToken>,FunctionArgument<Value>>> entries, Function<ServerCommandSource, Boolean> useValidator
|
||||||
) throws CommandSyntaxException
|
) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
String hostName = main.getName();
|
String hostName = main.getName();
|
||||||
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
||||||
requires((player) -> CarpetServer.scriptServer.modules.containsKey(hostName));
|
requires((player) -> CarpetServer.scriptServer.modules.containsKey(hostName) && useValidator.apply(player));
|
||||||
for (Pair<List<CommandToken>,FunctionArgument<Value>> commandData : entries)
|
for (Pair<List<CommandToken>,FunctionArgument<Value>> commandData : entries)
|
||||||
{
|
{
|
||||||
command = this.addPathToCommand(command, commandData.getKey(), commandData.getValue());
|
command = this.addPathToCommand(command, commandData.getKey(), commandData.getValue());
|
||||||
@@ -243,7 +244,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiteralArgumentBuilder<ServerCommandSource> readCommands() throws CommandSyntaxException
|
public LiteralArgumentBuilder<ServerCommandSource> readCommands(Function<ServerCommandSource, Boolean> useValidator) throws CommandSyntaxException
|
||||||
{
|
{
|
||||||
Value commands = appConfig.get(StringValue.of("commands"));
|
Value commands = appConfig.get(StringValue.of("commands"));
|
||||||
|
|
||||||
@@ -279,7 +280,7 @@ public class CarpetScriptHost extends ScriptHost
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.getNewCommandTree(commandEntries);
|
return this.getNewCommandTree(commandEntries, useValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.util.List;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
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;
|
||||||
@@ -53,7 +54,7 @@ public class CarpetScriptServer
|
|||||||
/**
|
/**
|
||||||
* Registers a Scarpet App to be always available to be loaded
|
* Registers a Scarpet App to be always available to be loaded
|
||||||
* in the /script load list.
|
* in the /script load list.
|
||||||
* @see BundledModule#fromPath(ClassLoader, String, String, boolean)
|
* @see BundledModule#fromPath(String, String, boolean)
|
||||||
*
|
*
|
||||||
* @param app The {@link BundledModule} of the app
|
* @param app The {@link BundledModule} of the app
|
||||||
*/
|
*/
|
||||||
@@ -66,7 +67,7 @@ public class CarpetScriptServer
|
|||||||
* Registers a Scarpet App to be used as a Rule App
|
* Registers a Scarpet App to be used as a Rule App
|
||||||
* (to be controlled with the value of a Carpet rule).
|
* (to be controlled with the value of a Carpet rule).
|
||||||
* Libraries should be registered with {@link #registerBuiltInScript(BundledModule)} instead
|
* Libraries should be registered with {@link #registerBuiltInScript(BundledModule)} instead
|
||||||
* @see BundledModule#fromPath(ClassLoader, String, String, boolean)
|
* @see BundledModule#fromPath(String, String, boolean)
|
||||||
*
|
*
|
||||||
* @param app The {@link BundledModule} of the app.
|
* @param app The {@link BundledModule} of the app.
|
||||||
*/
|
*/
|
||||||
@@ -116,7 +117,7 @@ public class CarpetScriptServer
|
|||||||
Messenger.m(server.getCommandSource(), "Auto-loading world scarpet apps");
|
Messenger.m(server.getCommandSource(), "Auto-loading world scarpet apps");
|
||||||
for (String moduleName: listAvailableModules(false))
|
for (String moduleName: listAvailableModules(false))
|
||||||
{
|
{
|
||||||
addScriptHost(server.getCommandSource(), moduleName, true, true, false);
|
addScriptHost(server.getCommandSource(), moduleName, true, true, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,9 +193,10 @@ public class CarpetScriptServer
|
|||||||
return modules.get(name);
|
return modules.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer, boolean autoload, boolean isRuleApp)
|
public boolean addScriptHost(ServerCommandSource source, String name, boolean perPlayer, boolean autoload, Function<ServerCommandSource, Boolean> commandValidator)
|
||||||
{
|
{
|
||||||
//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
|
||||||
|
boolean isRuleApp = commandValidator != null;
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
name = name.toLowerCase(Locale.ROOT);
|
name = name.toLowerCase(Locale.ROOT);
|
||||||
boolean reload = false;
|
boolean reload = false;
|
||||||
@@ -242,7 +244,7 @@ public class CarpetScriptServer
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LiteralArgumentBuilder<ServerCommandSource> command = newHost.readCommands();
|
LiteralArgumentBuilder<ServerCommandSource> command = newHost.readCommands(commandValidator);
|
||||||
if (command != null)
|
if (command != null)
|
||||||
{
|
{
|
||||||
if (!isRuleApp) Messenger.m(source, "gi "+name+" app "+action+" with /"+name+" command");
|
if (!isRuleApp) Messenger.m(source, "gi "+name+" app "+action+" with /"+name+" command");
|
||||||
@@ -261,7 +263,7 @@ public class CarpetScriptServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (!addLegacyCommand(source, name, reload, !isRuleApp)) // this needs to be moved to config reader, only supporting legacy command here
|
else if (!addLegacyCommand(source, name, reload, !isRuleApp, commandValidator)) // this needs to be moved to config reader, only supporting legacy command here
|
||||||
{
|
{
|
||||||
removeScriptHost(source, name, false, false);
|
removeScriptHost(source, name, false, false);
|
||||||
Messenger.m(source, "r Failed to build command system for "+name+" thus failed to load the app");
|
Messenger.m(source, "r Failed to build command system for "+name+" thus failed to load the app");
|
||||||
@@ -272,7 +274,7 @@ public class CarpetScriptServer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addLegacyCommand(ServerCommandSource source, String hostName, boolean isReload, boolean notifySource)
|
private boolean addLegacyCommand(ServerCommandSource source, String hostName, boolean isReload, boolean notifySource, Function<ServerCommandSource, Boolean> useValidator)
|
||||||
{
|
{
|
||||||
CarpetScriptHost host = modules.get(hostName);
|
CarpetScriptHost host = modules.get(hostName);
|
||||||
String loaded = isReload?"reloaded":"loaded";
|
String loaded = isReload?"reloaded":"loaded";
|
||||||
@@ -293,7 +295,7 @@ public class CarpetScriptServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
LiteralArgumentBuilder<ServerCommandSource> command = literal(hostName).
|
||||||
requires((player) -> modules.containsKey(hostName)).
|
requires((player) -> modules.containsKey(hostName) && useValidator.apply(player)).
|
||||||
executes( (c) ->
|
executes( (c) ->
|
||||||
{
|
{
|
||||||
Value response = modules.get(hostName).retrieveForExecution(c.getSource()).
|
Value response = modules.get(hostName).retrieveForExecution(c.getSource()).
|
||||||
@@ -439,6 +441,6 @@ public class CarpetScriptServer
|
|||||||
apps.keySet().forEach(s -> removeScriptHost(server.getCommandSource(), s, false, false));
|
apps.keySet().forEach(s -> removeScriptHost(server.getCommandSource(), s, false, false));
|
||||||
CarpetEventServer.Event.clearAllBuiltinEvents();
|
CarpetEventServer.Event.clearAllBuiltinEvents();
|
||||||
init();
|
init();
|
||||||
apps.forEach((s, pp) -> addScriptHost(server.getCommandSource(), s, pp, false, false));
|
apps.forEach((s, pp) -> addScriptHost(server.getCommandSource(), s, pp, false, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ public class BundledModule extends Module
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link BundledModule} with an app located at a specified place.
|
* Creates a new {@link BundledModule} with an app located at a specified place.
|
||||||
* @see #fromPathWithCustomName(ClassLoader, String, String, boolean)
|
* @see #fromPathWithCustomName(String, String, boolean)
|
||||||
*
|
*
|
||||||
* @param path A {@link String} being the path to the directory where the app is located.
|
* @param path A {@link String} being the path to the directory where the app is located.
|
||||||
* @param scriptName A {@link String} being the name of the script. The extension will be autocompleted
|
* @param scriptName A {@link String} being the name of the script. The extension will be autocompleted
|
||||||
@@ -43,10 +43,10 @@ public class BundledModule extends Module
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link BundledModule} with an app located at the specified fullPath with a custom name.
|
* Creates a new {@link BundledModule} with an app located at the specified fullPath with a custom name.
|
||||||
* @see #fromPath(ClassLoader, String, String, boolean)
|
* @see #fromPath(String, String, boolean)
|
||||||
*
|
*
|
||||||
* @param fullPath A {@link String} being the full path to the app's code, including file and extension.
|
* @param fullPath A {@link String} being the full path to the app's code, including file and extension.
|
||||||
* @param scriptName A {@link String} being the custom name for the script.
|
* @param customName A {@link String} being the custom name for the script.
|
||||||
* @param isLibrary A {@link boolean} indicating whether or not the script is a library
|
* @param isLibrary A {@link boolean} indicating whether or not the script is a library
|
||||||
* @return The created {@link BundledModule}
|
* @return The created {@link BundledModule}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -180,17 +180,17 @@ public class SettingsManager
|
|||||||
observers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
observers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
||||||
staticObservers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
staticObservers.forEach(observer -> observer.accept(source, rule, userTypedValue));
|
||||||
ServerNetworkHandler.updateRuleWithConnectedClients(rule);
|
ServerNetworkHandler.updateRuleWithConnectedClients(rule);
|
||||||
switchScarpetRule(source, rule);
|
switchScarpetRuleIfNeeded(source, rule);
|
||||||
if (CARPET_RULE_CHANGES.isNeeded()) CARPET_RULE_CHANGES.onCarpetRuleChanges(rule, source);
|
if (CARPET_RULE_CHANGES.isNeeded()) CARPET_RULE_CHANGES.onCarpetRuleChanges(rule, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
void switchScarpetRule(ServerCommandSource source, ParsedRule<?> rule)
|
private void switchScarpetRuleIfNeeded(ServerCommandSource source, ParsedRule<?> rule)
|
||||||
{
|
{
|
||||||
if (!rule.scarpetApp.isEmpty())
|
if (!rule.scarpetApp.isEmpty())
|
||||||
{
|
{
|
||||||
if (rule.getBoolValue() || (rule.type == String.class && !rule.get().equals("false")))
|
if (rule.getBoolValue() || (rule.type == String.class && !rule.get().equals("false")))
|
||||||
{
|
{
|
||||||
CarpetServer.scriptServer.addScriptHost(source, rule.scarpetApp, false, false, true);
|
CarpetServer.scriptServer.addScriptHost(source, rule.scarpetApp, false, false, s -> canUseCommand(s, rule.get()));
|
||||||
} else {
|
} else {
|
||||||
CarpetServer.scriptServer.removeScriptHost(source, rule.scarpetApp, false, true);
|
CarpetServer.scriptServer.removeScriptHost(source, rule.scarpetApp, false, true);
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ public class SettingsManager
|
|||||||
for (ParsedRule<?> rule : rules.values())
|
for (ParsedRule<?> rule : rules.values())
|
||||||
{
|
{
|
||||||
if (!rule.scarpetApp.isEmpty()) {
|
if (!rule.scarpetApp.isEmpty()) {
|
||||||
switchScarpetRule(server.getCommandSource(), rule);
|
switchScarpetRuleIfNeeded(server.getCommandSource(), rule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,9 +332,11 @@ public class SettingsManager
|
|||||||
* {@link boolean} value or "ops".
|
* {@link boolean} value or "ops".
|
||||||
* @return Whether or not the {@link ServerCommandSource} meets the required level
|
* @return Whether or not the {@link ServerCommandSource} meets the required level
|
||||||
*/
|
*/
|
||||||
public static boolean canUseCommand(ServerCommandSource source, String commandLevel)
|
public static boolean canUseCommand(ServerCommandSource source, Object commandLevel)
|
||||||
{
|
{
|
||||||
switch (commandLevel)
|
if (commandLevel instanceof Boolean) return (Boolean) commandLevel;
|
||||||
|
String commandLevelString = commandLevel.toString();
|
||||||
|
switch (commandLevelString)
|
||||||
{
|
{
|
||||||
case "true": return true;
|
case "true": return true;
|
||||||
case "false": return false;
|
case "false": return false;
|
||||||
@@ -344,7 +346,7 @@ public class SettingsManager
|
|||||||
case "2":
|
case "2":
|
||||||
case "3":
|
case "3":
|
||||||
case "4":
|
case "4":
|
||||||
return source.hasPermissionLevel(Integer.parseInt(commandLevel));
|
return source.hasPermissionLevel(Integer.parseInt(commandLevelString));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import net.minecraft.util.math.Vec3d;
|
|||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class Messenger
|
public class Messenger
|
||||||
{
|
{
|
||||||
public static final Logger LOG = LogManager.getLogger();
|
public static final Logger LOG = LogManager.getLogger("Messaging System");
|
||||||
|
|
||||||
private static final Pattern colorExtract = Pattern.compile("#([0-9a-fA-F]{6})");
|
private static final Pattern colorExtract = Pattern.compile("#([0-9a-fA-F]{6})");
|
||||||
public enum CarpetFormatting
|
public enum CarpetFormatting
|
||||||
|
|||||||
Reference in new issue
Block a user