Skip to content

Commit

Permalink
Fix player count not updating on player logout
Browse files Browse the repository at this point in the history
The player is still on the player list when the logged out event fires,
so an offset needs to be applied.
  • Loading branch information
sciwhiz12 committed Mar 1, 2024
1 parent a8f48d4 commit f925a4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/main/java/dev/sciwhiz12/concord/ChatBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()));
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dev/sciwhiz12/concord/msg/PlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down

0 comments on commit f925a4a

Please sign in to comment.