diff --git a/src/main/java/net/citizensnpcs/npc/entity/HumanController.java b/src/main/java/net/citizensnpcs/npc/entity/HumanController.java index 02e714e99..5d79a2dc1 100644 --- a/src/main/java/net/citizensnpcs/npc/entity/HumanController.java +++ b/src/main/java/net/citizensnpcs/npc/entity/HumanController.java @@ -2,6 +2,7 @@ package net.citizensnpcs.npc.entity; import java.lang.reflect.Method; import java.net.URL; +import java.util.Iterator; import java.util.Map; import java.util.UUID; import java.util.concurrent.BlockingDeque; @@ -13,6 +14,7 @@ import net.citizensnpcs.api.CitizensAPI; import net.citizensnpcs.api.event.DespawnReason; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.Colorizer; +import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.npc.AbstractEntityController; import net.citizensnpcs.util.NMS; import net.minecraft.server.v1_7_R4.PlayerInteractManager; @@ -122,8 +124,8 @@ public class HumanController extends AbstractEntityController { private GameProfile fillProfileProperties(YggdrasilAuthenticationService auth, GameProfile profile, boolean requireSecure) throws Exception { URL url = HttpAuthenticationService.constantURL(new StringBuilder() - .append("https://sessionserver.mojang.com/session/minecraft/profile/") - .append(UUIDTypeAdapter.fromUUID(profile.getId())).toString()); + .append("https://sessionserver.mojang.com/session/minecraft/profile/") + .append(UUIDTypeAdapter.fromUUID(profile.getId())).toString()); url = HttpAuthenticationService.concatenateURL(url, new StringBuilder().append("unsigned=").append(!requireSecure).toString()); MinecraftProfilePropertiesResponse response = (MinecraftProfilePropertiesResponse) MAKE_REQUEST.invoke( @@ -148,6 +150,10 @@ public class HumanController extends AbstractEntityController { GameProfile skinProfile = null; Property cached = TEXTURE_CACHE.get(realUUID); if (cached != null) { + if (Messaging.isDebugging()) { + Messaging + .debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId()); + } skinProfile = new GameProfile(UUID.fromString(realUUID), ""); skinProfile.getProperties().put("textures", cached); } else { @@ -168,6 +174,11 @@ public class HumanController extends AbstractEntityController { Property textures = Iterables.getFirst(skinProfile.getProperties().get("textures"), null); if (textures.getValue() == null || textures.getSignature() == null) return; + + if (Messaging.isDebugging()) { + Messaging.debug("Fetched skin texture for UUID " + realUUID + " for NPC " + npc.getName() + + " UUID " + npc.getUniqueId()); + } TEXTURE_CACHE.put(realUUID, new Property("textures", textures.getValue(), textures.getSignature())); } Bukkit.getScheduler().callSyncMethod(CitizensAPI.getPlugin(), new Callable() { @@ -188,6 +199,12 @@ public class HumanController extends AbstractEntityController { private final BlockingDeque tasks = new LinkedBlockingDeque(); public void addRunnable(Runnable r) { + Iterator itr = tasks.iterator(); + while (itr.hasNext()) { + if (((SkinFetcher) itr.next()).npc.getUniqueId().equals(((SkinFetcher) r).npc.getUniqueId())) { + itr.remove(); + } + } tasks.offer(r); } @@ -233,18 +250,22 @@ public class HumanController extends AbstractEntityController { .getGameProfileRepository(); repo.findProfilesByNames(new String[] { ChatColor.stripColor(reportedUUID) }, Agent.MINECRAFT, new ProfileLookupCallback() { - @Override - public void onProfileLookupFailed(GameProfile arg0, Exception arg1) { - throw new RuntimeException(arg1); - } + @Override + public void onProfileLookupFailed(GameProfile arg0, Exception arg1) { + throw new RuntimeException(arg1); + } - @Override - public void onProfileLookupSucceeded(final GameProfile profile) { - UUID_CACHE.put(reportedUUID, profile.getId().toString()); - npc.data().setPersistent(CACHED_SKIN_UUID_METADATA, profile.getId().toString()); - npc.data().setPersistent(CACHED_SKIN_UUID_NAME_METADATA, profile.getName()); - } - }); + @Override + public void onProfileLookupSucceeded(final GameProfile profile) { + UUID_CACHE.put(reportedUUID, profile.getId().toString()); + if (Messaging.isDebugging()) { + Messaging.debug("Fetched UUID " + profile.getId() + " for NPC " + npc.getName() + + " UUID " + npc.getUniqueId()); + } + npc.data().setPersistent(CACHED_SKIN_UUID_METADATA, profile.getId().toString()); + npc.data().setPersistent(CACHED_SKIN_UUID_NAME_METADATA, profile.getName()); + } + }); return npc.data().get(CACHED_SKIN_UUID_METADATA, reportedUUID); } }