Advertisement
Evyatar12

header

Mar 5th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. public static void sendTablist(Player p, String header, String footer) {
  2.         if (header == null)
  3.             header = "";
  4.         if (footer == null)
  5.             footer = "";
  6.         header = ChatColor.translateAlternateColorCodes('&', header);
  7.         footer = ChatColor.translateAlternateColorCodes('&', footer);
  8.  
  9.         header = header.replaceAll("%PLAYER%", p.getDisplayName());
  10.         footer = footer.replaceAll("%PLAYER%", p.getDisplayName());
  11.  
  12.         PlayerConnection con = ((CraftPlayer) p).getHandle().playerConnection;
  13.  
  14.         IChatBaseComponent tabheader = ChatSerializer.a("{\"text\": \""
  15.                 + header + "\"}");
  16.         IChatBaseComponent tabfooter = ChatSerializer.a("{\"text\": \""
  17.                 + footer + "\"}");
  18.  
  19.         PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter(
  20.                 tabheader);
  21.         try {
  22.             Field f = packet.getClass().getDeclaredField("b");
  23.             f.setAccessible(true);
  24.             f.set(packet, tabfooter);
  25.         } catch (Exception e) {
  26.             e.printStackTrace();
  27.         } finally {
  28.             con.sendPacket(packet);
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement