Error when reading config

Discussion in 'Plugin Development' started by jwnordquist, Dec 10, 2012.

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

    jwnordquist

    I am currently getting this issue when i'm trying to read the config file to set the location of a player when he logs in... if anyone knows how to fix this issue, the help would be greatly appreciated!

    Error:
    Code:
    22:27:22 [SEVERE] Could not pass event PlayerLoginEvent to Logout TP v1.0.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
        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.ServerConfigurationManagerAbstract.attemptLogin(ServerConfigurationManagerAbstract.java:268)
        at net.minecraft.server.NetLoginHandler.d(NetLoginHandler.java:123)
        at net.minecraft.server.NetLoginHandler.c(NetLoginHandler.java:45)
        at net.minecraft.server.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:44)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:29)
        at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
        at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    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 com.gmail.jwnordquist.LogoutTP.PlayerListener.onPlayerLogin(PlayerListener.java:22)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
    code:

    Code:
    package com.gmail.jwnordquist.LogoutTP;
     
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class PlayerListener extends JavaPlugin implements Listener {
        public LogoutTP plugin;
       
        public PlayerListener(LogoutTP instance){
            plugin = instance;
        }
       
        @EventHandler 
        public void onPlayerLogin(PlayerLoginEvent event) {
            Player p = event.getPlayer();
           
            Location location = p.getLocation();
            location.setX(getConfig().getDouble("x"));
            location.setY(getConfig().getDouble("y"));
            location.setZ(getConfig().getDouble("Z"));
            location.setYaw((float) getConfig().getDouble("yaw"));
            location.setPitch((float) getConfig().getDouble("pitch"));
           
            p.teleport(location);
            p.sendMessage("Welcome");
           
        }
    }
     
  2. Offline

    gomeow

    The file does not exist.
    Add a config.yml to your project folder and make a default config.
    In your onEnable, write this line:
    Code:
    saveDefaultConfig();
     
  3. Offline

    jwnordquist

    Well, the thing is, the config has already been made and can be edited using the command from the main class, but when i try and use the listener, it throws the error.
     
  4. Offline

    gomeow

    I thought it was your main class... You can only have ONE main class. The main class is the ONE that extends JavaPlugin which can only happen ONCE.

    Then just do plugin.getConfig()
     
  5. Offline

    Barinade

    Make your listener extend your main class, not JavaPlugin
     
  6. Offline

    jwnordquist

    Thanks for the help! Just one last question, is it possible to get variables from my main class and vice versa?
     
  7. Offline

    gomeow

    I believe you could do this:

    if(plugin.variableName ...)
     
  8. Offline

    Barinade

    Keep all global variables in your main class and let your other classes extend your main class.
     
Thread Status:
Not open for further replies.

Share This Page