How to send a title to a player :: [Without API]

Discussion in 'Spigot Plugin Development' started by fujiboy4, May 26, 2015.

  1. Hello! I would like to know how to send a title/subtitle to a player. WITHOUT AN API.

    I'm assuming that it would be something like this:
    Code (Text):
    Title title = new Title();

    title.titleMessage(int fadeIn, int stay, int fadeOut, String);
     
  2. It isn't that. If it was that then there wouldn't be a need for API's. Titles involves NMS and wacky other stuff.
     
  3. Do you know of a good API for titles. I've tried many, they dont seem to work.
     
  4. Here's an util I'm using:
    Code (Text):
      @Deprecated
      public static void sendTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message)
      {
        sendTitle(player, fadeIn, stay, fadeOut, message, null);
      }
     
      @Deprecated
      public static void sendSubtitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String message)
      {
        sendTitle(player, fadeIn, stay, fadeOut, null, message);
      }
     
      @Deprecated
      public static void sendFullTitle(Player player, Integer fadeIn, Integer stay, Integer fadeOut, String title, String subtitle)
      {
        sendTitle(player, fadeIn, stay, fadeOut, title, subtitle);
      }
     
      @Deprecated
      public static Integer getPlayerProtocol(Player player)
      {
        return Integer.valueOf(47);
      }
     
      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(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 = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
          PacketPlayOutTitle packetPlayOutSubTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, titleSub);
          connection.sendPacket(packetPlayOutSubTitle);
        }
        if (title != null)
        {
          title = title.replaceAll("%player%", player.getDisplayName());
          title = ChatColor.translateAlternateColorCodes('&', title);
          IChatBaseComponent titleMain = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
          PacketPlayOutTitle packetPlayOutTitle = new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
          connection.sendPacket(packetPlayOutTitle);
        }
      }
     
     
  5. My plugin NiftyBukkit supports 1.7.10 through 1.8.3+:

    Code (Java):
    String title = "Welcome";
    String subtitle = "to my server";

    try {
        TitleManager title = new TitleManager(title, subtitle);
        title.setTimeFadeIn(0);
        title.setTimeStay(40);
        title.setTimeFadeOut(0);
        title.broadcastTitle();
    } catch (Exception ex) {
        // Unable to send title, check reason, possibly report it to me
    }
     
  6. Nogtail

    Artist

    ProtocolLib is useful for this kind of stuff, just send a new title packet. I guess this counts as an external API but it is used for so many plugins it is probably already installed on most servers.
     
    • Agree Agree x 1
  7. Kinda impossible to do it without an API.
     
  8. Look at my snipets. It is possible. In only 10 lines of code.
     
  9. Yep.
     
  10. Uhm, all I can see is that you call some API methods.
     
  11. Bukkit api, yes. Please code me a working toaster without any additional hardware.
     
    • Funny Funny x 1