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

View File

@ -27,10 +27,10 @@ public class ChatUser {
this.partyId = partyId; this.partyId = partyId;
this.toggledPartyChat = toggledChat; this.toggledPartyChat = toggledChat;
//displayName = Queries.getNickname(uuid); // todo fix sql displayName = Queries.getNickname(uuid); // todo fix sql
//if (displayName == null) { if (displayName == null) {
displayName = Utility.getDisplayName(uuid); displayName = Utility.getDisplayName(uuid);
//} }
prefix = Utility.getPrefix(uuid, true); prefix = Utility.getPrefix(uuid, true);
staffPrefix = Utility.getStaffPrefix(uuid); 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.Message;
import com.alttd.chat.commands.Reply; import com.alttd.chat.commands.Reply;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.handler.ChatHandler; import com.alttd.chat.handler.ChatHandler;
import com.alttd.chat.listeners.ChatListener; import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.PlayerListener; import com.alttd.chat.listeners.PlayerListener;
@ -28,6 +29,7 @@ public class ChatPlugin extends JavaPlugin {
ALogger.init(getSLF4JLogger()); ALogger.init(getSLF4JLogger());
chatAPI = new ChatImplementation(); chatAPI = new ChatImplementation();
chatHandler = new ChatHandler(); chatHandler = new ChatHandler();
DatabaseConnection.initialize();
registerListener(new PlayerListener(), new ChatListener()); registerListener(new PlayerListener(), new ChatListener());
registerCommand("globalchat", new GlobalChat()); registerCommand("globalchat", new GlobalChat());
registerCommand("message", new Message()); registerCommand("message", new Message());

View File

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