mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 00:51:34 +01:00
Use a proper regex to check for valid player username
This commit is contained in:
parent
509f8f7851
commit
fbb0ddd7db
@ -1,12 +1,10 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.registry.Registries;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
@ -17,6 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represents the target selector argument.
|
||||
@ -30,6 +29,7 @@ public class ArgumentEntity extends Argument<EntityFinder> {
|
||||
public static final int INVALID_ARGUMENT_NAME = -5;
|
||||
public static final int INVALID_ARGUMENT_VALUE = -6;
|
||||
|
||||
private static final Pattern USERNAME_PATTERN = Pattern.compile("[a-zA-Z0-9_]{1,16}");
|
||||
private static final String SELECTOR_PREFIX = "@";
|
||||
private static final List<String> SELECTOR_VARIABLES = Arrays.asList("@p", "@r", "@a", "@e", "@s");
|
||||
private static final List<String> PLAYERS_ONLY_SELECTOR = Arrays.asList("@p", "@r", "@a", "@s");
|
||||
@ -105,8 +105,7 @@ public class ArgumentEntity extends Argument<EntityFinder> {
|
||||
}
|
||||
|
||||
// Check if the input is a valid player name
|
||||
final Player player = MinecraftServer.getConnectionManager().getPlayer(input);
|
||||
if (player != null) {
|
||||
if (USERNAME_PATTERN.matcher(input).matches()) {
|
||||
return new EntityFinder()
|
||||
.setTargetSelector(EntityFinder.TargetSelector.MINESTOM_USERNAME)
|
||||
.setConstantName(input);
|
||||
|
Loading…
Reference in New Issue
Block a user