From 21739e2f1e53777dfa3924b595eb904653da6646 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 8 Apr 2023 18:28:20 +0700 Subject: [PATCH] add a trash username change event (VERY trash) --- .../chomens_bot/plugins/PlayersPlugin.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java index 2cf26cd..0f47e7a 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java @@ -12,14 +12,14 @@ import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntr import lombok.Getter; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import java.util.*; public class PlayersPlugin extends SessionAdapter { private final Bot bot; @Getter private List list = new ArrayList<>(); + private final Map loginNames = new HashMap<>(); + private final List listeners = new ArrayList<>(); public PlayersPlugin (Bot bot) { @@ -86,9 +86,24 @@ public class PlayersPlugin extends SessionAdapter { final MutablePlayerListEntry target = new MutablePlayerListEntry(newEntry); list.add(target); + loginNames.put(target, target.profile().getIdAsString()); if (duplicate == null) for (PlayerListener listener : listeners) { listener.playerJoined(target); } - else for (PlayerListener listener : listeners) { listener.playerUnVanished(target); } + else { + for (Map.Entry entry : loginNames.entrySet()) { + if ( + !entry.getValue().equals(newEntry.getProfile().getIdAsString()) || + entry.getKey().profile().getName().equals(newEntry.getProfile().getName()) + ) continue; + + loginNames.remove(entry.getKey(), entry.getValue()); + + for (PlayerListener listener : listeners) { listener.playerUserNameChanged(entry.getKey()); } + + return; + } + for (PlayerListener listener : listeners) { listener.playerUnVanished(target); } + } } private void updateGamemode (PlayerListEntry newEntry) { @@ -155,6 +170,7 @@ public class PlayersPlugin extends SessionAdapter { public void playerGameModeUpdated (MutablePlayerListEntry target, GameMode gameMode) {} public void playerLatencyUpdated (MutablePlayerListEntry target, int ping) {} public void playerDisplayNameUpdated (MutablePlayerListEntry target, Component displayName) {} + public void playerUserNameChanged (MutablePlayerListEntry target) {} public void playerLeft (MutablePlayerListEntry target) {} public void playerVanished (MutablePlayerListEntry target) {} }