Add some settings to control NPC skin retries

This commit is contained in:
fullwall 2014-12-17 19:48:47 +08:00
parent fc8d7e104d
commit 954a3bd27b
2 changed files with 26 additions and 18 deletions

View File

@ -91,12 +91,14 @@ public class Settings {
KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false), KEEP_CHUNKS_LOADED("npc.chunks.always-keep-loaded", false),
LOCALE("general.translation.locale", ""), LOCALE("general.translation.locale", ""),
MAX_NPC_LIMIT_CHECKS("npc.limits.max-permission-checks", 100), MAX_NPC_LIMIT_CHECKS("npc.limits.max-permission-checks", 100),
MAX_NPC_SKIN_RETRIES("npc.skins.max-retries", -1),
MAX_SPEED("npc.limits.max-speed", 100), MAX_SPEED("npc.limits.max-speed", 100),
MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500), MAX_TEXT_RANGE("npc.chat.options.max-text-range", 500),
MESSAGE_COLOUR("general.color-scheme.message", "<a>"), MESSAGE_COLOUR("general.color-scheme.message", "<a>"),
NEW_PATHFINDER_OPENS_DOORS("npc.pathfinding.new-finder-open-doors", false), NEW_PATHFINDER_OPENS_DOORS("npc.pathfinding.new-finder-open-doors", false),
NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75), NPC_ATTACK_DISTANCE("npc.pathfinding.attack-range", 1.75 * 1.75),
NPC_COST("economy.npc.cost", 100D), NPC_COST("economy.npc.cost", 100D),
NPC_SKIN_RETRY_DELAY("npc.skins.retry-delay", 120),
PACKET_UPDATE_DELAY("npc.packets.update-delay", 30), PACKET_UPDATE_DELAY("npc.packets.update-delay", 30),
QUICK_SELECT("npc.selection.quick-select", false), QUICK_SELECT("npc.selection.quick-select", false),
REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true), REMOVE_PLAYERS_FROM_PLAYER_LIST("npc.player.remove-from-list", true),

View File

@ -173,7 +173,7 @@ public class HumanController extends AbstractEntityController {
if (cached != null) { if (cached != null) {
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging Messaging
.debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId()); .debug("Using cached skin texture for NPC " + npc.getName() + " UUID " + npc.getUniqueId());
} }
skinProfile = new GameProfile(UUID.fromString(realUUID), ""); skinProfile = new GameProfile(UUID.fromString(realUUID), "");
skinProfile.getProperties().put("textures", cached); skinProfile.getProperties().put("textures", cached);
@ -185,7 +185,7 @@ public class HumanController extends AbstractEntityController {
} catch (Exception e) { } catch (Exception e) {
if ((e.getMessage() != null && e.getMessage().contains("too many requests")) if ((e.getMessage() != null && e.getMessage().contains("too many requests"))
|| (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage() || (e.getCause() != null && e.getCause().getMessage() != null && e.getCause().getMessage()
.contains("too many requests"))) { .contains("too many requests"))) {
SKIN_THREAD.delay(); SKIN_THREAD.delay();
SKIN_THREAD.addRunnable(this); SKIN_THREAD.addRunnable(this);
} }
@ -219,6 +219,7 @@ public class HumanController extends AbstractEntityController {
public static class SkinThread implements Runnable { public static class SkinThread implements Runnable {
private volatile int delay = 0; private volatile int delay = 0;
private volatile int retryTimes = 0;
private final BlockingDeque<Runnable> tasks = new LinkedBlockingDeque<Runnable>(); private final BlockingDeque<Runnable> tasks = new LinkedBlockingDeque<Runnable>();
public void addRunnable(Runnable r) { public void addRunnable(Runnable r) {
@ -232,13 +233,18 @@ public class HumanController extends AbstractEntityController {
} }
public void delay() { public void delay() {
delay = 120; // need to wait a minute before Mojang accepts API delay = Setting.NPC_SKIN_RETRY_DELAY.asInt();
// calls again // need to wait before Mojang accepts API calls again
retryTimes++;
if (Setting.MAX_NPC_SKIN_RETRIES.asInt() >= 0 && retryTimes > Setting.MAX_NPC_SKIN_RETRIES.asInt()) {
tasks.clear();
retryTimes = 0;
}
} }
@Override @Override
public void run() { public void run() {
if (delay != 0) { if (delay > 0) {
delay--; delay--;
return; return;
} }
@ -275,21 +281,21 @@ public class HumanController extends AbstractEntityController {
.getGameProfileRepository(); .getGameProfileRepository();
repo.findProfilesByNames(new String[] { ChatColor.stripColor(reportedUUID) }, Agent.MINECRAFT, repo.findProfilesByNames(new String[] { ChatColor.stripColor(reportedUUID) }, Agent.MINECRAFT,
new ProfileLookupCallback() { new ProfileLookupCallback() {
@Override @Override
public void onProfileLookupFailed(GameProfile arg0, Exception arg1) { public void onProfileLookupFailed(GameProfile arg0, Exception arg1) {
} }
@Override @Override
public void onProfileLookupSucceeded(final GameProfile profile) { public void onProfileLookupSucceeded(final GameProfile profile) {
UUID_CACHE.put(reportedUUID, profile.getId().toString()); UUID_CACHE.put(reportedUUID, profile.getId().toString());
if (Messaging.isDebugging()) { if (Messaging.isDebugging()) {
Messaging.debug("Fetched UUID " + profile.getId() + " for NPC " + npc.getName() Messaging.debug("Fetched UUID " + profile.getId() + " for NPC " + npc.getName()
+ " UUID " + npc.getUniqueId()); + " UUID " + npc.getUniqueId());
} }
npc.data().setPersistent(CACHED_SKIN_UUID_METADATA, profile.getId().toString()); npc.data().setPersistent(CACHED_SKIN_UUID_METADATA, profile.getId().toString());
npc.data().setPersistent(CACHED_SKIN_UUID_NAME_METADATA, profile.getName()); npc.data().setPersistent(CACHED_SKIN_UUID_NAME_METADATA, profile.getName());
} }
}); });
return npc.data().get(CACHED_SKIN_UUID_METADATA, reportedUUID); return npc.data().get(CACHED_SKIN_UUID_METADATA, reportedUUID);
} }
} }