diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java index c16f0b59..78e61332 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/HDSkinManager.java @@ -18,6 +18,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.InsecureTextureException; import com.mojang.authlib.minecraft.MinecraftProfileTexture; @@ -27,6 +28,8 @@ import com.mojang.authlib.properties.Property; import com.mojang.util.UUIDTypeAdapter; import com.mumfrey.liteloader.core.LiteLoader; import com.mumfrey.liteloader.util.log.LiteLoaderLogger; +import com.mumfrey.webprefs.WebPreferencesManager; +import com.mumfrey.webprefs.interfaces.IWebPreferences; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.IImageBuffer; @@ -36,7 +39,6 @@ import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.resources.DefaultPlayerSkin; import net.minecraft.client.resources.SkinManager.SkinAvailableCallback; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.StringUtils; public final class HDSkinManager { @@ -51,6 +53,8 @@ public final class HDSkinManager { private Map> skinCache = Maps.newHashMap(); private List skinModifiers = Lists.newArrayList(); + private WebPreferencesManager webprefs = WebPreferencesManager.getDefault(); + private HDSkinManager() {} public Optional getSkinLocation(GameProfile profile1, Type type, boolean loadIfAbsent) { @@ -103,6 +107,7 @@ public final class HDSkinManager { if (texture == null) { return; } + String dir = type.toString().toLowerCase() + "s/"; final ResourceLocation skin = new ResourceLocation(dir + texture.getHash()); File file1 = new File(new File("assets/" + dir), texture.getHash().substring(0, 2)); @@ -135,14 +140,18 @@ public final class HDSkinManager { Map textures = this.profileTextures.get(profile.getId()); if (textures == null) { + IWebPreferences prefs = this.webprefs.getPreferences(profile); + Map metadata = new Gson().fromJson(prefs.get("hdskins.metadata"), new TypeToken>() {}.getType()); String uuid = UUIDTypeAdapter.fromUUID(profile.getId()); - String skinUrl = getCustomSkinURLForId(uuid, false); - String capeUrl = getCustomCloakURLForId(uuid); + String skinUrl = getCustomTextureURLForId(Type.SKIN, uuid, false); + String capeUrl = getCustomTextureURLForId(Type.CAPE, uuid); + String elytraUrl = getCustomTextureURLForId(Type.ELYTRA, uuid); // TODO metadata (needs server support) textures = ImmutableMap.of( - Type.SKIN, new MinecraftProfileTexture(skinUrl, null), - Type.CAPE, new MinecraftProfileTexture(capeUrl, null)); + Type.SKIN, new MinecraftProfileTexture(skinUrl, metadata), + Type.CAPE, new MinecraftProfileTexture(capeUrl, null), + Type.ELYTRA, new MinecraftProfileTexture(elytraUrl, null)); this.profileTextures.put(profile.getId(), textures); } return textures; @@ -184,13 +193,14 @@ public final class HDSkinManager { return String.format("http://%s/", gatewayUrl); } - public String getCustomSkinURLForId(String uuid, boolean gateway) { - uuid = StringUtils.stripControlCodes(uuid); - return String.format("http://%s/skins/%s.png", gateway ? gatewayUrl : skinUrl, uuid); + public String getCustomTextureURLForId(Type type, String uuid, boolean gateway) { + String server = gateway ? gatewayUrl : skinUrl; + String path = type.toString().toLowerCase() + "s"; + return String.format("http://%s/%s/%s.png", server, path, uuid); } - public String getCustomCloakURLForId(String uuid) { - return String.format("http://%s/capes/%s.png", skinUrl, StringUtils.stripControlCodes(uuid)); + public String getCustomTextureURLForId(Type type, String uuid) { + return getCustomTextureURLForId(type, uuid, false); } public void setEnabled(boolean enabled) { @@ -203,7 +213,7 @@ public final class HDSkinManager { Map textures = getTexturesForProfile(profile); MinecraftProfileTexture skin = textures.get(Type.SKIN); if (skin != null) { - String url = INSTANCE.getCustomSkinURLForId(UUIDTypeAdapter.fromUUID(profile.getId()), true); + String url = INSTANCE.getCustomTextureURLForId(Type.SKIN, UUIDTypeAdapter.fromUUID(profile.getId()), true); skinTexture = new PreviewTexture(url, DefaultPlayerSkin.getDefaultSkin(profile.getId()), new ImageBufferDownloadHD()); textureManager.loadTexture(skinResource, skinTexture); } diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinPlayerInfo.java b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinPlayerInfo.java index 776e291f..a2a18f5c 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinPlayerInfo.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/mixin/MixinPlayerInfo.java @@ -1,6 +1,5 @@ package com.voxelmodpack.hdskins.mixin; -import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -19,36 +18,15 @@ import net.minecraft.util.ResourceLocation; @Mixin(NetworkPlayerInfo.class) public abstract class MixinPlayerInfo { - @Final @Shadow - private GameProfile gameProfile; - @Shadow - private ResourceLocation locationSkin; - @Shadow - public String skinType; - - @Inject( - method = "hasLocationSkin", - cancellable = true, - at = @At("RETURN")) - private void hasLocationSkin(CallbackInfoReturnable ci) { - if (locationSkin == null) { - // in case has no skin - Optional skin = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.SKIN, false); - ci.setReturnValue(skin.isPresent()); - } - } + public abstract GameProfile getGameProfile(); @Inject( method = "getLocationSkin", cancellable = true, at = @At("RETURN")) private void getLocationSkin(CallbackInfoReturnable ci) { - Optional skin = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.SKIN, true); - if (skin.isPresent()) { - // set the skin - ci.setReturnValue(skin.get()); - } + getTextureLocation(ci, Type.SKIN); } @Inject( @@ -56,10 +34,21 @@ public abstract class MixinPlayerInfo { cancellable = true, at = @At("RETURN")) private void getLocationCape(CallbackInfoReturnable ci) { - Optional cape = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.CAPE, true); - if (cape.isPresent()) { - // set the cape - ci.setReturnValue(cape.get()); + getTextureLocation(ci, Type.CAPE); + } + + @Inject( + method = "getLocationElytra", + cancellable = true, + at = @At("RETURN")) + private void getLocationElytra(CallbackInfoReturnable ci) { + getTextureLocation(ci, Type.ELYTRA); + } + + private void getTextureLocation(CallbackInfoReturnable ci, Type type) { + Optional texture = HDSkinManager.INSTANCE.getSkinLocation(getGameProfile(), type, true); + if (texture.isPresent()) { + ci.setReturnValue(texture.get()); } } @@ -68,10 +57,10 @@ public abstract class MixinPlayerInfo { cancellable = true, at = @At("RETURN")) private void getSkinType(CallbackInfoReturnable ci) { - MinecraftProfileTexture data = HDSkinManager.INSTANCE.getProfileData(gameProfile).get(Type.SKIN); + MinecraftProfileTexture data = HDSkinManager.INSTANCE.getProfileData(getGameProfile()).get(Type.SKIN); if (data != null) { String type = data.getMetadata("model"); - boolean hasSkin = HDSkinManager.INSTANCE.getSkinLocation(gameProfile, Type.SKIN, false).isPresent(); + boolean hasSkin = HDSkinManager.INSTANCE.getSkinLocation(getGameProfile(), Type.SKIN, false).isPresent(); if (hasSkin) { if (type == null) type = "default";