From 7f2b2e09133efa004964e807cd8e5a8a996335e2 Mon Sep 17 00:00:00 2001 From: rtm516 Date: Fri, 23 Oct 2020 05:01:03 +0100 Subject: [PATCH] Bedrock <-> Bedrock skin display fix (#1195) * Implement partial bedrock skin fix * Fix equals method * Fix ViaVersion Co-authored-by: DoctorMacc --- .../connector/utils/SkinProvider.java | 22 ++++++++++++------- .../geysermc/connector/utils/SkinUtils.java | 12 +++++++++- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java index 7c30e48a..82fc3a3a 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinProvider.java @@ -33,6 +33,7 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import org.geysermc.connector.GeyserConnector; +import org.geysermc.connector.network.session.GeyserSession; import javax.imageio.ImageIO; import java.awt.*; @@ -42,13 +43,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.concurrent.*; public class SkinProvider { @@ -157,10 +152,21 @@ public class SkinProvider { public static CompletableFuture requestSkinAndCape(UUID playerId, String skinUrl, String capeUrl) { return CompletableFuture.supplyAsync(() -> { long time = System.currentTimeMillis(); + 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; + } + } + } CapeProvider provider = capeUrl != null ? CapeProvider.MINECRAFT : null; SkinAndCape skinAndCape = new SkinAndCape( - getOrDefault(requestSkin(playerId, skinUrl, false), EMPTY_SKIN, 5), + getOrDefault(requestSkin(playerId, newSkinUrl, false), EMPTY_SKIN, 5), getOrDefault(requestCape(capeUrl, provider, false), EMPTY_CAPE, 5) ); diff --git a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java index 5505acdf..d65dbc81 100644 --- a/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java +++ b/connector/src/main/java/org/geysermc/connector/utils/SkinUtils.java @@ -251,6 +251,7 @@ public class SkinUtils { try { GameProfile.Property skinProperty = profile.getProperty("textures"); + // TODO: Remove try/catch here JsonNode skinObject = new ObjectMapper().readTree(new String(Base64.getDecoder().decode(skinProperty.getValue()), StandardCharsets.UTF_8)); JsonNode textures = skinObject.get("textures"); @@ -271,7 +272,16 @@ public class SkinUtils { GeyserConnector.getInstance().getLogger().debug("Got invalid texture data for " + profile.getName() + " " + exception.getMessage()); } // return default skin with default cape when texture data is invalid - return new GameProfileData((isAlex ? SkinProvider.EMPTY_SKIN_ALEX.getTextureUrl() : SkinProvider.EMPTY_SKIN.getTextureUrl()), SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex); + 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; + } + } + } + return new GameProfileData(skinUrl, SkinProvider.EMPTY_CAPE.getTextureUrl(), isAlex); } } }