Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert Json Text to nms.nbt.CompoundTag ? #3273

Open
4 tasks done
Anarchick opened this issue Oct 12, 2024 · 0 comments
Open
4 tasks done

How to convert Json Text to nms.nbt.CompoundTag ? #3273

Anarchick opened this issue Oct 12, 2024 · 0 comments

Comments

@Anarchick
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant