mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-12 01:27:33 +00:00
Support 1.21.8. Split GameProfileLoader and MojangAPILoader. (#343)
This commit is contained in:
1 parent
1a15951791
commit
d0d71b8557
6 files changed
+125
-52
No files matched your search
@@ -21,7 +21,7 @@ import com.mojang.authlib.properties.Property;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.fake.itf.FakeInterfaceManager;
|
||||
import customskinloader.fake.texture.FakeThreadDownloadImageData;
|
||||
import customskinloader.loader.MojangAPILoader;
|
||||
import customskinloader.loader.GameProfileLoader;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
import customskinloader.utils.HttpTextureUtil;
|
||||
@@ -301,7 +301,7 @@ public class FakeSkinManager {
|
||||
public static class FakeCacheKey {
|
||||
public static Object wrapCacheKey(Object cacheKey, GameProfile profile) {
|
||||
if (FakeInterfaceManager.SkinManagerCacheKey_profile(cacheKey) == null) { // 23w42a+
|
||||
TextureUtil.AuthlibField.PROPERTY_SIGNATURE.set(FakeInterfaceManager.SkinManagerCacheKey_packedTextures(cacheKey), MojangAPILoader.GSON.toJson(profile, GameProfile.class));
|
||||
TextureUtil.AuthlibField.PROPERTY_SIGNATURE.set(FakeInterfaceManager.SkinManagerCacheKey_packedTextures(cacheKey), GameProfileLoader.GSON.toJson(profile, GameProfile.class));
|
||||
}
|
||||
return cacheKey;
|
||||
}
|
||||
@@ -315,7 +315,7 @@ public class FakeSkinManager {
|
||||
}
|
||||
|
||||
public static GameProfile unwrapProperty(Property property) {
|
||||
return MojangAPILoader.GSON.fromJson((String) TextureUtil.AuthlibField.PROPERTY_SIGNATURE.get(property), GameProfile.class); // 23w42a+
|
||||
return GameProfileLoader.GSON.fromJson((String) TextureUtil.AuthlibField.PROPERTY_SIGNATURE.get(property), GameProfile.class); // 23w42a+
|
||||
}
|
||||
|
||||
public static class IncompletedContainer {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package customskinloader.loader;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
import customskinloader.utils.TextureUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class GameProfileLoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
@Override
|
||||
public ProfileLoader.IProfileLoader getProfileLoader() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDefaultProfile> getDefaultProfiles() {
|
||||
return Lists.newArrayList(new ServerGameProfile(this));
|
||||
}
|
||||
|
||||
public static class ServerGameProfile implements ICustomSkinLoaderPlugin.IDefaultProfile {
|
||||
protected final GameProfileLoader loader;
|
||||
|
||||
public ServerGameProfile(GameProfileLoader loader) {
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GameProfile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSkinSiteProfile(SkinSiteProfile ssp) {
|
||||
ssp.type = this.loader.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) throws Exception {
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
|
||||
if (!map.isEmpty()) {
|
||||
CustomSkinLoader.logger.info("Default profile will be used.");
|
||||
return ModelManager0.toUserProfile(map);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "GameProfile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(SkinSiteProfile ssp) {
|
||||
|
||||
}
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
||||
if (textureProperty == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
String value = TextureUtil.AuthlibField.PROPERTY_VALUE.get(textureProperty);
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
String json = new String(Base64.decodeBase64(value), StandardCharsets.UTF_8);
|
||||
MinecraftTexturesPayload result = GSON.fromJson(json, MinecraftTexturesPayload.class);
|
||||
|
||||
if (result == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures = TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result);
|
||||
if (textures == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
return textures;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,15 @@
|
||||
package customskinloader.loader;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftTexturesPayload;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.config.SkinSiteProfile;
|
||||
import customskinloader.plugin.ICustomSkinLoaderPlugin;
|
||||
@@ -26,7 +17,6 @@ import customskinloader.profile.ModelManager0;
|
||||
import customskinloader.profile.UserProfile;
|
||||
import customskinloader.utils.HttpRequestUtil;
|
||||
import customskinloader.utils.TextureUtil;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.IProfileLoader {
|
||||
@@ -88,11 +78,6 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
|
||||
@Override
|
||||
public UserProfile loadProfile(SkinSiteProfile ssp, GameProfile gameProfile) {
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = getTextures(gameProfile);
|
||||
if (!map.isEmpty()) {
|
||||
CustomSkinLoader.logger.info("Default profile will be used.");
|
||||
return ModelManager0.toUserProfile(map);
|
||||
}
|
||||
String username = gameProfile.getName();
|
||||
GameProfile newGameProfile = loadGameProfileCached(ssp.apiRoot, username);
|
||||
if (newGameProfile == null) {
|
||||
@@ -100,7 +85,7 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
return null;
|
||||
}
|
||||
newGameProfile = fillGameProfile(ssp.sessionRoot, newGameProfile);
|
||||
map = getTextures(newGameProfile);
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> map = GameProfileLoader.getTextures(newGameProfile);
|
||||
if (!map.isEmpty()) {
|
||||
gameProfile.getProperties().putAll(newGameProfile.getProperties());
|
||||
return ModelManager0.toUserProfile(map);
|
||||
@@ -109,7 +94,6 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final Gson GSON = new GsonBuilder().registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer()).create();
|
||||
private static final Map<String, GameProfile> gameProfileCache = new ConcurrentHashMap<>();
|
||||
|
||||
public static GameProfile loadGameProfileCached(String apiRoot, String username) {
|
||||
@@ -119,12 +103,12 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
//Username -> UUID
|
||||
public static GameProfile loadGameProfile(String apiRoot, String username) {
|
||||
//Doc (https://minecraft.wiki/w/Mojang_API#Query_player_UUIDs_in_batch)
|
||||
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft").setCacheTime(600).setPayload(GSON.toJson(Collections.singletonList(username))));
|
||||
HttpRequestUtil.HttpResponce responce = HttpRequestUtil.makeHttpRequest(new HttpRequestUtil.HttpRequest(apiRoot + "profiles/minecraft").setCacheTime(600).setPayload(GameProfileLoader.GSON.toJson(Collections.singletonList(username))));
|
||||
if (StringUtils.isEmpty(responce.content)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GameProfile[] profiles = GSON.fromJson(responce.content, GameProfile[].class);
|
||||
GameProfile[] profiles = GameProfileLoader.GSON.fromJson(responce.content, GameProfile[].class);
|
||||
if (profiles.length == 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -160,38 +144,13 @@ public class MojangAPILoader implements ICustomSkinLoaderPlugin, ProfileLoader.I
|
||||
return profile;
|
||||
}
|
||||
|
||||
MinecraftProfilePropertiesResponse propertiesResponce = GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
|
||||
MinecraftProfilePropertiesResponse propertiesResponce = GameProfileLoader.GSON.fromJson(responce.content, MinecraftProfilePropertiesResponse.class);
|
||||
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;
|
||||
}
|
||||
|
||||
public static Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile gameProfile) {
|
||||
if (gameProfile == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
Property textureProperty = Iterables.getFirst(gameProfile.getProperties().get("textures"), null);
|
||||
if (textureProperty == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
String value = TextureUtil.AuthlibField.PROPERTY_VALUE.get(textureProperty);
|
||||
if (StringUtils.isBlank(value)) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
String json = new String(Base64.decodeBase64(value), StandardCharsets.UTF_8);
|
||||
MinecraftTexturesPayload result = GSON.fromJson(json, MinecraftTexturesPayload.class);
|
||||
|
||||
if (result == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures = TextureUtil.AuthlibField.MINECRAFT_TEXTURES_PAYLOAD_TEXTURES.get(result);
|
||||
if (textures == null) {
|
||||
return Maps.newHashMap();
|
||||
}
|
||||
return textures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean compare(SkinSiteProfile ssp0, SkinSiteProfile ssp1) {
|
||||
return (!StringUtils.isNoneEmpty(ssp0.apiRoot) || ssp0.apiRoot.equalsIgnoreCase(ssp1.apiRoot)) || (!StringUtils.isNoneEmpty(ssp0.sessionRoot) || ssp0.sessionRoot.equalsIgnoreCase(ssp1.sessionRoot));
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.util.ServiceLoader;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.GameProfileLoader;
|
||||
import customskinloader.loader.JsonAPILoader;
|
||||
import customskinloader.loader.LegacyLoader;
|
||||
import customskinloader.loader.MojangAPILoader;
|
||||
@@ -17,6 +18,7 @@ import org.apache.commons.io.FileUtils;
|
||||
|
||||
public class PluginLoader {
|
||||
public static final ICustomSkinLoaderPlugin[] DEFAULT_PLUGINS = new ICustomSkinLoaderPlugin[]{
|
||||
new GameProfileLoader(),
|
||||
new MojangAPILoader(),
|
||||
new LegacyLoader(),
|
||||
new JsonAPILoader(new CustomSkinAPI()),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
dependencies=Fabric|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6;\
|
||||
Quilt|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6
|
||||
dependencies=Fabric|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8;\
|
||||
Quilt|1.14,1.14.1,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5,1.17,1.17.1,1.18,1.18.1,1.18.2,1.19,1.19.1,1.19.2,1.19.3,1.19.4,1.20,1.20.1,1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8
|
||||
java_full_versions=8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
|
||||
#forge gradle needs forge version
|
||||
forge_mc_version=1.12.2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
dependencies=Forge|1.20.6,1.21,1.21.1,1.21.3,1.21.4,1.21.5,1.21.6;\
|
||||
NeoForge|1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6
|
||||
dependencies=Forge|1.20.6,1.21,1.21.1,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8;\
|
||||
NeoForge|1.20.2,1.20.3,1.20.4,1.20.5,1.20.6,1.21,1.21.1,1.21.2,1.21.3,1.21.4,1.21.5,1.21.6,1.21.7,1.21.8
|
||||
java_full_versions=17,18,19,20,21,22
|
||||
#forge gradle needs forge version
|
||||
forge_mc_version=1.12.2
|
||||
|
||||
Reference in new issue
Block a user