[Help] TranslateAlternateColorCodes

Discussion in 'Spigot Plugin Development' started by SwagiWagi, Jun 12, 2016.

  1. Hey there,
    I don't know how to TranslateAlternateColorCodes a list.
    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg3) {
            if(label.equalsIgnoreCase("Website") && sender.hasPermission("KPM.use")) {
                if (!(sender instanceof Player)){
                    sender.sendMessage("Hey! You must be a player to use this command!");
                    return false;
                Player player = (Player) sender;
                List<String> ws = plugin.getConfig().getStringList("Website");
                for (String wsm : ws){
                return true;
  2. You can try this.

    Code (Text):
    List<String> Colored_List = new List<>();

    for( String s : List ){

    //New colored list
  3. I don't get what you did here, explain?
    • Optimistic Optimistic x 1
  4. I created a new list called "Colored_List" and used a for loop to translate each individual string and insert it into the new list but with color. you end up with a new list of same text but with colors working
  5. If you want to colorize a lits it's quite easy, i would first create the method to colorize a single String
    Code (Java):

    public String color(String text) {
     return ChatColor.translateAlternateColorCodes('&', text);
    Then create a method to colorize the list, it's quite easy actually, you just have to loop throught the list colorize it and put it on a new List
    Code (Java):

    public List<String> color(List<String> list) {
     List<String> colorized = new ArrayList<>();

     for(String line : list) {
    Then you can easily use it doing something like :
    Code (Java):

    for(String message : colorize(config.getStringList("List"))) {
    • Useful Useful x 1
  6. Just send them the translated message when you use the sendMessage method.
  7. Making things over complicated :p

    Use this code

    Code (Text):
    for (String s : getConfig().getStringList("Path")) {
      player.sendMessage(ChatColor.translateAlternateColorCodes('&', s));
    Basically what that does is says string s is a line in the stringlist, this allows you to treat it like a string.
    Since it's a for loop it loops through every string in the stringlist and makes it a string.
    I probably described that wrong, but I don't know a better way to explain it.
    • Agree Agree x 1
  8. for loop string through the list then translate color code of string.
  9. This is my code:
    Code (Text):
    Player player = (Player) sender;
                List<String> ws = plugin.getConfig().getStringList("Website");
                for (String wsm : plugin.getConfig().getStringList("Website")) {
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', wsm));
    Every time that i'm adding &NUMBER to the config it just removes the word.
  10. you can use replace('&' ,'§')
    Code (Text):
     player.sendMessage(wsm.replace('&' ,'§'));
  11. Doesn't work.
  12. What does your config look like?
    Also that ws list is pointless
  13. Won't work, normal & will be replaced than.
  14. try
    Code (Text):
    player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Website"));
  15. Don't do that.
    He's trying to translate a stringlist...
    Not a string, did you read the post?
  16. OH sorry! can you explain me what string? for example a player name to a config?
    but he wants to add String wsm : plugin.getConfig().getStringList("Website")) {
    to a player message ?
  17. 4chan


    Any chance the list is empty?

    If the message sends though, and you just need colour, should be this:

    player.sendMessage(ChatColor.translateAlternateColorCodes('&', wsm));
  18. Please... learn Java.
  19. You're the one that is doing it over complicated.
  20. HOW THO

    3 lines compared to your 15ish