Solved Problem with config loading

Discussion in 'Plugin Development' started by Webster56, Dec 7, 2013.

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

    Webster56

    Hello world :)

    I'm having a weird issue with my lang system, it doesn't load for some reason (actually, the exceptions are below) and i quite don't know how to fix it :/

    Code:
    [SEVERE] Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: expected '<document start>', but found BlockMappingStart
    in "<string>", line 5, column 5:
            default:
            ^
     
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55)
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:138)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:202)
        at fr.iwebster.wizardxp.WizardXP.reloadLangConfig(WizardXP.java:58)
        at fr.iwebster.wizardxp.WizardXP.onEnable(WizardXP.java:46)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugin(CraftServer.java:284)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.enablePlugins(CraftServer.java:266)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.reload(CraftServer.java:615)
        at org.bukkit.Bukkit.reload(Bukkit.java:277)
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:528)
        at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchServerCommand(CraftServer.java:515)
        at net.minecraft.server.v1_6_R3.DedicatedServer.as(DedicatedServer.java:263)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:228)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: expected '<document start>', but found BlockMappingStart
    in "<string>", line 5, column 5:
            default:
            ^
     
        at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentStart.produce(ParserImpl.java:231)
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:109)
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:53)
        ... 20 more
    My config file is the following

    Code:
    #
    # WizardXP config file
    # References Materials required for the actions in the plugin
    #
    # Below values can be either upper or lower cased.
    # Materials link : http://jd.bukkit.org/rb/apidocs/org/bukkit/Material.html
    #
    blocks:
      interact: ENCHANTMENT_TABLE
    items:
        single: STICK
        stack: REDSTONE_TORCH_ON
        fill: BLAZE_ROD
    # Cost in XP points of one bottle creation, and interval of XP releasing from a thrown bottle
    data:
        expcost: 11
        minexp: 3
        maxexp: 11
    #
    # Language of the plugin
    # Available values are : default/french
    # Prefer use the /wizardxp lang <lang> command rather than editing this manually !
    #
    lang:
        server: default
     
    
    Any idea ? I don't see anything wrong in a Yaml parser :/

    We might don't see it, but there's the empty line at the end of the file.

    Edit : Oh dear, forgot to finish the title before posting -_-'
     
  2. Offline

    Deleted user

  3. Offline

    Wingzzz

  4. Offline

    Webster56

    The parser outputs this, which looks okay

    Code:
    {
      "lang": {
        "server": "default"
      },
      "items": {
        "single": "STICK",
        "stack": "REDSTONE_TORCH_ON",
        "fill": "BLAZE_ROD"
      },
      "blocks": {
        "interact": "ENCHANTMENT_TABLE"
      },
      "data": {
        "minexp": 3,
        "maxexp": 11,
        "expcost": 11
      }
    }
    Talking about the line of code where the exception is raised, it is the following

    Code:java
    1. public void onEnable() {
    2. this.handler = new WizardXPEventsHandler(this);
    3. getServer().getPluginManager().registerEvents(new WizardXPEventsListener(handler, this), this);
    4.  
    5. //loads default config on first execution
    6. File file = new File(this.getDataFolder(), "config.yml");
    7. if (!file.exists())
    8. {
    9. saveDefaultConfig();
    10. }
    11.  
    12. config = this.getConfig();
    13. EXP_COST=config.getInt("data.expcost");
    14. LANG=config.getString("lang.server");
    15. reloadLangConfig(); // line 46
    16. }


    Code:java
    1. public void reloadLangConfig() {
    2. if (langConfigFile == null) {
    3. langConfigFile = new File(getDataFolder(), "langConfig.yml");
    4. }
    5. langConfig = YamlConfiguration.loadConfiguration(langConfigFile);
    6.  
    7. // Look for defaults in the jar
    8. InputStream defConfigStream = this.getResource("langConfig.yml");
    9. if (defConfigStream != null) {
    10. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream); // line 58
    11. langConfig.setDefaults(defConfig);
    12. }
    13. }


    (The line indication comments were added while posting this)

    And if you're looking for the langConfig.yml, here it is

    Code:
    #
    # Below are the different languages texts available, default is english.
    # Feel free to translate and send it to [email protected] so i can put them in upcoming versions ;)
    #
        default:
            made:
                nBottles1: "You transmuted "
                nBottles2: " glass bottles into Bottles o' Enchanting."
                oneBottle: You transmuted 1 glass bottle into a Bottle o' Enchanting.
            notEnoughBottles:
                nBottles1: "You don't have enough glass bottles to fill "
                nBottles2: " Bottles o' Enchanting."
                oneBottle: You don't have enough glass bottles to fill 1 Bottle o' Enchanting.
                anyBottle: You don't have enough glass bottles to be transmuted into any Bottle o' Enchanting.
            notEnoughXp:
                nBottles1: "You don't have enough xp points to be conveyed into "
                nBottles2: " Bottles o' Enchanting."
                oneBottle: You don't have enough xp points to be conveyed into 1 Bottle o' Enchanting.
            permissions:
                single: You're not a powerful enough wizard to convey a single Bottle O' Enchanting.
                stack: You're not a powerful enough wizard to convey a stack of Bottle O' Enchanting.
                fill: You're not a powerful enough wizard to convey your inventory of Bottle O' Enchanting.
            help:
                page1:
                    line1: WizardXP is a plugin about conveying your XP points into glass bottles, transforming them into Bottles o' Enchanting.
                    line2: "To do it, you need to left click on an enchantment table with one of the 3 magical wands that are, sorted in an ascendent power way : the wooden stick, the redstone torch and the blaze rod."
                page2:
                    line1: Clicking with the stick will eventually gives you a Bottle o' Enchanting, assuming you have enough glass bottles and XP points.
                    line2: The same goes for the torch and the rod, with either one stack of bottles, or the maximum amount of glass bottles you already have.
                page3:
                    line1: But extracting XP points from your body is a very tough process ! Even the best Wizards of the realm can't really master it, that's why some of the XP points will be lost during the conveying.
                    line2_1: "It costs you "
                    line2_2: " xp points to create a single Bottle o' Enchanting, but you're not sure to be able to extract "
                    line2_3: " points from it..."
            console: God doesn't need to know how to convey XP, He can give it !
        french:
            made:
                nBottles1: "Vous avez transmuté "
                nBottles2: " fioles en Fioles d'Experience."
                oneBottle: Vous avez transmuté 1 fiole en Fiole d'Experience.
            notEnoughBottles:
                nBottles1: "Vous n'avez pas assez de fioles pour remplir "
                nBottles2: " Fioles d'Experience."
                oneBottle: Vous n'avez pas assez de fioles pour remplir 1 Fiole d'Experience.
                anyBottle: Vous n'avez pas assez de fioles pour remplir la moindre Fiole d'Experience.
            notEnoughXp:
                nBottles1: "Vous n'avez pas assez de points d'XP à transvaser dans "
                nBottles2: " Fioles d'Experience."
                oneBottle: Vous n'avez pas assez de points d'XP à transvaser dans 1 Fiole d'Experience.
            permissions:
                single: Vous n'êtes pas un mage assez puissant pour remplir une seule Fiole d'Experience.
                stack: Vous n'êtes pas un mage assez puissant pour remplir une pile de Fioles d'Experience.
                fill: Vous n'êtes pas un mage assez puissant pour remplir votre inventaire de Fioles d'Experience.
            help:
                page1:
                    line1: WizardXP est un plugin pour transvaser vos points d'XP dans des fioles de verre, les transformant en Fioles d'Enchantement.
                    line2: "Pour ce faire, cliquez gauche sur une table d'enchantement avec une des 3 baguettes magiques qui sont, dans un ordre croissant de puissance : le bâtonnet de bois, la torche de redstone et le bâton de blaze."
                page2:
                    line1: Cliquer avec le bâtonnet de bois vous donnera une bouteille, en supposant que vous ayez suffisamment de fioles de verre et de points d'XP.
                    line2: La même chose se produira avec la torche de redstone et le bâton de blaze, avec soit une pile de bouteilles, ou le maximum de fioles en verre que vous avez dans votre inventaire.
                page3:
                    line1: Mais extraire des points d'XP de votre corps est une exercice complexe ! Même les meilleurs mages du royaume ne le maîtrisent pas, c'est pourquoi une partie de l'xp sera perdue lors du transvasement.
                    line2_1: "Il vous coutera "
                    line2_2: " points d'XP pour créer une Fiole d'Enchantement, mais vous n'êtes pas sur d'extraire "
                    line2_3: " points d'XP de celle-ci..."
            console: Dieu n'a pas besoin de savoir comment transvaser l'XP, il peut en donner !
    
    The parser seems okay with this one too.
    I've tried removing the whole tab on the whole langConfig.yml, same exception.
     
  5. Offline

    Njol

    I suggest to remove the superfluous spaces from langConfig.yml. In most text editors you can simply highlight the lines and press shift+tab to do so.
     
  6. Offline

    Webster56

    I've done it, the exception stays, but on the first column now.
     
  7. Offline

    Webster56

    Found it :)

    In case you were wondering, looks like this thing doesn't like files that start with comments
     
Thread Status:
Not open for further replies.

Share This Page