Minestom/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtCompoundTag.java

44 lines
1.2 KiB
Java
Raw Normal View History

package net.minestom.server.command.builder.arguments.minecraft;
import net.minestom.server.command.builder.arguments.Argument;
import org.jglrxavpok.hephaistos.nbt.NBT;
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
import org.jglrxavpok.hephaistos.nbt.NBTException;
import org.jglrxavpok.hephaistos.nbt.SNBTParser;
import java.io.StringReader;
public class ArgumentNbtCompoundTag extends Argument<NBTCompound> {
public static final int INVALID_NBT = 1;
public ArgumentNbtCompoundTag(String id) {
super(id, true);
}
@Override
public int getCorrectionResult(String value) {
try {
NBT nbt = new SNBTParser(new StringReader(value)).parse();
return nbt instanceof NBTCompound ? SUCCESS : INVALID_NBT;
} catch (NBTException e) {
return INVALID_NBT;
}
}
@Override
public NBTCompound parse(String value) {
try {
NBT nbt = new SNBTParser(new StringReader(value)).parse();
return (NBTCompound) nbt;
} catch (NBTException e) {
return null;
}
}
@Override
public int getConditionResult(NBTCompound value) {
return SUCCESS;
}
}