1

I'm attempting to produce a Message.yml file using Spigot's YAMLConfiguration. This is my code:

public static void create() {

    if(messagesFile.exists()) return;

    try {

        messagesFile.createNewFile();
        messages.options().copyDefaults(true);

        messages.addDefault("MESSAGES.PREFIX", "&c[YourServer] ");
        messages.addDefault("MESSAGES.DESIGN", "§8§l- ");
        messages.addDefault("MESSAGES.NOPERMS", "§c§lDazu hast du keine Rechte!");

        messages.addDefault("MESSAGES.ADDMAP.USAGE", "§c§lBitte nutze /addmap [mapname]!");

        messages.save(messagesFile);

    } catch(Exception e) {
        e.printStackTrace();
    }

}

However, the config.yml file I received after running it read as follows:

MESSAGES:
  PREFIX: '&c[YourServer] '
  DESIGN: "\xa78\xa7l- "
  NOPERMS: "\xa7c\xa7lDazu hast du keine Rechte!"
  ADDMAP:
    USAGE: "\xa7c\xa7lBitte nutze /addmap [mapname]!"

Is there any way to fix it?

Seal
  • 140
  • 4

3 Answers3

0

It thinks the text is a string and not a standalone character.

https://www.spigotmc.org/threads/special-characters-in-config.298138/

Seal
  • 140
  • 4
0

Yeah u use special caracter to save the color but it's a String. Don't put your color here just save the String. When you want to resend the text from the config just put for example.

player.sendMessage(ChatColor.RED + config.get("MESSAGES.PREFIX"));

this is just an example

0

Like @Minecraft said in his answer, the issue is that Java is recognizing the § as a part of your string and translating it to unicode.

What I would do is have your custom config file stored in your plugin resources directory with all the default values you want it to have already defined.

Then when you want to use the custom message, get it from the config file using getConfig()'s returned value's methods. Then, if you want to support color codes, you should use message = ChatColor.translateAlternateColorCodes('&', yourMessage); or something along those lines. Should be plenty to get you going.

Also, be sure and use a unified symbol for these color codes (default is &), but you can set it in the aforementioned method translateAlternativeColorCodes(). You seem to be using & or §, I would stick to &.

Sources: https://www.spigotmc.org/wiki/config-files/#using-custom-configurations https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/ChatColor.html#translateAlternateColorCodes(char,java.lang.String)

andromda
  • 35
  • 5