Modifying chat messages not working.

Discussion in 'Plugin Development' started by plobnob, Jul 31, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    plobnob

    Anyone have any ideas on why this code causes an error when chat has an action on it, such as a hover event or click event? I am using ProtocolLib to modify messages being sent to a client, but get the following error when such messages arise:

    Error Message (open)

    01.08 07:48:06 [Server] INFO at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.ComponentSerializer.deserialize(ComponentSerializer.java:17) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.ComponentSerializer.deserialize(ComponentSerializer.java:60) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson$1.deserialize(Gson.java:126) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson.fromJson(Gson.java:868) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson.fromJson(Gson.java:803) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.TranslatableComponentSerializer.deserialize(TranslatableComponentSerializer.java:16) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.TranslatableComponentSerializer.deserialize(TranslatableComponentSerializer.java:28) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson$1.deserialize(Gson.java:126) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson.fromJson(Gson.java:868) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson.fromJson(Gson.java:803) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.internal.bind.ArrayTypeAdapter.read(ArrayTypeAdapter.java:72) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.ComponentSerializer.deserialize(ComponentSerializer.java:17) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.ComponentSerializer.deserialize(ComponentSerializer.java:62) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson$1.deserialize(Gson.java:126) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson.fromJson(Gson.java:868) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.Gson.fromJson(Gson.java:803) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.TextComponentSerializer.deserialize(TextComponentSerializer.java:17) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.TextComponentSerializer.deserialize(TextComponentSerializer.java:25) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.chat.BaseComponentSerializer.deserialize(BaseComponentSerializer.java:71) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at net.md_5.bungee.api.chat.HoverEvent$Action.valueOf(HoverEvent.java:16) ~[spigot-1.8.7-20150721a.jar:git-Spigot-c8a0d06-58d972f]
    01.08 07:48:06 [Server] INFO at java.lang.Enum.valueOf(Enum.java:238) ~[?:1.8.0_45]
    01.08 07:48:06 [Server] INFO java.lang.IllegalArgumentException: No enum constant net.md_5.bungee.api.chat.HoverEvent.Action.SHOW_ENTITY
    01.08 07:48:06 [Server] ERROR Unhandled exception occured in onPacketSending(PacketEvent) for RankHider
    01.08 07:48:06 [Server] INFO Lol


    That error occurred when I used /say to input a message in chat, with the entity UUID as a hover effect.

    Code at which the error arises:
    Code:
                                    do
                                    {
                                        WrappedChatComponent chat = packet.getChatComponents().read(0);
                                        List<IChatBaseComponent> components = ChatSerializer.a(chat.getJson()).a();
                                        BaseComponent[] translatedComponents = ComponentSerializer.parse(chat.getJson());
                                        System.out.println(translatedComponents[0].toLegacyText());
                                        String chatMessage = colour(translatedComponents[0].toLegacyText());
                                        chatMessage = colour(chatMessage);
                                        List<String> toCheck = (List<String>) ranks.getList(String.valueOf(counter));
                                        if(chatMessage.contains(colour(toCheck.get(0))))
                                        {
                                            chatMessage = chatMessage.replace(colour(toCheck.get(0)), colour(toCheck.get(1)));
                                        }      
                                        chat = WrappedChatComponent.fromChatMessage(chatMessage)[0];
                                        packet.getChatComponents().write(0, chat);
                                        counter++;
                                    } while (ranks.get(String.valueOf(counter)) != null);
    I am pretty sure the error occurs on line 5 of this code, at BaseComponent[] translatedComponents. However, I am not sure of a workaround for this, personally. Anyone have any ideas?

    Thanks, Plob.

    Bump: Anyone got any ideas on a solution for this? Still stuck with this problem.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  2. Offline

    PDKnight

    I'm not a pro in this, but is it the full error showing in console?
     
  3. Offline

    plobnob

    @PDKnight
    Yes, that is the full console error I get.

    @Comphenix - Any ideas? I am using ProtocolLib to do this, and it seems like you would know that best. I did some research before and saw a post from you saying this method doesn't handle Translate components. Do you know of a way to make it handle these correctly?

    Thanks, Plob.
     
    Last edited: Aug 1, 2015
Thread Status:
Not open for further replies.

Share This Page