Changed CachedChunk return type and used #thenAccept.

This commit is contained in:
Fernando Pettinelli 2020-10-31 17:16:31 -03:00 committed by Brianna
parent 12a9f02348
commit f481a2d5cd
2 changed files with 29 additions and 26 deletions

View File

@ -57,7 +57,8 @@ public class BiomeManager {
AtomicInteger progress = new AtomicInteger();
ChunkLoader.startChunkLoadingPerChunk(island, world, plugin.isPaperAsync(), (cachedChunk) -> {
Chunk chunk = cachedChunk.getChunk();
// I don't like this. But CompletableFuture#join causes a crash on some setups.
cachedChunk.getChunk().thenAccept(chunk -> {
try {
if (chunk != null)
biome.setBiome(chunk);
@ -81,6 +82,7 @@ public class BiomeManager {
plugin.getMessageManager().sendMessage(player, message);
}
}
});
}, (island1 -> {
removeUpdatingIsland(island1);
if(task != null) {

View File

@ -7,6 +7,7 @@ import org.bukkit.ChunkSnapshot;
import org.bukkit.World;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
public class CachedChunk {
@ -41,11 +42,11 @@ public class CachedChunk {
return this.z;
}
public Chunk getChunk() {
public CompletableFuture<Chunk> getChunk() {
World world = Bukkit.getWorld(this.world);
if (world == null)
return null;
return PaperLib.getChunkAtAsync(world, this.x, this.z).join();
return PaperLib.getChunkAtAsync(world, this.x, this.z);
}
public ChunkSnapshot getSnapshot() {
@ -55,7 +56,7 @@ public class CachedChunk {
}
public ChunkSnapshot takeSnapshot() {
return this.latestSnapshot = getChunk().getChunkSnapshot();
return this.latestSnapshot = getChunk().join().getChunkSnapshot();
}
@Override