Color Codes Not Working In language.yml

Discussion in 'Spigot Plugin Development' started by Bladian, May 1, 2015.

Thread Status:
Not open for further replies.
  1. I have the language.yml set up and working perfect except when I add color support it screws up completely.

    I currently have this string:

    Code (Text):
     displayC = Configs.getLanguageConfig().getString(path + ".display");
                    display = ChatColor.translateAlternateColorCodes('&', displayC);
    When there is this color code in the language.yml:

    cow: &3Cow

    It simply tells me it's null:


    Any help?
  2. gigosaurus


    You're probably not accessing the correct value in the config.
    In your code you're getting a value under a key named "display", but in the example you showed a key named "cow".
  3. Jesus Christ I'm an idiot.
    • Agree Agree x 1
    • Optimistic Optimistic x 1
  4. It then gives me this error unfortunately:

    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'msmounts' in plugin Mounts v1.0
        at org.bukkit.command.PluginCommand.execute( ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at org.bukkit.command.SimpleCommandMap.dispatch( ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand( ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$ [spigot.jar:git-Spigot-dbe012b-61ef214]
        at java.util.concurrent.Executors$ [?:1.6.0_65]
        at java.util.concurrent.FutureTask$Sync.innerRun( [?:1.6.0_65]
        at [?:1.6.0_65]
        at net.minecraft.server.v1_8_R2.SystemUtils.a(SourceFile:60) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.MinecraftServer.A( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z( [spigot.jar:git-Spigot-dbe012b-61ef214]
        at [spigot.jar:git-Spigot-dbe012b-61ef214]
        at [?:1.6.0_65]
    Caused by: java.lang.NullPointerException
        at org.bukkit.ChatColor.translateAlternateColorCodes( ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at me.mounts.core.Inventories.createMobHead( ~[?:?]
        at me.mounts.core.Inventories.createChest( ~[?:?]
        at me.mounts.core.Commands.onCommand( ~[?:?]
        at org.bukkit.command.PluginCommand.execute( ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        ... 16 more
  5. gigosaurus


    That seems to confirm what I was saying.
    What is the full string you're passing to the getString method? (path + ".display") - what's path?
    What is the full location of the color code in your language.yml? path.something.cow
    They should be the same.
    • Like Like x 1
  7. Not helpful. Of course I know how to read it. Seems like an idiotic comment to me.

    The problem is not the path. When I remove the color code it works perfectly. When I add the &4 to Cow it stops working.
  8. gigosaurus


    Possibly try surrounding the string with '. E.g. cow: '&4Cow'
    Try outputting the value of displayC to console and see if it equals "&4Cow" as you want.
  9. Will try it out, thanks.
  10. The color works but it returns this:
  11. gigosaurus


    Weird that you're getting some character set issues. Could you tell me what displayC equals?
  13. gigosaurus


    Somehow the ' you entered in the yml is being changed to those ,Ao characters.
    You sure you used ' and not some weird character that it can't understand?
  14. Well, seeing the fact that you still don't know how to fix a NullPointerException after seeing this tutorial makes you look more idiotic than me.
  15. gigosaurus


    You know that reading stack traces doesn't tell you anything about how to actually fix an error, right? Just where and what caused it.
  16. Well, if you know what is null, then you can easily fix it.
  17. This comment is really sad...
  18. Listen here, I've dealt with hundreds of NPE, I was able to fix all of them, this might be some weird things, with my language.yml.
  19. You might be right, here is a snapshot of what it looks like. It does change it.
  20. gigosaurus


    Not true. Getting a NPE means something was null when you were expecting it not to be, and sometimes working out why it is null can be quite difficult.

    Try changing the ' to ".
Thread Status:
Not open for further replies.