Solved MySQL Points System

Discussion in 'Plugin Development' started by YoRHaNo2TypB, Sep 23, 2017.

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

    YoRHaNo2TypB

    I'm getting a NullPointerException and I don't know why..

    Show Spoiler
    Code:
    [20:24:02] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to ServerPlugin v0.1
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:298) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:157) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java:148) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:814) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
    Caused by: java.lang.NullPointerException
        at me.ahriox.listeners.PlayerListener.onPlayerJoin(PlayerListener.java:114) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
        ... 14 more
    [20:24:02] [Server thread/INFO]: YoRHaNr2TypB[/127.0.0.1:55376] logged in with entity id 15 at ([world]309.6640482568802, 18.0, -635.8880560753288)
    


    I've got this code at line 114:

    Line 114: "if(!cManager.isUserExists(p.getUniqueId())) {"

    Show Spoiler

    PlayerListener:
    Code:
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            MySQLPoints cManager = ServerMain.getPointsManager();
            InventoryManager invManager = ServerMain.getInventoryManager();
            int startCoins = 300;
          
            ItemStack gameMenu = invManager.gameMenu();
            ItemStack shopMenu = invManager.shopMenu();
            ItemStack statsMenu = invManager.statsMenu();
          
            p.getInventory().clear();
            p.getInventory().setItem(0, gameMenu);
            p.getInventory().setItem(4, shopMenu);
            p.getInventory().setItem(8, statsMenu);
          
            this.plugin.lobby.add(p);
            e.setJoinMessage(null);
            if(!cManager.isUserExists(p.getUniqueId())) {
                cManager.add(p.getUniqueId(), startCoins, p.getName());
                p.sendMessage("Du bekommst fürs erstemal einloggen " + startCoins + " geschenkt!");
            } else {
                //Daily login reward
            }
        }
    
    MySQLPoints:
    Code:
        public boolean isUserExists(UUID uuid) {
            try {
                PreparedStatement ps = MySQL.getConnection().prepareStatement("SELECT Punkte FROM punktesystem WHERE UUID = ?");
                ps.setString(1, uuid.toString());
                ResultSet rs = ps.executeQuery();
                return rs.next();
            } catch(SQLException e) {
                e.printStackTrace();
            }
            return false;
        }
    


    Has someone an idea?
     
    Last edited: Sep 23, 2017
  2. Offline

    Zombie_Striker

  3. Offline

    YoRHaNo2TypB

    Well, I guess it was null in my main.java...

    Hm, we might consider update on a newer version.
    Thank you anyway.
     
Thread Status:
Not open for further replies.

Share This Page