Support standalone itemstack string parsing

This commit is contained in:
TheMode 2021-04-25 21:42:40 +02:00
parent 34d81f2bca
commit 47e7d35949

View File

@ -33,6 +33,18 @@ public class ArgumentItemStack extends Argument<ItemStack> {
@NotNull
@Override
public ItemStack parse(@NotNull String input) throws ArgumentSyntaxException {
return staticParse(input);
}
@Override
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
argumentNode.parser = "minecraft:item_stack";
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
}
public static ItemStack staticParse(@NotNull String input) throws ArgumentSyntaxException {
final int nbtIndex = input.indexOf("{");
if (nbtIndex == 0)
@ -60,14 +72,6 @@ public class ArgumentItemStack extends Argument<ItemStack> {
}
}
@Override
public void processNodes(@NotNull NodeMaker nodeMaker, boolean executable) {
DeclareCommandsPacket.Node argumentNode = simpleArgumentNode(this, executable, false, false);
argumentNode.parser = "minecraft:item_stack";
nodeMaker.addNodes(new DeclareCommandsPacket.Node[]{argumentNode});
}
@Override
public String toString() {
return String.format("ItemStack<%s>", getId());