Tablist issues 1.9.4

Discussion in 'Spigot Plugin Development' started by Simagdo, May 25, 2016.

  1. Hey there,
    I updated my plugin to 1.9.4 which was still on 1.8. Now i have issues with the tablist.

    Code (Text):

    public void sendHeaderAndFooter(Player player, String head, String foot) {
       head = "┬žaWillkommen auf MineGame-mc.de";
       foot = "┬žaminegame-mc.de";

       PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
       IChatBaseComponent header = IChatBaseComponent.ChatSerializer.a("{'color':'', 'text':'" + head + "'}");
       IChatBaseComponent footer = IChatBaseComponent.ChatSerializer.a("{'color':'', 'text':'" + foot + "'}");

       PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
       try {
          Field headerField = packet.getClass().getDeclaredField("a");
          headerField.setAccessible(true);
          headerField.set(packet, header);
          headerField.setAccessible(!headerField.isAccessible());

          Field footerField = packet.getClass().getDeclaredField("b");
          footerField.setAccessible(true);
          footerField.set(packet, footer);
          footerField.setAccessible(!footerField.isAccessible());
       } catch (Exception e) {
          e.printStackTrace();
       }
       connection.sendPacket(packet);
    }
     
    Issue:
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.PlayerList.onPlayerJoin(PlayerList.java:333) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.PlayerList.a(PlayerList.java:159) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.LoginListener.b(LoginListener.java:144) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.LoginListener.c(LoginListener.java:54) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.NetworkManager.a(NetworkManager.java:233) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.ServerConnection.c(ServerConnection.java:140) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:825) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [spigot.jar:git-Spigot-4af49dc-4e19de1]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 3
    at com.google.gson.internal.Streams.parse(Streams.java:56) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:54) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.ChatDeserializer.a(SourceFile:501) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.ChatDeserializer.a(SourceFile:512) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.IChatBaseComponent$ChatSerializer.a(SourceFile:205) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at de.simagdo.simagdoLobby.methods.sendHeaderAndFooter.sendHeaderAndFooter(sendHeaderAndFooter.java:25) ~[?:?]
    at de.simagdo.simagdoLobby.handler.gameHandler.onPlayerJoin(gameHandler.java:79) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    ... 14 more
    Caused by: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 3
    at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1505) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.stream.JsonReader.checkLenient(JsonReader.java:1386) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:488) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:403) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:666) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.internal.bind.TypeAdapters$25.read(TypeAdapters.java:642) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.internal.Streams.parse(Streams.java:44) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:54) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.ChatDeserializer.a(SourceFile:501) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.ChatDeserializer.a(SourceFile:512) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at net.minecraft.server.v1_9_R2.IChatBaseComponent$ChatSerializer.a(SourceFile:205) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    at de.simagdo.simagdoLobby.methods.sendHeaderAndFooter.sendHeaderAndFooter(sendHeaderAndFooter.java:25) ~[?:?]
    at de.simagdo.simagdoLobby.handler.gameHandler.onPlayerJoin(gameHandler.java:79) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_91]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_91]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-4af49dc-4e19de1]
    ... 14 more
    Error line 25:
    IChatBaseComponent header = IChatBaseComponent.ChatSerializer.a("{'color':'', 'text':'" + head + "'}");
     
  2. That's why I don't work with NMS code.
     
    • Agree Agree x 2
  3. You need to update your imports. Since your not using reflection of is version specific for the version of imports you are using
     
  4. The error says that it is malformed JSON so try taking a look at that.
     
  5. I know it's an old thread but could I bump this? :/

    I'm having the exact same issue and I can't find a solution anywhere else.
     
  6. 1) don't necropost
    2) the JSON strings are incorrect. You need to get the string using JSONObject.
     
  7. Already figured it out:
    For people looking at this thread, go and make sure that you're using the right methods for 1.9, 1.10, and/or 1.8.
    My plugin has a method to check what version the server's running and create a tab message in the specific manner for that version.

    If you want code for this, message me at www.minedrix.com/profile/5222917