Solved Making a playerName.yml for each player upon logging in, error.

Discussion in 'Plugin Development' started by MrCyberMonkey, Dec 28, 2012.

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

    MrCyberMonkey

    I'm currently trying to make a configuration file for each player that logs in, to store things such as their home position, their last seen date, and the sorts.

    It's all working as planned, it will make a plugins/GoximoBasic/players/MrCyberMonkey.yml
    Except, the error is that it won't load the default configuration options, in this case test.test2.
    Code:
    package me.goximo.net;
     
    import java.io.File;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    import java.util.Map.Entry;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class PlayerFileHandler implements Listener{
     
    public PlayerFileHandler(JavaPlugin plugin) {
    }
    public File folder = new File("plugins/GoximoBasic/players/");
     
    @EventHandler
    public void onFirstLogin(PlayerLoginEvent event) {
    if(!folder.exists()) {
    folder.mkdir();
    }
    File playerFile = new File(folder, event.getPlayer().getName() + ".yml");
    if(!playerFile.exists()) {
    try {
    playerFile.createNewFile();
    } catch (IOException e1) {
    e1.printStackTrace();
    }
    }
     
    YamlConfiguration playerYaml = YamlConfiguration.loadConfiguration(playerFile);
     
    final Map<String, Object> defParams = new HashMap<String, Object>();
    playerYaml.options().copyDefaults(true);
    // This is the default configuration
    defParams.put("test.test2", "yes");
     
    // If config does not include a default parameter, add it
    for (final Entry <String, Object> e : defParams.entrySet())
    if (!playerYaml.contains(e.getKey()))
    playerYaml.set(e.getKey(), e.getValue());
     
    //Save the config
    this.saveConfig();
    }
     
    }
    
    Here is the error:
    Code:
    10:17:07 [SEVERE] Could not pass event PlayerLoginEvent to GoximoBasic v1.0
    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    at net.minecraft.server.v1_4_6.PlayerList.attemptLogin(PlayerList.java:274)
    at net.minecraft.server.v1_4_6.PendingConnection.d(PendingConnection.java:121)
    at net.minecraft.server.v1_4_6.PendingConnection.c(PendingConnection.java:45)
    at net.minecraft.server.v1_4_6.DedicatedServerConnectionThread.a(DedicatedServerConnectionTh
    read.java:44)
    at net.minecraft.server.v1_4_6.DedicatedServerConnection.b(SourceFile:29)
    at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:585)
    at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:481)
    at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:416)
    at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:
    170)
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    at org.bukkit.plugin.java.JavaPlugin.saveConfig(JavaPlugin.java:129)
    at me.goximo.net.PlayerFileHandler.onFirstLogin(PlayerFileHandler.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 13 more
    10:17:07 [INFO] MrCyberMonkey[/127.0.0.1:54474] logged in with entity id 4437 at ([world] 213.439013
    5310749, 115.81747761554766, 743.4224004737873)
     
  2. Offline

    chaseoes

    Looks like you cut something out of your code or added something (comments?).
     
  3. Offline

    raGan.

    Code:
    try {
        if(!playerFile.exists()) {
            playerFile.createNewFile();
        }
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    EDIT: looking at it again, i'm not sure what i wanted to achieve with this
     
  4. Offline

    MrCyberMonkey

    Thanks for all of the help, but after I noticed I was attempting to save the default config, I realized that I'm a dunce...
     
  5. Offline

    HeartsFlame

    MrCyberMonkey, you realise you made the first thing with goximo, I searched it and top result :D

    -not about codes
     
Thread Status:
Not open for further replies.

Share This Page