Solved Having trouble with config color codes.

Discussion in 'Plugin Development' started by coolmonkeyguy, Apr 23, 2014.

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

    coolmonkeyguy

    So Ive tried and tried but I can't seem to get my config to accept color codes for in game messages.

    This is what i currently have in my main class.

    Code:java
    1. public class supremeinfo extends JavaPlugin implements Listener {
    2.  
    3. public final Logger logger = Logger.getLogger("Minecraft");
    4. public void onEnable() {
    5. getServer().getPluginManager().registerEvents(this, this);
    6. getConfig().options().copyDefaults(true);
    7. saveConfig();
    8. }
    9. {
    10. logger.info("[ItemMessages] has been enabled!");
    11. }
    12. public void onDisable() {
    13. logger.info("[ItemMessages] has been disabled!");
    14. }
    15.  
    16.  
    17.  
    18.  
    19.  
    20. @SuppressWarnings("deprecation")
    21. @EventHandler
    22. public void onPlayerInteract(PlayerInteractEvent e) {
    23.  
    24. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    25. if (e.getPlayer().getItemInHand().getType() == Material.getMaterial(388)) {
    26. Player player = e.getPlayer();
    27. player.sendMessage(getConfig().getString("Message").replaceAll("(&([a-f0-9]))", "\u00A7$2"));;
    28.  
    29.  
    30. }
    31. }
    32. }



    Here is my config file
    Code:
    Message: This is a test message!
    Anyways I would highly appreciate any help with solving my issue. Thanks!
     
  2. Offline

    Gater12

    coolmonkeyguy
    Don't see a problem. You haven't put any color codes in the config.
     
  3. Offline

    coolmonkeyguy

    When I put for example &1 when i reload on minecraft the message shows up as "is a test message!" it does not know what & is so it removes the word attached to it.
     
  4. Offline

    SuppaTim

    Why don't you use:
    Code:java
    1. String string = getConfig().getString("Message");
    2. player.sendMessage(ChatColor.translateAlternateColorcodes("&", string));
    3.  

    *Note: Did it on my phone, there could be typos
     
  5. Offline

    1Rogue Retired Staff

    Just use this:

    Code:java
    1. ChatColor.translateAlternateColorCodes('&', getConfig().getString("your-path"));


    This will return a colored string
     
  6. Offline

    coolmonkeyguy

    Im having issues initializing the variable "ChatColor" it says to replace it and import bukkit.org Color
    What do I do?
     
  7. Offline

    1Rogue Retired Staff


    What's your current import for it? the actual class is "org.bukkit.ChatColor"
     
  8. Offline

    Wizehh

    You could also do this:
    PHP:
    String str;
    str.replace('&''§');
     
  9. Offline

    coolmonkeyguy

    So i imported chatcolor and everything works but when i add &1 to the config it resets the config back to the default config file.
     
  10. Offline

    stamline

    Use this, it works for me perfektly! :D

    Code:java
    1. player.sendMessage(getConfig().getString("Message").replaceAll("&", "§"));
     
  11. Offline

    1Rogue Retired Staff


    You overwrite your own config during your onEnable (copyDefaults)
     
  12. Offline

    coolmonkeyguy

    Ok i get what your saying. so how would I do this without reseting the config on each reload?
     
  13. Offline

    1Rogue Retired Staff

    Keep a config.yml file of your default config in the same directory as your "plugin.yml", and call:

    Code:java
    1. saveDefaultConfig()


    in your onEnable
     
  14. Offline

    coolmonkeyguy

    perfect i figured out i needed ' ' to be around the... &1this is a test message this worked: '&1this is a test message'
     
Thread Status:
Not open for further replies.

Share This Page