Skip to content

Commit

Permalink
Only download the the textures once and cache them.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Aug 30, 2020
1 parent bb6e26a commit 9438da4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>de.lemaik.chunkymap</groupId>
<artifactId>ChunkyMap</artifactId>
<version>2.4.1</version>
<version>2.4.2</version>

<licenses>
<license>
Expand Down
26 changes: 14 additions & 12 deletions src/main/java/de/lemaik/chunkymap/dynmap/ChunkyMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* A map that uses the RenderService for rendering the tiles.
*/
public class ChunkyMap extends HDMap {
private static final String DEFAULT_TEXTUREPACK_VERSION = "1.16.1";
private static final String DEFAULT_TEXTUREPACK_VERSION = "1.16.2";
public final DynmapCameraAdapter cameraAdapter;
private final Renderer renderer;
private File defaultTexturepackPath;
Expand All @@ -52,17 +52,19 @@ public ChunkyMap(DynmapCore dynmap, ConfigurationNode config) {
chunkPadding = config.getInteger("chunkPadding", 0);

String texturepackVersion = config.getString("texturepackVersion", DEFAULT_TEXTUREPACK_VERSION);
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
.info("Downloading additional textures for Minecraft " + texturepackVersion);
try (Response response = MinecraftDownloader.downloadMinecraft(texturepackVersion).get()) {
File tempFile = File.createTempFile("minecraft", ".jar");
try (BufferedSink sink = Okio.buffer(Okio.sink(tempFile))) {
sink.writeAll(response.body().source());
}
defaultTexturepackPath = tempFile;
} catch (IOException | ExecutionException | InterruptedException e) {
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
.log(Level.SEVERE, "Downloading the textures failed, your Chunky dynmap might look bad!", e);
File texturepackPath = new File(ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getDataFolder(), texturepackVersion + ".jar");
if (!texturepackPath.exists()) {
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
.info("Downloading additional textures for Minecraft " + texturepackVersion);
try (Response response = MinecraftDownloader.downloadMinecraft(texturepackVersion).get()) {
try (BufferedSink sink = Okio.buffer(Okio.sink(texturepackPath))) {
sink.writeAll(response.body().source());
}
defaultTexturepackPath = texturepackPath;
} catch (IOException | ExecutionException | InterruptedException e) {
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
.log(Level.SEVERE, "Downloading the textures failed, your Chunky dynmap might look bad!", e);
}
}

if (config.containsKey("texturepack")) {
Expand Down

0 comments on commit 9438da4

Please sign in to comment.