Skip to content

Commit 9438da4

Browse files
committed
Only download the the textures once and cache them.
1 parent bb6e26a commit 9438da4

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>de.lemaik.chunkymap</groupId>
88
<artifactId>ChunkyMap</artifactId>
9-
<version>2.4.1</version>
9+
<version>2.4.2</version>
1010

1111
<licenses>
1212
<license>

src/main/java/de/lemaik/chunkymap/dynmap/ChunkyMap.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* A map that uses the RenderService for rendering the tiles.
3232
*/
3333
public class ChunkyMap extends HDMap {
34-
private static final String DEFAULT_TEXTUREPACK_VERSION = "1.16.1";
34+
private static final String DEFAULT_TEXTUREPACK_VERSION = "1.16.2";
3535
public final DynmapCameraAdapter cameraAdapter;
3636
private final Renderer renderer;
3737
private File defaultTexturepackPath;
@@ -52,17 +52,19 @@ public ChunkyMap(DynmapCore dynmap, ConfigurationNode config) {
5252
chunkPadding = config.getInteger("chunkPadding", 0);
5353

5454
String texturepackVersion = config.getString("texturepackVersion", DEFAULT_TEXTUREPACK_VERSION);
55-
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
56-
.info("Downloading additional textures for Minecraft " + texturepackVersion);
57-
try (Response response = MinecraftDownloader.downloadMinecraft(texturepackVersion).get()) {
58-
File tempFile = File.createTempFile("minecraft", ".jar");
59-
try (BufferedSink sink = Okio.buffer(Okio.sink(tempFile))) {
60-
sink.writeAll(response.body().source());
61-
}
62-
defaultTexturepackPath = tempFile;
63-
} catch (IOException | ExecutionException | InterruptedException e) {
64-
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
65-
.log(Level.SEVERE, "Downloading the textures failed, your Chunky dynmap might look bad!", e);
55+
File texturepackPath = new File(ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getDataFolder(), texturepackVersion + ".jar");
56+
if (!texturepackPath.exists()) {
57+
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
58+
.info("Downloading additional textures for Minecraft " + texturepackVersion);
59+
try (Response response = MinecraftDownloader.downloadMinecraft(texturepackVersion).get()) {
60+
try (BufferedSink sink = Okio.buffer(Okio.sink(texturepackPath))) {
61+
sink.writeAll(response.body().source());
62+
}
63+
defaultTexturepackPath = texturepackPath;
64+
} catch (IOException | ExecutionException | InterruptedException e) {
65+
ChunkyMapPlugin.getPlugin(ChunkyMapPlugin.class).getLogger()
66+
.log(Level.SEVERE, "Downloading the textures failed, your Chunky dynmap might look bad!", e);
67+
}
6668
}
6769

6870
if (config.containsKey("texturepack")) {

0 commit comments

Comments
 (0)