Need help with my modchat

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.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. Rather than using ChatColor#translateAlternateColorCodes, you should take a look at BaseComponent#setColor.

    EDIT: For your use case, TextComponent#fromLegacyText is more useful though I think.
  3. this section is for spigot related development only, take a look here for bungeecord support:
  4. I don't have much experience with both ChatColor#translateAlternateColorCodes and BaseComponent#setColor. I'm just trying to get this plugin working because it is starting to annoy the other staff members now, haha. Is there any other information your able to give me?
  5. just report your post so staff will review it and it gets moved :)
  6. You should really look around in the documentation.
    ChatColor#translateAlternateColorCodes basically just replaces a specific symbol with the minecraft color code symbol (§).
    TextComponent#fromLegacyText can then be used to convert the color-coded message to a proper JSON message, whose colors will span over multiple lines.
  7. mathhulk

    mathhulk Retired Moderator

    Moved to BungeeCord Plugin Development.
  8. So I basically just have to change the ChatColor.translateAlternateColorCodes to TextComponent#fromLegacyText?
  9. I think you'll also have to keep ChatColor.translateAlternateColorCodes (make that the argument for the fromLegacyText). That will give you a TextComponent back.