Swedish characters getting messed up in config.yml

Discussion in 'Plugin Development' started by tizrain, Nov 20, 2015.

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

    tizrain

    Hello!

    I'm trying to save swedish characters into a config. It works perfectly and it does it correctly, because the comments in the yaml file has no trouble with the Swedish characters, but my messages keeps getting messed up.

    I.E: Swedish letter Ä = \xc3\xa4 in a message while it's normal in a comment in the same file.

    It is coded in UTF-8 without BOM so it should support the swedish characters..

    Do you have any idea of why it does this?

    I found a "solution" for the config, but then it messes up ingame instead.
    When I use saveConfig(); to save the config after reload/restart or similar the weird symbols appear as i have shown you above. But when I use saveDefaultConfig(); it sves it normally and keeps everything as it should in the config.

    The problem is that when the config is messed up, it's good ingame, and vice versa.

    My code:

    Code:
    public void onDisable() {
            if (obj != null) {
                obj.unregister();
                obj = null;
            }
            if (countdownTask != null) countdownTask.cancel();
            if (timerTask != null) timerTask.cancel();
        }
    
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
          
            registerConfig();
            ....
        }
        ....
    
        private void registerConfig() {
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
        }
    my config:
    Code:
    # Om denna är true så sparas allas inventory när eventet börjar
    # och återställer det när eventet är över
    # Om den däremot är false så rensas alla deltagares inventory och återställs ej
    saveinv: true
    # Alla meddelanden för kommandon m.m
    messages:
      abba_help_header: '&a--- AbbaRules Commands --- %n'
      abba_help_create: '&a%c &3Create an AbbaRules game %n'
      abba_help_join: '&a%c &3Join the AbbaRules event %n'
      abba_help_leave: '&a%c &3Leave the AbbaRules event %n'
      abba_help_start: '&a%c &3Start the timer %n'
      abba_help_stop: '&a%c &3Stop the timer %n'
      abba_help_reset: '&a%c &3Stop the AbbaRules game %n'
     
      abba_noconsole: '&cNot runnable from console.'
      abba_nopermission: '&cYou can''t do this command!'
      abba_nojoin: '&cYou can''t join the event when it has started!'
      abba_noeventtoleave: '&cYou can''t leave something you never joined!'
      abba_noeventfound: '&cYou are not in any event!'
      abba_noleaveforhost: '&cYou can''t leave the event since you''re hosting it!'
      abba_nogametostart: '&cThere''s no event to start.'
      abba_nogametoend: '&cThere''s no game to end.'
      abba_nogameactive: '&cNo AbbaRules event is active at the moment.'
      abba_noblockplace: '&cYou can''t place this block while the event is going.'
     
      abba_startsettime: '&c%c &3[time]'
      abba_alreadyjoined: '&cYou already joined the event!'
      abba_invcleared: '&c&lYour inventory has been cleared!'
     
      abba_invrestored: '&a&lYour inventory has been restored!'
      abba_gamecreated: '&6&l%p &dhas created an AbbaRules event! Join with &f&l/abba join.'
      abba_hostready: '&bWhen everybody has joined, start the event with &l/abba start'
      abba_joinedevent: '&aYou have joined the event!'
      abba_leftevent: '&6%p &bleft the event!'
      abba_countdownheader: '&bThe AbbaRules event starts in:'
      abba_broadcaststart: '&6Let the AbbaRules event begin!'
      abba_timesup: '&6Times up!'
     
  2. Offline

    Xerox262

    Just because it works in a comment does not mean it will work in the config file. The point of the comments is the YAML file doesn't read them at all, You could try wrapping the character with'' since it's the escape characters for example:
    Code:
    Test: 'This is a test string with the Swedish character 'Ä''
    P.S. You do not need getConfig().options().copyDefaults(true); all you need to do is saveDefaultConfig(); the reason this works is because when it's saving it saves the file as is in the jar file, it doesn't read it or store it or anything, it also only saves if the file does not already exist. This is also the reason it saves comments when you use saveDefaultConfig(); but not when you do saveConfig();, because when you saveConfig(); It saves the file that is stored in memory. If you are not making the config editable in game (with commands, etc.) then you do not need to save it on disable.

    TL;DR: If you're not editing it in game then there's no need to save it after, it's dead code since it's either saving what is already there (With different encoding) or it is overwriting any changes you made while the server was running.
     
  3. Offline

    tizrain

    @Xerox262 Hi, wrapping the character still gave the same result ingame. I've changed the code slightly to where i removed the registerconfig method and just wrote saveDefaultConfig(); in onEnable(). Nothing changed.
     
  4. Offline

    Xerox262

    The point of the saveDefaultConfig(); is that is doesn't change anything... If you mean that it's still showing up as \xc3\xa4 in the config then try deleting the config and reloading/restarting your server and it shouldn't change them after that (unless you saveConfig() again).
     
  5. Offline

    tizrain

    @Xerox262 The config is saved correctly. What I mean is that The character isn't shown properly ingame when it's displayed. Instead of 'Ä' it's 'Ã,,'
     
  6. Offline

    tizrain

    bump
     
    Last edited: Nov 22, 2015
  7. Offline

    tizrain

    really need help with this.. :/
     
  8. Offline

    mcdorli

    Store it as a ASCII code, and convert it back when you display it.
     
    ChipDev likes this.
Thread Status:
Not open for further replies.

Share This Page