mirror of
https://github.com/Minestom/Minestom.git
synced 2024-06-25 05:54:53 +02:00
44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
|
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;
|
||
|
}
|
||
|
}
|