Config is created incorrectly

Discussion in 'Plugin Development' started by MadMarvin, Jun 15, 2019.

Thread Status:
Not open for further replies.
  1. Hey guys,
    In my Plugin is a pre-created config which is in the src Folder where is also the Plugin.yml
    My Problem is that the config is created differently than it is in the src Folder.
    Here the config in the src Folder:

    Code:
    ##################################
    #      Unscramble the Word       #
    #      AnIdeaBy: MadMarvin       #
    #       Authors MadMarvin        #
    #    CreatedFor: Bausucht.net    #
    ##################################
    
    # Prefix, welcher immer vor den Nachrichten angezeigt wird.
    prefix: "§8[§aBauSucht§8]§r"
    # Grundeinstellungen für WortEvent
    WordSettings:
      messages:
        rundruf: "Ihr habt 3Minuten zeit, dass folgende Wort zu entschlüsseln>> %mxedword%"
        winner: "Der Spieler %player% hat gewonnen und 1000Münzen erhalten. Das Wort war %word%"
    # Erweiterteeinstellungen für WortEvent
    ExpandedWordSettings:
      stellintervall:
        sekunden: '1200'
      antwortzeit:
        sekunden: '180'
    # Wortliste|| die Wörter werden belibig ausgewählt, und gemischt.
    # Wordlistlenght gibt an, wieviele wörter in der WordList sind! Bitte bei neuen wörtern Anpassen
    Wordlistlenght: '1'
    WordList:
      '1': "Wolf"
    
      
    Here the config after Export it and run the Server:

    Code:
    #
    #      Unscramble the Word       #
    #      AnIdeaBy: MadMarvin       #
    #       Authors MadMarvin        #
    #    CreatedFor: Bausucht.net    #
    prefix: "\xa78[\xa7aBauSucht\xa78]\xa7r"
    WordSettings:
      messages:
        rundruf: "Ihr habt 3Minuten zeit, dass folgende Wort zu entschl\xfcsseln>> %mxedword%"
        winner: "Der Spieler %player% hat gewonnen und 1000M\xfcnzen erhalten. Das Wort\
          \ war %word%"
    ExpandedWordSettings:
      stellintervall:
        sekunden: '1200'
      antwortzeit:
        sekunden: '180'
    Wordlistlenght: '1'
    WordList:
      '1': Wolf
    
    Here the onLoad of my Code. here is the only place where I call the config:

    Code:
        @Override
        public void onEnable() {
            super.onEnable();
           
            String PluginName = this.getDescription().getName();
            String PluginVersion = this.getDescription().getVersion();
            System.out.println("§a====================");
            System.out.println("§a   " + PluginName + "");
            System.out.println("§a   Von: MadMarvin");
            System.out.println("§a   Version: "+ PluginVersion + "");
            System.out.println("§a     Aktiviert");
            System.out.println("§a====================");
           
            this.getConfig().options().copyDefaults(true);
            this.saveConfig();
           
        }

    I think this is Pretty stupid and would like to finde a solution.
    Anyone know how to fix this?
    Sry for my Bad english
    ~MadMarvin
     
  2. Online

    timtower Administrator Administrator Moderator

    @MadMarvin yml doesn't copy comments.
    Use saveResource instead
     
  3. What do you mean and how would that look? Im not the best and only an Beginner XD

    And it also changed the colorcodes in something like this \xfd7
     
  4. What I recommend is checking if file exists, if not do saveDefaultConfig. Preserves all formatting perfectly

    Code:java
    1. if (!new File(getDataFolder(), "config.yml").exists())
    2. saveDefaultConfig();
     
  5. Thank you very much!
    My onLoad now look so:
    Code:
        @Override
        public void onEnable() {
            super.onEnable();
           
            String PluginName = this.getDescription().getName();
            String PluginVersion = this.getDescription().getVersion();
            System.out.println("§a====================");
            System.out.println("§a   " + PluginName + "");
            System.out.println("§a   Von: MadMarvin");
            System.out.println("§a   Version: "+ PluginVersion + "");
            System.out.println("§a     Aktiviert");
            System.out.println("§a====================");
            if (!new File(getDataFolder(), "config.yml").exists()) {
                saveDefaultConfig();
            }
           
        }
    And it works perfectly thank you!
     
Thread Status:
Not open for further replies.

Share This Page