Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a simple way to get a player by their xuid #1642

Merged
merged 10 commits into from
Dec 17, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 <code>null</code> 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 <code>null</code> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ public static CompletableFuture<SkinAndCape> 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();
}
}

Expand Down