Solved Protocollib PacketPlayOutTileEntityData Sign text

Discussion in 'Spigot Plugin Development' started by Litona, May 26, 2016.

Thread Status:
Not open for further replies.
  1. Hii devs!
    I want to set the text of a sign. With Protocollib 1.8 I used to make a new Server.UPDATE_SIGN packet and then write the ChatComponentArrays
    Code (Text):
    packet = manager.createPacket(PacketType.Play.Server.UPDATE_SIGN);
    packet.getBlockPositionModifier().write(0, signPos);
    packet.getChatComponentArrays().write(0, new WrappedChatComponent[]{WrappedChatComponent.fromText(line1), WrappedChatComponent.fromText(line2), WrappedChatComponent.fromText(line3), WrappedChatComponent.fromText(line4)});
    manager.sendServerPacket(p, packet);
    But now the packet was changed to Server.TILE_ENTITY_DATA. This packet has no ChatComponentArrays, so I looked it up in the PacketWrappers. Here it says I need to use the NbtModifiers, so I looked the NBT Stuff for signs up. I came to the solution that I needed to set JSON Text stuff for the NBT Attributes Text1, Text2, etc.
    This is the code I came up with:
    Code (Text):
    packet = manager.createPacket(PacketType.Play.Server.TILE_ENTITY_DATA);
    packet.getBlockPositionModifier().write(0, signPos);
    ArrayList<NbtBase<?>> tags = new ArrayList<NbtBase<?>>();
    tags.add(NbtFactory.of("Text1", "{text:\"testline\"}"));
    tags.add(NbtFactory.of("Text2", "{text:\"testline\"}"));
    tags.add(NbtFactory.of("Text3", "{text:\"testline\"}"));
    tags.add(NbtFactory.of("Text4", "{text:\"testline\"}"));
    packet.getNbtModifier().write(0, NbtFactory.ofCompound("", tags));
    manager.sendServerPacket(p, packet);
    I'm using this to open a SignEditor for this Sign later. With this code, the sign can be opened at least, but still there is no text :(

    I hope you know what mistake I made
  2. I have a similar issue to your problem. Although I don't have a solution (sorry), but you can use the following way to identify what's in a packet:

    1. Join a server with ProtocolLib, use a superflat world with no other mobs spawning to prevent anything that disturbs you.
    2. /packet add play server <packet_name> true. In your case use TILE_ENTITY_DATA, if this is not working, try look for other packets.
    3. Use some plugin to make a sign change, causing the sign being sent to client.
    4. See console for update sign packet output.
    • Useful Useful x 1
  3. For my Pl3xSigns plugin this is how I updated to 1.9.4:


    It's pretty straight forward and simple.
    • Agree Agree x 3
    • Like Like x 1
    • Winner Winner x 1
    • Informative Informative x 1
  4. Hey, first of all, thank you very much! While I was trying to get a solution for my problem I came to a pretty similar solution. But sadly my solution and even the copy pastaed code from you didn't work. Like, I'm doing exactly the same, but it doesn't work. I've looked over my code 100 times, but I don't see the mistake..
    #4 Litona, May 26, 2016
    Last edited: May 31, 2016
  5. I don't understand why you guys are using packets to modify the text on a sign. You can just cast the state of a block to sign and edit it from there.
  6. By using packets we don't need to update the block for everyone on the server
  7. Oh it's only for a single player? Sorry, didn't know.
  8. I hit this snag for a while as well, you need to write a value of 9 to the integer in the packet. I'm unable to grab the wiki page but 9 means Sign for TileEntityData:
    Code (Text):
    packets[1].getIntegerModifier().write(0, 9);
    • Like Like x 1
  9. Oh yeah!! That worked!!
    [Just for strangers from the internet, the method name is: getIntegers()]
    The only thing with this solution is, that the JSON Formatting BillyGalbreath posted doesn't work.
    This JSON Formatting will do it's thing:
    Code (Text):
    NbtCompound nbt = (NbtCompound) packet[1].getNbtModifier().read(0);
    for(int i = 0; i < 4; i++)
        nbt.put("Text" + (i + 1), "{\"extra\":[{\"text\":\"" + lines[i] + "\"}],\"text\":\"\"}");
    packet[1].getNbtModifier().write(0, nbt);
    Thank you very much to everyone!
Thread Status:
Not open for further replies.