Color Chat in Console

Discussion in 'Plugin Development' started by ThunderWaffeMC, Jun 9, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ThunderWaffeMC

    How can I add color to text in the console? I've seen it before but I don't know how to do it and am quite curious.

    Thanks in advance!
     
  2. Offline

    kreashenz

    ThunderWaffeMC Are you talking about a cmd.exe console, or a multicraft like one?
    For CMD.exe ones, you can just use '§' or ChatColor to make it coloured, but I don't think it works in onEnable() methods.
    For multicraft ones, I don't think it's possible.
     
  3. Offline

    ZeusAllMighty11

    kreashenz

    Actually, the command prompt does not display the section symbol as colour, but instead, displays it as a different character. (don't know the name of it)

    You must use ChatColor, and you must use a console the supports colors. My server host does, and it's a webhost
     
  4. Offline

    kreashenz

    TheGreenGamerHD Can you tell me why when I use § it works as colours? If you take a look at the ChatColor.java, it even uses § to do colours, unless I misread.
     
  5. Offline

    ZeusAllMighty11

  6. Offline

    kreashenz

  7. Offline

    ZeusAllMighty11

    Doesn't matter when it is called kreashenz
     
  8. Offline

    FurmigaHumana

    Use the ConsoleCommandSender

    Code:
        public void log(String message) {
            ConsoleCommandSender console = Bukkit.getServer().getConsoleSender();
            console.sendMessage(message.replaceAll("&([0-9a-fk-or])", "\u00a7$1"));
        }
     
  9. Offline

    InflamedSebi

    i use ansi coloring

    Code:java
    1.  
    2. public void l(String message, Level level) {
    3. if (logDepth == -1)
    4. initLogger();
    5. String result = "[" + namePrefix + name + ChatColor.RESET + "] " + message + ChatColor.RESET;
    6. for (ChatColor color : colors) {
    7. if (replacements.containsKey(color) && Ansi.isEnabled() && useColor) {
    8. result = result.replaceAll("(?i)" + color.toString(), replacements.get(color));
    9. } else {
    10. result = result.replaceAll("(?i)" + color.toString(), "");
    11. }
    12. message = result;
    13. logger.log(level, message);
    14. }
    15. }
    16.  


    replacements contains all chat colores and the corresponding ansi color.
    my full logger is here: https://github.com/InflamedSebi/Bas...medsebi/Basic/utilities/DynLoggerUtility.java
     
  10. Guys. There is a VERY simple way! getServer().getConsoleCommandSender().sendMessage(ChatColor.BLUE+"Blue Text");
     
Thread Status:
Not open for further replies.

Share This Page