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

Fixed Invalid JSON Format #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SteuerungC
Copy link

On PaperSpigot 1.9 an error occoures when the plugin tries to send a JSON-formated Title to a player, e.g. on Arena Join:

[17:47:05] [Server thread/WARN]: java.lang.reflect.InvocationTargetException
[17:47:05] [Server thread/WARN]:    at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
[17:47:05] [Server thread/WARN]:    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[17:47:05] [Server thread/WARN]:    at java.lang.reflect.Method.invoke(Method.java:498)
[17:47:05] [Server thread/WARN]:    at tntrun.utils.Title.send(Title.java:270)
[17:47:05] [Server thread/WARN]:    at tntrun.utils.TitleMsg.sendFullTitle(TitleMsg.java:36)
[17:47:05] [Server thread/WARN]:    at tntrun.arena.handlers.GameHandler.startEnding(GameHandler.java:425)
[17:47:05] [Server thread/WARN]:    at tntrun.arena.handlers.GameHandler.handlePlayer(GameHandler.java:299)
[17:47:05] [Server thread/WARN]:    at tntrun.arena.handlers.GameHandler$3.run(GameHandler.java:261)
[17:47:05] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftTask.run(CraftTask.java:58)
[17:47:05] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_9_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:352)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:822)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:404)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:723)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:622)
[17:47:05] [Server thread/WARN]:    at java.lang.Thread.run(Thread.java:745)
[17:47:05] [Server thread/WARN]: Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 3
[17:47:05] [Server thread/WARN]:    at com.google.gson.internal.Streams.parse(Streams.java:56)
[17:47:05] [Server thread/WARN]:    at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:54)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.ChatDeserializer.a(SourceFile:501)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.ChatDeserializer.a(SourceFile:512)
[17:47:05] [Server thread/WARN]:    at net.minecraft.server.v1_9_R1.IChatBaseComponent$ChatSerializer.a(SourceFile:205)
[17:47:05] [Server thread/WARN]:    ... 15 more
[17:47:05] [Server thread/WARN]: Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 3
[17:47:05] [Server thread/WARN]:    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505)
[17:47:05] [Server thread/WARN]:    at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386)
[17:47:05] [Server thread/WARN]:    at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:497)
[17:47:05] [Server thread/WARN]:    at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:403)
[17:47:05] [Server thread/WARN]:    at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:666)
[17:47:05] [Server thread/WARN]:    at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:642)
[17:47:05] [Server thread/WARN]:    at com.google.gson.internal.Streams.parse(Streams.java:44)
[17:47:05] [Server thread/WARN]:    ... 19 more

To prevent this error you need to put the JSON-keys in quoutes.
I think it will worked with the changes in this pull request. Because you have dependencies to a paid plugin extension I was not able to compile the plugin and test the changes.
There is also a problem with you line breaks the java-files will appear here as complete changed. Changed were only made in the following lines:
Title.java: 272, 274, 283 and 287
Title_1_7_R4.java: 250, 252, 262 and 267
It would be fine if you update your plugin as fast as possible.

@Gabscap
Copy link

Gabscap commented May 6, 2016

This doesnt seem to work. Now I get
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 34
I think the color value must be quoted.
So

                // Send title
                Object serialized = getMethod(nmsChatSerializer, "a",
                        String.class).invoke(
                        null,
                        "{\"text\":\""
                                + ChatColor.translateAlternateColorCodes('&',
                                        title) + "\",\"color\":"
                                + titleColor.name().toLowerCase() + "}");
                packet = packetTitle.getConstructor(packetActions,
                        chatBaseComponent).newInstance(actions[0], serialized);
                sendPacket.invoke(connection, packet);
                if (subtitle != "") {
                    // Send subtitle if present
                    serialized = getMethod(nmsChatSerializer, "a", String.class)
                            .invoke(null,
                                    "{\"text\":\""
                                            + ChatColor
                                                    .translateAlternateColorCodes(
                                                            '&', subtitle)
                                            + "\",\"color\":"
                                            + subtitleColor.name()
                                                    .toLowerCase() + "}");
                    packet = packetTitle.getConstructor(packetActions,
                            chatBaseComponent).newInstance(actions[1],
                            serialized);
                    sendPacket.invoke(connection, packet);
                }

to

                // Send title
                Object serialized = getMethod(nmsChatSerializer, "a",
                        String.class).invoke(
                        null,
                        "{\"text\":\""
                                + ChatColor.translateAlternateColorCodes('&',
                                        title) + "\",\"color\":\""
                                + titleColor.name().toLowerCase() + "\"}");
                packet = packetTitle.getConstructor(packetActions,
                        chatBaseComponent).newInstance(actions[0], serialized);
                sendPacket.invoke(connection, packet);
                if (subtitle != "") {
                    // Send subtitle if present
                    serialized = getMethod(nmsChatSerializer, "a", String.class)
                            .invoke(null,
                                    "{\"text\":\""
                                            + ChatColor
                                                    .translateAlternateColorCodes(
                                                            '&', subtitle)
                                            + "\",\"color\":\""
                                            + subtitleColor.name()
                                                    .toLowerCase() + "\"}");
                    packet = packetTitle.getConstructor(packetActions,
                            chatBaseComponent).newInstance(actions[1],
                            serialized);
                    sendPacket.invoke(connection, packet);
                }

@Shevchik
Copy link
Member

Shevchik commented May 6, 2016

I think you should just use spigot title api, because 1.8 support is dropped anyway.

@Gabscap
Copy link

Gabscap commented May 6, 2016

Its the newest version (1.9) of Paper.

@Gabscap
Copy link

Gabscap commented May 6, 2016

Unfortunately I cant test it by myself, because it is not compilable.

@tadeas-drab
Copy link
Collaborator

This api for title is broken, tomorrow will be new

@Gabscap
Copy link

Gabscap commented May 6, 2016

Thank You

@tadeas-drab
Copy link
Collaborator

You can test it myself, only remove imports and error methods

@Gabscap
Copy link

Gabscap commented May 6, 2016

Ok, I did like you said and with my changes the title messages are working again, but I would like to see a new title system.

@Katta01
Copy link

Katta01 commented Aug 19, 2022

{tnt_run must be in arena bounds} please can u solve guys

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

Successfully merging this pull request may close these issues.

5 participants