Compare commits

...
2 Commits
Author SHA1 Message Date
33 119892489f feat: rename enum AuthlibField 2023-10-10 13:58:32 +08:00
ZekerZhayard 9a55a4c615 Adapting to Authlib changes (#269) 2023-10-10 13:54:23 +08:00
6 changed files with 32 additions and 36 deletions

No files matched your search

@@ -163,8 +163,8 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
MinecraftProfilePropertiesResponse propertiesResponce = gson.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
GameProfile newGameProfile = new GameProfile(propertiesResponce.getId(), propertiesResponce.getName());
newGameProfile.getProperties().putAll(propertiesResponce.getProperties());
GameProfile newGameProfile = new GameProfile(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID.get(propertiesResponce), TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME.get(propertiesResponce));
newGameProfile.getProperties().putAll(TextureUtil.AuthlibField.MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES.get(propertiesResponce));
return newGameProfile;
}
@@ -177,7 +177,7 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
if (textureProperty == null) {
return Maps.newHashMap();
}
String value = TextureUtil.getPropertyValue(textureProperty);
String value = TextureUtil.AuthlibField.PROPERTY_VALUE_FIELD.get(textureProperty);
if (StringUtils.isBlank(value)) {
return Maps.newHashMap();
}
@@ -185,10 +185,10 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
Gson gson = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create();
MinecraftTexturesPayload result = gson.fromJson(json, MinecraftTexturesPayload.class);
if (result == null || TextureUtil.getMinecraftTexturesPayloadTextures(result) == null) {
if (result == null || TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result) == null) {
return Maps.newHashMap();
}
return TextureUtil.getMinecraftTexturesPayloadTextures(result);
return TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result);
}
@Override
@@ -49,7 +49,7 @@ public class DynamicSkullManager {
staticTextures.put(profile, Maps.newHashMap());
return;
}
String value = TextureUtil.getPropertyValue(textureProperty);
String value = TextureUtil.AuthlibField.PROPERTY_VALUE_FIELD.get(textureProperty);
if (StringUtils.isBlank(value)) {
staticTextures.put(profile, Maps.newHashMap());
return;
@@ -2,11 +2,10 @@ package customskinloader.utils;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.UUID;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
import customskinloader.CustomSkinLoader;
import org.apache.commons.codec.binary.Base64;
@@ -40,34 +39,31 @@ public class TextureUtil {
// Some of the classes in Authlib used after Minecraft 23w31a were changed to record classes,
// resulting in changes to method names, so reflection is used here to be compatible with these changes.
private final static Field VALUE_FIELD;
private final static Field TEXTURES_FIELD;
public enum AuthlibField {
PROPERTY_VALUE_FIELD(Property.class, "value"),
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_ID(MinecraftProfilePropertiesResponse.class, "id"),
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_NAME(MinecraftProfilePropertiesResponse.class, "name"),
MINECRAFT_PROFILE_PROPERTIES_RESPONSE_PROPERTIES(MinecraftProfilePropertiesResponse.class, "properties"),
MINECRAFT_TEXTURES_PAYLOAD_TEXTURES(MinecraftTexturesPayload.class, "textures");
static {
try {
VALUE_FIELD = Property.class.getDeclaredField("value");
VALUE_FIELD.setAccessible(true);
TEXTURES_FIELD = MinecraftTexturesPayload.class.getDeclaredField("textures");
TEXTURES_FIELD.setAccessible(true);
} catch (Exception e) {
throw new RuntimeException(e);
private final Field field;
AuthlibField(Class<?> clazz, String name) {
try {
this.field = clazz.getDeclaredField(name);
this.field.setAccessible(true);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
public static String getPropertyValue(Property property) {
try {
return (String) VALUE_FIELD.get(property);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("unchecked")
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getMinecraftTexturesPayloadTextures(MinecraftTexturesPayload payload) {
try {
return (Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>) TEXTURES_FIELD.get(payload);
} catch (Exception e) {
throw new RuntimeException(e);
@SuppressWarnings("unchecked")
public <T> T get(Object o) {
try {
return (T) this.field.get(o);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
}
+1 -1
View File
@@ -51,7 +51,7 @@ net/minecraft/client/resources/SkinManager net/minecraft/client/resources/SkinMa
loadSkin (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;)Lnet/minecraft/util/ResourceLocation; m_118825_
net/minecraft/client/resources/SkinManager$1 net/minecraft/client/resources/SkinManager$1
net/minecraft/client/resources/SkinManager$CacheKey net/minecraft/client/resources/SkinManager$CacheKey
profile ()Lcom/mojang/authlib/GameProfile; profile
profile ()Lcom/mojang/authlib/GameProfile; f_290972_
net/minecraft/client/resources/SkinManager$SkinAvailableCallback net/minecraft/client/resources/SkinManager$SkinTextureCallback
skinAvailable (Lcom/mojang/authlib/minecraft/MinecraftProfileTexture$Type;Lnet/minecraft/util/ResourceLocation;Lcom/mojang/authlib/minecraft/MinecraftProfileTexture;)V m_118856_
net/minecraft/client/resources/SkinManager$TextureCache net/minecraft/client/resources/SkinManager$TextureCache
+1 -1
View File
@@ -1,6 +1,6 @@
minecraft_version=1.12.2
minecraft_full_versions=1.8,1.8.8,1.8.9,1.9,1.9.4,1.10,1.10.2,1.11,1.11.2,1.12,1.12.1,1.12.2,1.13.2,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5
java_full_versions=8,9,10,11,12,13,14,15,16,17,18
java_full_versions=8,9,10,11,12,13,14,15,16,17,18,19,20,21
#forge gradle needs forge version
forge_mc_version=1.12.2
forge_version=14.23.5.2768
+1 -1
View File
@@ -1,3 +1,3 @@
name=CustomSkinLoader
group=customskinloader
version=14.18
version=14.18.1