No suitable driver (mysql-connector)



  • Bonjour, je suis actuellement en train de développer des métiers pour un projet de serveur moddé en 1.7.10 Tout est géré par les bases de données mysql. En local, j'utilise XAMPP et ca marche nickel mais dès que j'essai de mettre le mod sur le serveur, il me met que la connexion est impossible No suitable

    No suitable driver
    

    et du coup, dès que j'ouvre le menu je crash. J'ai ajouté dans les librairies du mods (sur eclipse) la librairy mysql-connector. Je ne sais pas si il faut aussi la mettre coté serveur et si oui où ?

    Merci de votre aide.



  • Le problème du suitable n'est plus. Mais maintenant, dés que j'ouvre le menu sur le serveur je crash, je ne comprend pas pourquoi. A l'ouverture du menu, des requetes sont effectués et je pense que ca vient de là mais pourquoi dès qu'une requete est executée, seul le client crash et pas le serveur. Quelqu'un a une idée ?


  • Moddeurs confirmés Rédacteurs Administrateurs

    Oui la bibliothèque doit aussi être mise sur le serveur. Soit l'intégrer au mod, soit l'ajouter au classpath.

    Sinon dire que ton jeu crash mais sans donner le rapport de crash ça ne nous permet pas de t'aider (rappel, c'est indiquer dans les règles de la section qu'il faut envoyer les rapports de crash quand il y en a ...)



  • Désolé, voici le rapport d'erreur. En fait, dès qu'un joueur se connecte, la création du compte est lancée sauf que quand je me connecte coté client ca me met "Internal server error"

    Erreurs coté serveur

    [20:50:36 ERROR]: HandshakeCompletionHandler exception
    java.lang.NullPointerException
            at fr.fulllager.elonia.jobs.JobsManager.hasAnAccount(JobsManager.java:29) ~[JobsManager.class:?]
            at fr.fulllager.elonia.jobs.JobsManager.createAccount(JobsManager.java:43) ~[JobsManager.class:?]
            at fr.fulllager.elonia.jobs.JobsListenerFML.onJoin(JobsListenerFML.java:54) ~[JobsListenerFML.class:?]
            at cpw.mods.fml.common.eventhandler.ASMEventHandler_25_JobsListenerFML_onJoin_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?]
            at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) ~[ASMEventHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) ~[EventBus.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.FMLCommonHandler.firePlayerLoggedIn(FMLCommonHandler.java:568) ~[FMLCommonHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.server.management.ServerConfigurationManager.a(ServerConfigurationManager.java:236) ~[oi.class:?]
            at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:173) ~[NetworkDispatcher.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeHandshake(NetworkDispatcher.java:448) ~[NetworkDispatcher.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:21) ~[HandshakeCompletionHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:11) ~[HandshakeCompletionHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
            at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?]
            at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?]
            at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?]
            at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:77) [FMLProxyPacket.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:244) [ej.class:?]
            at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:173) [nc.class:?]
            at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:980) [MinecraftServer.class:?]
            at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:423) [lt.class:?]
            at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:798) [MinecraftServer.class:?]
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:658) [MinecraftServer.class:?]
            at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
    

    2ème erreur

    [20:50:36 ERROR]: There was a critical exception handling a packet on channel FML
    java.lang.NullPointerException
            at fr.fulllager.elonia.jobs.JobsManager.hasAnAccount(JobsManager.java:29) ~[JobsManager.class:?]
            at fr.fulllager.elonia.jobs.JobsManager.createAccount(JobsManager.java:43) ~[JobsManager.class:?]
            at fr.fulllager.elonia.jobs.JobsListenerFML.onJoin(JobsListenerFML.java:54) ~[JobsListenerFML.class:?]
            at cpw.mods.fml.common.eventhandler.ASMEventHandler_25_JobsListenerFML_onJoin_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?]
            at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) ~[ASMEventHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) ~[EventBus.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.FMLCommonHandler.firePlayerLoggedIn(FMLCommonHandler.java:568) ~[FMLCommonHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.server.management.ServerConfigurationManager.a(ServerConfigurationManager.java:236) ~[oi.class:?]
            at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:173) ~[NetworkDispatcher.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeHandshake(NetworkDispatcher.java:448) ~[NetworkDispatcher.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:21) ~[HandshakeCompletionHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:11) ~[HandshakeCompletionHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
            at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
            at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
            at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:77) [FMLProxyPacket.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:244) [ej.class:?]
            at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:173) [nc.class:?]
            at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:980) [MinecraftServer.class:?]
            at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:423) [lt.class:?]
            at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:798) [MinecraftServer.class:?]
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:658) [MinecraftServer.class:?]
            at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
    

    3ème erreur

    [20:50:36 WARN]: Failed to handle packet for /IP de FullLager
    java.lang.NullPointerException
            at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:101) ~[FMLProxyPacket.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:244) ~[ej.class:?]
            at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:173) [nc.class:?]
            at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:980) [MinecraftServer.class:?]
            at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:423) [lt.class:?]
            at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:798) [MinecraftServer.class:?]
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:658) [MinecraftServer.class:?]
            at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
    [20:50:36 INFO]: FullLager lost connection: Internal server error
    

    Et le problème de connexion est réglé je l’ai ajouté dans les libs et dans le gradle.build L’erreur vient uniquement lors d’une requête à la bdd.


  • Moddeurs confirmés Rédacteurs Administrateurs

    @FullLager a dit dans No suitable driver (mysql-connector) :

    at fr.fulllager.elonia.jobs.JobsManager.hasAnAccount(JobsManager.java:29

    Tu peux envoyer la code de la classe JobsManager ?



  • 
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import fr.fulllager.elonia.Main;
    import fr.fulllager.elonia.events.EventsMod;
    import fr.fulllager.elonia.init.ItemMod;
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.util.ChatComponentText;
    
    public class JobsManager {
    	
    	public static Main main;
    	public JobsManager(Main main) {
    		JobsManager.main = main;
    	}
    	
    	public static boolean hasAnAccount(EntityPlayer p) {
    		try {
    	            PreparedStatement q = main.connection.prepareStatement("SELECT uuid FROM jobs WHERE uuid = ?");
    	            q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    	            ResultSet resultat = q.executeQuery();
    	            boolean hasAccount = resultat.next();
    	            q.close();
    	            return hasAccount;
    	        } catch (SQLException e) {
    	            e.printStackTrace();
    	        }
    		return false;
    	}
    	
    	public static void createAccount(EntityPlayer p) {
    		if(!hasAnAccount(p)) {
    		    try {
    			    PreparedStatement r = main.connection.prepareStatement("INSERT INTO jobs(uuid,pseudo) VALUES (?,?)");
    		     	r.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getName().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    			    System.out.println("La création du compte de "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" a échoué !");
    			    return;
    		    }
    		    System.out.println("La création de compte de "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" a été réalisée avec succès !");
    		}
    	}
    	
    	
    	public static int getFarmerLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT farmer_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("farmer_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	public static int getMinerLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT miner_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("miner_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	
    	public static int getHunterLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT hunter_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("hunter_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	
    	public static double getFarmerXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT farmer_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("farmer_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static double getMinerXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT miner_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("miner_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static double getHunterXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT hunter_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("hunter_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static int getMaxXpForLevel(int level) {
    		int max = 666;
    		if(level == 1) {max = 666;}
    		if(level == 2) {max = 1973;}
    		if(level == 3) {max = 4873;}
    		if(level == 4) {max = 9154;}
    		if(level == 5) {max = 18397;}
    		if(level == 6) {max = 23947;}
    		if(level == 7) {max = 32947;}
    		if(level == 8) {max = 44293;}
    		if(level == 9) {max = 53382;}
    		if(level == 10) {max = 66846;}
    		if(level == 11) {max = 79374;}
    		if(level == 12) {max = 89836;}
    		if(level == 13) {max = 100000;}
    		if(level == 14) {max = 118712;}
    		if(level == 15) {max = 128364;}
    		if(level == 16) {max = 139374;}
    		if(level == 17) {max = 154302;}
    		if(level == 18) {max = 179273;}
    		if(level == 19) {max = 200000;}
    		if(level == 20) {max = 250000;}
    		return max;
    	}
    	
    	
    	public static double getXpForLevel(int level, double xp) {
    		if(level == 1) {return xp;}
    		xp = xp - (level - 1);
    		if(xp <= 0) {return 0;}
    		return xp;
    	}
    	
    	
    	public static void addXp(EntityPlayer p, double xp, String job) {
    		if(job == "Farmer") {
    			double farmer_base_xp = getFarmerXp(p);
    			int farmer_base_level = getFarmerLevel(p);
    			double farmer_xp = farmer_base_xp + getXpForLevel(farmer_base_level, xp);
    			int farmer_max_xp = getMaxXpForLevel(farmer_base_level);
    			long time = System.currentTimeMillis();
    			if(Main.overlay_xp.containsKey(p) && getXpForLevel(farmer_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(farmer_base_level, xp) + sup);
    			} else if(!Main.overlay_xp.containsKey(p) && getXpForLevel(farmer_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(farmer_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			}
    			if(farmer_xp >= farmer_max_xp && !(farmer_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET farmer_level = ? WHERE uuid = ?");
    				    r.setInt(1, farmer_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, farmer_base_level++);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET farmer_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, farmer_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    		if(job == "Miner") {
    			double miner_base_xp = getMinerXp(p);
    			int miner_base_level = getMinerLevel(p);
    			double miner_xp = miner_base_xp + getXpForLevel(miner_base_level, xp);
    			int miner_max_xp = getMaxXpForLevel(miner_base_level);
    			long time = System.currentTimeMillis();
    			if(!Main.overlay_xp.containsKey(p) && getXpForLevel(miner_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(miner_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			} else if(getXpForLevel(miner_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(miner_base_level, xp) + sup);
    			}
    			if(miner_xp >= miner_max_xp && !(miner_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET miner_level = ? WHERE uuid = ?");
    				    r.setInt(1, miner_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, miner_base_level + 1);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET miner_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, miner_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    		if(job == "Hunter") {
    			double hunter_base_xp = getHunterXp(p);
    			int hunter_base_level = getHunterLevel(p);
    			double hunter_xp = hunter_base_xp + getXpForLevel(hunter_base_level, xp);
    			int hunter_max_xp = getMaxXpForLevel(hunter_base_level);
    			long time = System.currentTimeMillis();
    			if(!Main.overlay_xp.containsKey(p) && getXpForLevel(hunter_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(hunter_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			} else if(getXpForLevel(hunter_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(hunter_base_level, xp) + sup);
    			}
    			if(hunter_xp >= hunter_max_xp && !(hunter_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET hunter_level = ? WHERE uuid = ?");
    				    r.setInt(1, hunter_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, hunter_base_level + 1);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET hunter_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, hunter_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    	}
    	
    	
    	public static void giftForLevel(EntityPlayer p, int level) {
    		p.addChatMessage(new ChatComponentText("Bravo, tu passes niveau "+level+" félicitations ! Voici un petit cadeau pour toi !"));
    		System.out.println("Récompense de niveau "+level+" pour "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName());
    		if(level == 2) {MinecraftServer.getServer().getCommandManager().executeCommand(MinecraftServer.getServer(), "give "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" elonia:fluorine_sword");}
    		if(level == 3) {}
    		if(level == 4) {}
    		if(level == 5) {}
    		if(level == 6) {}
    		if(level == 7) {}
    		if(level == 8) {}
    		if(level == 9) {}
    		if(level == 10) {}
    		if(level == 11) {}
    		if(level == 12) {}
    		if(level == 13) {}
    		if(level == 14) {}
    		if(level == 15) {}
    		if(level == 16) {}
    		if(level == 17) {}
    		if(level == 18) {}
    		if(level == 19) {}
    		if(level == 20) {}
    	}
    }
    

    Dès l'ouverture du menu, une requête est éxecutée pour récupérer le niveau et l'xp de chaque métier du joueur (c'est pas opti je sais mais ca fait le taf pour l'instant)


  • Moddeurs confirmés Rédacteurs Administrateurs

    La ligne 29 c'est laquelle ?
    Il semble avoir un décalage dans ce que tu as envoyé, c'est la ligne PreparedStatement q = main.connection.prepareStatement("SELECT uuid FROM jobs WHERE uuid = ?"); ?



  • Ha oui j’ai pas mis le package la ligne 29 c’est le result set.


  • Moddeurs confirmés Rédacteurs Administrateurs

    Je ne vois pas comment il peut avoir un NPE ici.
    Lances ton jeu depuis ton IDE en debug et mets un point d'arrêt pour voir quelle variable est null.



  • J'ai mal transmis la ligne, je reupload le code

    package fr.fulllager.elonia.jobs;
    
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import fr.fulllager.elonia.Main;
    import fr.fulllager.elonia.events.EventsMod;
    import fr.fulllager.elonia.init.ItemMod;
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.util.ChatComponentText;
    
    public class JobsManager {
    	
    	public static Main main;
    	public JobsManager(Main main) {
    		JobsManager.main = main;
    	}
    	
    	public static boolean hasAnAccount(EntityPlayer p) {
    		try {
    	            PreparedStatement q = main.connection.prepareStatement("SELECT uuid FROM jobs WHERE uuid = ?");
    	            q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    	            ResultSet resultat = q.executeQuery();
    	            boolean hasAccount = resultat.next();
    	            q.close();
    	            return hasAccount;
    	        } catch (SQLException e) {
    	            e.printStackTrace();
    	        }
    		return false;
    	}
    	
    	public static void createAccount(EntityPlayer p) {
    		if(!hasAnAccount(p)) {
    		    try {
    			    PreparedStatement r = main.connection.prepareStatement("INSERT INTO jobs(uuid,pseudo) VALUES (?,?)");
    		     	r.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getName().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    			    System.out.println("La création du compte de "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" a échoué !");
    			    return;
    		    }
    		    System.out.println("La création de compte de "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" a été réalisée avec succès !");
    		}
    	}
    	
    	
    	public static int getFarmerLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT farmer_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("farmer_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	public static int getMinerLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT miner_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("miner_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	
    	public static int getHunterLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT hunter_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("hunter_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	
    	public static double getFarmerXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT farmer_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("farmer_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static double getMinerXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT miner_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("miner_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static double getHunterXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT hunter_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("hunter_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static int getMaxXpForLevel(int level) {
    		int max = 666;
    		if(level == 1) {max = 666;}
    		if(level == 2) {max = 1973;}
    		if(level == 3) {max = 4873;}
    		if(level == 4) {max = 9154;}
    		if(level == 5) {max = 18397;}
    		if(level == 6) {max = 23947;}
    		if(level == 7) {max = 32947;}
    		if(level == 8) {max = 44293;}
    		if(level == 9) {max = 53382;}
    		if(level == 10) {max = 66846;}
    		if(level == 11) {max = 79374;}
    		if(level == 12) {max = 89836;}
    		if(level == 13) {max = 100000;}
    		if(level == 14) {max = 118712;}
    		if(level == 15) {max = 128364;}
    		if(level == 16) {max = 139374;}
    		if(level == 17) {max = 154302;}
    		if(level == 18) {max = 179273;}
    		if(level == 19) {max = 200000;}
    		if(level == 20) {max = 250000;}
    		return max;
    	}
    	
    	
    	public static double getXpForLevel(int level, double xp) {
    		if(level == 1) {return xp;}
    		xp = xp - (level - 1);
    		if(xp <= 0) {return 0;}
    		return xp;
    	}
    	
    	
    	public static void addXp(EntityPlayer p, double xp, String job) {
    		if(job == "Farmer") {
    			double farmer_base_xp = getFarmerXp(p);
    			int farmer_base_level = getFarmerLevel(p);
    			double farmer_xp = farmer_base_xp + getXpForLevel(farmer_base_level, xp);
    			int farmer_max_xp = getMaxXpForLevel(farmer_base_level);
    			long time = System.currentTimeMillis();
    			if(Main.overlay_xp.containsKey(p) && getXpForLevel(farmer_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(farmer_base_level, xp) + sup);
    			} else if(!Main.overlay_xp.containsKey(p) && getXpForLevel(farmer_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(farmer_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			}
    			if(farmer_xp >= farmer_max_xp && !(farmer_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET farmer_level = ? WHERE uuid = ?");
    				    r.setInt(1, farmer_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, farmer_base_level++);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET farmer_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, farmer_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    		if(job == "Miner") {
    			double miner_base_xp = getMinerXp(p);
    			int miner_base_level = getMinerLevel(p);
    			double miner_xp = miner_base_xp + getXpForLevel(miner_base_level, xp);
    			int miner_max_xp = getMaxXpForLevel(miner_base_level);
    			long time = System.currentTimeMillis();
    			if(!Main.overlay_xp.containsKey(p) && getXpForLevel(miner_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(miner_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			} else if(getXpForLevel(miner_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(miner_base_level, xp) + sup);
    			}
    			if(miner_xp >= miner_max_xp && !(miner_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET miner_level = ? WHERE uuid = ?");
    				    r.setInt(1, miner_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, miner_base_level + 1);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET miner_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, miner_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    		if(job == "Hunter") {
    			double hunter_base_xp = getHunterXp(p);
    			int hunter_base_level = getHunterLevel(p);
    			double hunter_xp = hunter_base_xp + getXpForLevel(hunter_base_level, xp);
    			int hunter_max_xp = getMaxXpForLevel(hunter_base_level);
    			long time = System.currentTimeMillis();
    			if(!Main.overlay_xp.containsKey(p) && getXpForLevel(hunter_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(hunter_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			} else if(getXpForLevel(hunter_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(hunter_base_level, xp) + sup);
    			}
    			if(hunter_xp >= hunter_max_xp && !(hunter_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET hunter_level = ? WHERE uuid = ?");
    				    r.setInt(1, hunter_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, hunter_base_level + 1);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET hunter_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, hunter_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    	}
    	
    	
    	public static void giftForLevel(EntityPlayer p, int level) {
    		p.addChatMessage(new ChatComponentText("Bravo, tu passes niveau "+level+" félicitations ! Voici un petit cadeau pour toi !"));
    		System.out.println("Récompense de niveau "+level+" pour "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName());
    		if(level == 2) {MinecraftServer.getServer().getCommandManager().executeCommand(MinecraftServer.getServer(), "give "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" elonia:fluorine_sword");}
    		if(level == 3) {}
    		if(level == 4) {}
    		if(level == 5) {}
    		if(level == 6) {}
    		if(level == 7) {}
    		if(level == 8) {}
    		if(level == 9) {}
    		if(level == 10) {}
    		if(level == 11) {}
    		if(level == 12) {}
    		if(level == 13) {}
    		if(level == 14) {}
    		if(level == 15) {}
    		if(level == 16) {}
    		if(level == 17) {}
    		if(level == 18) {}
    		if(level == 19) {}
    		if(level == 20) {}
    	}
    }
    
    

    Donc c'est la ligne

    q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    

    Il ne doit pas trouver l'UUID du joueur.


  • Moddeurs confirmés Rédacteurs Administrateurs

    Ah mais oui, je ne sais pas pourquoi je n'ai pas vu ça plutôt ...

    Pourquoi tu utilises Minecraft.getMinecraft().thePlayer dans des fonctions avec du sql qui sont sensé être exécuté sur le serveur ?

    Surtout que tu as déjà p en argument de ta fonction ... Remplaces Minecraft.getMinecraft().thePlayer. par p. Tu as ce problème partout. La classe Minecraft ne doit jamais être utilisé sur la partie serveur d'un mod.



  • C'est corrigé. Maintenant j'ai ça comme erreur :

    [14:33:32 ERROR]: There was a critical exception handling a packet on channel FML
    java.lang.NullPointerException
            at fr.fulllager.elonia.jobs.JobsManager.hasAnAccount(JobsManager.java:28) ~[JobsManager.class:?]
            at fr.fulllager.elonia.jobs.JobsListenerFML.onJoin(JobsListenerFML.java:54) ~[JobsListenerFML.class:?]
            at cpw.mods.fml.common.eventhandler.ASMEventHandler_25_JobsListenerFML_onJoin_PlayerLoggedInEvent.invoke(.dynamic) ~[?:?]
            at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) ~[ASMEventHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) ~[EventBus.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.FMLCommonHandler.firePlayerLoggedIn(FMLCommonHandler.java:568) ~[FMLCommonHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.server.management.ServerConfigurationManager.a(ServerConfigurationManager.java:236) ~[oi.class:?]
            at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeServerSideConnection(NetworkDispatcher.java:173) ~[NetworkDispatcher.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.handshake.NetworkDispatcher.completeHandshake(NetworkDispatcher.java:448) ~[NetworkDispatcher.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:21) ~[HandshakeCompletionHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at cpw.mods.fml.common.network.internal.HandshakeCompletionHandler.channelRead0(HandshakeCompletionHandler.java:11) ~[HandshakeCompletionHandler.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[SimpleChannelInboundHandler.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) ~[MessageToMessageDecoder.class:?]
            at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) ~[MessageToMessageCodec.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) ~[DefaultChannelHandlerContext.class:?]
            at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) ~[DefaultChannelPipeline.class:?]
            at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) ~[EmbeddedChannel.class:?]
            at cpw.mods.fml.common.network.internal.FMLProxyPacket.func_148833_a(FMLProxyPacket.java:77) [FMLProxyPacket.class:git-Cauldron-MCPC-Plus-1.7.10-1.1207.01.198]
            at net.minecraft.network.NetworkManager.func_74428_b(NetworkManager.java:244) [ej.class:?]
            at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:173) [nc.class:?]
            at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:980) [MinecraftServer.class:?]
            at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:423) [lt.class:?]
            at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:798) [MinecraftServer.class:?]
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:658) [MinecraftServer.class:?]
            at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
    

    Je reupload la classe JobsManager

    package fr.fulllager.elonia.jobs;
    
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    import cpw.mods.fml.common.SidedProxy;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;
    import fr.fulllager.elonia.Main;
    import fr.fulllager.elonia.events.EventsMod;
    import fr.fulllager.elonia.init.ItemMod;
    import net.minecraft.client.Minecraft;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.ItemStack;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.util.ChatComponentText;
    
    public class JobsManager {
    	
    	public static Main main;
    	public JobsManager(Main main) {
    		JobsManager.main = main;
    	}
    	
    	public static boolean hasAnAccount(EntityPlayer p) {
    		try {
    	            PreparedStatement q = main.connection.prepareStatement("SELECT uuid FROM jobs WHERE uuid = ?");
    	            q.setString(1, p.getUniqueID().toString());
    	            ResultSet resultat = q.executeQuery();
    	            boolean hasAccount = resultat.next();
    	            q.close();
    	            return hasAccount;
    	        } catch (SQLException e) {
    	            e.printStackTrace();
    	        }
    		return false;
    	}
    	
    	public static void createAccount(EntityPlayer p) {
    		if(!hasAnAccount(p)) {
    		    try {
    			    PreparedStatement r = main.connection.prepareStatement("INSERT INTO jobs(uuid,pseudo) VALUES (?,?)");
    		     	r.setString(1, p.getUniqueID().toString());
    		    	r.setString(2, p.getDisplayName());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    			    System.out.println("La création du compte de "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" a échoué !");
    			    return;
    		    }
    		    System.out.println("La création de compte de "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" a été réalisée avec succès !");
    		}
    	}
    	
    	
    	public static int getFarmerLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT farmer_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("farmer_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	public static int getMinerLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT miner_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("miner_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	
    	public static int getHunterLevel(EntityPlayer p) {
            try {
            	int res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT hunter_level FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getInt("hunter_level");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 1;
    	}
    	
    	
    	public static double getFarmerXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT farmer_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("farmer_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static double getMinerXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT miner_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("miner_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static double getHunterXp(EntityPlayer p) {
            try {
            	double res = 1;
            	PreparedStatement q = main.connection.prepareStatement("SELECT hunter_xp FROM jobs WHERE uuid = ?");
    			q.setString(1, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			ResultSet resultat = q.executeQuery();
    			while(resultat.next()) {
    				res = resultat.getDouble("hunter_xp");
    			}
    	        q.close();
    	        return res;
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
            return 0;
    	}
    	
    	
    	public static int getMaxXpForLevel(int level) {
    		int max = 666;
    		if(level == 1) {max = 666;}
    		if(level == 2) {max = 1973;}
    		if(level == 3) {max = 4873;}
    		if(level == 4) {max = 9154;}
    		if(level == 5) {max = 18397;}
    		if(level == 6) {max = 23947;}
    		if(level == 7) {max = 32947;}
    		if(level == 8) {max = 44293;}
    		if(level == 9) {max = 53382;}
    		if(level == 10) {max = 66846;}
    		if(level == 11) {max = 79374;}
    		if(level == 12) {max = 89836;}
    		if(level == 13) {max = 100000;}
    		if(level == 14) {max = 118712;}
    		if(level == 15) {max = 128364;}
    		if(level == 16) {max = 139374;}
    		if(level == 17) {max = 154302;}
    		if(level == 18) {max = 179273;}
    		if(level == 19) {max = 200000;}
    		if(level == 20) {max = 250000;}
    		return max;
    	}
    	
    	
    	public static double getXpForLevel(int level, double xp) {
    		if(level == 1) {return xp;}
    		xp = xp - (level - 1);
    		if(xp <= 0) {return 0;}
    		return xp;
    	}
    	
    	
    	public static void addXp(EntityPlayer p, double xp, String job) {
    		if(job == "Farmer") {
    			double farmer_base_xp = getFarmerXp(p);
    			int farmer_base_level = getFarmerLevel(p);
    			double farmer_xp = farmer_base_xp + getXpForLevel(farmer_base_level, xp);
    			int farmer_max_xp = getMaxXpForLevel(farmer_base_level);
    			long time = System.currentTimeMillis();
    			if(Main.overlay_xp.containsKey(p) && getXpForLevel(farmer_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(farmer_base_level, xp) + sup);
    			} else if(!Main.overlay_xp.containsKey(p) && getXpForLevel(farmer_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(farmer_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			}
    			if(farmer_xp >= farmer_max_xp && !(farmer_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET farmer_level = ? WHERE uuid = ?");
    				    r.setInt(1, farmer_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, farmer_base_level++);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET farmer_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, farmer_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    		if(job == "Miner") {
    			double miner_base_xp = getMinerXp(p);
    			int miner_base_level = getMinerLevel(p);
    			double miner_xp = miner_base_xp + getXpForLevel(miner_base_level, xp);
    			int miner_max_xp = getMaxXpForLevel(miner_base_level);
    			long time = System.currentTimeMillis();
    			if(!Main.overlay_xp.containsKey(p) && getXpForLevel(miner_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(miner_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			} else if(getXpForLevel(miner_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(miner_base_level, xp) + sup);
    			}
    			if(miner_xp >= miner_max_xp && !(miner_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET miner_level = ? WHERE uuid = ?");
    				    r.setInt(1, miner_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, miner_base_level + 1);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET miner_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, miner_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    		if(job == "Hunter") {
    			double hunter_base_xp = getHunterXp(p);
    			int hunter_base_level = getHunterLevel(p);
    			double hunter_xp = hunter_base_xp + getXpForLevel(hunter_base_level, xp);
    			int hunter_max_xp = getMaxXpForLevel(hunter_base_level);
    			long time = System.currentTimeMillis();
    			if(!Main.overlay_xp.containsKey(p) && getXpForLevel(hunter_base_level, xp) != 0) {
    				Main.overlay_xp.put(p, getXpForLevel(hunter_base_level, xp));
    				Main.overlay_time.put(p, time + 2000);
    			} else if(getXpForLevel(hunter_base_level, xp) != 0){
    				Double sup = Main.overlay_xp.get(p);
    				Main.overlay_xp.remove(p);
    				Main.overlay_time.remove(p);
    				Main.overlay_time.put(p, time + 2000);
    				Main.overlay_xp.put(p, getXpForLevel(hunter_base_level, xp) + sup);
    			}
    			if(hunter_xp >= hunter_max_xp && !(hunter_base_level + 1 == 21)) {
    				try {
    				    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET hunter_level = ? WHERE uuid = ?");
    				    r.setInt(1, hunter_base_level + 1);
    				    r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    				    r.execute();
    				    r.close();
    			    } catch (SQLException e) {
    				    e.printStackTrace();
    			    }
    				giftForLevel(p, hunter_base_level + 1);
    			}
    			try {
    			    PreparedStatement r = main.connection.prepareStatement("UPDATE jobs SET hunter_xp = ? WHERE uuid = ?");
    		     	r.setDouble(1, hunter_xp);
    		    	r.setString(2, Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString());
    			    r.execute();
    			    r.close();
    		    } catch (SQLException e) {
    			    e.printStackTrace();
    		    }
    		}
    	}
    	
    	
    	public static void giftForLevel(EntityPlayer p, int level) {
    		p.addChatMessage(new ChatComponentText("Bravo, tu passes niveau "+level+" félicitations ! Voici un petit cadeau pour toi !"));
    		System.out.println("Récompense de niveau "+level+" pour "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName());
    		if(level == 2) {MinecraftServer.getServer().getCommandManager().executeCommand(MinecraftServer.getServer(), "give "+Minecraft.getMinecraft().thePlayer.getGameProfile().getName()+" elonia:fluorine_sword");}
    		if(level == 3) {}
    		if(level == 4) {}
    		if(level == 5) {}
    		if(level == 6) {}
    		if(level == 7) {}
    		if(level == 8) {}
    		if(level == 9) {}
    		if(level == 10) {}
    		if(level == 11) {}
    		if(level == 12) {}
    		if(level == 13) {}
    		if(level == 14) {}
    		if(level == 15) {}
    		if(level == 16) {}
    		if(level == 17) {}
    		if(level == 18) {}
    		if(level == 19) {}
    		if(level == 20) {}
    	}
    }
    

    Logiquement, ca retourne false si le joueur n'est pas inscrit et si oui ca return true. La ca me met juste une erreur.


  • Moddeurs confirmés Rédacteurs Administrateurs

    Tu as toujours un NPE.
    Utilises ton débogueur pour trouver quelle variable est null.



  • C'est bon j'arrive à me connecter maintenant. Mais lorsque j'ouvre le menu, le client n'arrive pas à récupérer les données du joueur stockées dans la bdd. Comment faire pour que :
    -Le client demande au serveur les données
    -Le serveur interroge la base de données
    -Le client reçoit les données et les écrits dans le GUI

    Merci


  • Moddeurs confirmés Rédacteurs Administrateurs


Log in to reply