How to add colors to console messages

Discussion in 'Plugin Development' started by iKeirNez, May 23, 2012.

Thread Status:
Not open for further replies.
  1. Since bukkit now supports ANSICon, how do I change the Colour of text I print to the console?

    I have tries Color, ChatColor and many other methods with no success.
  2. Offline


    ChatColor should work, does your console support color?
  3. Offline


    Im guessing That ANSICon would have its own Api to use to send color messages but only a guess.
  4. Offline


    I'm pretty sure that ChatColor=Color should work...
    No guarantees though...
  5. Tried that didn't work, I tried System.out and the Logger, also yes it does. I have seen it.

    I looked but I cannot find any API, even I know it must have one.

    Tried that, doesn't work.
  6. Offline


    vsams14 said:
    I'm pretty sure that ChatColor=Color should work...
    No guarantees though...​
    Tried that, doesn't work.
    Did you try ChatColor=Red? Because that wont work, try ChatColor.RED + "Your string here";
  7. Tried that too :\
  8. Offline


    Are you printing to the console via a Logger or what? Because Logger isn't part of Bukkit, so I doubt ChatColor will work for it. What are we dealing with here?
  9. I have tried by doing: Bukkit.getLogger.log(Level.INFO, ChatColor.RED + "This should be red");

    and I have also tried System.out.println(ChatColor.RED + "This should be red.");

    neither work, but I know the console works becuase I have seen colors in it when doing /reload and chatting and doing /say etc.

  10. Offline


    Well i dont think the colorcodes in ChatColor has the same codes as the ones for ANSI. Try lookin the colors up and send those to the console instead. They look like this ( [35;1m )
  11. Offline


    Yeah, I wouldn't expect those to work.

    ChatColor.RED is just a char (or a String, I don't remember) that Bukkit can pick up on and go "Oh, this means all the text from here on out is red."

    System.out is native to Java. It doesn't care that there's the Bukkit color-change character in what it's printing. It'll just print the chars in plaintext. Let me guess, when you tried it with that method, it printed some odd symbols before your text? Probably &4 or something to that effect?

    The same thing applies to Bukkit.getLogger(). It's returning a java.util.logging.Logger, which is not part of Bukkit either.

    What you CAN do, though, is this:
    //Get a reference to the server, whichever way you can
    Server server = ...
    ConsoleCommandSender console = server.getConsoleSender();
    //Send the console something!
    console.sendMessage(ChatColor.RED + "It's but a flesh wound!");
    This should work.
  12. Offline


    We have a winner! :D

    It's a String - the unicode 00A7 (§) followed by a character which is a hex digit.

    Yep, this will definitely work (assuming your console terminal actually supported ANSI colour codes). The ConsoleCommandSender will in fact be an instance of the CraftBukkit ColouredConsoleSender (a class that can't be instantiated directly by plugins), which contains the logic to map the Minecraft colour sequences (§) to ANSI control codes - see

  13. Thanks! This works! Also isn't that a Monty Python quote?

    Yeah, I use ANSICon on Windows and it works! Thanks to you and Everdras its working!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 25, 2016
  14. Nice, but I'm curious, does these colors work for other OSs that have built in colored consoles ?
  15. Offline


    I can confirm it works on Linux using gnome-terminal (I would expect it to work with most terminal emulators, e.g. kconsole, xterm, etc.).
  16. Yes, I have tried in Ubuntu and it works. I am pretty sure its only Windows that doesn't have color support.
  17. Yep, unless you install ANSICon XD

    Thanks for replies :p I'm going to add this as an option in my plugin.

    Hmm, I got in a bit of a annoyance behaviour... apart from the fact that this new jline thing removes the ability to use up/down arrows to repeat previous commands, the colors display fine but the server.log has those escape characters with color string, how can I filter them out for server.log but not the console ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 25, 2016
  18. Offline


    I use
    Bukkit.broadcastMessage(ChatColour.COLOUR + "MESSAGE HERE");
  19. Good for you but this thread is about printing in the console, not in the chat for players.
  20. Yeah, that would work but it also sends to players, this is just for console messages in color.
  21. Offline


    Ohh, you mean console messages. I did not know you could get them colourful
  22. You can if you use the latest update, if you are on Windows though you will have to install ANSICon, because the Windows Console does not natively support colours.
  23. So... I repeat my question due to irelevant posts...
    How do I skip color characters from being stored in server.log while using them to color the console ?
  24. Hmmmm, I'm sure I saw this somewhere, I'll look for it and tell you if I find it.
  25. Offline


    I am not sure if this will apply to you, but I use a .sh script to filter out all color messages. That would only work if you were using a Linux distribution such as Ubuntu server, but here it is anyways:
    I include this in my auto restart script every day and I use absolute directories, but I changed them to be relative for this.
    That copies the log into a /logs/DATE.log file, and removes the colors from the copy.

    EDIT: Sorry for posting this, I didn't realize how old this thread was!
  26. Offline


    I have colors in console, but i'm still having the ESC symbols in the log file.

    I found this bukkit page with someone saying, "You can use the "log-strip-colors" option when starting the server to make it strip this from the server.log output.":

    But how do you do that?
  27. Offline


    I think I just figured it out. Change your command that you start your server with with --log-strip-color, like this:
    java -Xms1g -Xmx1g -jar craftbukkit.jar --log-strip-color
    This works for me!
    If you need to reply so that I will listen please tag me with daboross
    spydercanopus likes this.
  28. Offline


    Thanks JOPHESTUS just what i wanted i thought this forum ment something else. well its just what code i needed thanks! all i wanted to do is make onEnable and onDisabled messages in console in color!
Thread Status:
Not open for further replies.

Share This Page