Solved Config Color Codes?

Discussion in 'Plugin Development' started by ImPhantom, Mar 8, 2014.

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

    ImPhantom

    How would i allow my config to accept color codes like &b, etc? Is there like a pre-made type color code that i should call?
     
  2. Offline

    Stealth2800

    In the config, use the color codes that you're talking about. Then, to convert it to actual chat messages, use:
    ChatColor.translateAlternateColorCodes('&', <String from config or whatever>);
     
  3. Offline

    ImPhantom


    Stealth2800
    Is there a certain method i should put this in? And also, in the config if you start the message with & it completely ignores the first word.
     
  4. Offline

    acecheesecr14

    Okay so if you have your config.yml:
    Code:java
    1. ## Config for myPlugin
    2. motd: '&5Hello world!'


    So you get the "motd:" by using
    Code:java
    1. String motd = getConfig().getString("motd");

    then with that motd variable you can execute the ChatColor.translateAlternateColorCodes.
    Like so:
    Code:java
    1. String colouredMOTD = ChatColor.translateAlternateColorCodes('&', motd);
    2.  

    That should show the MOTD var as a coloured message if you send it to a player.
     
  5. Offline

    Gater12

    ImPhantom
    If you don't like typing all that junk, you can create a method to do that.
     
  6. Offline

    acecheesecr14

    Create a method for 2 lines? :confused: that doesn't even have to be 2 lines...
     
  7. Offline

    ImPhantom


    acecheesecr14
    Is there a certain way for when im generating my config.yml to force it to have the apostrophe's?
     
  8. Offline

    Gater12

    acecheesecr14
    A method is like a recipe instead of recreating variables, typing out everything (Unless you're a big fan of copy and pasting or just want to exercise your fingers).
    Code:java
    1. /* Method example*/
    2. public String colorMessage(String s){
    3. return ChatColor.translateAlternateColorCodes('&', s);
    4. }
    5.  
    6. p.sendMessage(colorMessage("&7Hello"));

    And so instead of typing all that, you can just use the method colorMessage(String s) to have it return a the colorized String.
     
  9. Offline

    acecheesecr14

    Now there's a new kind of lazy xD
     
  10. Offline

    ImPhantom

  11. Offline

    acecheesecr14

    ImPhantom Acctually no... Sorry xD
    I don't know if there is... If you find a way please message me!
    Although i'm not sure that it'll make a difference?
     
Thread Status:
Not open for further replies.

Share This Page