From 1368f86d134eb46fad7bf6293582f5397c04a1d6 Mon Sep 17 00:00:00 2001 From: "Lukas Rieger (Blue)" Date: Mon, 28 Nov 2022 20:38:34 +0100 Subject: [PATCH] Also reset texture-gallery on map-purge --- .../bluemap/common/rendermanager/MapPurgeTask.java | 11 ++++++++--- .../java/de/bluecolored/bluemap/core/map/BmMap.java | 5 +++++ .../bluecolored/bluemap/core/map/TextureGallery.java | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapPurgeTask.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapPurgeTask.java index 03a2a911..7d27c012 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapPurgeTask.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapPurgeTask.java @@ -29,6 +29,7 @@ import de.bluecolored.bluemap.core.storage.Storage; import de.bluecolored.bluemap.core.storage.file.FileStorage; import de.bluecolored.bluemap.core.util.DeletingPathVisitor; +import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.nio.file.Files; @@ -56,7 +57,7 @@ public static MapPurgeTask create(Path mapDirectory) throws IOException { @DebugDump private static class MapFilePurgeTask extends MapPurgeTask { - private final BmMap map; + @Nullable private final BmMap map; private final Path directory; private final int subFilesCount; private final LinkedList subFiles; @@ -72,7 +73,7 @@ public MapFilePurgeTask(BmMap map, FileStorage fileStorage) throws IOException { this(map, fileStorage.getFilePath(map.getId())); } - private MapFilePurgeTask(BmMap map, Path directory) throws IOException { + private MapFilePurgeTask(@Nullable BmMap map, Path directory) throws IOException { this.map = map; this.directory = directory; try (Stream pathStream = Files.walk(directory, 3)) { @@ -92,7 +93,7 @@ public void doWork() throws Exception { try { // save lowres-tile-manager to clear/flush any buffered data - this.map.getLowresTileManager().save(); + if (this.map != null) this.map.getLowresTileManager().save(); // delete subFiles first to be able to track the progress and cancel while (!subFiles.isEmpty()) { @@ -106,6 +107,10 @@ public void doWork() throws Exception { if (Files.exists(directory)) { Files.walkFileTree(directory, DeletingPathVisitor.INSTANCE); } + + // reset texture-gallery + if (this.map != null) this.map.resetTextureGallery(); + } finally { // reset map render state if (this.map != null) { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java index 0a936ada..a1d1f686 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/BmMap.java @@ -181,6 +181,11 @@ private void saveTextureGallery() { } } + public synchronized void resetTextureGallery() { + this.textureGallery.clear(); + this.textureGallery.put(this.resourcePack); + } + private void saveMapSettings() { try ( OutputStream out = storage.writeMeta(id, MetaType.SETTINGS); diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java index 4c7cd583..d0d70bc6 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java @@ -24,6 +24,11 @@ public TextureGallery() { this.nextId = 0; } + public void clear() { + this.ordinalMap.clear(); + this.nextId = 0; + } + public int get(@Nullable ResourcePath textureResourcePath) { if (textureResourcePath == null) textureResourcePath = ResourcePack.MISSING_TEXTURE; Integer ordinal = ordinalMap.get(textureResourcePath);