Solved How to send Tablist and get the player's ping in 1.17

Discussion in 'Spigot Plugin Development' started by Xitecraft1, Jun 14, 2021.

  1. How can i send a tablist (header, footer) to a player and get the player's ping in Spigot 1.17?

    I've used this
    Code (Text):
        public static Integer getPing(Player p) {
            return ((CraftPlayer) p).getHandle().ping;
        }
        public static void sendTab(Player p, String msg1, String msg2) {
          PacketPlayOutPlayerListHeaderFooter packetPlayOutPlayerListHeaderFooter = new PacketPlayOutPlayerListHeaderFooter();
          packetPlayOutPlayerListHeaderFooter.header = IChatBaseComponent.ChatSerializer.a("{\"text\": \""+msg1+"\"}");
          packetPlayOutPlayerListHeaderFooter.footer = IChatBaseComponent.ChatSerializer.a("{\"text\": \""+msg2+"\"}");
          ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packetPlayOutPlayerListHeaderFooter);
        }
    but now it doesn't work anymore.
     
  2. It works now with:
    Code (Text):
        public static Integer getPing(Player p) {
            return ((CraftPlayer)p).getPing();
        }
        public static void sendTab(Player p, String msg1, String msg2) {
            p.setPlayerListHeaderFooter(msg1, msg2);
        }
     
  3. hey! Personally for my part I have since 1.17 a problem because it tells me that the maximum size is 16 characters while in 1.16 there was none ...
     
  4. getPing() now exists in interface Player, so you can just do p.getPing()