Color Codes Help

Discussion in 'Plugin Development' started by iiHeroo, Sep 17, 2013.

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

    iiHeroo

    How do you do translate color codes in the config.yml ?
     
  2. Offline

    chasechocolate

    String colored = ChatColor.translateAlternateColorCodes('&', config.getString("path")).
     
  3. Offline

    iiHeroo


    okay, does "path" need to be anything specific ?
     
  4. Offline

    mattrick

    The path you want to use like:
    key1:
    key2:
    key3:
    key4:

    So the path is usually key1.key2.
     
  5. Offline

    iiHeroo

    ok thanks !
     
  6. Offline

    mattrick

    No problem :)
     
  7. Offline

    JPG2000

    chasechocolate mattrick16 I guess I'll just ask this question here.

    I've noticed that I can't add color support, because when ever I save the config with a wierd characted (such as &), it throws and error, saying "invalid character".

    Any way around this?
     
  8. Offline

    Gater12

    JPG2000 Well when I added a & to my config it deleted it so I added ' so basically:
    Key1: '&7HEY'
     
  9. Offline

    JPG2000

    Gater12 I don't get it. So just tell the person using the file to add 'path here', and then when ever I look for a string I add '' around it?
     
  10. Offline

    Gater12

    JPG2000 Your question confuses me :p. I'm trying to say like when I have something to from the config that is a string and translate the color code I add a '. So what I'm saying that when you leave a string you do:
    String: MEHRANDOMSTRING
    But when I put a & it deleted it and who knows what the console said so I put a '
    String: '&7MEHRANDOMSTRONG'
    And it worked and probably there's better explanation but that's what I see.
     
  11. Offline

    JPG2000

  12. Offline

    iiHeroo


    Here, it took me a while to get this, here's my code, and look SPECIFICALLY at Line 39. And yes, he's correct, you also need to add 'MSG', as you see here, it didn't work for color codes because I didn't add ' '

    Code:java
    1. package org.horrgs.me;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.configuration.file.FileConfiguration;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class serverinfoplus extends JavaPlugin {
    13.  
    14. public final Logger logger = Logger.getLogger("Minecraft");
    15. private FileConfiguration config;
    16. public static serverinfoplus plugin;
    17.  
    18. @Override
    19. public void onEnable(){
    20. config = getConfig();
    21. saveDefaultConfig();
    22. }
    23.  
    24. @Override
    25. public void onDisable(){
    26.  
    27. }
    28.  
    29.  
    30.  
    31. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    32. Player player = (Player) sender;
    33. if(commandLabel.equalsIgnoreCase("sip"))
    34. if(args.length == 1) {
    35. if(args[0].equalsIgnoreCase("1"))
    36. player.sendMessage(ChatColor.DARK_BLUE + "[" + ChatColor.BLUE + "SIP" + ChatColor.DARK_BLUE + "] " + ChatColor.GOLD + "Version 1.5 by " + ChatColor.DARK_AQUA + "iiHeroo" + ChatColor.AQUA + " " + ChatColor.GOLD + "Type /sip (1/2/3) for command information. " + ChatColor.GOLD + "/sip" + ChatColor.GRAY + " - " + ChatColor.BLUE + "The ServerInfoPlus help command. " + ChatColor.GOLD + "/open" + ChatColor.GRAY + " - " + ChatColor.BLUE + "Tell's you the date the server opened.");
    37. }
    38. if(commandLabel.equalsIgnoreCase("facebook"))
    39. player.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("pfacebook")) + ChatColor.translateAlternateColorCodes('&', getConfig().getString("facebook")));
    40.  
    41.  
    42.  
    43.  
    44.  
    45. return false;
    46.  
    47. }
    48. }
    49.  
    50.  
     
Thread Status:
Not open for further replies.

Share This Page