Solved [HELP] For Loop

Discussion in 'Spigot Plugin Development' started by DragonLord__, Jan 28, 2020.

Thread Status:
Not open for further replies.
  1. Error:
    Code (Text):

    Could not pass event PlayerJoinEvent to VenomLR v1.0
    org.bukkit.event.EventException: null
            at$1.execute( ~[Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at org.bukkit.plugin.RegisteredListener.callEvent( ~[Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at org.bukkit.plugin.SimplePluginManager.fireEvent( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at org.bukkit.plugin.SimplePluginManager.callEvent( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.PlayerList.a( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.LoginListener.c( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.LoginListener.tick( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.NetworkManager.a( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.ServerConnection.c( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.MinecraftServer.b( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.DedicatedServer.b( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at net.minecraft.server.v1_14_R1.MinecraftServer.a( [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at [Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            at [?:1.8.0_232]
    Caused by: java.lang.NullPointerException
            at ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_232]
            at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_232]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_232]
            at java.lang.reflect.Method.invoke( ~[?:1.8.0_232]
            at$1.execute( ~[Spigot.jar:git-Spigot-cbd1a1b-009d8af]
            ... 13 more
    Code (Text):

        public void onJoin(PlayerJoinEvent e)
            Player p = e.getPlayer();
            boolean pronadjen = false;
            if(plugin.enabledSQL == false)
                for(String players : plugin.players.getConfigurationSection("Players").getKeys(false)) //Line with an error
                        plugin.registered = true;
                        pronadjen = true;
                        Bukkit.getServer().getConsoleSender().sendMessage("Igrac je pronadjen!");
                if(pronadjen == false)
                    Bukkit.getServer().getConsoleSender().sendMessage("Igrac nije pronadjen!");
                    plugin.registered = false;
    Code (Text):

      //Here should be UUID when added
        //Here should be PlayerName when added, but not for now
    Tried: Adding UUID and everything needed so players is not empty, not fixed.

    I don't understand why and how...
  2. Whatever line 22 references in your Events class is null. I'd assume it's plugin.players, you probably forgot to initialize it. This is one of the reasons why you should not make variables static for easy access, but rather access them through getter and setter methods.

    Very minor side note, you don't need to check for if (boolean == false) on booleans, if(!boolean) is enough.
  3. Something on line 22 is null.
    As a guess it is plugin.players.getConfigurationSection("Players").getKeys(false).
    could be the "plugin" variable is null, the "players" variable found in your plugin is null, or the configuration section "Players" can not be found in your config.yml or is blank and results in being null.
  4. Main plugin = Main.getPlugin(Main.class) (plugin is clearly here)
    players refers to players.yml
    players = New YamlConfiguration(); in main class
    "Players" is not in config but in players.yml thats why I used plugin.players
    (Gadse, thansk for getter and setter)
  5. If you don't understand the exact cause, break your code down and debug it. Make a few checks for null.

    Code (Java):
    if (plugin == null) {
      System.out.println("Plugin is null");

    if (plugin.players == null) {
     // etc.
    You'll surely find the root cause through that :)
  6. Thanks, it ended up that ConfigurationSection was null. Apparently it seems like Main class didn't execute players.load(playersFile); ....
Thread Status:
Not open for further replies.