Skip to content

Commit

Permalink
More bugfixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
itsMatoosh committed Dec 22, 2021
1 parent e6456f8 commit 85eca5e
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/java/me/matoosh/blockmetadata/BlockMetadataStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -447,13 +444,19 @@ private CompletableFuture<Map<String, Map<String, T>>> loadRegion(
* @return
*/
public CompletableFuture<Void> saveAllLoadedRegions() {
CompletableFuture<Void>[] saves = new CompletableFuture[regions.size()];
// copy region references
List<Region> toSave = new ArrayList<>(regions.size());
toSave.addAll(regions.values());

// save all
CompletableFuture<Void>[] futures = new CompletableFuture[toSave.size()];
int i = 0;
for (Region region : regions.values()) {
saves[i] = saveRegion(region);
i++;
for (Region r : toSave) {
futures[i++] = saveRegion(r);
}
return CompletableFuture.allOf(saves);

// wait for all to save
return CompletableFuture.allOf(futures);
}

/**
Expand Down

0 comments on commit 85eca5e

Please sign in to comment.