Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle) {
- PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
- PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn.intValue(), stay.intValue(), fadeOut.intValue());
- connection.sendPacket(packetPlayOutTimes);
- if (subtitle != null)
- {
- subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
- subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
- IChatBaseComponent titleSub = ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
- PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, titleSub);
- connection.sendPacket(packetPlayOutSubTitle);
- }
- if (title != null)
- {
- title = title.replaceAll("%player%", player.getDisplayName());
- title = ChatColor.translateAlternateColorCodes('&', title);
- IChatBaseComponent titleMain = ChatSerializer.a("{\"text\": \"" + title + "\"}");
- PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleMain);
- connection.sendPacket(packetPlayOutTitle);
- }
- }
- public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title) {
- PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
- PacketPlayOutTitle packetPlayOutTimes = new PacketPlayOutTitle(EnumTitleAction.TIMES, null, fadeIn.intValue(), stay.intValue(), fadeOut.intValue());
- connection.sendPacket(packetPlayOutTimes);
- if (title != null)
- {
- title = title.replaceAll("%player%", player.getDisplayName());
- title = ChatColor.translateAlternateColorCodes('&', title);
- IChatBaseComponent titleMain = ChatSerializer.a("{\"text\": \"" + title + "\"}");
- PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(EnumTitleAction.TITLE, titleMain);
- connection.sendPacket(packetPlayOutTitle);
- }
- }
- public static void sendTabTitle(Player player, String header, String footer)
- {
- if (header == null) {
- header = "";
- }
- header = ChatColor.translateAlternateColorCodes('&', header);
- if (footer == null) {
- footer = "";
- }
- footer = ChatColor.translateAlternateColorCodes('&', footer);
- header = header.replaceAll("%player%", player.getDisplayName());
- footer = footer.replaceAll("%player%", player.getDisplayName());
- PlayerConnection connection = ((CraftPlayer)player).getHandle().playerConnection;
- IChatBaseComponent tabTitle = ChatSerializer.a("{\"text\": \"" + header + "\"}");
- IChatBaseComponent tabFoot = ChatSerializer.a("{\"text\": \"" + footer + "\"}");
- PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
- try
- {
- Field field = headerPacket.getClass().getDeclaredField("b");
- field.setAccessible(true);
- field.set(headerPacket, tabFoot);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- finally
- {
- connection.sendPacket(headerPacket);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement