23
23
import java .lang .reflect .Field ;
24
24
import java .net .HttpURLConnection ;
25
25
import java .net .URL ;
26
- import java .util .Collections ;
27
- import java .util .Set ;
28
26
import java .util .UUID ;
29
- import java .util .concurrent .ConcurrentHashMap ;
30
27
import java .util .concurrent .ExecutionException ;
31
28
32
29
/**
@@ -49,7 +46,7 @@ public UniSkinCore(UniSkinConfig configuration, File localSkin) {
49
46
for (String str : cfg .rootURIs ) UniSkinMod .log .info ("Added Root URI: {}" , str );
50
47
for (String str : cfg .legacySkinURIs ) UniSkinMod .log .info ("Added Skin URI: {}" , str );
51
48
for (String str : cfg .legacyCapeURIs ) UniSkinMod .log .info ("Added Cape URI: {}" , str );
52
- UniSkinMod .log .info ("Load genuine skins: {}" , cfg .loadGenuineSkins ? "Enabled" : "Disabled" );
49
+ UniSkinMod .log .info ("Load genuine skins: {}" , cfg .loadGenuineSkins ? "Enabled" : "Disabled" );
53
50
mojangProfileRepo = new YggdrasilAuthenticationService (Minecraft .getMinecraft ().getProxy (), UUID .randomUUID ().toString ())
54
51
.createProfileRepository ();
55
52
@@ -65,7 +62,9 @@ public UniSkinCore(UniSkinConfig configuration, File localSkin) {
65
62
f .setAccessible (true );
66
63
Object obj = f .get (Minecraft .getMinecraft ());
67
64
assertDir = (File ) obj ;
68
- } catch (ReflectiveOperationException ex ) {
65
+ } catch (NoSuchFieldException ex ) {
66
+ throw new RuntimeException ("Unable to determine skin cache dir." , ex );
67
+ } catch (IllegalAccessException ex ) {
69
68
throw new RuntimeException ("Unable to determine skin cache dir." , ex );
70
69
}
71
70
if (assertDir == null ) throw new RuntimeException ("Unable to determine skin cache dir." );
@@ -170,10 +169,9 @@ private void injectLocalProfile(GameProfile profile) {
170
169
UniSkinProfile api = UniSkinProfile .getLocalProfile (f , new File (localSkinDir , "textures" ));
171
170
if (api == null ) return ;
172
171
MojangTexturePayload payload = MojangTexturePayload .fromGameProfile (profile );
173
- payload .addCape (dynamicSkinManager .forceLoadTexture (api .getCapeURL (), MinecraftProfileTexture .Type .CAPE , false ));
174
- boolean isAlex = ("slim" .equalsIgnoreCase (api .getModel ()) || "alex" .equalsIgnoreCase (api .getModel ()));
175
- payload .addSkin (dynamicSkinManager .forceLoadTexture (api .getSkinURL (), MinecraftProfileTexture .Type .SKIN , isAlex ), api .getModel ());
176
- payload .addElytra (dynamicSkinManager .forceLoadTexture (api .getElytraURL (), MinecraftProfileTexture .Type .ELYTRA , false ));
172
+ payload .addCape (dynamicSkinManager .forceCopyTexture (api .getCapeURL ()));
173
+ payload .addSkin (dynamicSkinManager .forceCopyTexture (api .getSkinURL ()), api .getModel ());
174
+ payload .addElytra (dynamicSkinManager .forceCopyTexture (api .getElytraURL ()));
177
175
payload .dumpIntoGameProfile (profile );
178
176
return ;
179
177
}
@@ -241,7 +239,7 @@ private void injectLegacyProfile(GameProfile profile) {
241
239
try {
242
240
File localFile = new File (localTexture , hash );
243
241
FileUtils .writeByteArrayToFile (localFile , skinData );
244
- dynamicSkinManager .forceLoadTexture (localFile , MinecraftProfileTexture . Type . SKIN , false );
242
+ dynamicSkinManager .forceCopyTexture (localFile );
245
243
payload .addSkin ("http://127.0.0.1/" + hash , "default" );
246
244
UniSkinMod .log .info ("Injecting legacy skin: {} {}" , playerName , hash );
247
245
} catch (IOException ex ) {
@@ -263,7 +261,7 @@ private void injectLegacyProfile(GameProfile profile) {
263
261
try {
264
262
File localFile = new File (localTexture , hash );
265
263
FileUtils .writeByteArrayToFile (localFile , capeData );
266
- dynamicSkinManager .forceLoadTexture (localFile , MinecraftProfileTexture . Type . CAPE , false );
264
+ dynamicSkinManager .forceCopyTexture (localFile );
267
265
payload .addCape ("http://127.0.0.1/" + hash );
268
266
UniSkinMod .log .info ("Injecting legacy cape: {} {}" , playerName , hash );
269
267
} catch (IOException ex ) {
@@ -289,39 +287,25 @@ public ResourceLocation getDynamicSkinResource(NetworkPlayerInfo player) {
289
287
/**
290
288
* called from TileEntitySkllRenderer.renderSkull()
291
289
*/
292
- private final Set <String > loading = Collections .newSetFromMap (new ConcurrentHashMap <String , Boolean >());
293
-
294
290
public ResourceLocation getDynamicSkinResourceForSkull (GameProfile gp , ResourceLocation def ) {
295
291
if (gp == null ) return def ;
296
- final String name = gp .getName ();
292
+ String name = gp .getName ();
297
293
if (name == null || name .length () <= 0 ) return def ;
298
-
299
- if (loading .contains (name )) return def ;
300
- DynamicSkinManager .CachedDynamicSkin s = dynamicSkinManager .cache .getIfPresent (name );
301
- if (s == null ) {
302
- loading .add (name );
303
- new Thread (new Runnable () {
304
- @ Override
305
- public void run () {
306
- try {
307
- dynamicSkinManager .cache .get (name );
308
- } catch (ExecutionException ex ) {
309
- UniSkinMod .log .catching (Level .WARN , ex );
310
- }
311
- loading .remove (name );
312
- }
313
- }, "Skull-Texture-Fetch-" + name ).start ();
294
+ try {
295
+ DynamicSkinManager .CachedDynamicSkin s = dynamicSkinManager .cache .get (name );
296
+ if (s .skin != null && s .skin .length != 0 ) {
297
+ double spf = (double ) s .skinInterval / (double ) s .skin .length ;
298
+ int id = ((int ) Math .floor ((double ) (System .currentTimeMillis () % s .skinInterval ) / spf )) % (s .skin .length );
299
+ return s .skin [id ];
300
+ }
301
+ } catch (ExecutionException ex ) {
302
+ UniSkinMod .log .catching (Level .WARN , ex );
314
303
return def ;
315
304
}
316
- if (s .skin != null && s .skin .length != 0 ) {
317
- double spf = (double ) s .skinInterval / (double ) s .skin .length ;
318
- int id = ((int ) Math .floor ((double ) (System .currentTimeMillis () % s .skinInterval ) / spf )) % (s .skin .length );
319
- return s .skin [id ];
320
- }
321
-
322
305
return def ;
323
306
}
324
307
308
+
325
309
/**
326
310
* called from AbstractClientPlayer.getSkinType()
327
311
*/
0 commit comments