From b7f5cc9748a205409fd57faf3ab700ce15b94764 Mon Sep 17 00:00:00 2001 From: Benjamin Elsdon Date: Wed, 20 Apr 2022 17:31:41 +0800 Subject: [PATCH] Added OnGameServerStop EventBus There is a temporary warning message telling users to ignore the 'No subscribers registered' error. This can be removed once things actually subscribe to it --- .../java/emu/grasscutter/server/game/GameServer.java | 10 ++++++++-- .../grasscutter/server/game/GameServerStopEvent.java | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/game/GameServerStopEvent.java diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index 7304abc9d..155e84979 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -38,13 +38,14 @@ public final class GameServer extends MihoyoKcpServer { private final CommandMap commandMap; public EventBus OnGameServerTick; - public EventBus OnGameServerStop; // TODO + public EventBus OnGameServerStop; public GameServer(InetSocketAddress address) { super(address); OnGameServerTick = EventBus.builder().throwSubscriberException(true).build(); - + OnGameServerStop = EventBus.builder().throwSubscriberException(true).build(); + this.setServerInitializer(new GameServerInitializer(this)); this.address = address; this.packetHandler = new GameServerPacketHandler(PacketHandler.class); @@ -173,6 +174,11 @@ public final class GameServer extends MihoyoKcpServer { } public void onServerShutdown() { + OnGameServerStop.post(new GameServerStopEvent()); + Grasscutter.getLogger().info("Ignore the 'No subscribers registered' error"); + // TODO: Remove the log once things actually listen to OnGameServerStop. + // I just added it there to prevent people from flooding #support with this error + // Kick and save all players List list = new ArrayList<>(this.getPlayers().size()); list.addAll(this.getPlayers().values()); diff --git a/src/main/java/emu/grasscutter/server/game/GameServerStopEvent.java b/src/main/java/emu/grasscutter/server/game/GameServerStopEvent.java new file mode 100644 index 000000000..7a7ef40d7 --- /dev/null +++ b/src/main/java/emu/grasscutter/server/game/GameServerStopEvent.java @@ -0,0 +1,5 @@ +package emu.grasscutter.server.game; + +public class GameServerStopEvent { + // Placeholder class for now, probably will get used later +}