Esempio n. 1
0
  public static void sendTabTitle(Player player, String header, String footer) {
    if (header == null) {
      header = "";
    }

    header = ChatColor.translateAlternateColorCodes((char) '&', (String) header);

    if (footer == null) {
      footer = "";
    }

    footer = ChatColor.translateAlternateColorCodes((char) '&', (String) footer);
    header = header.replaceAll("%player%", player.getDisplayName());
    footer = footer.replaceAll("%player%", player.getDisplayName());
    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
    IChatBaseComponent tabTitle =
        IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + header + "\"}"));
    IChatBaseComponent tabFoot =
        IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + footer + "\"}"));
    PacketPlayOutPlayerListHeaderFooter headerPacket =
        new PacketPlayOutPlayerListHeaderFooter(tabTitle);

    try {
      Field field = headerPacket.getClass().getDeclaredField("b");
      field.setAccessible(true);
      field.set((Object) headerPacket, (Object) tabFoot);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      connection.sendPacket(headerPacket);
    }
  }
Esempio n. 2
0
  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((char) '&', (String) subtitle);
      IChatBaseComponent titleSub =
          IChatBaseComponent.ChatSerializer.a((String) ("{\"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((char) '&', (String) title);
      IChatBaseComponent titleMain =
          IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + title + "\"}"));
      PacketPlayOutTitle packetPlayOutTitle =
          new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, titleMain);
      connection.sendPacket(packetPlayOutTitle);
    }
  }
Esempio n. 3
0
 public static void sendActionBar(Player player, String message) {
   CraftPlayer p = (CraftPlayer) player;
   IChatBaseComponent cbc =
       IChatBaseComponent.ChatSerializer.a((String) ("{\"text\": \"" + message + "\"}"));
   PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);
   p.getHandle().playerConnection.sendPacket(ppoc);
 }
Esempio n. 4
0
 public void sendMessageRaw(Player player, String message) {
   if (player instanceof CraftPlayer) {
     ((CraftPlayer) player)
         .getHandle()
         .playerConnection
         .sendPacket(new PacketPlayOutChat(IChatBaseComponent.ChatSerializer.a(message)));
   }
 }
Esempio n. 5
0
 public void sendMessageActionBar(Player player, String message) {
   if (player instanceof CraftPlayer) {
     IChatBaseComponent cbc =
         IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + JSONObject.escape(message) + "\"}");
     ((CraftPlayer) player)
         .getHandle()
         .playerConnection
         .sendPacket(new PacketPlayOutChat(cbc, (byte) 2));
   }
 }