-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathPlayers.java
More file actions
128 lines (98 loc) · 3.77 KB
/
Players.java
File metadata and controls
128 lines (98 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package fr.revivemc.data.wrapper;
import fr.revivemc.Main;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.UUID;
public class Players {
/**
* This function allows the player to be initialized in the table
* @param uuid Player uuid
*/
public static void addPlayer(UUID uuid) {
try {
Connection connection = Main.sql.getConnection();
String query = "INSERT INTO players (uuid, kill, death) VALUES (?, 0, 0)";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, uuid.toString());
ps.executeUpdate();
} catch (SQLException e) {
System.err.println("Error while executing SQL statement " + e.getMessage());
}
}
/**
* This function allows you to add n to the player's kills
* @param uuid Player uuid
* @param n Number to add
*/
public static void setKillByUuid(UUID uuid, int n) {
try {
Connection connection = Main.sql.getConnection();
String query = "UPDATE players SET kill = ? WHERE uuid = ?";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, String.valueOf(n));
ps.setString(2, uuid.toString());
ps.executeUpdate();
} catch (SQLException e) {
System.err.println("Error while executing SQL statement " + e.getMessage());
}
}
/**
* This function allows you to add n to the player's deaths
* @param uuid Player uuid
* @param n Number to add
*/
public static void setDeathByUuid(UUID uuid, int n) {
try {
Connection connection = Main.sql.getConnection();
String query = "UPDATE players SET death = ? WHERE uuid = ?";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, String.valueOf(n));
ps.setString(2, uuid.toString());
ps.executeUpdate();
} catch (SQLException e) {
System.err.println("Error while executing SQL statement " + e.getMessage());
}
}
/**
* Function that allows you to retrieve the number of kills in relation to the player's UUID
* @param uuid Player uuid
* @return Returns the correct value or 0
*/
public static int getKillByUuid(UUID uuid) {
int kills = 0;
try {
Connection connection = Main.sql.getConnection();
String query = "SELECT kill FROM players WHERE uuid=?";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, uuid.toString());
ResultSet row = ps.executeQuery();
if (row.next())
kills = row.getInt("kill");
} catch (SQLException e) {
System.err.println("Error while executing SQL statement " + e.getMessage());
}
return (kills);
}
/**
* Function that allows you to retrieve the number of deaths in relation to the player's UUID
* @param uuid Player uuid
* @return Returns the correct value or 0
*/
public static int getDeathByUuid(UUID uuid) {
int deaths = 0;
try {
Connection connection = Main.sql.getConnection();
String query = "SELECT death FROM players WHERE uuid=?";
PreparedStatement ps = connection.prepareStatement(query);
ps.setString(1, uuid.toString());
ResultSet row = ps.executeQuery();
if (row.next())
deaths = row.getInt("death");
} catch (SQLException e) {
System.err.println("Error while executing SQL statement " + e.getMessage());
}
return (deaths);
}
}