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

* Added IGeyserPingPassthrough#getPingInformation(InetSocketAddress) to make logging of the pinging IPs possible

* Added GeyserConnector#getPlayerByXboxUuid

* Added GeyserConnector#getPlayerByUuid and added some javadocs

* Update connector/src/main/java/org/geysermc/connector/GeyserConnector.java

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>

* Update connector/src/main/java/org/geysermc/connector/GeyserConnector.java

Co-authored-by: rtm516 <rtm516@users.noreply.github.com>

* Update GeyserConnector.java

* Update SkinManager.java

* Update SkinProvider.java

* Renamed getPlayerByXboxUuid to getPlayerByXuid

Co-authored-by: qlow <info@qlow.eu>
Co-authored-by: rtm516 <rtm516@users.noreply.github.com>
This commit is contained in:
qlow 2020-12-17 17:58:49 +01:00 committed by GitHub
parent 02d99380d3
commit 9f6182f8df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 21 deletions

View file

@ -44,6 +44,7 @@ import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.BiomeTranslator; import org.geysermc.connector.network.translators.BiomeTranslator;
import org.geysermc.connector.network.translators.EntityIdentifierRegistry; import org.geysermc.connector.network.translators.EntityIdentifierRegistry;
import org.geysermc.connector.network.translators.PacketTranslatorRegistry; 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.effect.EffectRegistry;
import org.geysermc.connector.network.translators.item.ItemRegistry; import org.geysermc.connector.network.translators.item.ItemRegistry;
import org.geysermc.connector.network.translators.item.ItemTranslator; import org.geysermc.connector.network.translators.item.ItemTranslator;
@ -54,7 +55,6 @@ import org.geysermc.connector.network.translators.sound.SoundRegistry;
import org.geysermc.connector.network.translators.world.WorldManager; 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.BlockTranslator;
import org.geysermc.connector.network.translators.world.block.entity.BlockEntityTranslator; 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.network.translators.world.block.entity.SkullBlockEntityTranslator;
import org.geysermc.connector.utils.DimensionUtils; import org.geysermc.connector.utils.DimensionUtils;
import org.geysermc.connector.utils.LanguageUtils; import org.geysermc.connector.utils.LanguageUtils;
@ -67,10 +67,7 @@ import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
@ -326,6 +323,38 @@ public class GeyserConnector {
players.remove(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) { public static GeyserConnector start(PlatformType platformType, GeyserBootstrap bootstrap) {
return new GeyserConnector(platformType, bootstrap); return new GeyserConnector(platformType, bootstrap);
} }

View file

@ -81,11 +81,10 @@ public class SkinManager {
// This attempts to find the xuid of the player so profile images show up for xbox accounts // This attempts to find the xuid of the player so profile images show up for xbox accounts
String xuid = ""; String xuid = "";
for (GeyserSession player : GeyserConnector.getInstance().getPlayers()) { GeyserSession player = GeyserConnector.getInstance().getPlayerByUuid(uuid);
if (player.getPlayerEntity().getUuid().equals(uuid)) {
xuid = player.getAuthData().getXboxUUID(); if (player != null) {
break; xuid = player.getAuthData().getXboxUUID();
}
} }
PlayerListPacket.Entry entry; PlayerListPacket.Entry entry;
@ -268,11 +267,10 @@ public class SkinManager {
// return default skin with default cape when texture data is invalid // return default skin with default cape when texture data is invalid
String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl(); String skinUrl = isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl();
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) { if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) { GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(profile.getId());
if (session.getPlayerEntity().getUuid().equals(profile.getId())) {
skinUrl = session.getClientData().getSkinId(); if (session != null) {
break; skinUrl = session.getClientData().getSkinId();
}
} }
} }
return new GameProfileData(skinUrl, SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex); return new GameProfileData(skinUrl, SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex);

View file

@ -144,12 +144,10 @@ public class SkinProvider {
String newSkinUrl = skinUrl; String newSkinUrl = skinUrl;
if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) { if ("steve".equals(skinUrl) || "alex".equals(skinUrl)) {
// TODO: Don't have a for loop for this? Have a proper map? GeyserSession session = GeyserConnector.getInstance().getPlayerByUuid(playerId);
for (GeyserSession session : GeyserConnector.getInstance().getPlayers()) {
if (session.getPlayerEntity().getUuid().equals(playerId)) { if (session != null) {
newSkinUrl = session.getClientData().getSkinId(); newSkinUrl = session.getClientData().getSkinId();
break;
}
} }
} }