Utilizing Title Packets [1.8 Compatible Servers]

Discussion in 'Plugin Help/Development/Requests' started by Monkeyboystein, Nov 2, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Monkeyboystein

    I was recently on Mineplex and I noticed they were using the title feature in 1.8 for 1.8 clients, and I thought to myself there is no 1.8 API out yet, so they must have custom coded it which means its possible, so I played around a bit with the packets and I came out with this class,


    Code:java
    1. package monkeyboystein;
    2.  
    3. import net.minecraft.server.v1_7_R4.ChatComponentText;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
    8. import org.bukkit.entity.Player;
    9. import org.spigotmc.ProtocolInjector;
    10.  
    11. /**
    12. * Created by Andrew on 11/2/2014.
    13. */
    14. public class Title {
    15. String message = "";
    16. ProtocolInjector.PacketTitle.Action action = null;
    17. int in = 0;
    18. int out = 0;
    19. int stay = 0;
    20. public Title(String m, ProtocolInjector.PacketTitle.Action a, int i, int o, int s)
    21. {
    22. message = m;
    23. action = a;
    24. in = i;
    25. out = o;
    26. stay = s;
    27. }
    28. public static final int TITLE_PROTOCOL_VERSION = 18;
    29. ProtocolInjector.PacketTitle packet = null;
    30. public void build()
    31. {
    32. if(action == ProtocolInjector.PacketTitle.Action.TIMES)
    33. {
    34.  
    35. ProtocolInjector.PacketTitle title = new ProtocolInjector.PacketTitle(action,in,stay,out);
    36.  
    37. packet = title;
    38. }
    39. else if(action == ProtocolInjector.PacketTitle.Action.CLEAR || action == ProtocolInjector.PacketTitle.Action.RESET)
    40. {
    41. ProtocolInjector.PacketTitle title = new ProtocolInjector.PacketTitle(action);
    42.  
    43. packet = title;
    44. }
    45. else if(action == ProtocolInjector.PacketTitle.Action.TITLE || action == ProtocolInjector.PacketTitle.Action.SUBTITLE)
    46. {
    47. ProtocolInjector.PacketTitle title = new ProtocolInjector.PacketTitle(action, new ChatComponentText(ChatColor.translateAlternateColorCodes('&',message)));
    48. packet = title;
    49. }
    50. }
    51. public void send(Player player) {
    52. if (packet == null) return;
    53. if (player == null) {
    54. for (Player p : Bukkit.getOnlinePlayers())
    55. {
    56. send(p);
    57. }
    58.  
    59. } else if (hasTitleSupport(player)) {
    60. ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    61. }
    62. }
    63. public static boolean hasTitleSupport(CommandSender sender) {
    64. return sender instanceof CraftPlayer &&
    65. ((CraftPlayer) sender).getHandle().playerConnection.networkManager.getVersion()
    66. >= TITLE_PROTOCOL_VERSION;
    67. }
    68. }
    69.  


    Which works pretty well,
    Example:
    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent event)
    3. {
    4. if(event.getPlayer().getName().equalsIgnoreCase("Andrewcpu") && event.getPlayer().getItemInHand().getType()==Material.DIAMOND_SWORD)
    5. {
    6. for(Player p : Bukkit.getOnlinePlayers())
    7. {
    8. Title title = new Title(event.getMessage(),Action.TITLE,5,5,5);
    9. title.build();
    10. title.send(p);
    11. Title subtitle = new Title("&6- " + event.getPlayer().getDisplayName(),Action.SUBTITLE,5,5,5);
    12. subtitle.build();
    13. subtitle.send(p);
    14. event.setCancelled(true);
    15. }
    16.  
    17. }
    18. }
    19.  


    Usage:
    Code:java
    1. Title title = new Title("The message here",Action.TITLE/SUBTITLE/TIMES/RESET/CLEAR,inTime,outTime,stayTime);
    2. /* in out stay times only apply when using the Action.TIMES but you must put them in */
    3. title.build();
    4. title.send(player);
    5. Title timing = new Title("",Action.TIMES,1,1,2);
    6. timing.build();
    7. timing.send(player);
    8.  



    I read through the rules and I didnt see anything against *modified* servers, but if its breaks a rule I missed let me know and ill remove this post
     
  2. Monkeyboystein
    You do realize that ProtocolInjector is a Spigot class, and you're posting this on Bukkit forums?
     
  3. Offline

    Monkeyboystein

    I do realize, but I figured people use bukkit as well as spigot, and people who use spigot are also on the bukkit forums, so it could help them,
     
  4. Monkeyboystein
    But wouldn't this fit better in the Spigot forums as this is for Spigot only? Also I'd like to point out that this section is for Bukkit resources only, hence the "Bukkit" parent directory.
     
  5. Offline

    MiniDigger

    Monkeyboystein mineplex most likely don't that with the bungeecord api since there is a api for title in bungeecord. Good ressource anyways
     
  6. Offline

    jts3304

    I do realize this post is kind of old and its not in the correct place, but I have been looking for a way to send title packets.

    So I am making a deathmatch minigame and I want a player to have a title displayed on their screen when they get a kill.

    Example;

    Title: Longshot +60
    Subtitle: Kill a player from 50m+

    I have written the packets and they are ready to send. Here is what i wrote for the them:
    Code:
    PacketPlayOutTitle packet = new PacketPlayOutTitle(fadein, show, fadeout);
    PacketPlayOutTitle packet1 = new PacketPlayOutTitle(EnumTitleAction.TITLE, getRevisedIChatBaseComponent(title));
    If there is a way to send packets written like this please tell me.
     
Thread Status:
Not open for further replies.

Share This Page