mirror of https://github.com/Minestom/Minestom.git
Arg block state, registry, uuid done
This commit is contained in:
parent
209122874f
commit
56e99424e0
|
@ -1,5 +1,6 @@
|
|||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.CommandReader;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
|
@ -14,24 +15,12 @@ public class ArgumentBlockState extends Argument<Block> {
|
|||
public static final int INVALID_PROPERTY_VALUE = 4;
|
||||
|
||||
public ArgumentBlockState(@NotNull String id) {
|
||||
super(id, true, false);
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Block parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
return staticParse(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parser() {
|
||||
return "minecraft:block_state";
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link Argument#parse(Argument)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static Block staticParse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
public @NotNull Block parse(CommandReader reader) throws ArgumentSyntaxException {
|
||||
final String input = reader.getWord();
|
||||
final int nbtIndex = input.indexOf("[");
|
||||
if (nbtIndex == 0)
|
||||
throw new ArgumentSyntaxException("No block type", input, NO_BLOCK);
|
||||
|
@ -41,8 +30,10 @@ public class ArgumentBlockState extends Argument<Block> {
|
|||
final Block block = Block.fromNamespaceId(input);
|
||||
if (block == null)
|
||||
throw new ArgumentSyntaxException("Invalid block type", input, INVALID_BLOCK);
|
||||
reader.consume();
|
||||
return block;
|
||||
} else {
|
||||
reader.consume();
|
||||
if (!input.endsWith("]"))
|
||||
throw new ArgumentSyntaxException("Property list need to end with ]", input, INVALID_PROPERTY);
|
||||
// Block state
|
||||
|
@ -62,6 +53,11 @@ public class ArgumentBlockState extends Argument<Block> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parser() {
|
||||
return "minecraft:block_state";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("BlockState<%s>", getId());
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.command.CommandReader;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -14,11 +15,13 @@ public class ArgumentUUID extends Argument<UUID> {
|
|||
super(id);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public UUID parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
public @NotNull UUID parse(CommandReader reader) throws ArgumentSyntaxException {
|
||||
final String input = reader.getWord();
|
||||
try {
|
||||
return UUID.fromString(input);
|
||||
final UUID uuid = UUID.fromString(input);
|
||||
reader.consume();
|
||||
return uuid;
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw new ArgumentSyntaxException("Invalid UUID", input, INVALID_UUID);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.minestom.server.command.builder.arguments.minecraft.registry;
|
||||
|
||||
import net.minestom.server.command.CommandReader;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
@ -14,13 +15,14 @@ public abstract class ArgumentRegistry<T> extends Argument<T> {
|
|||
|
||||
public abstract T getRegistry(@NotNull String value);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public T parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
public @NotNull T parse(CommandReader reader) throws ArgumentSyntaxException {
|
||||
final String input = reader.getWord();
|
||||
final T registryValue = getRegistry(input);
|
||||
if (registryValue == null)
|
||||
throw new ArgumentSyntaxException("Registry value is invalid", input, INVALID_NAME);
|
||||
|
||||
reader.consume();
|
||||
return registryValue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue