Skip to content

Commit bc7a7ee

Browse files
committed
Fix formatting adding
1 parent bfac36a commit bc7a7ee

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

API/src/main/java/me/innectic/permissify/api/database/handlers/MySQLHandler.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ public void initialize() {
7979
databaseStatement.execute();
8080
databaseStatement.close();
8181

82-
PreparedStatement formattingStatement = connection.get().prepareStatement("CREATE TABLE IF NOT EXISTS " + database + ".formatting (`format` VARCHAR(400) NOT NULL, formatter VARCHAR(200) NOT NULL)");
83-
formattingStatement.execute();
84-
formattingStatement.close();
85-
8682
PreparedStatement groupMembersStatement = connection.get().prepareStatement("CREATE TABLE IF NOT EXISTS " + database + ".groupMembers (uuid VARCHAR(767) NOT NULL, `group` VARCHAR(700) NOT NULL, `primary` TINYINT NOT NULL)");
8783
groupMembersStatement.execute();
8884
groupMembersStatement.close();
@@ -103,17 +99,24 @@ public void initialize() {
10399
superAdminStatement.execute();
104100
superAdminStatement.close();
105101

106-
PreparedStatement defaultChatFormat = connection.get().prepareStatement("INSERT INTO " + database + ".formatting (`format`, formatter) VALUES (?,?)");
107-
defaultChatFormat.setString(1, "{group} {username}: {message}");
108-
defaultChatFormat.setString(2, "chat");
109-
defaultChatFormat.execute();
110-
defaultChatFormat.close();
111-
112-
PreparedStatement defaultWhisperFormat = connection.get().prepareStatement("INSERT INTO " + database + ".formatting (`format`, formatter) VALUES (?,?)");
113-
defaultWhisperFormat.setString(1, "{senderGroup} {username} > {receiverGroup} {to}: {message}");
114-
defaultWhisperFormat.setString(2, "whisper");
115-
defaultWhisperFormat.execute();
116-
defaultWhisperFormat.close();
102+
ResultSet results = connection.get().getMetaData().getTables(database, null, "formatting", new String[]{"TABLE"});
103+
if (results.next()) {
104+
PreparedStatement formattingStatement = connection.get().prepareStatement("CREATE TABLE IF NOT EXISTS " + database + ".formatting (`format` VARCHAR(400) NOT NULL, formatter VARCHAR(200) NOT NULL)");
105+
formattingStatement.execute();
106+
formattingStatement.close();
107+
108+
PreparedStatement defaultChatFormat = connection.get().prepareStatement("INSERT INTO " + database + ".formatting (`format`, formatter) VALUES (?,?)");
109+
defaultChatFormat.setString(1, "{group} {username}: {message}");
110+
defaultChatFormat.setString(2, "chat");
111+
defaultChatFormat.execute();
112+
defaultChatFormat.close();
113+
114+
PreparedStatement defaultWhisperFormat = connection.get().prepareStatement("INSERT INTO " + database + ".formatting (`format`, formatter) VALUES (?,?)");
115+
defaultWhisperFormat.setString(1, "{senderGroup} {username} > {receiverGroup} {to}: {message}");
116+
defaultWhisperFormat.setString(2, "whisper");
117+
defaultWhisperFormat.execute();
118+
defaultWhisperFormat.close();
119+
}
117120

118121
connection.get().close();
119122
} catch (SQLException e) {

0 commit comments

Comments
 (0)