Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de.julian.holostats.mysql;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import org.bukkit.Bukkit;
- import de.julian.holostats.main.Main;
- public class Mysql {
- public String password = "";
- public String database = "";
- public String user = "";
- public String host = "";
- public static Connection con;
- // public Mysql(String password, String database, String user, String host)
- // {
- // this.password = password;
- // this.database = database;
- // this.user = user;
- // this.host = host;
- // connect();
- // }
- public Mysql(String password, String database, String user, String host)
- {
- this.password = "";
- this.database = "minecraft_knockffa";
- this.user = "Julian";
- this.host = "localhost";
- connect();
- }
- public void connect()
- {
- if (!isConnected()) {
- try{
- con = DriverManager.getConnection("jdbc:mysql://" + this.host + ":3360/" + this.database, this.user, this.password);
- Bukkit.getConsoleSender().sendMessage(Main.getPrefix() + "§aErfolgreich aufgebaut");
- }catch (SQLException ex){
- ex.printStackTrace();
- }
- }
- }
- public void disconnect()
- {
- if (isConnected()) {
- try
- {
- con.close();
- System.out.println("[MYSQL] Disonnected!");
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public boolean isConnected()
- {
- return con != null;
- }
- public void update(String qry)
- {
- try
- {
- PreparedStatement ps = con.prepareStatement(qry);
- ps.executeUpdate();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- public ResultSet query(String qry)
- {
- ResultSet rs = null;
- try
- {
- Statement st = con.createStatement();
- rs = st.executeQuery(qry);
- }
- catch (SQLException e)
- {
- connect();
- System.err.println(e);
- }
- return rs;
- }
- public ResultSet getResult(String qry)
- {
- try
- {
- PreparedStatement ps = con.prepareStatement(qry);
- return ps.executeQuery();
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return null;
- }
- public Connection getConnection()
- {
- return con;
- }
- public void reconnect()
- {
- if (con == null) {
- connect();
- }
- }
- public static boolean playerExists(String uuid)
- {
- try
- {
- ResultSet rs = Main.mysql.query("SELECT * FROM knockout WHERE UUID= '" + uuid + "'");
- if (rs.next()) {
- return rs.getString("UUID") != null;
- }
- return false;
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return false;
- }
- public static Integer getKills(String uuid)
- {
- Integer i = Integer.valueOf(0);
- if (playerExists(uuid))
- {
- try
- {
- ResultSet rs = Main.mysql.query("SELECT * FROM knockout WHERE UUID= '" + uuid + "'");
- if (rs.next()) {
- Integer.valueOf(rs.getInt("KILLS"));
- }
- i = Integer.valueOf(rs.getInt("KILLS"));
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- getKills(uuid);
- }
- return i;
- }
- public static Integer getDeaths(String uuid)
- {
- Integer i = Integer.valueOf(0);
- if (playerExists(uuid))
- {
- try
- {
- ResultSet rs = Main.mysql.query("SELECT * FROM knockout WHERE UUID= '" + uuid + "'");
- if (rs.next()) {
- Integer.valueOf(rs.getInt("DEATHS"));
- }
- i = Integer.valueOf(rs.getInt("DEATHS"));
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- getDeaths(uuid);
- }
- return i;
- }
- public static int getRank(String uuid)
- {
- int rank = 0;
- try
- {
- PreparedStatement ps = con.prepareStatement("SELECT * FROM knockout ORDER BY KILLS DESC");
- ResultSet result = ps.executeQuery();
- while (result.next())
- {
- rank++;
- String uuid2 = result.getString("UUID");
- if (uuid2.equalsIgnoreCase(uuid)) {
- return rank;
- }
- }
- result.close();
- ps.close();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- return rank;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement