Config Color Support?

Discussion in 'Plugin Development' started by gaz1812, May 12, 2014.

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

    gaz1812

    Hi,

    Before you even comment please read this, I have googled to find information on how to do this however the places I have come across are old threads, sites etc. I did infact come across a recent one which stated about ChatColor.ReplaceAlternateColorCodes in the code. I tried this and I just get an error in eclipse.

    I have the following:
    PHP:
    public boolean onCommand(CommandSender senderCommand cmdString commandLabelString[] args){
            
    Player player = (Playersender;
            if(
    commandLabel.equalsIgnoreCase("ranks")){
                
    player.sendMessage(getConfig().getString("RANKS").replaceAll("(&([a-f0-9]))""\u00A7$2"));
                
    String coloredString ChatColor.ReplaceAlternateColorCodes ('&', (getConfig().getString("RANKS""&4default &aif &bnot &3in &fconfig")));
               
           
           
            }
            return 
    false;
     
  2. Offline

    theguynextdoor

  3. Offline

    gaz1812

    theguynextdoor I can't seem to find it unless it's "public static ChatColor"?

    I'm quite new to bukkit coding
     
  4. Offline

    theguynextdoor

    Scroll down on the javadoc page until you see the method summary section. Look at each method in this section. Look at the inputs each method takes. Only one method will take the inputs you need. The inputs you need is a character (in your case '&') and the other input will be a string (which is the string you want to get the colours from in your case this is the string from your config). Only 4 of the methods in the javadoc return a String, which is what you want.

    Take another look.
     
  5. Offline

    gaz1812

    theguynextdoor So it must be the static string right? Now how would I implement that into my code? Would I remove this part of the code "String coloredString = ChatColor.ReplaceAlternateColorCodes" and replace it with the method?
     
  6. Offline

    cdriza

    Hint: look at my signature :3
     
  7. Offline

    gaz1812

    cdriza That's not helped.. I already know how to do the ChatColor.COLORNAME I need to know how to enable it for config support?
     
  8. Offline

    theguynextdoor

    Below I have circled 3 possible methods, by 2 criteria. 1) They must be static and 2) They must return a String

    Each of these methods are called by ChatColor.methodNameHere
    All you need to do, is read the description for each, and think which one looks like the one you need.
    If you still dont know, then try all 3 and one will have the outcome you want.
    [​IMG]


    You would only be replacing the 'ChatColor.ReplaceAlternateColorCodes' bit with
    'ChatColor.TheStaticMethodToColouriseStringsWhichYouFound'
     
  9. Offline

    gaz1812

    theguynextdoor You have been really helpful! Thank you for time and effort you are putting in to help me. I some how keep getting the error for "ChatColor" that says "ChatColor can not be resolved". I have 8 quick fixes to choose which include "Change to 'Color' (org.bukkit)" and creating a local variable. Which do I choose? I think this has been one of my errors I've come across recently.
     
  10. Offline

    theguynextdoor

    Ensure you have imported ChatColor. If you get the choice to import 'org.bukkit.ChatColor'. If you do not get this option, then go to the top, where the rest of your imports are for this class, remove any other Color, ChatColor imports and ensure you have the line 'import org.bukkit.ChatColor;'.
     
  11. Offline

    gaz1812

    theguynextdoor Okay well that worked. I'm not sure why I didn't think of that haha. I've tried using the below which I had at the start before importing the correct ChatColor.

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    2. Player player = (Player) sender;
    3. if(commandLabel.equalsIgnoreCase("ranks")){
    4. player.sendMessage(getConfig().getString("RANKS").replaceAll("(&([a-f0-9]))", "\u00A7$2"));
    5. String coloredString = ChatColor.translateAlternateColorCodes('&', (getConfig().getString("RANKS", "&4default &aif &bnot &3in &fconfig")));
    6.  
    7.  
    8.  
    9. }
    10. return false;


    My plugin now get's rid of the first message for example my config has:

    RANKS: &bEnter rank list here

    and this is what is showed in game:
    [​IMG]
     
  12. Offline

    theguynextdoor

    gaz1812 remove the line
    Code:java
    1. player.sendMessage(getConfig().getString("RANKS").replaceAll("(&([a-f0-9]))", "\u00A7$2"));


    And instead, just send the player the 'coloredString' in a message
     
  13. Offline

    gaz1812

    theguynextdoor Okay, I've now done that. I reuploaded the plugin and tried the command /ranks and it displays nothing. No console errors either? [​IMG]
     
  14. Offline

    theguynextdoor

    gaz1812 Read the last line of my previous message.
     
  15. Offline

    gaz1812

    theguynextdoor I'm really sorry, I've tried doing player.sendMessage(coloredString); and I'm sure it's not that as the config still doesn't allow the colors. I'm quite new to all this and sorry for the issues. Do I send the player:
    String coloredString = ChatColor.translateAlternateColorCodes('&', (getConfig().getString("RANKS","&4default &aif &bnot &3in &fconfig"))); this as a message?
     
  16. Offline

    theguynextdoor

    gaz1812 You were right to do player.sendMessage(coloredString)
    Just do this for me and tell me what happens.
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    2. Player player = (Player) sender;
    3. if (commandLabel.equalsIgnoreCase("ranks")) {
    4. String coloredString = ChatColor.translateAlternateColorCodes('&', (getConfig().getString("RANKS", "&4default &aif &bnot &3in &fconfig")));
    5. player.sendMessage(getConfig().getString("RANKS"));
    6. player.sendMessage(coloredString);
    7. }
    8.  
    9. return true;
    10. }


    Once we have solved this message sending, there are a few things I wish to change about the layout of your command
     
  17. Offline

    gaz1812

    theguynextdoor This is what I get when peforming the command. I get double the messages no color either.
    [​IMG]

    I'm heading off now but will be on tomorrow and can continue this. Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page