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:

    [​IMG]

    http://imgur.com/sokikO0

    Any help?
     
  2. gigosaurus

    Supporter

    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(PluginCommand.java:46) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at org.bukkit.craftbukkit.v1_8_R2.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PlayerConnection.handleCommand(PlayerConnection.java:1133) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PlayerConnection.a(PlayerConnection.java:968) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439) [?:1.6.0_65]
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [?:1.6.0_65]
        at java.util.concurrent.FutureTask.run(FutureTask.java:138) [?: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(MinecraftServer.java:710) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.DedicatedServer.A(DedicatedServer.java:368) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.MinecraftServer.z(MinecraftServer.java:651) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:554) [spigot.jar:git-Spigot-dbe012b-61ef214]
        at java.lang.Thread.run(Thread.java:695) [?:1.6.0_65]
    Caused by: java.lang.NullPointerException
        at org.bukkit.ChatColor.translateAlternateColorCodes(ChatColor.java:210) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        at me.mounts.core.Inventories.createMobHead(Inventories.java:110) ~[?:?]
        at me.mounts.core.Inventories.createChest(Inventories.java:47) ~[?:?]
        at me.mounts.core.Commands.onCommand(Commands.java:28) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-dbe012b-61ef214]
        ... 16 more
    >
     
     
  5. gigosaurus

    Supporter

    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.
     
  6.  
    • 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

    Supporter

    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:

    http://imgur.com/KVzjbvX
     
  11. gigosaurus

    Supporter

    Weird that you're getting some character set issues. Could you tell me what displayC equals?
     
  12. http://imgur.com/iVVvE1K
     
  13. gigosaurus

    Supporter

    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

    Supporter

    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.

    http://imgur.com/U39Y1ar
     
  20. gigosaurus

    Supporter

    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.