Cleanup and add SkinApplyEvent

This commit is contained in:
rtm516 2024-03-17 17:50:39 +00:00
parent 5d95ee0ba7
commit f490d84958
No known key found for this signature in database
GPG Key ID: 331715B8B007C67A
12 changed files with 304 additions and 593 deletions

View File

@ -0,0 +1,80 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.event.lifecycle;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.event.Event;
import org.geysermc.geyser.api.skin.Cape;
import org.geysermc.geyser.api.skin.Skin;
import org.geysermc.geyser.api.skin.SkinData;
import org.geysermc.geyser.api.skin.SkinGeometry;
import java.util.UUID;
public abstract class SkinApplyEvent implements Event {
private final String username;
private final UUID uuid;
private final boolean slim;
private final boolean isBedrock;
private final SkinData skinData;
public SkinApplyEvent(String username, UUID uuid, boolean slim, boolean isBedrock, SkinData skinData) {
this.username = username;
this.uuid = uuid;
this.slim = slim;
this.isBedrock = isBedrock;
this.skinData = skinData;
}
public String username() {
return username;
}
public UUID uuid() {
return uuid;
}
public boolean slim() {
return slim;
}
public boolean isBedrock() {
return isBedrock;
}
public SkinData skinData() {
return skinData;
}
public abstract void skin(@NonNull Skin newSkin);
public abstract void cape(@NonNull Cape newCape);
public abstract void geometry(@NonNull SkinGeometry newGeometry);
public void geometry(@NonNull String geometryName, @NonNull String geometryData) {
geometry(new SkinGeometry("{\"geometry\" :{\"default\" :\"" + geometryName + "\"}}", geometryData));
}
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.skin;
public record Cape(String textureUrl, String capeId, byte[] capeData, boolean failed) {
}

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.skin;
public record Skin(String textureUrl, byte[] skinData) {
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.skin;
/**
* Represents a full package of skin, cape, and geometry.
*/
public record SkinData(Skin skin, Cape cape, SkinGeometry geometry) {
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.geyser.api.skin;
public record SkinGeometry(String geometryName, String geometryData) {
public static SkinGeometry WIDE = getLegacy(false);
public static SkinGeometry SLIM = getLegacy(true);
/**
* Generate generic geometry
*
* @param isSlim Should it be the alex model
* @return The generic geometry object
*/
private static SkinGeometry getLegacy(boolean isSlim) {
return new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.custom" + (isSlim ? "Slim" : "") + "\"}}", "");
}
}

View File

@ -36,6 +36,10 @@ import lombok.Getter;
import lombok.Setter;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.skin.Cape;
import org.geysermc.geyser.api.skin.Skin;
import org.geysermc.geyser.api.skin.SkinData;
import org.geysermc.geyser.api.skin.SkinGeometry;
import org.geysermc.geyser.entity.type.LivingEntity;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.session.GeyserSession;
@ -53,27 +57,27 @@ import java.util.concurrent.TimeUnit;
* Responsible for modifying a player's skin when wearing a player head
*/
public class FakeHeadProvider {
private static final LoadingCache<FakeHeadEntry, SkinProvider.SkinData> MERGED_SKINS_LOADING_CACHE = CacheBuilder.newBuilder()
private static final LoadingCache<FakeHeadEntry, SkinData> MERGED_SKINS_LOADING_CACHE = CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.HOURS)
.maximumSize(10000)
.build(new CacheLoader<>() {
@Override
public SkinProvider.SkinData load(@NonNull FakeHeadEntry fakeHeadEntry) throws Exception {
SkinProvider.SkinData skinData = SkinProvider.getOrDefault(SkinProvider.requestSkinData(fakeHeadEntry.getEntity()), null, 5);
public SkinData load(@NonNull FakeHeadEntry fakeHeadEntry) throws Exception {
SkinData skinData = SkinProvider.getOrDefault(SkinProvider.requestSkinData(fakeHeadEntry.getEntity()), null, 5);
if (skinData == null) {
throw new Exception("Couldn't load player's original skin");
}
SkinProvider.Skin skin = skinData.skin();
SkinProvider.Cape cape = skinData.cape();
SkinProvider.SkinGeometry geometry = skinData.geometry().geometryName().equals("{\"geometry\" :{\"default\" :\"geometry.humanoid.customSlim\"}}")
Skin skin = skinData.skin();
Cape cape = skinData.cape();
SkinGeometry geometry = skinData.geometry().geometryName().equals("{\"geometry\" :{\"default\" :\"geometry.humanoid.customSlim\"}}")
? SkinProvider.WEARING_CUSTOM_SKULL_SLIM : SkinProvider.WEARING_CUSTOM_SKULL;
SkinProvider.Skin headSkin = SkinProvider.getOrDefault(
Skin headSkin = SkinProvider.getOrDefault(
SkinProvider.requestSkin(fakeHeadEntry.getEntity().getUuid(), fakeHeadEntry.getFakeHeadSkinUrl(), false), SkinProvider.EMPTY_SKIN, 5);
BufferedImage originalSkinImage = SkinProvider.imageDataToBufferedImage(skin.getSkinData(), 64, skin.getSkinData().length / 4 / 64);
BufferedImage headSkinImage = SkinProvider.imageDataToBufferedImage(headSkin.getSkinData(), 64, headSkin.getSkinData().length / 4 / 64);
BufferedImage originalSkinImage = SkinProvider.imageDataToBufferedImage(skin.skinData(), 64, skin.skinData().length / 4 / 64);
BufferedImage headSkinImage = SkinProvider.imageDataToBufferedImage(headSkin.skinData(), 64, headSkin.skinData().length / 4 / 64);
Graphics2D graphics2D = originalSkinImage.createGraphics();
graphics2D.setComposite(AlphaComposite.Clear);
@ -84,14 +88,14 @@ public class FakeHeadProvider {
// Make the skin key a combination of the current skin data and the new skin data
// Don't tie it to a player - that player *can* change skins in-game
String skinKey = "customPlayerHead_" + fakeHeadEntry.getFakeHeadSkinUrl() + "_" + skin.getTextureUrl();
String skinKey = "customPlayerHead_" + fakeHeadEntry.getFakeHeadSkinUrl() + "_" + skin.textureUrl();
byte[] targetSkinData = SkinProvider.bufferedImageToImageData(originalSkinImage);
SkinProvider.Skin mergedSkin = new SkinProvider.Skin(fakeHeadEntry.getEntity().getUuid(), skinKey, targetSkinData, System.currentTimeMillis(), false, false);
Skin mergedSkin = new Skin(skinKey, targetSkinData);
// Avoiding memory leak
fakeHeadEntry.setEntity(null);
return new SkinProvider.SkinData(mergedSkin, cape, geometry);
return new SkinData(mergedSkin, cape, geometry);
}
});
@ -136,7 +140,7 @@ public class FakeHeadProvider {
String texturesProperty = entity.getTexturesProperty();
SkinProvider.getExecutorService().execute(() -> {
try {
SkinProvider.SkinData mergedSkinData = MERGED_SKINS_LOADING_CACHE.get(new FakeHeadEntry(texturesProperty, fakeHeadSkinUrl, entity));
SkinData mergedSkinData = MERGED_SKINS_LOADING_CACHE.get(new FakeHeadEntry(texturesProperty, fakeHeadSkinUrl, entity));
SkinManager.sendSkinPacket(session, entity, mergedSkinData);
} catch (ExecutionException e) {
GeyserImpl.getInstance().getLogger().error("Couldn't merge skin of " + entity.getUsername() + " with head skin url " + fakeHeadSkinUrl, e);

View File

@ -26,6 +26,7 @@
package org.geysermc.geyser.skin;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.skin.Skin;
import org.geysermc.geyser.util.AssetUtils;
import javax.imageio.ImageIO;
@ -67,7 +68,7 @@ public final class ProvidedSkins {
}
public static final class ProvidedSkin {
private SkinProvider.Skin data;
private Skin data;
private final boolean slim;
ProvidedSkin(String asset, boolean slim) {
@ -94,14 +95,14 @@ public final class ProvidedSkins {
image.flush();
String identifier = "geysermc:" + assetName + "_" + (slim ? "slim" : "wide");
this.data = new SkinProvider.Skin(-1, identifier, byteData);
this.data = new Skin(identifier, byteData);
} catch (IOException e) {
e.printStackTrace();
}
}));
}
public SkinProvider.Skin getData() {
public Skin getData() {
// Fall back to the default skin if we can't load our skins, or it's not loaded yet.
return Objects.requireNonNullElse(data, SkinProvider.EMPTY_SKIN);
}

View File

@ -35,6 +35,10 @@ import org.cloudburstmc.protocol.bedrock.data.skin.SerializedSkin;
import org.cloudburstmc.protocol.bedrock.packet.PlayerListPacket;
import org.cloudburstmc.protocol.bedrock.packet.PlayerSkinPacket;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.skin.Cape;
import org.geysermc.geyser.api.skin.Skin;
import org.geysermc.geyser.api.skin.SkinData;
import org.geysermc.geyser.api.skin.SkinGeometry;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.entity.type.player.SkullPlayerEntity;
import org.geysermc.geyser.session.GeyserSession;
@ -56,21 +60,21 @@ public class SkinManager {
public static PlayerListPacket.Entry buildCachedEntry(GeyserSession session, PlayerEntity playerEntity) {
// First: see if we have the cached skin texture ID.
GameProfileData data = GameProfileData.from(playerEntity);
SkinProvider.Skin skin = null;
SkinProvider.Cape cape = null;
SkinProvider.SkinGeometry geometry = SkinProvider.SkinGeometry.WIDE;
Skin skin = null;
Cape cape = null;
SkinGeometry geometry = SkinGeometry.WIDE;
if (data != null) {
// GameProfileData is not null = server provided us with textures data to work with.
skin = SkinProvider.getCachedSkin(data.skinUrl());
cape = SkinProvider.getCachedCape(data.capeUrl());
geometry = data.isAlex() ? SkinProvider.SkinGeometry.SLIM : SkinProvider.SkinGeometry.WIDE;
geometry = data.isAlex() ? SkinGeometry.SLIM : SkinGeometry.WIDE;
}
if (skin == null || cape == null) {
// The server either didn't have a texture to send, or we didn't have the texture ID cached.
// Let's see if this player is a Bedrock player, and if so, let's pull their skin.
// Otherwise, grab the default player skin
SkinProvider.SkinData fallbackSkinData = SkinProvider.determineFallbackSkinData(playerEntity.getUuid());
SkinData fallbackSkinData = SkinProvider.determineFallbackSkinData(playerEntity.getUuid());
if (skin == null) {
skin = fallbackSkinData.skin();
geometry = fallbackSkinData.geometry();
@ -95,10 +99,10 @@ public class SkinManager {
* With all the information needed, build a Bedrock player entry with translated skin information.
*/
public static PlayerListPacket.Entry buildEntryManually(GeyserSession session, UUID uuid, String username, long geyserId,
SkinProvider.Skin skin,
SkinProvider.Cape cape,
SkinProvider.SkinGeometry geometry) {
SerializedSkin serializedSkin = getSkin(skin.getTextureUrl(), skin, cape, geometry);
Skin skin,
Cape cape,
SkinGeometry geometry) {
SerializedSkin serializedSkin = getSkin(skin.textureUrl(), skin, cape, geometry);
// This attempts to find the XUID of the player so profile images show up for Xbox accounts
String xuid = "";
@ -128,10 +132,10 @@ public class SkinManager {
return entry;
}
public static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinProvider.SkinData skinData) {
SkinProvider.Skin skin = skinData.skin();
SkinProvider.Cape cape = skinData.cape();
SkinProvider.SkinGeometry geometry = skinData.geometry();
public static void sendSkinPacket(GeyserSession session, PlayerEntity entity, SkinData skinData) {
Skin skin = skinData.skin();
Cape cape = skinData.cape();
SkinGeometry geometry = skinData.geometry();
if (entity.getUuid().equals(session.getPlayerEntity().getUuid())) {
// TODO is this special behavior needed?
@ -153,16 +157,16 @@ public class SkinManager {
PlayerSkinPacket packet = new PlayerSkinPacket();
packet.setUuid(entity.getUuid());
packet.setOldSkinName("");
packet.setNewSkinName(skin.getTextureUrl());
packet.setSkin(getSkin(skin.getTextureUrl(), skin, cape, geometry));
packet.setNewSkinName(skin.textureUrl());
packet.setSkin(getSkin(skin.textureUrl(), skin, cape, geometry));
packet.setTrustedSkin(true);
session.sendUpstreamPacket(packet);
}
}
private static SerializedSkin getSkin(String skinId, SkinProvider.Skin skin, SkinProvider.Cape cape, SkinProvider.SkinGeometry geometry) {
private static SerializedSkin getSkin(String skinId, Skin skin, Cape cape, SkinGeometry geometry) {
return SerializedSkin.of(skinId, "", geometry.geometryName(),
ImageData.of(skin.getSkinData()), Collections.emptyList(),
ImageData.of(skin.skinData()), Collections.emptyList(),
ImageData.of(cape.capeData()), geometry.geometryData(),
"", true, false, false, cape.capeId(), skinId);
}

View File

@ -35,7 +35,12 @@ import lombok.NoArgsConstructor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.event.lifecycle.SkinApplyEvent;
import org.geysermc.geyser.api.network.AuthType;
import org.geysermc.geyser.api.skin.Cape;
import org.geysermc.geyser.api.skin.Skin;
import org.geysermc.geyser.api.skin.SkinData;
import org.geysermc.geyser.api.skin.SkinGeometry;
import org.geysermc.geyser.entity.type.player.PlayerEntity;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
@ -45,7 +50,6 @@ import org.geysermc.geyser.util.WebUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
@ -61,7 +65,7 @@ public class SkinProvider {
private static ExecutorService EXECUTOR_SERVICE;
static final Skin EMPTY_SKIN;
static final Cape EMPTY_CAPE = new Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, -1, true);
static final Cape EMPTY_CAPE = new Cape("", "no-cape", ByteArrays.EMPTY_ARRAY, true);
private static final Cache<String, Cape> CACHED_JAVA_CAPES = CacheBuilder.newBuilder()
.expireAfterAccess(1, TimeUnit.HOURS)
@ -111,17 +115,17 @@ public class SkinProvider {
outputStream.write((rgba >> 24) & 0xFF); // Alpha
}
}
EMPTY_SKIN = new Skin(-1, "geysermc:empty", outputStream.toByteArray());
EMPTY_SKIN = new Skin("geysermc:empty", outputStream.toByteArray());
/* Load in the custom skull geometry */
String skullData = new String(FileUtils.readAllBytes("bedrock/skin/geometry.humanoid.customskull.json"), StandardCharsets.UTF_8);
SKULL_GEOMETRY = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.customskull\"}}", skullData, false);
SKULL_GEOMETRY = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.customskull\"}}", skullData);
/* Load in the player head skull geometry */
String wearingCustomSkull = new String(FileUtils.readAllBytes("bedrock/skin/geometry.humanoid.wearingCustomSkull.json"), StandardCharsets.UTF_8);
WEARING_CUSTOM_SKULL = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.wearingCustomSkull\"}}", wearingCustomSkull, false);
WEARING_CUSTOM_SKULL = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.wearingCustomSkull\"}}", wearingCustomSkull);
String wearingCustomSkullSlim = new String(FileUtils.readAllBytes("bedrock/skin/geometry.humanoid.wearingCustomSkullSlim.json"), StandardCharsets.UTF_8);
WEARING_CUSTOM_SKULL_SLIM = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.wearingCustomSkullSlim\"}}", wearingCustomSkullSlim, false);
WEARING_CUSTOM_SKULL_SLIM = new SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.wearingCustomSkullSlim\"}}", wearingCustomSkullSlim);
}
public static ExecutorService getExecutorService() {
@ -195,7 +199,7 @@ public class SkinProvider {
// We don't have a skin for the player right now. Fall back to a default.
ProvidedSkins.ProvidedSkin providedSkin = ProvidedSkins.getDefaultPlayerSkin(uuid);
skin = providedSkin.getData();
geometry = providedSkin.isSlim() ? SkinProvider.SkinGeometry.SLIM : SkinProvider.SkinGeometry.WIDE;
geometry = providedSkin.isSlim() ? SkinGeometry.SLIM : SkinGeometry.WIDE;
}
if (cape == null) {
@ -229,7 +233,7 @@ public class SkinProvider {
return CACHED_JAVA_CAPES.getIfPresent(capeUrl);
}
static CompletableFuture<SkinProvider.SkinData> requestSkinData(PlayerEntity entity) {
static CompletableFuture<SkinData> requestSkinData(PlayerEntity entity) {
SkinManager.GameProfileData data = SkinManager.GameProfileData.from(entity);
if (data == null) {
// This player likely does not have a textures property
@ -251,7 +255,31 @@ public class SkinProvider {
cape = getCachedBedrockCape(entity.getUuid());
}
return new SkinData(skin, cape, geometry);
// TODO: Call event to allow extensions to modify the skin, cape and geo
// Pass in if the skin is from a Bedrock player or java
GeyserImpl geyser = GeyserImpl.getInstance();
geyser.getLogger().debug("Processing skin, isBedrock: " + (geyser.connectionByUuid(entity.getUuid()) != null));
boolean isBedrock = geyser.connectionByUuid(entity.getUuid()) != null;
final SkinData[] skinData = {new SkinData(skin, cape, geometry)};
GeyserImpl.getInstance().eventBus().fire(new SkinApplyEvent(entity.getUsername(), entity.getUuid(), data.isAlex(), isBedrock, skinData[0]) {
@Override
public void skin(@NonNull Skin newSkin) {
skinData[0] = new SkinData(newSkin, skinData[0].cape(), skinData[0].geometry());
}
@Override
public void cape(@NonNull Cape newCape) {
skinData[0] = new SkinData(skinData[0].skin(), newCape, skinData[0].geometry());
}
@Override
public void geometry(@NonNull SkinGeometry newGeometry) {
skinData[0] = new SkinData(skinData[0].skin(), skinData[0].cape(), newGeometry);
}
});
return skinData[0];
} catch (Exception e) {
GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.skin.fail", entity.getUuid()), e);
}
@ -292,7 +320,6 @@ public class SkinProvider {
if (newThread) {
future = CompletableFuture.supplyAsync(() -> supplySkin(playerId, textureUrl), getExecutorService())
.whenCompleteAsync((skin, throwable) -> {
skin.updated = true;
CACHED_JAVA_SKINS.put(textureUrl, skin);
requestedSkins.remove(textureUrl);
});
@ -334,27 +361,27 @@ public class SkinProvider {
}
static void storeBedrockSkin(UUID playerID, String skinId, byte[] skinData) {
Skin skin = new Skin(playerID, skinId, skinData, System.currentTimeMillis(), true, false);
CACHED_BEDROCK_SKINS.put(skin.getTextureUrl(), skin);
Skin skin = new Skin(skinId, skinData);
CACHED_BEDROCK_SKINS.put(skin.textureUrl(), skin);
}
static void storeBedrockCape(String capeId, byte[] capeData) {
Cape cape = new Cape(capeId, capeId, capeData, System.currentTimeMillis(), false);
Cape cape = new Cape(capeId, capeId, capeData, false);
CACHED_BEDROCK_CAPES.put(capeId, cape);
}
static void storeBedrockGeometry(UUID playerID, byte[] geometryName, byte[] geometryData) {
SkinGeometry geometry = new SkinGeometry(new String(geometryName), new String(geometryData), false);
SkinGeometry geometry = new SkinGeometry(new String(geometryName), new String(geometryData));
cachedGeometry.put(playerID, geometry);
}
private static Skin supplySkin(UUID uuid, String textureUrl) {
try {
byte[] skin = requestImageData(textureUrl, null);
return new Skin(uuid, textureUrl, skin, System.currentTimeMillis(), false);
return new Skin(textureUrl, skin);
} catch (Exception ignored) {} // just ignore I guess
return new Skin(uuid, "empty", EMPTY_SKIN.getSkinData(), System.currentTimeMillis(), false);
return new Skin("empty", EMPTY_SKIN.skinData());
}
private static Cape supplyCape(String capeUrl, CapeProvider provider) {
@ -370,7 +397,6 @@ public class SkinProvider {
capeUrl,
urlSection[urlSection.length - 1], // get the texture id and use it as cape id
cape,
System.currentTimeMillis(),
cape.length == 0
);
}
@ -590,46 +616,6 @@ public class SkinProvider {
public record SkinAndCape(Skin skin, Cape cape) {
}
/**
* Represents a full package of skin, cape, and geometry.
*/
public record SkinData(Skin skin, Cape cape, SkinGeometry geometry) {
}
@AllArgsConstructor
@Getter
public static class Skin {
private UUID skinOwner;
private final String textureUrl;
private final byte[] skinData;
private final long requestedOn;
private boolean updated;
Skin(long requestedOn, String textureUrl, byte[] skinData) {
this.requestedOn = requestedOn;
this.textureUrl = textureUrl;
this.skinData = skinData;
}
}
public record Cape(String textureUrl, String capeId, byte[] capeData, long requestedOn, boolean failed) {
}
public record SkinGeometry(String geometryName, String geometryData, boolean failed) {
public static SkinGeometry WIDE = getLegacy(false);
public static SkinGeometry SLIM = getLegacy(true);
/**
* Generate generic geometry
*
* @param isSlim Should it be the alex model
* @return The generic geometry object
*/
private static SkinGeometry getLegacy(boolean isSlim) {
return new SkinProvider.SkinGeometry("{\"geometry\" :{\"default\" :\"geometry.humanoid.custom" + (isSlim ? "Slim" : "") + "\"}}", "", true);
}
}
/*
* Sorted by 'priority'
*/

View File

@ -29,6 +29,8 @@ import org.cloudburstmc.protocol.bedrock.data.skin.ImageData;
import org.cloudburstmc.protocol.bedrock.data.skin.SerializedSkin;
import org.cloudburstmc.protocol.bedrock.packet.PlayerSkinPacket;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.api.skin.Skin;
import org.geysermc.geyser.api.skin.SkinData;
import org.geysermc.geyser.entity.type.player.SkullPlayerEntity;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.text.GeyserLocale;
@ -50,14 +52,14 @@ public class SkullSkinManager extends SkinManager {
}
public static void requestAndHandleSkin(SkullPlayerEntity entity, GeyserSession session,
Consumer<SkinProvider.Skin> skinConsumer) {
BiConsumer<SkinProvider.Skin, Throwable> applySkin = (skin, throwable) -> {
Consumer<Skin> skinConsumer) {
BiConsumer<Skin, Throwable> applySkin = (skin, throwable) -> {
try {
PlayerSkinPacket packet = new PlayerSkinPacket();
packet.setUuid(entity.getUuid());
packet.setOldSkinName("");
packet.setNewSkinName(skin.getTextureUrl());
packet.setSkin(buildSkullEntryManually(skin.getTextureUrl(), skin.getSkinData()));
packet.setNewSkinName(skin.textureUrl());
packet.setSkin(buildSkullEntryManually(skin.textureUrl(), skin.skinData()));
packet.setTrustedSkin(true);
session.sendUpstreamPacket(packet);
} catch (Exception e) {
@ -74,7 +76,7 @@ public class SkullSkinManager extends SkinManager {
GeyserImpl.getInstance().getLogger().debug("Using fallback skin for skull at " + entity.getSkullPosition() +
" with texture value: " + entity.getTexturesProperty() + " and UUID: " + entity.getSkullUUID());
// No texture available, fallback using the UUID
SkinProvider.SkinData fallback = SkinProvider.determineFallbackSkinData(entity.getSkullUUID());
SkinData fallback = SkinProvider.determineFallbackSkinData(entity.getSkullUUID());
applySkin.accept(fallback.skin(), null);
} else {
SkinProvider.requestSkin(entity.getUuid(), data.skinUrl(), true)

View File

@ -1,249 +0,0 @@
{
"format_version": "1.14.0",
"minecraft:geometry": [
{
"bones": [
{
"name" : "root",
"pivot" : [ 0.0, 0.0, 0.0 ]
},
{
"name" : "waist",
"parent" : "root",
"pivot" : [ 0.0, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "body",
"parent" : "waist",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 16 ]
}
]
},
{
"name": "jacket",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 32 ],
"inflate": 0.25
}
]
},
{
"name": "head",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 0, 0 ]
}
]
},
{
"name": "hat",
"parent" : "head",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 32, 0 ],
"inflate": 0.5
}
]
},
{
"name": "leftArm",
"parent" : "body",
"pivot": [ 5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 32, 48 ]
}
]
},
{
"name": "rightArm",
"parent" : "body",
"pivot": [ -5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -8.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 40, 16 ]
}
]
},
{
"name": "leftSleeve",
"parent" : "leftArm",
"pivot": [ 5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 48, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightSleeve",
"parent" : "rightArm",
"pivot": [ -5.0, 22.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -8.0, 12.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 40, 32 ],
"inflate": 0.25
}
]
},
{
"name": "leftLeg",
"parent" : "root",
"pivot": [ 1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "rightLeg",
"parent" : "root",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "leftPants",
"parent" : "leftLeg",
"pivot": [1.9, 12.0, 0.0],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightPants",
"parent" : "rightLeg",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0] ,
"size": [ 4, 12, 4 ],
"uv": [ 0, 32],
"inflate": 0.25
}
]
},
{
"name" : "rightItem",
"parent" : "rightArm",
"pivot" : [ -6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name" : "leftItem",
"parent" : "leftArm",
"pivot" : [ 6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "leftEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ 3.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
},
{
"name": "rightEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ -9.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
}
],
"description": {
"identifier": "geometry.humanoid.ears",
"texture_height": 64,
"texture_width": 64
}
}
]
}

View File

@ -1,249 +0,0 @@
{
"format_version": "1.14.0",
"minecraft:geometry": [
{
"bones": [
{
"name" : "root",
"pivot" : [ 0.0, 0.0, 0.0 ]
},
{
"name" : "waist",
"parent" : "root",
"pivot" : [ 0.0, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "body",
"parent" : "waist",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 16 ]
}
]
},
{
"name": "jacket",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 12.0, -2.0 ],
"size": [ 8, 12, 4 ],
"uv": [ 16, 32 ],
"inflate": 0.25
}
]
},
{
"name": "head",
"parent" : "body",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 0, 0 ]
}
]
},
{
"name": "hat",
"parent" : "head",
"pivot": [ 0.0, 24.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -4.0, 24.0, -4.0 ],
"size": [ 8, 8, 8 ],
"uv": [ 32, 0 ],
"inflate": 0.5
}
]
},
{
"name": "leftArm",
"parent" : "body",
"pivot": [ 5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 12, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 32, 48 ]
}
]
},
{
"name": "rightArm",
"parent" : "body",
"pivot": [ -5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -7.0, 12, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 40, 16 ]
}
]
},
{
"name": "leftSleeve",
"parent" : "leftArm",
"pivot": [ 5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ 4.0, 11.5, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 48, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightSleeve",
"parent" : "rightArm",
"pivot": [ -5.0, 21.5, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -7.0, 11.5, -2.0 ],
"size": [ 3, 12, 4 ],
"uv": [ 40, 32 ],
"inflate": 0.25
}
]
},
{
"name": "leftLeg",
"parent" : "root",
"pivot": [ 1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "rightLeg",
"parent" : "root",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 16 ]
}
]
},
{
"name": "leftPants",
"parent" : "leftLeg",
"pivot": [1.9, 12.0, 0.0],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -0.1, 0.0, -2.0 ],
"size": [ 4, 12, 4 ],
"uv": [ 0, 48 ],
"inflate": 0.25
}
]
},
{
"name": "rightPants",
"parent" : "rightLeg",
"pivot": [ -1.9, 12.0, 0.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes": [
{
"origin": [ -3.9, 0.0, -2.0] ,
"size": [ 4, 12, 4 ],
"uv": [ 0, 32],
"inflate": 0.25
}
]
},
{
"name" : "rightItem",
"parent" : "rightArm",
"pivot" : [ -6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name" : "leftItem",
"parent" : "leftArm",
"pivot" : [ 6.0, 15.0, 1.0 ],
"rotation" : [ 0.0, 0.0, 0.0 ],
"cubes" : []
},
{
"name": "leftEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ 3.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
},
{
"name": "rightEar",
"parent" : "head",
"pivot": [ -1.9, 12.0, 0.0 ],
"cubes": [
{
"origin": [ -9.0, 31.0, -0.5 ],
"size": [ 6, 6, 1 ],
"uv": [ 24, 0 ],
"inflate": 0.5
}
]
}
],
"description": {
"identifier": "geometry.humanoid.earsSlim",
"texture_height": 64,
"texture_width": 64
}
}
]
}