Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MySQL
- {
- public static boolean playerExists(String uuid)
- {
- try
- {
- ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if (rs.next()) {
- return rs.getString("UUID") != null;
- }
- return false;
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return false;
- }
- public static void createPlayer(String uuid, String name)
- {
- if (!playerExists(uuid)) {
- MySQLConnector.update("INSERT INTO Stats(UUID, NAME, KILLS, DEATHS, POINTS) VALUES ('" + uuid + "', '" + name + "', '0', '0', '0')");
- }
- }
- public static void setName(String uuid, String name)
- {
- if (playerExists(uuid))
- {
- MySQLConnector.update("UPDATE Stats SET NAME= '" + name + "' WHERE UUID= '" + uuid + "';");
- }
- else
- {
- createPlayer(uuid, name);
- setName(uuid, name);
- }
- }
- public static Integer getKills(String uuid, String name)
- {
- Integer i = Integer.valueOf(0);
- if (playerExists(uuid))
- {
- try
- {
- ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if ((rs.next()) && (Integer.valueOf(rs.getInt("KILLS")) == null)) {}
- i = Integer.valueOf(rs.getInt("KILLS"));
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- createPlayer(uuid, name);
- getKills(uuid, name);
- }
- return i;
- }
- public static Integer getDeaths(String uuid, String name)
- {
- Integer i = Integer.valueOf(0);
- if (playerExists(uuid))
- {
- try
- {
- ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if ((rs.next()) && (Integer.valueOf(rs.getInt("DEATHS")) == null)) {}
- i = Integer.valueOf(rs.getInt("DEATHS"));
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- createPlayer(uuid, name);
- getDeaths(uuid, name);
- }
- return i;
- }
- public static void setKills(String uuid, String name, Integer kills)
- {
- if (playerExists(uuid))
- {
- MySQLConnector.update("UPDATE Stats SET KILLS= '" + kills + "' WHERE UUID= '" + uuid + "';");
- }
- else
- {
- createPlayer(uuid, name);
- setKills(uuid, name, kills);
- }
- }
- public static void setDeaths(String uuid, String name, Integer deaths)
- {
- if (playerExists(uuid))
- {
- MySQLConnector.update("UPDATE Stats SET DEATHS= '" + deaths + "' WHERE UUID= '" + uuid + "';");
- }
- else
- {
- createPlayer(uuid, name);
- setDeaths(uuid, name, deaths);
- }
- }
- public static Integer getRanking(String p)
- {
- boolean done = false;
- int i = 0;
- try
- {
- ResultSet rs = MySQLConnector.query("SELECT UUID FROM Stats ORDER BY POINTS DESC;");
- while ((rs.next()) && (!done))
- {
- i++;
- if (rs.getString(1).equalsIgnoreCase(p)) {
- done = true;
- }
- }
- rs.close();
- }
- catch (SQLException e)
- {
- System.out.println("Ranking Fehler");
- }
- return Integer.valueOf(i);
- }
- public static void addKills(String uuid, String name, Integer kills)
- {
- if (playerExists(uuid))
- {
- setKills(uuid, name, Integer.valueOf(getKills(uuid, name).intValue() + kills.intValue()));
- }
- else
- {
- createPlayer(uuid, name);
- addKills(uuid, name, kills);
- }
- }
- public static void addDeaths(String uuid, String name, Integer deaths)
- {
- if (playerExists(uuid))
- {
- setDeaths(uuid, name, Integer.valueOf(getDeaths(uuid, name).intValue() + deaths.intValue()));
- }
- else
- {
- createPlayer(uuid, name);
- addDeaths(uuid, name, deaths);
- }
- }
- public static void setPoints(String uuid, String name, Integer points)
- {
- if (playerExists(uuid))
- {
- MySQLConnector.update("UPDATE Stats SET POINTS= '" + points + "' WHERE UUID= '" + uuid + "';");
- }
- else
- {
- createPlayer(uuid, name);
- setPoints(uuid, name, points);
- }
- }
- public static void addPoints(String uuid, String name, Integer points)
- {
- if (playerExists(uuid))
- {
- setPoints(uuid, name, Integer.valueOf(getPoints(uuid, name).intValue() + points.intValue()));
- }
- else
- {
- createPlayer(uuid, name);
- addPoints(uuid, name, points);
- }
- }
- public static Integer getPoints(String uuid, String name)
- {
- Integer i = Integer.valueOf(0);
- if (playerExists(uuid))
- {
- try
- {
- ResultSet rs = MySQLConnector.query("SELECT * FROM Stats WHERE UUID= '" + uuid + "'");
- if ((rs.next()) && (Integer.valueOf(rs.getInt("POINTS")) == null)) {}
- i = Integer.valueOf(rs.getInt("POINTS"));
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- }
- else
- {
- createPlayer(uuid, name);
- getPoints(uuid, name);
- }
- return i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement