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
This commit is contained in:
Benjamin Elsdon 2022-04-20 17:31:41 +08:00
parent 22781ac6e7
commit b7f5cc9748
2 changed files with 13 additions and 2 deletions

View File

@ -38,12 +38,13 @@ public final class GameServer extends MihoyoKcpServer {
private final CommandMap commandMap; private final CommandMap commandMap;
public EventBus OnGameServerTick; public EventBus OnGameServerTick;
public EventBus OnGameServerStop; // TODO public EventBus OnGameServerStop;
public GameServer(InetSocketAddress address) { public GameServer(InetSocketAddress address) {
super(address); super(address);
OnGameServerTick = EventBus.builder().throwSubscriberException(true).build(); OnGameServerTick = EventBus.builder().throwSubscriberException(true).build();
OnGameServerStop = EventBus.builder().throwSubscriberException(true).build();
this.setServerInitializer(new GameServerInitializer(this)); this.setServerInitializer(new GameServerInitializer(this));
this.address = address; this.address = address;
@ -173,6 +174,11 @@ public final class GameServer extends MihoyoKcpServer {
} }
public void onServerShutdown() { 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 // Kick and save all players
List<GenshinPlayer> list = new ArrayList<>(this.getPlayers().size()); List<GenshinPlayer> list = new ArrayList<>(this.getPlayers().size());
list.addAll(this.getPlayers().values()); list.addAll(this.getPlayers().values());

View File

@ -0,0 +1,5 @@
package emu.grasscutter.server.game;
public class GameServerStopEvent {
// Placeholder class for now, probably will get used later
}