· 7 years ago · Feb 15, 2019, 11:26 PM
1void verifyTableState() throws SQLException {
2 try(Connection connection = hikariDataSource.getConnection()) {
3 connection.createStatement().executeUpdate(
4 "create table if not exists JasPVP" +
5 " (uuid varchar(36) not null primary key," +
6 " kills int(10)," +
7 " deaths int(10)," +
8 " exp decimal(10)," +
9 " level int(10)," +
10 " kdr decimal(10)," +
11 " wins int(10));"
12 );
13 }
14 }
15
16 public boolean playerExists(Player p) throws SQLException {
17 try(Connection connection = hikariDataSource.getConnection()) {
18 PreparedStatement sql = connection.prepareStatement("select uuid from JasPVP where uuid = ?");
19 sql.setString(1, p.getUniqueId().toString());
20 ResultSet rs = sql.executeQuery();
21 rs.beforeFirst();
22 boolean hasEntry = rs.next();
23 rs.close();
24 return hasEntry;
25 }
26 }
27
28 public void savePlayer(Player p, int kills, int deaths, double exp, int level, float kdr, int wins) throws SQLException {
29 try(Connection connection = hikariDataSource.getConnection()) {
30 PreparedStatement sql = connection.prepareStatement("UPDATE JasPVP set kills = ?, deaths = ?, exp = ?, level = ?, kdr = ?, wins = ? where uuid = ?");
31 sql.setInt(1, kills);
32 sql.setInt(2, deaths);
33 sql.setDouble(3, exp);
34 sql.setInt(4, level);
35 sql.setFloat(5, kdr);
36 sql.setInt(6, wins);
37 sql.setString(7, p.getUniqueId().toString());
38 sql.execute();
39 sql.close();
40 }
41 }
42
43
44
45
46
47
48
49
50
51 /*
52 * GETTERS
53 */
54
55 public int getPlayerKills(Player p) throws SQLException {
56 try(Connection connection = hikariDataSource.getConnection()) {
57 PreparedStatement sql = connection.prepareStatement("select kills from JasPVP where uuid = ?");
58 sql.setString(1, p.getUniqueId().toString());
59 ResultSet rs = sql.executeQuery();
60 rs.beforeFirst();
61 rs.next();
62 int kills = rs.getInt("kills");
63 rs.close();
64 return kills;
65 }
66 }