diff --git a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
index 96c7089897f..d4caf437667 100644
--- a/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
+++ b/connector/src/main/java/org/geysermc/connector/GeyserConnector.java
@@ -44,6 +44,7 @@
import org.geysermc.connector.network.translators.BiomeTranslator;
import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry;
+import org.geysermc.connector.network.translators.collision.CollisionTranslator;
import org.geysermc.connector.network.translators.effect.EffectRegistry;
import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator;
@@ -54,7 +55,6 @@
import org.geysermc.connector.network.translators.world.WorldManager;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator;
-import org.geysermc.connector.network.translators.collision.CollisionTranslator;
import org.geysermc.connector.network.translators.world.block.entity.SkullBlockEntityTranslator;
import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.LanguageUtils;
@@ -67,10 +67,7 @@
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -325,6 +322,38 @@ public void removePlayer(GeyserSession player) {
players.remove(player);
}
+ /**
+ * Gets a player by their current UUID
+ *
+ * @param uuid the uuid
+ * @return the player or null
if there is no player online with this UUID
+ */
+ public GeyserSession getPlayerByUuid(UUID uuid) {
+ for (GeyserSession session : players) {
+ if (session.getPlayerEntity().getUuid().equals(uuid)) {
+ return session;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Gets a player by their Xbox user identifier
+ *
+ * @param xboxUuid the Xbox user identifier
+ * @return the player or null
if there is no player online with this xuid
+ */
+ public GeyserSession getPlayerByXuid(String xuid) {
+ for (GeyserSession session : players) {
+ if (session.getAuthData() != null && session.getAuthData().getXboxUUID().equals(xuid)) {
+ return session;
+ }
+ }
+
+ return null;
+ }
+
public static GeyserConnector start(PlatformType platformType, GeyserBootstrap bootstrap) {
return new GeyserConnector(platformType, bootstrap);
}
diff --git a/connector/src/main/java/org/geysermc/connector/skin/SkinManager.java b/connector/src/main/java/org/geysermc/connector/skin/SkinManager.java
index db8f25929e7..a08f567a30a 100644
--- a/connector/src/main/java/org/geysermc/connector/skin/SkinManager.java
+++ b/connector/src/main/java/org/geysermc/connector/skin/SkinManager.java
@@ -81,11 +81,10 @@ public static PlayerListPacket.Entry buildEntryManually(GeyserSession session, U
// This attempts to find the xuid of the player so profile images show up for xbox accounts
String xuid = "";
- for (GeyserSession player : GeyserConnector.getInstance().getPlayers()) {
- if (player.getPlayerEntity().getUuid().equals(uuid)) {
- xuid = player.getAuthData().getXboxUUID();
- break;
- }
+ GeyserSession player = GeyserConnector.getInstance().getPlayerByUuid(uuid);
+
+ if (player != null) {
+ xuid = player.getAuthData().getXboxUUID();
}
PlayerListPacket.Entry entry;
@@ -268,11 +267,10 @@ public static GameProfileData from(GameProfile profile) {
// return default skin with default cape when texture data is invalid
String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
- for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
- if (session.getPlayerEntity().getUuid().equals(profile.getId())) {
- skinUrl = session.getClientData().getSkinId();
- break;
- }
+ GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());
+
+ if (session != null) {
+ skinUrl = session.getClientData().getSkinId();
}
}
return new GameProfileData(skinUrl, SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex);
diff --git a/connector/src/main/java/org/geysermc/connector/skin/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/skin/SkinProvider.java
index 117198685a5..948e4b37447 100644
--- a/connector/src/main/java/org/geysermc/connector/skin/SkinProvider.java
+++ b/connector/src/main/java/org/geysermc/connector/skin/SkinProvider.java
@@ -144,12 +144,10 @@ public static CompletableFuture requestSkinAndCape(UUID playerId, S
String newSkinUrl = skinUrl;
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
- // TODO: Don't have a for loop for this? Have a proper map?
- for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
- if (session.getPlayerEntity().getUuid().equals(playerId)) {
- newSkinUrl = session.getClientData().getSkinId();
- break;
- }
+ GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(playerId);
+
+ if (session != null) {
+ newSkinUrl = session.getClientData().getSkinId();
}
}