Skip to content

Commit 2227f89

Browse files
committed
MySQL Functional
Fixed problems that were not known before testing like my really bad consistency. I blame being tired but that's why we test code ig. Tested and works. Referencing PR #2
1 parent 0d96cdd commit 2227f89

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/main/java/simplexity/simpleprefixes/config/Config.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public static void loadConfig() {
4242
headerLore = config.getStringList("header.lore");
4343
headerCount = config.getString("header.count", "1");
4444

45-
sqlUser = config.getString("sql.user");
46-
sqlPass = config.getString("sql.pass");
47-
sqlDbName = config.getString("sql.dbName");
48-
sqlIp = config.getString("sql.ip");
45+
sqlUser = config.getString("mysql.user");
46+
sqlPass = config.getString("mysql.pass");
47+
sqlDbName = config.getString("mysql.name");
48+
sqlIp = config.getString("mysql.ip");
4949
}
5050

5151
public static void generateBaseHeaderItem() {

src/main/java/simplexity/simpleprefixes/util/saving/MySQL.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class MySQL extends SaveHandler {
1717
private final String CREATE_TABLE = """
1818
CREATE TABLE IF NOT EXISTS player_prefixes (
1919
id VARCHAR(36) PRIMARY KEY,
20-
prefix_id VARCHAR(256) NOT NULL
20+
prefix_id VARCHAR(255) NOT NULL
2121
);""";
2222
private final String INSERT_ROW = "REPLACE INTO player_prefixes (id, prefix_id) VALUES (?, ?);";
2323
private final String REMOVE_ROW = "DELETE FROM player_prefixes WHERE id = ?;";
@@ -48,8 +48,8 @@ public void init() {
4848

4949
@Override
5050
public String getPrefixId(OfflinePlayer p) {
51-
String prefixId = null;
5251
if (!isEnabled()) return null;
52+
String prefixId = null;
5353
try (PreparedStatement statement = connection.prepareStatement(SELECT_ROW)) {
5454
statement.setString(1, p.getUniqueId().toString());
5555
try (ResultSet result = statement.executeQuery()) {
@@ -65,9 +65,11 @@ public String getPrefixId(OfflinePlayer p) {
6565

6666
@Override
6767
public void setPrefixId(OfflinePlayer p, String id) {
68+
if (!isEnabled()) return;
6869
if (id == null) {
6970
try (PreparedStatement statement = connection.prepareStatement(REMOVE_ROW)) {
7071
statement.setString(1, p.getUniqueId().toString());
72+
statement.execute();
7173
} catch (SQLException e) {
7274
e.printStackTrace();
7375
}
@@ -76,6 +78,7 @@ public void setPrefixId(OfflinePlayer p, String id) {
7678
try (PreparedStatement statement = connection.prepareStatement(INSERT_ROW)) {
7779
statement.setString(1, p.getUniqueId().toString());
7880
statement.setString(2, id);
81+
statement.execute();
7982
} catch (SQLException e) {
8083
e.printStackTrace();
8184
}

src/main/resources/config.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
# Don't touch unless asked to
88
debug-level: 0
99

10-
# Saving Types: PDC, File
10+
# Saving Types: PDC, File, MySQL
1111
saving-type: "file"
12+
mysql:
13+
ip: "localhost:3306"
14+
name: prefixes
15+
user: username1
16+
pass: badpassword!
17+
1218
default-prefix: "<white>[<gray>Player</gray>]</white> "
1319
prefix-menu-name: "<bold>Prefix Menu</bold>"
1420

0 commit comments

Comments
 (0)