mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-15 15:16:46 +01:00
Added ArgumentComponent
This commit is contained in:
parent
5ffd44449d
commit
f7ec45802f
@ -130,14 +130,18 @@ public class ArgumentType {
|
||||
return new ArgumentItemStack(id);
|
||||
}
|
||||
|
||||
public static ArgumentNbtCompoundTag NbtCompound(@NotNull String id) {
|
||||
return new ArgumentNbtCompoundTag(id);
|
||||
public static ArgumentComponent Component(@NotNull String id) {
|
||||
return new ArgumentComponent(id);
|
||||
}
|
||||
|
||||
public static ArgumentNbtTag NBT(@NotNull String id) {
|
||||
return new ArgumentNbtTag(id);
|
||||
}
|
||||
|
||||
public static ArgumentNbtCompoundTag NbtCompound(@NotNull String id) {
|
||||
return new ArgumentNbtCompoundTag(id);
|
||||
}
|
||||
|
||||
public static ArgumentRelativeBlockPosition RelativeBlockPosition(@NotNull String id) {
|
||||
return new ArgumentRelativeBlockPosition(id);
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import net.minestom.server.chat.JsonMessage;
|
||||
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.network.packet.server.play.DeclareCommandsPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ArgumentComponent extends Argument<JsonMessage> {
|
||||
|
||||
public static final int INVALID_JSON_ERROR = 1;
|
||||
|
||||
public ArgumentComponent(@NotNull String id) {
|
||||
super(id, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JsonMessage parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||
try {
|
||||
return new JsonMessage.RawJsonMessage(input);
|
||||
} catch (JsonParseException e) {
|
||||
throw new ArgumentSyntaxException("Invalid JSON", input, INVALID_JSON_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
|
||||
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
|
||||
|
||||
argumentNode.parser = "minecraft:component";
|
||||
|
||||
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user