How to convert Json Text to nms.nbt.CompoundTag ?
Anarchick opened this issue ยท 0 comments
Make sure you're doing the following
- You're using the latest build for your server version
- This isn't an issue caused by another plugin
- You've checked for duplicate issues
- You didn't use
/reload
Describe the question
I'm trying to convert a json string into NBT, may be used in PLAY_SERVER_TILE_ENTITY_DATA.
The input json is given by the player so I need a deserializer.
API method(s) used
I had try NbtTextSerializer.DEFAULT#deserialize and NbtFactory#ofCompound
Expected behavior
Have a method that deserialize a complex json string into nms.nbt.CompoundTag
Code
I tried something like this :
if (text == null || text.isEmpty()) {
return NbtFactory.ofCompound("").getHandle();
}
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
DataInputStream dataInput = new DataInputStream(byteArrayInputStream);
NbtWrapper<Object> wrapper = NbtTextSerializer.DEFAULT.getBinarySerializer().deserialize(dataInput); // Issue here
return wrapper.getHandle();
Additional context
This is for Skript-Packet.