Advertisement
Guest User

Title Announcement + Tab Header/Footer

a guest
Apr 13th, 2015
1,251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Icon 3.25 KB | None | 0 0
  1.     public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
  2.         PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
  3.         PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn.intValue(), stay.intValue(), fadeOut.intValue());
  4.         connection.sendPacket(packetPlayOutTimes);
  5.         if (subtitle != null)
  6.         {
  7.           subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
  8.           subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
  9.           IChatBaseComponent titleSub = ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
  10.           PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleSub);
  11.           connection.sendPacket(packetPlayOutSubTitle);
  12.         }
  13.         if (title != null)
  14.         {
  15.           title = title.replaceAll("%player%", player.getDisplayName());
  16.           title = ChatColor.translateAlternateColorCodes('&', title);
  17.           IChatBaseComponent titleMain = ChatSerializer.a("{\"text\": \"" + title + "\"}");
  18.           PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleMain);
  19.           connection.sendPacket(packetPlayOutTitle);
  20.         }
  21.        
  22.     }
  23.    
  24.     public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title) {
  25.         PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
  26.         PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn.intValue(), stay.intValue(), fadeOut.intValue());
  27.         connection.sendPacket(packetPlayOutTimes);
  28.         if (title != null)
  29.         {
  30.           title = title.replaceAll("%player%", player.getDisplayName());
  31.           title = ChatColor.translateAlternateColorCodes('&', title);
  32.           IChatBaseComponent titleMain = ChatSerializer.a("{\"text\": \"" + title + "\"}");
  33.           PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleMain);
  34.           connection.sendPacket(packetPlayOutTitle);
  35.         }
  36.        
  37.     }
  38.    
  39.       public static void sendTabTitle(Player player, String header, String footer)
  40.       {
  41.         if (header == null) {
  42.           header = "";
  43.         }
  44.         header = ChatColor.translateAlternateColorCodes('&', header);
  45.         if (footer == null) {
  46.           footer = "";
  47.         }
  48.         footer = ChatColor.translateAlternateColorCodes('&', footer);
  49.        
  50.         header = header.replaceAll("%player%", player.getDisplayName());
  51.         footer = footer.replaceAll("%player%", player.getDisplayName());
  52.        
  53.         PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
  54.         IChatBaseComponent tabTitle = ChatSerializer.a("{\"text\": \"" + header + "\"}");
  55.         IChatBaseComponent tabFoot = ChatSerializer.a("{\"text\": \"" + footer + "\"}");
  56.         PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
  57.         try
  58.         {
  59.           Field field = headerPacket.getClass().getDeclaredField("b");
  60.           field.setAccessible(true);
  61.           field.set(headerPacket, tabFoot);
  62.         }
  63.         catch (Exception e)
  64.         {
  65.           e.printStackTrace();
  66.         }
  67.         finally
  68.         {
  69.           connection.sendPacket(headerPacket);
  70.         }
  71.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement