Bungeecord Chatcolor help

Discussion in 'BungeeCord Plugin Development' started by Tomdaarom, Sep 22, 2017.

  1. Hello everyone, I made a Modchat for my server and everything is working just fine. The Chatcolor for the Mod chat is yellow, but the second line of the message is turning into white.
    This is the code of my plugin :

    Code (Text):
    package me.king.main;

    import net.md_5.bungee.BungeeCord;
    import net.md_5.bungee.api.ChatColor;
    import net.md_5.bungee.api.CommandSender;
    import net.md_5.bungee.api.chat.TextComponent;
    import net.md_5.bungee.api.config.ServerInfo;
    import net.md_5.bungee.api.connection.ProxiedPlayer;
    import net.md_5.bungee.api.connection.Server;
    import net.md_5.bungee.api.plugin.Command;

    public class StaffChat
      extends Command
      public StaffChat()
        super("mc", "bizzcraft.staffchat", new String[] { "modchat", "mcmodchat" });
      public void execute(CommandSender cs, String[] args)
        if (args.length == 0)
          cs.sendMessage(new TextComponent("§cNope! :3"));
          StringBuilder builder = new StringBuilder();
          for (int i = 0; i < args.length; i++) {
            builder.append(args[i]).append(" ");
          String message = ChatColor.translateAlternateColorCodes('&', builder.toString().trim());
          for (ProxiedPlayer pl : BungeeCord.getInstance().getPlayers())
            ProxiedPlayer sender1 = (ProxiedPlayer)cs;
            if (pl.hasPermission("bizzcraft.staffchat.send")) {
              pl.sendMessage(new TextComponent("§7[" + sender1.getServer().getInfo().getName() + "§7]<§9Mod Chat§7> §f" + sender1.getName() + "§7: §e" + ChatColor.YELLOW + message));

    Attached Files:

  2. This is caused by the JSON formatting of the chat message. You cannot prevent that afaik because it is a client side bug. You'd need to add another color code once the second row is reached but there is no good method to determine that.
  3. If you use a Component builder you can use its #setColor(Color) method, which will work.
  4. TextComponent#fromLegacyText( text );