| 32 | import java.util.concurrent.*; |
| 33 | |
| 34 | public class ResourceManager implements IResourceManager { |
| 35 | |
| 36 | private static final int PLAYER_RESOURCE_VERSION = 2; |
| 37 | |
| 38 | private static final ExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("5zig Texture Downloader #%d").setDaemon(true) |
| 39 | .build()); |
| 40 | private static final String BASE_URL = "http://textures.5zig.net/"; |
| 41 | private static final Gson gson = new Gson(); |
| 42 | |
| 43 | private final Object guiCameraTransform; |
| 44 | private final FaceBakery faceBakery = new FaceBakery(); |
| 45 | |
| 46 | private final GameProfile playerProfile; |
| 47 | private PlayerResource ownPlayerResource; |
| 48 | private final Cache<UUID, PlayerResource> playerResources = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.MINUTES).build(); |
| 49 | private final Cache<Integer, String> moduleIds = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.MINUTES).build(); |
| 50 | |
| 51 | public ResourceManager(GameProfile playerProfile) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException { |
| 52 | guiCameraTransform = Thread.currentThread().getContextClassLoader().loadClass(bpl.class.getName() + (Transformer.FORGE ? "$TransformType" : "$b")).getDeclaredField( |
| 53 | Transformer.FORGE ? "GUI" : "g").get(null); |
| 54 | this.playerProfile = playerProfile; |
| 55 | } |
| 56 | |
| 57 | public void loadPlayerTextures(final GameProfile gameProfile) { |
| 58 | if (gameProfile == null || gameProfile.getId() == null) { |
| 59 | return; |
| 60 | } |
| 61 | PlayerResource playerResource; |
| 62 | if (playerProfile.getName().equals(gameProfile.getName())) { |
| 63 | if (ownPlayerResource != null) { |
| 64 | playerResource = ownPlayerResource; |
| 65 | } else { |
| 66 | playerResource = ownPlayerResource = loadPlayerResource(playerProfile); |
| 67 | } |
| 68 | } else { |
| 69 | playerResource = playerResources.getIfPresent(gameProfile.getId()); |
| 70 | if (playerResource != null) { |
| 71 | MinecraftFactory.getClassProxyCallback().getLogger().debug("Loaded player resource textures from cache for player " + gameProfile.getName()); |
| 72 | } else { |
| 73 | playerResources.put(gameProfile.getId(), loadPlayerResource(gameProfile)); |
| 74 | } |
| 75 | } |
| 76 | if (playerResource == null) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (playerResource.getItemModelResources() != null) { |
| 81 | for (ItemModelResource itemModelResource : playerResource.getItemModelResources()) { |
| 82 | ResourceLocation resourceLocation = (ResourceLocation) itemModelResource.getResourceLocation(); |
| 83 | if (((Variables) MinecraftFactory.getVars()).getTextureManager().b(resourceLocation) == null) { |
| 84 | ((Variables) MinecraftFactory.getVars()).getTextureManager().a(resourceLocation, (SimpleTexture) itemModelResource.getSimpleTexture()); |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private PlayerResource loadPlayerResource(final GameProfile gameProfile) { |
| 91 | final MinecraftProfileTexture minecraftProfileTexture = new MinecraftProfileTexture( |
nothing calls this directly
no outgoing calls
no test coverage detected