[Solved] translateAlternateColorCodes Help

Discussion in 'Plugin Development' started by RealDope, Sep 23, 2012.

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

    RealDope

    My code:

    Code:
            final String prefixColor1 = this.getConfig().getConfigurationSection("Messages").getString("Prefix Color");
            final String prefixColor = ChatColor.translateAlternateColorCodes('&', prefixColor1);
    Console gives me a "java.lang.NullPointerException" on the line with ChatColor.translate

    Any help? I can't see the problem..
     
  2. Are spaces allowed for a config node? I'm really not sure. Anyway, try to give it a default:
    String prefixColor = ChatColor.translateAlternateColorCodes('&', this.getConfig().getConfigurationSection("Messages").getString("Prefix Color", "&4Default text"));
     
  3. Offline

    RealDope

    Yeah I know for a fact spaces are allowed, I have it in other places of my plugin with no problem.

    Also, I can't add that third argument or else Eclipse throws me the error that the method only allows 2 arguments.
     
  4. Offline

    RealDope

    Code:
            final String prefixColor = ChatColor.translateAlternateColorCodes('&', this.getConfig().getConfigurationSection("Messages").getString("Prefix Color", "&aDefault Prefix"));
    This code now displays "Default Prefix" in green. Now how can I get it to display the input from the config file?
     
  5. Then either your config file doesn't contain it or it's not allowed to have spaces in the node.
     
    xpaintall likes this.
  6. Offline

    RealDope

    The section of my config (just changed it to remove spaces):

    Code:
    Messages:
      #Prefix displayed before EasyVote messages
      Prefix: [EasyVote]
     
      #The color of the prefix, use Minecraft color codes
      PrefixColor: &4
     
      #The color of the messages that come after the prefix, use Minecraft color codes
      MessageColor: &f
    My code:

    Code:
            final String prefix = this.getConfig().getConfigurationSection("Messages").getString("Prefix");
            final String prefixColor = ChatColor.translateAlternateColorCodes('&', this.getConfig().getConfigurationSection("Messages").getString("PrefixColor"));
            final String messageColor = ChatColor.translateAlternateColorCodes('&', this.getConfig().getConfigurationSection("Messages").getString("MessageColor"));
    Still get NullPointerException on the first line that involves ChatColor.translateAlternateColorCodes


    Anybody know why?!

    Bump..

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  7. Offline

    Muddr

    Learn YAML. need quotes to force it to a string since it's starts with a &
    Code:
    Messages:
      #Prefix displayed before EasyVote messages
      Prefix: [EasyVote]
     
      #The color of the prefix, use Minecraft color codes
      PrefixColor: "&4"
     
      #The color of the messages that come after the prefix, use Minecraft color codes
      MessageColor: "&f"
     
Thread Status:
Not open for further replies.

Share This Page