Need help with config (I think)

Discussion in 'Plugin Development' started by sara4012, Feb 6, 2014.

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

    sara4012

    I currently have a listener running for when players log in, it checks if they've been on the server before, and if they haven't make a data slot for them (I am storing the data for them in a yml file). Whenever I log on to test, It throws this error:
    Code:
    [21:26:49] [Server thread/ERROR]: Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: expected '<document start>', but found Scalar
    in "<string>", line 5, column 1:
        max-lives:10
        ^
     
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:149) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:204) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:154) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:144) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at com.yubacraft.conqueror.Conqueror.playedBefore(Conqueror.java:100) [Conqueror091.jar:?]
        at com.yubacraft.conqueror.Conqueror$JoinListener.onJoin(Conqueror.java:157) [Conqueror091.jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_17]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_17]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_17]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_17]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:318) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:481) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:466) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.c(PlayerList.java:225) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.a(PlayerList.java:116) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.c(LoginListener.java:78) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.LoginListener.a(LoginListener.java:42) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:149) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
    Caused by: org.yaml.snakeyaml.parser.ParserException: null; expected '<document start>', but found Scalar
        at org.yaml.snakeyaml.parser.ParserImpl$ParseDocumentStart.produce(ParserImpl.java:231) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:109) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:399) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-10-gd51ccd1-b2987jnks]
        ... 25 more
    [21:28:32] [Server thread/INFO]: Unknown command. Type "help" for help.
    
    Here's the code of the Listener:
    Code:java
    1. private class JoinListener implements Listener {
    2.  
    3. @EventHandler (priority = EventPriority.HIGH)
    4. public void onJoin (PlayerJoinEvent e){
    5. Player player = e.getPlayer();
    6. if (!playedBefore(player) == true){
    7. int amountToAdd = getConfig().getInt("default-lives");
    8. addLives(amountToAdd, player);
    9. }
    10. }
    11. }


    Code for the method "playedBefore":
    Code:java
    1. public boolean playedBefore (Player playerName){
    2. Player player = playerName;
    3. if (getConfig().contains("data." + player)){
    4. return true;
    5. }
    6. return false;
    7. }

    Here's the code for the method addLives:
    Code:java
    1. public void addLives(int amount, Player playerName){
    2. Player player = playerName;
    3. int before = getConfig().getInt("data." + player);
    4. int after = before + amount;
    5. this.getConfig().set("data." + player, after);
    6. }

    And here's the default config:
    Code:
    #Amount of lives a player starts with
    default-lives:5
     
    #Max amount of lives
    max-lives:10
     
    #Does it say the player's lives over his head?
    display-lives-over-head: true
     
    data:
        # (PlayerName) : (Lives they have)
    Thanks in advance for the help!
     
  2. Offline

    mazentheamazin

    sara4012
    Join listener does not extend JavaPlugin 0_O
    You should make a reference to a main class. There are several ways to do this I will show you mine:
    1. Add a line to your Main class that is:
    Code:java
    1. Main plugin;

    2. Now add this to your onEnable. This will define the variable we just created:
    Code:java
    1. plugin = this;

    3. Add this method to the class. The name of it doesn't matter, you can use getInstance, getPlugin, or anything!
    Code:java
    1. public static Main getPlugin() {
    2. return plugin;
    3. }

    4. Now you can reference the main class by doing this:
    Code:java
    1. Main.getPlugin()
    2. // If you want to get the config
    3. Main.getPlugin().getConfig()

    Then we're done! You can now use methods from JavaPlugin in other classes!
    Optional:
    If you want to just do Main.getConfig() we can!
    Make a method called getConfig()
    Code:java
    1. public static FileConfiguration getConfig() {
    2. return plugin.getConfig();
    3. }
     
  3. Offline

    sara4012

    It's in my main class. Sorry, I should have been more clear about that
     
  4. Offline

    sockmonkey1

    Have you parsed the YAML doc? This is a good place.
     
  5. Offline

    sara4012

    what's that mean?
     
Thread Status:
Not open for further replies.

Share This Page