Skip to content
This repository was archived by the owner on Jan 3, 2020. It is now read-only.

Commit e5a9bdd

Browse files
committed
minor bug fix
1 parent 4e0de2a commit e5a9bdd

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

src/main/java/org/devinprogress/uniskinmod/DynamicSkinManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public DynamicSkinManager(List<String> r, File localSkin, File mcCache) {
4646
}
4747

4848
public final LoadingCache<String, CachedDynamicSkin> cache = CacheBuilder.newBuilder()
49-
.expireAfterWrite(60, TimeUnit.SECONDS).build(new CacheLoader<String, CachedDynamicSkin>() {
49+
.expireAfterWrite(30, TimeUnit.MINUTES).build(new CacheLoader<String, CachedDynamicSkin>() {
5050

5151
@Override
5252
public CachedDynamicSkin load(String playerName) throws Exception {
@@ -174,4 +174,18 @@ public void forceLoadTexture(File sourceFile, MinecraftProfileTexture.Type textu
174174
UniSkinMod.log.catching(Level.WARN, ex);
175175
}
176176
}
177+
178+
public String forceLoadTexture(String local_file, MinecraftProfileTexture.Type textureType, boolean isAlex) {
179+
try {
180+
if (local_file == null || textureType == null) return null;
181+
if (!local_file.startsWith("local:")) return null;
182+
File src = new File(local_file.substring(6));
183+
String sha256 = DigestUtils.sha256Hex(new FileInputStream(src)).toLowerCase();
184+
forceLoadTexture(src, textureType, isAlex);
185+
return "http://127.0.0.1/" + sha256;
186+
} catch (Exception ex) {
187+
UniSkinMod.log.catching(Level.WARN, ex);
188+
return null;
189+
}
190+
}
177191
}

src/main/java/org/devinprogress/uniskinmod/UniSkinConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static UniSkinConfig loadFromFile(File configFile) throws IOException {
2222
if (!configFile.exists()) {
2323
UniSkinMod.log.info("Creating new configuration file {}", configFile.getPath());
2424
UniSkinConfig tmpCfg = new UniSkinConfig();
25+
tmpCfg.rootURIs.add("http://www.skinme.cc/uniskin");
26+
tmpCfg.rootURIs.add("https://skin.prinzeugen.net");
2527
String json = gson.toJson(tmpCfg);
2628
configFile.getParentFile().mkdirs();
2729
FileWriter wr = new FileWriter(configFile);

src/main/java/org/devinprogress/uniskinmod/UniSkinCore.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import java.io.IOException;
2222
import java.io.InputStream;
2323
import java.lang.reflect.Field;
24+
import java.net.HttpURLConnection;
2425
import java.net.URL;
25-
import java.net.URLConnection;
2626
import java.util.UUID;
2727
import java.util.concurrent.ExecutionException;
2828

@@ -165,9 +165,10 @@ private void injectLocalProfile(GameProfile profile) {
165165
UniSkinProfile api = UniSkinProfile.getLocalProfile(f, new File(localSkinDir, "textures"));
166166
if (api == null) return;
167167
MojangTexturePayload payload = MojangTexturePayload.fromGameProfile(profile);
168-
payload.addCape(api.getCapeURL());
169-
payload.addSkin(api.getSkinURL(), api.getModel());
170-
payload.addElytra(api.getElytraURL());
168+
payload.addCape(dynamicSkinManager.forceLoadTexture(api.getCapeURL(), MinecraftProfileTexture.Type.CAPE, false));
169+
boolean isAlex = ("slim".equalsIgnoreCase(api.getModel()) || "alex".equalsIgnoreCase(api.getModel()));
170+
payload.addSkin(dynamicSkinManager.forceLoadTexture(api.getSkinURL(), MinecraftProfileTexture.Type.SKIN, isAlex), api.getModel());
171+
payload.addElytra(dynamicSkinManager.forceLoadTexture(api.getElytraURL(), MinecraftProfileTexture.Type.ELYTRA, false));
171172
payload.dumpIntoGameProfile(profile);
172173
return;
173174
}
@@ -202,13 +203,15 @@ private void injectPiracyProfile(final GameProfile gameProfile) {
202203

203204
private static byte[] fetchURL(String url) {
204205
try {
205-
URLConnection connection = new URL(url).openConnection();
206+
HttpURLConnection connection = (HttpURLConnection) (new URL(url).openConnection(Minecraft.getMinecraft().getProxy()));
206207
connection.setConnectTimeout(5000);
207208
connection.setReadTimeout(10000);
209+
connection.setInstanceFollowRedirects(true);
208210
InputStream input = connection.getInputStream();
209211
return IOUtils.toByteArray(input);
210212
} catch (Exception ex) {
211-
UniSkinMod.log.catching(Level.WARN, ex);
213+
UniSkinMod.log.catching(Level.DEBUG, ex);
214+
UniSkinMod.log.warn("Failed to fetch url: {}", url);
212215
return null;
213216
}
214217
}

src/main/java/org/devinprogress/uniskinmod/UniSkinProfile.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,31 @@ public DynamicTexture(int p, String[] t, String tp, String[] u) {
5050
}
5151

5252
public static UniSkinProfile getProfile(final String name, String root) {
53-
if (root.endsWith("/")) root = root.substring(0, root.length() - 1);
54-
UniSkinProfile prof = new UniSkinProfile(name, root);
55-
return prof.hasProfile ? prof : null;
53+
try {
54+
if (root.endsWith("/")) root = root.substring(0, root.length() - 1);
55+
UniSkinProfile prof = new UniSkinProfile(name, root);
56+
return prof.hasProfile ? prof : null;
57+
} catch (Exception ex) {
58+
UniSkinMod.log.catching(Level.DEBUG, ex);
59+
UniSkinMod.log.warn("Failed to get remote profile for {} @{} due to Exception: {}", name, root, ex);
60+
return null;
61+
}
5662
}
5763

5864
public static UniSkinProfile getLocalProfile(File profileFile, File textureFolder) {
5965
if (profileFile == null || textureFolder == null) return null;
60-
UniSkinProfile prof = new UniSkinProfile(profileFile, textureFolder);
61-
return prof.hasProfile ? prof : null;
66+
try {
67+
UniSkinProfile prof = new UniSkinProfile(profileFile, textureFolder);
68+
return prof.hasProfile ? prof : null;
69+
} catch (Exception ex) {
70+
UniSkinMod.log.catching(Level.DEBUG, ex);
71+
UniSkinMod.log.warn("Failed to get local profile @{} due to Exception: {}", profileFile.getAbsolutePath(), ex);
72+
return null;
73+
}
6274
}
6375

6476
// === Profile === //
65-
public boolean hasProfile = false;
77+
private boolean hasProfile = false;
6678

6779
private static String httpRequest(String url) {
6880
try {
@@ -130,7 +142,16 @@ public ProfileJSON call() throws Exception {
130142
return;
131143
}
132144

133-
if (!json.player_name.equalsIgnoreCase(name)) return;
145+
if (json == null || !name.equalsIgnoreCase(json.player_name)) return;
146+
147+
if (json.cape != null && json.cape.length() > 3) {
148+
cape = URL_TEXTURE_FMT.replace("{root}", root).replace("{texture_hash}", json.cape);
149+
hasProfile = true;
150+
UniSkinMod.log.info("Player Cape Selected: {} {}", name, json.cape);
151+
}
152+
153+
if (json.model_preference == null || json.skins == null) return;
154+
134155
for (String m : json.model_preference) {
135156
if (json.skins.containsKey(m) && (m.equals("default") || m.equals("slim"))) {
136157
model = m;
@@ -147,11 +168,6 @@ public ProfileJSON call() throws Exception {
147168
hasProfile = true;
148169
UniSkinMod.log.info("Player Cape Selected: {} {}", name, tmp);
149170
}
150-
if (json.cape != null && json.cape.length() > 3 && cape != null) {
151-
cape = URL_TEXTURE_FMT.replace("{root}", root).replace("{texture_hash}", json.cape);
152-
hasProfile = true;
153-
UniSkinMod.log.info("Player Cape Selected: {} {}", name, json.cape);
154-
}
155171

156172
if (json.model_preference.contains("elytra") && json.skins.containsKey("elytra")) {
157173
String tmp = json.skins.get("elytra");

0 commit comments

Comments
 (0)