Discussion in 'Spigot Plugin Development' started by Daeshan, Jun 1, 2016.

Thread Status:
Not open for further replies.
  1. So I am trying to intialize Main in my classes to avoid me :D

    Code (Text):
    public class MYSQL_InsertPlayerData implements Listener {
        private Main m;
        public MYSQL_InsertPlayerData(Main main) {
            this.m = main;
        private  int air;
        private  int level;
        private  String rank;
        private  int money;
        // CHECK IF PLAYER EXIST===========================
        public boolean playerExists(String uuid) throws SQLException {
            PreparedStatement rs = m.c.prepareStatement("SELECT * FROM Atlas WHERE UUID='"+ uuid + "';");
                if (rs.getResultSet().next()) {
                    return rs.getResultSet().getString("UUID") != null;
            return false;
    Stack Trace:
    Code (Text):
    [01:14:24 ERROR]: Could not pass event PlayerJoinEvent to AtlasCraft v1.0
            at$1.execute( ~[latest.jar:git-Spigot-8a048fe-a022dd2]
            at org.bukkit.plugin.RegisteredListener.callEvent( ~[latest.jar:git-Spigot-8a048fe-a022dd2]
            at org.bukkit.plugin.SimplePluginManager.fireEvent( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at org.bukkit.plugin.SimplePluginManager.callEvent( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.PlayerList.onPlayerJoin( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.PlayerList.a( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.LoginListener.b( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.LoginListener.c( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.NetworkManager.a( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.ServerConnection.c( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.MinecraftServer.D( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.DedicatedServer.D( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at net.minecraft.server.v1_9_R2.MinecraftServer.C( [latest.jar:git-Spigot-8a048fe-a022dd2]
            at [latest.jar:git-Spigot-8a048fe-a022dd2]
            at [?:1.7.0_79]
    Caused by: java.lang.NullPointerException
            at me.dabuseck.atlas.MYSQL.MYSQL_InsertPlayerData.playerExists( ~[?:?]
            at ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
            at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.7.0_79]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.7.0_79]
            at java.lang.reflect.Method.invoke( ~[?:1.7.0_79]
            at$1.execute( ~[latest.jar:git-Spigot-8a048fe-a022dd2]
            ... 14 more
  2. What is there on line 25? *Show me*
    Next, wtf avoid static, uhh, does passing instance doesn't for you
    #2 Banbeucmas, Jun 1, 2016
    Last edited: Jun 1, 2016
  3. It doesn't look like you actually execute the statement anywhere, so getResultSet() will always be null.

    Look into
    Don't forget to protect your code from SQL injection by using a '?' instead of uuid then inserting the uuid as a prepared parameter
    This code will lock your server's main thread while it is executing, consider using AsyncPlayerPreLoginEven instead
    Calling ResultSet::next twice will switch to the second row, which will always be null as you won't have two rows with the same player uuid
    Don't check if UUID is null in the result set, because if ResultSet::next isn't null, UUID won't be either, you need to check how many rows are in the result set instead (Hint: 0 rows means the player doesn't exist)
    • Winner Winner x 1
  4. This issue is with the public Main m;
  5. Try to pass the main instance instead, it should be easy
  6. 4chan


    • Optimistic Optimistic x 1
Thread Status:
Not open for further replies.