From f925a4a73785c95d7eece5ac77ae9f87f7e8b7aa Mon Sep 17 00:00:00 2001 From: sciwhiz12 Date: Sat, 2 Mar 2024 03:46:17 +0800 Subject: [PATCH] Fix player count not updating on player logout The player is still on the player list when the logged out event fires, so an offset needs to be applied. --- src/main/java/dev/sciwhiz12/concord/ChatBot.java | 6 +++--- src/main/java/dev/sciwhiz12/concord/msg/PlayerListener.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/dev/sciwhiz12/concord/ChatBot.java b/src/main/java/dev/sciwhiz12/concord/ChatBot.java index 23fc9e9a..5ea93281 100644 --- a/src/main/java/dev/sciwhiz12/concord/ChatBot.java +++ b/src/main/java/dev/sciwhiz12/concord/ChatBot.java @@ -93,7 +93,7 @@ public MinecraftServer getServer() { @Override public void onReady(ReadyEvent event) { - this.updateActivity(); + this.updateActivity(0); Concord.LOGGER.debug(BOT, "Checking guild and channel existence, and satisfaction of required permissions..."); // Required permissions are there. All checks satisfied. @@ -194,8 +194,8 @@ boolean checkSatisfaction() { } @ApiStatus.Internal - public void updateActivity() { - final int playerCount = server.getPlayerList().getPlayers().size(); + public void updateActivity(int offset) { + final int playerCount = server.getPlayerList().getPlayers().size() + offset; final Component message = Messages.BOT_STATUS_ONLINE.eagerComponent(playerCount); // TODO: make the activity type adjustable discord.getPresence().setPresence(OnlineStatus.ONLINE, Activity.playing(message.getString())); diff --git a/src/main/java/dev/sciwhiz12/concord/msg/PlayerListener.java b/src/main/java/dev/sciwhiz12/concord/msg/PlayerListener.java index 10f453d1..40b3c141 100644 --- a/src/main/java/dev/sciwhiz12/concord/msg/PlayerListener.java +++ b/src/main/java/dev/sciwhiz12/concord/msg/PlayerListener.java @@ -49,7 +49,7 @@ public PlayerListener(ChatBot bot) { @SubscribeEvent(priority = EventPriority.LOWEST) void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { if (event.getEntity().getCommandSenderWorld().isClientSide()) return; - bot.updateActivity(); + bot.updateActivity(0); if (!ConcordConfig.PLAYER_JOIN.get()) return; Component text = Messages.PLAYER_JOIN.component(event.getEntity().getDisplayName()); @@ -60,7 +60,8 @@ void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { @SubscribeEvent(priority = EventPriority.LOWEST) void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) { if (event.getEntity().getCommandSenderWorld().isClientSide()) return; - bot.updateActivity(); + // The player is still on the player list during this event, so offset to account for it + bot.updateActivity(-1); if (!ConcordConfig.PLAYER_LEAVE.get()) return; Component text = Messages.PLAYER_LEAVE.component(event.getEntity().getDisplayName());