2020-10-17 08:18:52 +02:00
|
|
|
package net.minestom.server.command.builder.arguments.minecraft;
|
|
|
|
|
2024-03-17 21:07:29 +01:00
|
|
|
import net.kyori.adventure.nbt.BinaryTag;
|
2024-04-24 18:24:12 +02:00
|
|
|
import net.kyori.adventure.nbt.TagStringIOExt;
|
2023-03-25 14:29:20 +01:00
|
|
|
import net.minestom.server.command.CommandSender;
|
2020-10-17 08:18:52 +02:00
|
|
|
import net.minestom.server.command.builder.arguments.Argument;
|
2021-01-08 03:07:37 +01:00
|
|
|
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
2020-10-24 16:58:27 +02:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2020-10-17 08:18:52 +02:00
|
|
|
|
2024-03-17 21:07:29 +01:00
|
|
|
import java.io.IOException;
|
2020-10-17 08:18:52 +02:00
|
|
|
|
2020-10-17 11:29:05 +02:00
|
|
|
/**
|
2024-03-17 21:07:29 +01:00
|
|
|
* Argument used to retrieve a {@link BinaryTag} based object, can be any kind of tag like
|
|
|
|
* {@link net.kyori.adventure.nbt.CompoundBinaryTag}, {@link net.kyori.adventure.nbt.ListBinaryTag},
|
|
|
|
* {@link net.kyori.adventure.nbt.IntBinaryTag}, etc...
|
2020-10-17 11:29:05 +02:00
|
|
|
* <p>
|
|
|
|
* Example: {display:{Name:"{\"text\":\"Sword of Power\"}"}} or [{display:{Name:"{\"text\":\"Sword of Power\"}"}}]
|
|
|
|
*/
|
2024-03-17 21:07:29 +01:00
|
|
|
public class ArgumentNbtTag extends Argument<BinaryTag> {
|
2020-10-17 08:18:52 +02:00
|
|
|
|
|
|
|
public static final int INVALID_NBT = 1;
|
|
|
|
|
|
|
|
public ArgumentNbtTag(String id) {
|
|
|
|
super(id, true);
|
|
|
|
}
|
|
|
|
|
2020-10-24 16:58:27 +02:00
|
|
|
@NotNull
|
2020-10-17 08:18:52 +02:00
|
|
|
@Override
|
2024-03-17 21:07:29 +01:00
|
|
|
public BinaryTag parse(@NotNull CommandSender sender, @NotNull String input) throws ArgumentSyntaxException {
|
2020-10-17 08:18:52 +02:00
|
|
|
try {
|
2024-04-24 18:24:12 +02:00
|
|
|
return TagStringIOExt.readTag(input);
|
2024-03-17 21:07:29 +01:00
|
|
|
} catch (IOException e) {
|
2021-01-08 03:07:37 +01:00
|
|
|
throw new ArgumentSyntaxException("Invalid NBT", input, INVALID_NBT);
|
2020-10-17 08:18:52 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-09 00:25:10 +01:00
|
|
|
|
|
|
|
@Override
|
2022-07-02 05:39:39 +02:00
|
|
|
public String parser() {
|
|
|
|
return "minecraft:nbt_tag";
|
2021-02-09 00:25:10 +01:00
|
|
|
}
|
2021-04-25 10:42:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return String.format("NBT<%s>", getId());
|
|
|
|
}
|
2020-10-17 08:18:52 +02:00
|
|
|
}
|