Solved JSON text to colored string

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

i998979

Member
Jan 26, 2017
24
2
0
24
So the code I have is the following
Code:
    private ProtocolManager protocolManager;

    public void onEnable() {

        protocolManager = ProtocolLibrary.getProtocolManager();

        protocolManager.addPacketListener(new PacketAdapter(this, PacketType.Play.Server.CHAT) {
            @Override
            public void onPacketSending(PacketEvent event) {
                PacketContainer packet = event.getPacket();
                StructureModifier<WrappedChatComponent> chatComponents = packet.getChatComponents();
                String jsonText = chatComponents.read(0).getJson();
                Bukkit.getServer().getLogger().info(jsonText);
               
            }
        });
    }

For example, I executed a command "plugman", it will display a text like this
Code:
[PlugMan] You do not have permission to do this.
What I want to do is, get the exact same string from the packet
But currently I can only get this
Code:
{"extra":[{"color":"gray","text":"["},{"color":"green","text":"
PlugMan"},{"color":"gray","text":"] "},{"color":"red","text":"You do not have pe
rmission to do this."}],"text":""}

Is there any way to parse the message above to the exact text that the player receives?
 
Java:
String message = BaseComponent.toLegacyText(ComponentSerializer.parse(jsonText));