Improve distance selector detection

This commit is contained in:
Allink 2023-04-01 23:46:17 +01:00
parent a91c25f8c2
commit 634661e1fa
No known key found for this signature in database

View file

@ -19,6 +19,8 @@ import java.util.regex.Pattern;
public final class ServerCommand implements Listener { public final class ServerCommand implements Listener {
private static final Pattern AS_AT_PATTERN = Pattern.compile( private static final Pattern AS_AT_PATTERN = Pattern.compile(
"\\b(as|at|facing entity) @[ae]\\b"); "\\b(as|at|facing entity) @[ae]\\b");
private static final Pattern DISTANCE_SELECTOR_PATTERN = Pattern.compile(
"[\"']?distance[\"']?\\s*=\\s*");
private static final Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger(); private static final Logger LOGGER = JavaPlugin.getPlugin(Main.class).getLogger();
public static boolean checkExecuteCommand(final String cmd) { public static boolean checkExecuteCommand(final String cmd) {
@ -208,8 +210,8 @@ public final class ServerCommand implements Listener {
} }
if (command.contains("distance")) { if (command.contains("distance")) {
return command.replace("distance=", "]").replace("\"distance\"=", "]") final Matcher distanceMatcher = DISTANCE_SELECTOR_PATTERN.matcher(command);
.replace("'distance'=", "]"); return distanceMatcher.replaceAll("]");
} }
return null; return null;