mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-13 05:53:57 +01:00
Changed CachedChunk return type and used #thenAccept.
This commit is contained in:
parent
12a9f02348
commit
f481a2d5cd
@ -57,30 +57,32 @@ public class BiomeManager {
|
||||
AtomicInteger progress = new AtomicInteger();
|
||||
|
||||
ChunkLoader.startChunkLoadingPerChunk(island, world, plugin.isPaperAsync(), (cachedChunk) -> {
|
||||
Chunk chunk = cachedChunk.getChunk();
|
||||
try {
|
||||
if (chunk != null)
|
||||
biome.setBiome(chunk);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
progress.getAndIncrement();
|
||||
|
||||
if(language.getBoolean("Command.Island.Biome.Progress.Should-Display-Message") &&
|
||||
progress.get() == 1 || progress.get() == chunkAmount || progress.get() % runEveryX == 0){
|
||||
final double percent = ((double) progress.get() / (double) chunkAmount) * 100;
|
||||
|
||||
String message = language.getString("Command.Island.Biome.Progress.Message");
|
||||
message = message.replace("%current_updated_chunks%", String.valueOf(progress.get()));
|
||||
message = message.replace("%max_chunks%", String.valueOf(chunkAmount));
|
||||
message = message.replace("%percent_whole%", String.valueOf((int) percent));
|
||||
message = message.replace("%percent%", NumberFormat.getInstance().format(percent));
|
||||
|
||||
for (Player player : SkyBlock.getInstance().getIslandManager().getPlayersAtIsland(island)) {
|
||||
plugin.getMessageManager().sendMessage(player, message);
|
||||
// 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);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
progress.getAndIncrement();
|
||||
|
||||
if (language.getBoolean("Command.Island.Biome.Progress.Should-Display-Message") &&
|
||||
progress.get() == 1 || progress.get() == chunkAmount || progress.get() % runEveryX == 0) {
|
||||
final double percent = ((double) progress.get() / (double) chunkAmount) * 100;
|
||||
|
||||
String message = language.getString("Command.Island.Biome.Progress.Message");
|
||||
message = message.replace("%current_updated_chunks%", String.valueOf(progress.get()));
|
||||
message = message.replace("%max_chunks%", String.valueOf(chunkAmount));
|
||||
message = message.replace("%percent_whole%", String.valueOf((int) percent));
|
||||
message = message.replace("%percent%", NumberFormat.getInstance().format(percent));
|
||||
|
||||
for (Player player : SkyBlock.getInstance().getIslandManager().getPlayersAtIsland(island)) {
|
||||
plugin.getMessageManager().sendMessage(player, message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}, (island1 -> {
|
||||
removeUpdatingIsland(island1);
|
||||
if(task != null) {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user