Add server state mapping for web integration.

This commit is contained in:
akastijn 2026-08-09 00:28:21 +02:00
parent 5eb470cfb6
commit e72f79cb29
4 changed files with 18 additions and 11 deletions

View File

@ -20,13 +20,13 @@ import java.util.concurrent.*;
@Slf4j @Slf4j
public class ChatLogHandler { public class ChatLogHandler {
private final WebHandler webHandler = new WebHandler(); private final WebHandler webHandler;
private static ChatLogHandler instance = null; private static ChatLogHandler instance = null;
private ScheduledExecutorService executorService = null; private ScheduledExecutorService executorService = null;
public static ChatLogHandler getInstance(boolean enableLogging) { public static ChatLogHandler getInstance(WebHandler webHandler, boolean enableLogging) {
if (instance == null) { if (instance == null) {
instance = new ChatLogHandler(enableLogging); instance = new ChatLogHandler(webHandler, enableLogging);
} }
return instance; return instance;
} }
@ -35,7 +35,8 @@ public class ChatLogHandler {
private final Queue<ChatLog> chatLogQueue = new ConcurrentLinkedQueue<>(); private final Queue<ChatLog> chatLogQueue = new ConcurrentLinkedQueue<>();
private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>(); private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>();
public ChatLogHandler(boolean enableLogging) { public ChatLogHandler(WebHandler webHandler, boolean enableLogging) {
this.webHandler = webHandler;
if (!enableLogging) { if (!enableLogging) {
ALogger.info("Logging is not enabled on this server."); ALogger.info("Logging is not enabled on this server.");
return; return;

View File

@ -13,6 +13,7 @@ import com.alttd.chat.nicknames.NicknamesEvents;
import com.alttd.chat.objects.channels.Channel; import com.alttd.chat.objects.channels.Channel;
import com.alttd.chat.objects.channels.CustomChannel; import com.alttd.chat.objects.channels.CustomChannel;
import com.alttd.chat.objects.chat_log.ChatLogHandler; import com.alttd.chat.objects.chat_log.ChatLogHandler;
import com.alttd.chat.objects.chat_log.WebHandler;
import com.alttd.chat.util.ALogger; import com.alttd.chat.util.ALogger;
import com.alttd.chat.util.ServerName; import com.alttd.chat.util.ServerName;
import com.alttd.chat.util.Utility; import com.alttd.chat.util.Utility;
@ -42,12 +43,13 @@ public class ChatPlugin extends JavaPlugin {
instance = this; instance = this;
ALogger.init(getSLF4JLogger()); ALogger.init(getSLF4JLogger());
chatAPI = new ChatImplementation(); chatAPI = new ChatImplementation();
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true); WebHandler webHandler = new WebHandler();
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(webHandler, true);
chatHandler = new ChatHandler(chatLogHandler); chatHandler = new ChatHandler(chatLogHandler);
DatabaseConnection.initialize(); DatabaseConnection.initialize();
serverConfig = new ServerConfig(ServerName.getServerName()); serverConfig = new ServerConfig(ServerName.getServerName());
ChatMessageSender chatMessageSender = new ChatMessageSender(chatLogHandler, chatAPI.getLuckPerms()); ChatMessageSender chatMessageSender = new ChatMessageSender(chatLogHandler, chatAPI.getLuckPerms());
registerListener(new PlayerListener(serverConfig), registerListener(new PlayerListener(webHandler, serverConfig),
new ChatListener(chatMessageSender), new ChatListener(chatMessageSender),
new BookListener(), new BookListener(),
new ShutdownListener(chatLogHandler, this) new ShutdownListener(chatLogHandler, this)

View File

@ -42,7 +42,8 @@ public class PlayerListener implements Listener {
private final ServerConfig serverConfig; private final ServerConfig serverConfig;
private final WebHandler webHandler; private final WebHandler webHandler;
public PlayerListener(ServerConfig serverConfig) { public PlayerListener(WebHandler webHandler, ServerConfig serverConfig) {
this.webHandler = webHandler;
this.serverConfig = serverConfig; this.serverConfig = serverConfig;
} }

View File

@ -8,6 +8,7 @@ import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.PartyManager; import com.alttd.chat.managers.PartyManager;
import com.alttd.chat.objects.ChatUser; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.chat_log.ChatLogHandler; import com.alttd.chat.objects.chat_log.ChatLogHandler;
import com.alttd.chat.objects.chat_log.WebHandler;
import com.alttd.chat.util.ALogger; import com.alttd.chat.util.ALogger;
import com.alttd.velocitychat.commands.*; import com.alttd.velocitychat.commands.*;
import com.alttd.velocitychat.handlers.ChatHandler; import com.alttd.velocitychat.handlers.ChatHandler;
@ -67,7 +68,9 @@ public class VelocityChat {
PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them PartyManager.initialize(); // load the parties from the db and add the previously loaded users to them
serverHandler = new ServerHandler(); serverHandler = new ServerHandler();
ChatLogHandler chatLogHandler = new ChatLogHandler(true); WebHandler webHandler = new WebHandler();
ChatLogHandler chatLogHandler = new ChatLogHandler(webHandler, true);
chatHandler = new ChatHandler(chatLogHandler); chatHandler = new ChatHandler(chatLogHandler);
server.getEventManager().register(this, new ChatListener()); server.getEventManager().register(this, new ChatListener());
server.getEventManager().register(this, new ProxyPlayerListener()); server.getEventManager().register(this, new ProxyPlayerListener());
@ -76,7 +79,7 @@ public class VelocityChat {
channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]); channelIdentifier = MinecraftChannelIdentifier.create(channels[0], channels[1]);
server.getChannelRegistrar().register(channelIdentifier); server.getChannelRegistrar().register(channelIdentifier);
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier)); server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
loadCommands(); loadCommands(webHandler);
// setup console chatuser // setup console chatuser
ChatUser console = new ChatUser(Config.CONSOLEUUID, -1, null); ChatUser console = new ChatUser(Config.CONSOLEUUID, -1, null);
console.setDisplayName(Config.CONSOLENAME); console.setDisplayName(Config.CONSOLENAME);
@ -113,8 +116,8 @@ public class VelocityChat {
return server; return server;
} }
public void loadCommands() { public void loadCommands(WebHandler webHandler) {
ChatLogHandler instance = ChatLogHandler.getInstance(false); ChatLogHandler instance = ChatLogHandler.getInstance(webHandler, false);
new SilentJoinCommand(server); new SilentJoinCommand(server);
new GlobalAdminChat(server); new GlobalAdminChat(server);
new Reload(server); new Reload(server);