Config returns null

Discussion in 'Spigot Help' started by sd_master92, May 26, 2018.

  1. This is a part of my code:

    Code (Text):
    package server.main;
    import java.util.logging.Logger;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin {
        public void onEnable() {
            PluginDescriptionFile pdf = this.getDescription();
            Logger logger = Logger.getLogger("Minecraft");
            this.registerConfig();
            this.registerListeners();
            logger.info(pdf.getName() + " v" + pdf.getVersion() + " has been enabled.");
        }
        public void onDisable() {
            PluginDescriptionFile pdf = this.getDescription();
            Logger logger = Logger.getLogger("Minecraft");
            logger.info(pdf.getName() + " v" + pdf.getVersion() + " has been disabled.");
        }
     
        private void registerConfig() {
            this.getConfig().options().copyDefaults(true);
            saveConfig();
        }
        private void registerListeners() {
            PluginManager pm = this.getServer().getPluginManager();
            pm.registerEvents(new EventManager(this), this);
        }
    }

    Code (Text):
    package server.main;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
    public class EventManager implements Listener {
        private Main plugin;
        public EventManager(Main pl) {
            this.plugin = pl;
        }
        FileConfiguration conf = plugin.getConfig(); // this gives me a null
     
        @EventHandler
        public void onPlayerLogin(AsyncPlayerPreLoginEvent event) {
        }
    }

    Code (Text):
    [19:06:37 ERROR]: Error occurred while enabling ServerComplete v1.0.1 (Is it up to date?)
    java.lang.NullPointerException: null
            at server.main.EventManager.<init>(EventManager.java:16) ~[?:?]
            at server.main.Main.registerListeners(Main.java:30) ~[?:?]
            at server.main.Main.onEnable(Main.java:16) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot.jar:git-Spigot-2086bb0-d0a3620]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:403) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:381) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:330) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:422) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:383) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:338) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:545) [spigot.jar:git-Spigot-2086bb0-d0a3620]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_171]
     
    #1 sd_master92, May 26, 2018
    Last edited: May 26, 2018
  2. Strahan

    Benefactor

    Is your console showing "players.yml loaded" when the server starts and it inits your plugin?
     
  3. It is loaded when the plugin enables.
     
  4. Now I have completely simplified the classes, and as you can see, the error STILL comes when trying to retreive the config.yml from the EventsManager class. What can I do?