Solved Get first chat color in string

Discussion in 'Plugin Development' started by Rexcantor64, Dec 28, 2015.

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

    Rexcantor64

    I have a multi-language system and when I replace the "%1" (a variable) the text after it becomes white: https://gyazo.com/acfdc6bdc00034fa3c3b8ec77ebca042
    The only thing I want to avoid is putting chatcolors in the middle of the string.

    Basically I want to get the first letter color and copy it after I replace the string.

    Waiting for an answer,
    Rexcantor64
     
  2. Offline

    elian1203

    You could use the method next() from Scanner and then have it keep doing that until it gets to % and save the character after that. I think that's what you're trying to do...
     
  3. Offline

    Rexcantor64

    @elian1203
    I don't know how to use that, and I found a easier way do to that:

    Code:
    a = a.replaceAll(replacement,
                            complements[i] + ChatColor.getByChar('a'));
    I used "a" because the whole message is green. But some messages are red, blue, etc...
    I want to get the color code from the first letter.
    Here is the method to get the first letter:

    Code:
    message.substring(0, 1)
    Waiting for an answer,
    Rexcantor64
     
  4. Your message.substring call gives you two letters.
    EDIT: Yeah, nvm... Just me mixing up languages :)
     
    Last edited: Dec 31, 2015
  5. Offline

    Rexcantor64

    @BreezerFly
    No, it doesn't.
    But I found something:

    If you get the second letter, it will be the color code:

    Code:
    ChatColor.GREEN + "Testing my %1 plugin!"
    On that example it will give you "a" (the color code of green).
    Using that I can replace the code I gave above with:

    Code:
    a = a.replaceAll(replacement,
                            complements[i] + ChatColor.getByChar(message.substring(1,2)));
    SOLVED
     
Thread Status:
Not open for further replies.

Share This Page