mirror of https://github.com/Minestom/Minestom.git
Add check for resource location
This commit is contained in:
parent
89d2f1b54c
commit
7d247003ca
|
@ -4,16 +4,24 @@ import net.minestom.server.command.CommandReader;
|
|||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ArgumentResourceLocation extends Argument<String> {
|
||||
|
||||
public static final Pattern RESOURCE_REGEX = Pattern.compile("([a-z\\d_\\-.]+:)?[a-z\\d_\\-./]+");
|
||||
|
||||
public ArgumentResourceLocation(@NotNull String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Result<String> parse(CommandReader reader) {
|
||||
//todo shouldn't this have some syntax checks?
|
||||
return Result.success(reader.readWord());
|
||||
final String word = reader.readWord();
|
||||
if (RESOURCE_REGEX.matcher(word).matches()) {
|
||||
return Result.success(word);
|
||||
} else {
|
||||
return Result.syntaxError("Invalid resource location format", word, -1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue