Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hub.ph1823.fr;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Hashtable;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.plugin.java.JavaPlugin;
- public class Main extends JavaPlugin{
- private String url =
- private String user = "serv
- private String passwd = "
- public java.sql.Connection conn;
- public static int easycoin;
- public static int easyeuro;
- public static Hashtable<Integer, ItemStack> ItemsCompass = null;
- public static Hashtable<Integer, ItemStack> ItemsShop = null;
- public void onEnable() {
- getServer().getPluginManager().registerEvents(new EventListener(this), this);
- CustomEntityType.registerEntities();
- getCommand("set").setExecutor(new Commanset(this));
- getCommand("setitem").setExecutor(new CommandSetItem(this));
- getCommand("settitle").setExecutor(new CommandSetTitle(this));
- ItemCompass I = new ItemCompass(this);
- ItemsCompass = I.BuildItems();
- ItemShop I1 = new ItemShop(this);
- ItemsShop = I1.BuildItems();
- connect();
- CustomEntityType.registerEntities();
- }
- public void onDisable() {
- CustomEntityType.unregisterEntities();
- try { //using a try catch to catch connection errors (like wrong sql password...)
- if(conn!=null && conn.isClosed()){ //checking if connection isn't null to
- //avoid recieving a nullpointer
- conn.close(); //closing the connection field variable.
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- public void connect(){
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch (ClassNotFoundException e1) {
- e1.printStackTrace();
- }
- try {
- conn = DriverManager.getConnection(url, user, passwd);
- System.out.println("Connexion établie!");
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void donne(String pseudo) {
- try { //using a try catch to catch connection errors (like wrong sql password...)
- if (this.conn == null || conn.isClosed()) { // on vérivie si la connection est active
- connect(); // si ce n'est pas le cas, on se reconnecte
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- try {
- Statement state = conn.createStatement();
- ResultSet result = state.executeQuery("SELECT * FROM easy_membre WHERE pseudo = '" + pseudo + "'");
- while(result.next())
- {
- easycoin = result.getInt(2);
- easyeuro = result.getInt(3);
- state.close();
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void Test(String pseudo) {
- try { //using a try catch to catch connection errors (like wrong sql password...)
- if (this.conn == null || conn.isClosed()) { // on vérivie si la connection est active
- connect(); // si ce n'est pas le cas, on se reconnecte
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- try {
- Statement state = conn.createStatement();
- ResultSet result = state.executeQuery("SELECT * FROM easy_membre WHERE pseudo = '" + pseudo + "'");
- if (!result.isBeforeFirst()) {
- state.executeUpdate("INSERT INTO easy_membre (pseudo, easycoin, easyeuro) VALUES ('"+pseudo+"',0,0)");
- state.close();
- }
- // result.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment