From 07b61540ef2db15af60095ac6a57bb5371e13327 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 19 Mar 2025 09:28:34 +0700 Subject: [PATCH] refactor: rewrite list command fix: set `target.listed` in PlayersPlugin (vanishing) --- build-number.txt | 2 +- .../chomens_bot/commands/ListCommand.java | 75 +++++++++++++++---- .../chomens_bot/plugins/PlayersPlugin.java | 4 + 3 files changed, 64 insertions(+), 17 deletions(-) diff --git a/build-number.txt b/build-number.txt index 2f75dbbd..6d92a178 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1943 \ No newline at end of file +1953 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ListCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ListCommand.java index 3edc4cb1..be7b348e 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/ListCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ListCommand.java @@ -40,24 +40,60 @@ public class ListCommand extends Command { for (PlayerEntry entry : list) { if (entry == null) continue; + + // chayapak + // b58cac19-066b-307b-97b1-d6e19ed08d7c + // + // Usernames: foo, bar, baz or No other usernames associated + // Vanished: false + // + // Click to copy the username to your clipboard + // Shift+Click to insert the UUID into your chat box + final Component hoverEvent = Component + .text(entry.profile.getName()) + .append(Component.newline()) + .append(Component.text(entry.profile.getIdAsString()).color(ColorUtilities.getColorByString(bot.config.colorPalette.uuid))) + .append(Component.newline()) + .append(Component.newline()) + .append( + entry.usernames.isEmpty() ? + Component + .text("No other usernames associated") + .color(NamedTextColor.GRAY) : + Component.translatable( + "Usernames: %s", + Component + .join( + JoinConfiguration.commas(true), + entry.usernames + .stream() + .map(Component::text) + .toList() + ) + .color(ColorUtilities.getColorByString(bot.config.colorPalette.string)) + ).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary)) + ) + .append(Component.newline()) + .append( + Component.translatable( + "Vanished: %s", + Component + .text(!entry.listed) + .color(ColorUtilities.getColorByString(bot.config.colorPalette.string)) + ).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary)) + ) + .append(Component.newline()) + .append(Component.newline()) + .append(Component.text("Click to copy the username to your clipboard").color(NamedTextColor.GREEN)) + .append(Component.newline()) + .append(Component.text("Shift+Click to insert the UUID into your chat box").color(NamedTextColor.GREEN)); + playersComponent.add( Component.translatable( - "%s › %s", + "%s", entry.displayName == null ? - Component.text(entry.profile.getName()).color(ColorUtilities.getColorByString(bot.config.colorPalette.username)) : - entry.displayName - .hoverEvent( - HoverEvent.showText( - Component - .text(entry.profile.getName()) - .append(Component.newline()) - .append(Component.text("Click here to copy the username to your clipboard").color(NamedTextColor.GREEN)) - ) - ) - .clickEvent( - ClickEvent.copyToClipboard(entry.profile.getName()) - ) - .color(NamedTextColor.WHITE), + Component.text(entry.profile.getName()) : + entry.displayName, Component .text(entry.profile.getIdAsString()) .hoverEvent( @@ -69,7 +105,14 @@ public class ListCommand extends Command { ClickEvent.copyToClipboard(entry.profile.getIdAsString()) ) .color(ColorUtilities.getColorByString(bot.config.colorPalette.uuid)) - ).color(NamedTextColor.DARK_GRAY) + ) + .hoverEvent( + HoverEvent.showText(hoverEvent) + ) + .clickEvent( + ClickEvent.copyToClipboard(entry.profile.getName()) + ) + .insertion(entry.profile.getIdAsString()) ); } diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPlugin.java index 91ba41ff..1519f07b 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPlugin.java @@ -182,6 +182,8 @@ public class PlayersPlugin extends Bot.Listener { if (duplicate != null) { list.remove(duplicate); + target.listed = true; + target.usernames.addAll(duplicate.usernames); list.add(target); @@ -268,6 +270,8 @@ public class PlayersPlugin extends Bot.Listener { for (PlayerEntry leftPlayers : new ArrayList<>(pendingLeftPlayers)) { if (!target.equals(leftPlayers)) continue; + target.listed = false; + for (Listener listener : listeners) listener.playerVanished(target); pendingLeftPlayers.remove(leftPlayers);