Пример #1
0
 public void sendTitle(
     Player player, int fadein, int stay, int fadeout, String title, String subtitle) {
   PlayerConnection pConn = ((CraftPlayer) player).getHandle().playerConnection;
   PacketPlayOutTitle pTitleInfo =
       new PacketPlayOutTitle(
           PacketPlayOutTitle.EnumTitleAction.TIMES,
           (IChatBaseComponent) null,
           (int) fadein,
           (int) stay,
           (int) fadeout);
   pConn.sendPacket(pTitleInfo);
   if (subtitle != null) {
     subtitle = subtitle.replaceAll("%player%", player.getDisplayName());
     subtitle = ChatColor.translateAlternateColorCodes('&', subtitle);
     IChatBaseComponent iComp =
         IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
     PacketPlayOutTitle pSubtitle =
         new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.SUBTITLE, iComp);
     pConn.sendPacket(pSubtitle);
   }
   if (title != null) {
     title = title.replaceAll("%player%", player.getDisplayName());
     title = ChatColor.translateAlternateColorCodes('&', title);
     IChatBaseComponent iComp =
         IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + title + "\"}");
     PacketPlayOutTitle pTitle =
         new PacketPlayOutTitle(PacketPlayOutTitle.EnumTitleAction.TITLE, iComp);
     pConn.sendPacket(pTitle);
   }
 }
Пример #2
0
  public static void sendPlayerMessage(Player player, String message) {
    HashMap<String, UrlEntry> urls = new HashMap<>();

    // JsonObject component = new JsonObject();
    String result = message;
    while (Regex.isMatch(result, REGEX_URL)) {
      String[] groups = Regex.getGroups(message, REGEX_URL);
      String url = groups[0];
      String name = groups[1];
      urls.put("\\{URL_" + (urls.size() + 1) + "\\}", new UrlEntry(url, name));
      result = Regex.replace(result, REGEX_URL, "\\{URL_" + (urls.size() + 1) + "\\}");
    }

    for (Map.Entry<String, UrlEntry> entry : urls.entrySet()) {
      result = result.replace(entry.getKey(), entry.getValue().getJson());
    }

    // component.addProperty("text", "test");

    IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(result);
    Bukkit.broadcastMessage("Sending: " + comp.getText());
    PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 0);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
  }
Пример #3
0
 public static IChatBaseComponent toICBC(String s) {
   return IChatBaseComponent.ChatSerializer.a(s);
 }