From e8601de5d565fbaa4cc622c94918797a89448521 Mon Sep 17 00:00:00 2001 From: Benjamin Elsdon Date: Wed, 20 Apr 2022 17:44:44 +0800 Subject: [PATCH] Added OnGameServerStartFinish EventBus Removed those temporary warning messages as I figured out how to disable them --- .../emu/grasscutter/server/game/GameServer.java | 13 ++++++------- .../server/game/GameServerStartFinishEvent.java | 5 +++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 src/main/java/emu/grasscutter/server/game/GameServerStartFinishEvent.java diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index 155e84979..282589a4b 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -3,7 +3,6 @@ package emu.grasscutter.server.game; import java.net.InetSocketAddress; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; import emu.grasscutter.GenshinConstants; import emu.grasscutter.Grasscutter; @@ -20,7 +19,6 @@ import emu.grasscutter.game.shop.ShopManager; import emu.grasscutter.net.packet.PacketHandler; import emu.grasscutter.net.proto.SocialDetailOuterClass.SocialDetail; import emu.grasscutter.netty.MihoyoKcpServer; -import jdk.internal.event.Event; import org.greenrobot.eventbus.EventBus; public final class GameServer extends MihoyoKcpServer { @@ -37,14 +35,16 @@ public final class GameServer extends MihoyoKcpServer { private final DungeonManager dungeonManager; private final CommandMap commandMap; + public EventBus OnGameServerStartFinish; public EventBus OnGameServerTick; public EventBus OnGameServerStop; public GameServer(InetSocketAddress address) { super(address); - OnGameServerTick = EventBus.builder().throwSubscriberException(true).build(); - OnGameServerStop = EventBus.builder().throwSubscriberException(true).build(); + OnGameServerStartFinish = EventBus.builder().throwSubscriberException(true).logNoSubscriberMessages(false).build(); + OnGameServerTick = EventBus.builder().throwSubscriberException(true).logNoSubscriberMessages(false).build(); + OnGameServerStop = EventBus.builder().throwSubscriberException(true).logNoSubscriberMessages(false).build(); this.setServerInitializer(new GameServerInitializer(this)); this.address = address; @@ -171,13 +171,12 @@ public final class GameServer extends MihoyoKcpServer { @Override public void onStartFinish() { Grasscutter.getLogger().info("Game Server started on port " + address.getPort()); + + OnGameServerStartFinish.post(new GameServerStartFinishEvent()); } 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()); diff --git a/src/main/java/emu/grasscutter/server/game/GameServerStartFinishEvent.java b/src/main/java/emu/grasscutter/server/game/GameServerStartFinishEvent.java new file mode 100644 index 000000000..5e960ad1d --- /dev/null +++ b/src/main/java/emu/grasscutter/server/game/GameServerStartFinishEvent.java @@ -0,0 +1,5 @@ +package emu.grasscutter.server.game; + +public class GameServerStartFinishEvent { + // Placeholder class for now, probably will get used later +}