Skip to content

Commit

Permalink
Run skin fetcher again if denied due to too many requests
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 29, 2014
1 parent e74af01 commit 1b875df
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/main/java/net/citizensnpcs/npc/entity/HumanController.java
Expand Up @@ -90,9 +90,8 @@ private void updateSkin(final NPC npc, final WorldServer nmsWorld, GameProfile p
if (cached != null) {
profile.getProperties().put("textures", cached);
} else {
Bukkit.getScheduler().runTaskLaterAsynchronously(CitizensAPI.getPlugin(),
new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().av(), npc),
(int) Math.ceil(Math.min(1, 40 * Math.random())));
Bukkit.getScheduler().runTaskAsynchronously(CitizensAPI.getPlugin(),
new SkinFetcher(new UUIDFetcher(skinUUID, npc), nmsWorld.getMinecraftServer().av(), npc));
}
}

Expand All @@ -119,6 +118,9 @@ public void run() {
try {
skinProfile = repo.fillProfileProperties(new GameProfile(UUID.fromString(realUUID), ""), true);
} catch (Exception e) {
if (e.getMessage().contains("too many requests")) {
Bukkit.getScheduler().runTaskLater(CitizensAPI.getPlugin(), this, 200);
}
return;
}
if (skinProfile == null || !skinProfile.getProperties().containsKey("textures"))
Expand Down Expand Up @@ -157,18 +159,18 @@ public String call() throws Exception {
.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());
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);
}
}
Expand Down

0 comments on commit 1b875df

Please sign in to comment.