diff --git a/src/main/java/com/minelittlepony/pony/data/Pony.java b/src/main/java/com/minelittlepony/pony/data/Pony.java index dfdc82d3..566aa505 100644 --- a/src/main/java/com/minelittlepony/pony/data/Pony.java +++ b/src/main/java/com/minelittlepony/pony/data/Pony.java @@ -42,11 +42,22 @@ public class Pony implements IPony { private final ResourceLocation texture; private final IPonyData metadata; + private long expirationPeriod; + public Pony(ResourceLocation resource) { texture = resource; metadata = checkSkin(texture); } + boolean hasExpired() { + return expirationPeriod <= System.currentTimeMillis(); + } + + Pony touch() { + expirationPeriod = System.currentTimeMillis() + 30000; + return this; + } + private IPonyData checkSkin(ResourceLocation resource) { IPonyData data = checkPonyMeta(resource); if (data != null) { diff --git a/src/main/java/com/minelittlepony/pony/data/PonyManager.java b/src/main/java/com/minelittlepony/pony/data/PonyManager.java index 50002867..ba638abf 100644 --- a/src/main/java/com/minelittlepony/pony/data/PonyManager.java +++ b/src/main/java/com/minelittlepony/pony/data/PonyManager.java @@ -49,7 +49,7 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl private PonyConfig config; - private Map poniesCache = Maps.newHashMap(); + private final Map poniesCache = Maps.newHashMap(); public PonyManager(PonyConfig config) { this.config = config; @@ -61,7 +61,11 @@ public class PonyManager implements IResourceManagerReloadListener, ISkinCacheCl * @param resource A texture resource */ public IPony getPony(ResourceLocation resource) { - return poniesCache.computeIfAbsent(resource, Pony::new); + IPony result = poniesCache.computeIfAbsent(resource, Pony::new).touch(); + + poniesCache.entrySet().removeIf(entry -> entry.getValue().hasExpired()); + + return result; } /**