Configuration file error

Discussion in 'Plugin Development' started by blaatz0r, Jan 22, 2011.

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

    blaatz0r

    I'm currently writing a plugin, but the configuration file seems to give some weird errors and I can't figure out what's wrong.

    Code:
    SEVERE: null; expected '<document start>', but found Scalar (Is it up to date?)
    expected '<document start>', but found Scalar
     in "<reader>", line 8, column 1:
        reward-items:true
        ^
    
            at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentStart.produce(ParserImpl.java:233)
            at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:163)
            at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:148)
            at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:108)
            at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:124)
            at org.yaml.snakeyaml.Yaml.load(Yaml.java:264)
            at org.bukkit.util.config.Configuration.load(Configuration.java:62)
            at com.bukkit.blaatz0r.Trivia.TriviaSettings.initialize(TriviaSettings.java:57)
            at com.bukkit.blaatz0r.Trivia.Trivia.onEnable(Trivia.java:66)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:135)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:282)
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:173)
            at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:60)
            at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:45)
            at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:153)
            at net.minecraft.server.MinecraftServer.c(MinecraftServer.java:140)
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:104)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:177)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:512)
    And this is TriviaSettings.java:

    Code:
    public class TriviaSettings {
        private static final String settingsFile = "Trivia.yml";
    
        public static HashMap<String,String> defaults;
        public static int timer;
        public static int backupTimer;
        public static int questionTimeout;
        public static int maxHints;
        public static boolean rewardPoints;
        public static boolean rewardItems;
        public static int points;
        public static List<Integer> items;
        public static int decrease;
        public static boolean permNext;
        public static boolean permHint;
        public static String dbName;
        public static int lettersPerHint;
    
        public static void initialize(File dataFolder) {
    
            defaults = new HashMap<String,String>();
            defaults.put("timer", "15");
            defaults.put("time-out", "5");
            defaults.put("max-hints", "3");
            defaults.put("reward-points", "true");
            defaults.put("reward-items", "true");
            defaults.put("points", "10");
            defaults.put("#items", "A list of item IDs of which one is randomly rewarded");
            defaults.put("items", "[1,3,4]");
            defaults.put("decrease", "2");
            defaults.put("permissions-next", "true");
            defaults.put("permissions-hint", "true");
            defaults.put("db-name", "trivia.db");
            defaults.put("letters-per-hint", "8");
    
            if(!dataFolder.exists()) {
                dataFolder.mkdirs();
            }
    
            File configFile = new File(dataFolder, settingsFile);
            if(!configFile.exists()) {
                createSettingsFile(configFile);
            }
            Configuration config = new Configuration(configFile);
            config.load();
            timer             = Math.max(1, config.getInt("timer", 15));
            backupTimer     = timer;
            questionTimeout = Math.max(1, config.getInt("time-out", 5));
            maxHints         = config.getInt("max-hints", 3);
            rewardPoints     = config.getBoolean("reward-points", true);
            rewardItems        = config.getBoolean("reward-items", true);
            points            = config.getInt("points", 10);
            items            = config.getIntList("items", null);
            decrease        = config.getInt("points-decrease", 2);
            permNext        = config.getBoolean("permissions-next", true);
            permHint        = config.getBoolean("permissions-hint", true);
            dbName            = config.getString("db-name", "trivia.db");
            lettersPerHint    = config.getInt("letters-per-hint", 8);
        }
    
        public static void resetTimer() {
            timer = Math.max(1, backupTimer);
        }
    
        public static void setTimer(int t) {
            timer = t;
        }
    
        private static void createSettingsFile(File configFile) {
            BufferedWriter bwriter = null;
            FileWriter fwriter = null;
            try {
                configFile.createNewFile();
                fwriter = new FileWriter(configFile, true);
                bwriter = new BufferedWriter(fwriter);
                bwriter.newLine();
    
                for (Map.Entry<String, String> e : defaults.entrySet()) {
    
                    bwriter.write(e.getKey() + ":" + e.getValue());
                    bwriter.newLine();
                }
                bwriter.flush();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (bwriter != null) {
                        bwriter.close();
                    }
                    if (fwriter != null)
                        fwriter.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    And finally Trivia.yml:

    Code:
    reward-points:true
    max-hints:3
    #items:A list of item IDs of which one is randomly rewarded
    reward-items:true
    db-name:trivia.db
    time-out:5
    items:[1,3,4]
    timer:15
    letters-per-hint:8
    permissions-next:true
    permissions-hint:true
    points:10
    decrease:2
    
    My guess is that sometthing is wrong with the yml file, but I don't see what.


    Edit: Seems like the comment is causing some problems. Dunno why tho.
    Also, the items list seems to break, what is the right syntax for specifying a list in YML?

    There needs to be a space between the colon and the value, so:

    timer: 15 instead of timer:15

    Took me ages to find >.<

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 6, 2016
  2. Offline

    matjam

    Hey, so does org.bukkit.util.config actually work?

    Docs say "This class is currently incomplete. It is not yet possible to get a node.".

    Are the docs just out of date?

    The javadoc for bukkit is frustrating. :)
     
Thread Status:
Not open for further replies.

Share This Page