1.17.x Returns as Null?

Discussion in 'Spigot Plugin Development' started by SyNeox, Jul 7, 2021.

  1. Hey i got a Problem today i made a cfg file as always with a Main-Singleton and for me everything was fine till 1.17 spigot i want to make a Plugin with 25+ survival Gamemodes like Hardcore ultrahardcore and more and i need a cfg file to set the gamemodes to true or false and when i load the plugin into the server this error comes up (i made a writting error dont blame me pls ;D):







    [16:35:15] [Server thread/ERROR]: Could not load 'plugins\Advanced-Diffs.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException: Cannot invoke "me.syneox.difficultys.Main.getConfig()" because the return value of "me.syneox.difficultys.Main.getPlugin()" is null
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:149) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:394) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:301) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.craftbukkit.v1_17_R1.CraftServer.loadPlugins(CraftServer.java:384) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.craftbukkit.v1_17_R1.CraftServer.reload(CraftServer.java:875) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.Bukkit.reload(Bukkit.java:651) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.craftbukkit.v1_17_R1.CraftServer.dispatchCommand(CraftServer.java:760) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.craftbukkit.v1_17_R1.CraftServer.dispatchServerCommand(CraftServer.java:745) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at net.minecraft.server.dedicated.DedicatedServer.handleCommandQueue(DedicatedServer.java:473) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:437) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1200) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1027) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at net.minecraft.server.MinecraftServer.lambda$0(MinecraftServer.java:307) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at java.lang.Thread.run(Thread.java:831) [?:?]
    Caused by: java.lang.NullPointerException: Cannot invoke "me.syneox.difficultys.Main.getConfig()" because the return value of "me.syneox.difficultys.Main.getPlugin()" is null
    at me.syneox.difficultys.Main.<init>(Main.java:13) ~[?:?]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78) ~[?:?]
    at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
    at java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128) ~[?:?]
    at jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350) ~[?:?]
    at java.lang.Class.newInstance(Class.java:642) ~[?:?]
    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:79) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:145) ~[spigot.jar:3159-Spigot-f773da8-887bc05]
    ... 15 more









    and idk what it means with null... i just return plugin in the method heres the src code:












    package me.syneox.difficultys;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.syneox.difficultys.commands.ADifficulties_CMD;
    import me.syneox.difficultys.commands.ADifficulty_CMD;

    public class Main extends JavaPlugin {

    public static String prefix = "§a[Advanced Difficulties] ";
    private static Main plugin;
    FileConfiguration config = Main.getPlugin().getConfig();
    @Override
    public void onEnable() {
    plugin = this;
    config.addDefault("AdvancedHardcore", false);
    System.out.println(Main.prefix + "§agot enabled!");
    System.out.println(Main.prefix + "§aType §6/ADifficulties §ato get all §6Commands §adisplayed!");

    new ADifficulties_CMD(this);
    getCommand("ADifficulty").setExecutor(new ADifficulty_CMD());
    }

    @Override
    public void onDisable() {

    }

    public static String getPrefix() {
    return prefix;
    }

    public static Main getPlugin() {
    return plugin;
    }

    }

    NOTE: In the error as you see it means that in getPlugin() {
    return null; is but it isnt any suggestions?
     
  2. SteelPhoenix

    Moderator

    You call #getPlugin() before #onEnable() is called, meaning your plugin field will still be null.
     
  3. LOL Thank you very much but for me it worked so many times like this lmao