Fixed DatabaseConnection not being loaded on startup

This commit is contained in:
Teriuihi 2021-06-30 02:02:35 +02:00
parent a9550c82fe
commit 313d09906d
4 changed files with 11 additions and 5 deletions

View File

@ -43,6 +43,7 @@ public class DatabaseConnection {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
connection = DriverManager.getConnection(
"jdbc:" + Config.DRIVER + "://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true&enabledTLSProtocols=TLSv1.1",
Config.USERNAME, Config.PASSWORD);
@ -64,13 +65,13 @@ public class DatabaseConnection {
e.printStackTrace();
}
return instance.connection;
return connection;
}
/**
* Sets the connection for this instance
*/
public boolean initialize() {
public static boolean initialize() {
instance = new DatabaseConnection();
return connection != null;
}

View File

@ -27,10 +27,10 @@ public class ChatUser {
this.partyId = partyId;
this.toggledPartyChat = toggledChat;
//displayName = Queries.getNickname(uuid); // todo fix sql
//if (displayName == null) {
displayName = Queries.getNickname(uuid); // todo fix sql
if (displayName == null) {
displayName = Utility.getDisplayName(uuid);
//}
}
prefix = Utility.getPrefix(uuid, true);
staffPrefix = Utility.getStaffPrefix(uuid);

View File

@ -4,6 +4,7 @@ import com.alttd.chat.commands.GlobalChat;
import com.alttd.chat.commands.Message;
import com.alttd.chat.commands.Reply;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.handler.ChatHandler;
import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.PlayerListener;
@ -28,6 +29,7 @@ public class ChatPlugin extends JavaPlugin {
ALogger.init(getSLF4JLogger());
chatAPI = new ChatImplementation();
chatHandler = new ChatHandler();
DatabaseConnection.initialize();
registerListener(new PlayerListener(), new ChatListener());
registerCommand("globalchat", new GlobalChat());
registerCommand("message", new Message());

View File

@ -2,6 +2,7 @@ package com.alttd.chat;
import com.alttd.chat.commands.GlobalAdminChat;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.handlers.ChatHandler;
import com.alttd.chat.handlers.ServerHandler;
import com.alttd.chat.listeners.ChatListener;
@ -51,7 +52,9 @@ public class VelocityChat {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
ALogger.init(logger);
chatAPI = new ChatImplementation();
DatabaseConnection.initialize();
serverHandler = new ServerHandler();
chatHandler = new ChatHandler();