Solved Specify/implement chat colors with a string

Discussion in 'Plugin Development' started by TerraVale, Oct 29, 2012.

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


    I wish for, in a command, players to be able to set a color for some text that will show up behind their name. Currently, you can set what the text will be with the use of a hashmap: /tag set <arg>, which works just fine. I've now run into troubles when it comes to setting a color, for I wish to be able to use a command such as /tag color <&colorcode>, where the argument will be added to another hashmap under the same character, and in turn be used in a variable to set the color of the text.

    If anyone knows how to do this, or knows of any resources (webpages) I can take a look at for reference, it'd be much appreciated! :)

    Hrm, been messing around all day and cannot get it to work. Perhaps I need to add a "ChatColor" to the hashmap and use it in the messages, but it can't change strings into ChatColors and vice versa.

    // Semi bump

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


    1. String a = "&cHey! &3I like colours, &4do you?!"; //"a" contains a string with colour codes
    2. a = ChatColor.translateAlternateColorCodes('&', a); //Translate all colour codes in "a"

    Once you translateAlternateColorCodes, you can send a and it will display coloured text.
  3. Offline


    I learn more every day! Thanks. :)
Thread Status:
Not open for further replies.

Share This Page