Better UUID/skin cache behaviour

This commit is contained in:
fullwall 2014-08-09 01:21:33 -07:00
parent 7cb22cc1c5
commit 901f7ad654

View File

@ -45,7 +45,7 @@ public class HumanController extends AbstractEntityController {
super();
if (SKIN_THREAD == null) {
Bukkit.getScheduler().runTaskTimerAsynchronously(CitizensAPI.getPlugin(), SKIN_THREAD = new SkinThread(),
10, 100);
10, 10);
}
}
@ -96,9 +96,6 @@ public class HumanController extends AbstractEntityController {
ChatColor.stripColor(npc.data().<String> get(CACHED_SKIN_UUID_NAME_METADATA)))) {
skinUUID = npc.data().get(CACHED_SKIN_UUID_METADATA);
}
if (UUID_CACHE.containsKey(skinUUID)) {
skinUUID = UUID_CACHE.get(skinUUID);
}
Property cached = TEXTURE_CACHE.get(skinUUID);
if (cached != null) {
profile.getProperties().put("textures", cached);
@ -149,6 +146,11 @@ public class HumanController extends AbstractEntityController {
return;
}
GameProfile skinProfile = null;
Property cached = TEXTURE_CACHE.get(realUUID);
if (cached != null) {
skinProfile = new GameProfile(UUID.fromString(realUUID), "");
skinProfile.getProperties().put("textures", cached);
} else {
try {
skinProfile = fillProfileProperties(
((YggdrasilMinecraftSessionService) repo).getAuthenticationService(),
@ -160,11 +162,14 @@ public class HumanController extends AbstractEntityController {
}
return;
}
if (skinProfile == null || !skinProfile.getProperties().containsKey("textures"))
return;
Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null);
if (textures.getValue() != null && textures.getSignature() != null) {
if (textures.getValue() == null || textures.getSignature() == null)
return;
TEXTURE_CACHE.put(realUUID, new Property("textures", textures.getValue(), textures.getSignature()));
}
Bukkit.getScheduler().callSyncMethod(CitizensAPI.getPlugin(), new Callable<Void>() {
@Override
public Void call() {
@ -177,7 +182,6 @@ public class HumanController extends AbstractEntityController {
});
}
}
}
public static class SkinThread implements Runnable {
private volatile int delay = 0;
@ -188,7 +192,8 @@ public class HumanController extends AbstractEntityController {
}
public void delay() {
delay = 12;
delay = 120; // need to wait a minute before Mojang accepts API
// calls again
}
@Override
@ -208,7 +213,7 @@ public class HumanController extends AbstractEntityController {
public static class UUIDFetcher implements Callable<String> {
private final NPC npc;
private final String reportedUUID;
private String reportedUUID;
public UUIDFetcher(String reportedUUID, NPC npc) {
this.reportedUUID = reportedUUID;
@ -217,6 +222,10 @@ public class HumanController extends AbstractEntityController {
@Override
public String call() throws Exception {
String skinUUID = UUID_CACHE.get(reportedUUID);
if (skinUUID != null) {
reportedUUID = skinUUID;
}
if (reportedUUID.contains("-")) {
return reportedUUID;
}