Does anyone know a working Title/SubTitleAPI? 1.8

Discussion in 'Spigot Plugin Development' started by Moderance, Jun 23, 2016.

  1. Subject says it all, I can't find or know of anyway on how to set titles/sub titles for 1.8
     
  2. @Moderance
    Code (Text):
    public static void sendPacket(Player p, Object packet) {
                String path = Bukkit.getServer().getClass().getPackage().getName();
                String version = path.substring(path.lastIndexOf(".") + 1, path.length());
                try {
                  Method getHandle = p.getClass().getMethod("getHandle");
                  Object entityPlayer = getHandle.invoke(p);
                  Object pConnection = entityPlayer.getClass().getField("playerConnection").get(entityPlayer);
                  Class<?> packetClass = Class.forName("net.minecraft.server." + version + ".Packet");
                  Method sendMethod = pConnection.getClass().getMethod("sendPacket", new Class[] {packetClass});
                  sendMethod.invoke(pConnection, new Object[] {packet});
                } catch (Exception e) {
                  e.printStackTrace();
                }
              }


    public static void sendTitle(Player p, String title) {
        IChatBaseComponent message = ChatSerializer.a("{\"text\": \"\"}").a(title);
        PacketPlayOutTitle packet = new PacketPlayOutTitle(EnumTitleAction.TITLE, message);

        sendPacket(p, packet);
      }

      public static void sendSubTitle(Player p, String subtitle) {
        IChatBaseComponent message = ChatSerializer.a("{\"text\": \"\"}").a(subtitle);
        PacketPlayOutTitle packet = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, message);

        sendPacket(p, packet);
      }
     
    • Like Like x 1
  3. Don't suppose you know how to change the timings for the packets, like how long they stay up etc
     
  4. of course. @Moderance

    Just learn a little bit of Packets. :)

    If i Helped you. give me a Like.

    Code (Text):
    public static void sendTiming(Player p, int fadeIn, int stay, int fadeOut) {
        try {
          Object h = getHandle(p);
          Object c = getField(h.getClass(), "playerConnection").get(h);

          Object packet =
              PacketPlayOutTitle.class.getConstructor(
                  new Class[] {PacketPlayOutTitle.class, Integer.TYPE, Integer.TYPE, Integer.TYPE})
                  .newInstance(
                      new Object[] {EnumTitleAction.TIMES, Integer.valueOf(fadeIn),
                          Integer.valueOf(stay), Integer.valueOf(fadeOut)});
          getMethod(h.getClass(), "sendPacket", new Class[0]).invoke(c, new Object[] {packet});
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
     
    • Like Like x 1