[Util][Codefragment] Send Colored Message to Console (Very easy)

Discussion in 'Resources' started by GameplayJDK, Mar 20, 2014.

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

    GameplayJDK

    This is a method to send a colored message to the console, which I've found the last few days. It's very easy but I think at least it's useful.

    Code:java
    1.  
    2. public static void printlnfx(String message) {
    3. Server server = Bukkit.getServer();
    4. ConsoleCommandSender console = server.getConsoleSender();
    5. console.sendMessage(message);
    6. }
    7.  


    Paste this into your main class to be able to call it from all your other classes.
    To change the text color use ChatColor.<Color_of_your_choice>.
     
  2. Offline

    Bammerbom

    GameplayJDK Nice work. But you can just do Bukkit.getConsoleSender().sendMessage(message);
     
  3. Offline

    GameplayJDK

    Jhtzb
    Yes, but in my opinion it looks nicer if you have a method for that. And it take less space to write PluginMain.printlnfx(ChatColor.RED+"Hello"). :D
     
    KingFaris11 likes this.
  4. You could use this in a way like this:
    Code:
    public static String pluginPrefix = ChatColor.GOLD + "[" + ChatColor.DARK_RED + "Swag" + ChatColor.GOLD + "] " + ChatColor.GREEN;
     
    public static void printLine(String message) {
        Bukkit.getServer().getConsoleSender().sendMessage(pluginPrefix + message);
    }
    
     
  5. Offline

    RawCode

    try doing this without bukkit API, current code is just "hey i managed to properly used api without reading javadocs"
     
    xTrollxDudex likes this.
  6. Offline

    Plo124

    What if.. the console doesn't support color, e.g. Multicraft
     
  7. Offline

    GameplayJDK

    Plo124
    It will be detected at the server start and then it will ignore the ChatColor for the console.

    KingFaris11
    That would be a good way if you want to mark every message of your plugin :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page