Wrap loadTexture in a executor.

Fixes #18
This commit is contained in:
Matthew Messinger 2016-11-10 17:34:59 -05:00
parent ab982a4125
commit 1fb6426bea

View file

@ -8,6 +8,8 @@ import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import javax.annotation.Nullable;
@ -61,10 +63,11 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
private List<ISkinModifier> skinModifiers = Lists.newArrayList();
private SkinResourceManager resources = new SkinResourceManager();
private ExecutorService executor = Executors.newCachedThreadPool();
public HDSkinManager() {}
public Optional<ResourceLocation> getSkinLocation(GameProfile profile1, Type type, boolean loadIfAbsent) {
public Optional<ResourceLocation> getSkinLocation(GameProfile profile1, final Type type, boolean loadIfAbsent) {
if (!enabled)
return Optional.absent();
@ -101,6 +104,9 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
if (skin == null) {
if (loadIfAbsent) {
skinCache.get(profile.getId()).put(type, LOADING);
executor.submit(new Runnable() {
@Override
public void run() {
loadTexture(profile, type, new SkinAvailableCallback() {
@Override
public void skinAvailable(Type type, ResourceLocation location, MinecraftProfileTexture profileTexture) {
@ -108,6 +114,8 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
}
});
}
});
}
return Optional.absent();
}