Multicolored text in one String

Discussion in 'Plugin Development' started by twinflyer, Jan 30, 2012.

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

    twinflyer

    Hi guys,
    I've got a problem with colored messages.
    In my plugin, some information are stored in a String. Every word can be colored in green or red (as symbol for "allowed" and "not allowed"). After all the information is stored in this String, it is sent to the player. The player should now see the colors.
    I tried something like this:

    &awheat &ccake &cpaper &ashugar

    I have also tried it with '$' instead of '&'.

    The names are not relevant ;)

    The text is colored, but only if the player is connected via a Spout Client. Players without Spout see the Code like above.
    How do I have to change my String, so every player can see the colors?

    Thanks for your help
    twinflyer
     
  2. Offline

    xpansive

    Use ChatColor.GREEN + "text" + ChatColor.RED + "more text"
     
  3. Offline

    twinflyer

    But "ChatColor.GREEN" does not work if this text is sent to the player as Variable (String).
    The player then sees "ChatColor.GREEN + "whatever" "

    Any other solution?

    [EDIT]
    Maybe this will help to understand what I want to do:
    Code:
    String HW_namen[] = {"Holzspitzhacke","Holzaxt      ","Holzschaufel","Holzharke    ","Angel        "};
    String HW_perms[] = {"banrecipe.270","banrecipe.271","banrecipe.269","banrecipe.290","banrecipe.346"};
                           
                                for (int i = 0; i < HW_namen.length; i++) {
     
                                    if (permissions.has(player, HW_perms[i])) {
                                        HWMessage = HWMessage + "&a" + HW_namen[i] + " ";
                                    } else {
                                        HWMessage = HWMessage + "&c" + HW_namen[i] + " ";
                                    }
     
  4. You don't put " " around ChatColor.GREEN and all the other colors.
     
  5. Offline

    fromgate

    You can use simbol "§" in text. For example "§cRed §aLightGreen"
     
  6. HWMessage = HWMessage + ChatColor.GREEN + HW_namen + " ";
    works like a charm...
     
  7. Offline

    twinflyer

    100 Points to fromgate.
    I knew that there is a symbol to make it VERY easy.
    Thank you so much :)

    twinflyer
     
Thread Status:
Not open for further replies.

Share This Page