Clear code - set worlds once on construction.

This commit is contained in:
tastybento 2021-09-08 19:50:23 -07:00
parent 23e3554c4d
commit 3650863fa1

View File

@ -7,7 +7,6 @@ import java.util.concurrent.CompletableFuture;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
@ -37,18 +36,34 @@ public class DeleteIslandChunks {
private boolean inDelete; private boolean inDelete;
private final BentoBox plugin; private final BentoBox plugin;
private NMSAbstraction nms; private NMSAbstraction nms;
private final World netherWorld;
private final World endWorld;
public DeleteIslandChunks(BentoBox plugin, IslandDeletion di) { public DeleteIslandChunks(BentoBox plugin, IslandDeletion di) {
this.plugin = plugin; this.plugin = plugin;
this.chunkX = di.getMinXChunk(); this.chunkX = di.getMinXChunk();
this.chunkZ = di.getMinZChunk(); this.chunkZ = di.getMinZChunk();
this.di = di; this.di = di;
// Nether
if (plugin.getIWM().isNetherGenerate(di.getWorld()) && plugin.getIWM().isNetherIslands(di.getWorld())) {
netherWorld = plugin.getIWM().getNetherWorld(di.getWorld());
} else {
netherWorld = null;
}
// End
if (plugin.getIWM().isEndGenerate(di.getWorld()) && plugin.getIWM().isEndIslands(di.getWorld())) {
endWorld = plugin.getIWM().getEndWorld(di.getWorld());
} else {
endWorld = null;
}
// NMS
try { try {
this.nms = Util.getNMS(); this.nms = Util.getNMS();
} catch (Exception e) { } catch (Exception e) {
plugin.logError("Could not delete chunks because of NMS error"); plugin.logError("Could not delete chunks because of NMS error");
return; return;
} }
// Fire event // Fire event
IslandEvent.builder().deletedIslandInfo(di).reason(Reason.DELETE_CHUNKS).build(); IslandEvent.builder().deletedIslandInfo(di).reason(Reason.DELETE_CHUNKS).build();
regenerateChunks(); regenerateChunks();
@ -64,11 +79,11 @@ public class DeleteIslandChunks {
boolean last = i == plugin.getSettings().getDeleteSpeed() -1; boolean last = i == plugin.getSettings().getDeleteSpeed() -1;
plugin.getIWM().getAddon(di.getWorld()).ifPresent(gm -> plugin.getIWM().getAddon(di.getWorld()).ifPresent(gm ->
// Overworld // Overworld
processChunk(gm, Environment.NORMAL, chunkX, chunkZ).thenRun(() -> processChunk(gm, di.getWorld(), chunkX, chunkZ).thenRun(() ->
// Nether // Nether
processChunk(gm, Environment.NETHER, chunkX, chunkZ).thenRun(() -> processChunk(gm, netherWorld, chunkX, chunkZ).thenRun(() ->
// End // End
processChunk(gm, Environment.THE_END, chunkX, chunkZ).thenRun(() -> finish(last))))); processChunk(gm, endWorld, chunkX, chunkZ).thenRun(() -> finish(last)))));
chunkZ++; chunkZ++;
if (chunkZ > di.getMaxZChunk()) { if (chunkZ > di.getMaxZChunk()) {
chunkZ = di.getMinZChunk(); chunkZ = di.getMinZChunk();
@ -91,29 +106,8 @@ public class DeleteIslandChunks {
} }
} }
private CompletableFuture<Boolean> processChunk(GameModeAddon gm, Environment env, int x, int z) { private CompletableFuture<Boolean> processChunk(GameModeAddon gm, World world, int x, int z) {
World world = di.getWorld(); if (world != null && PaperLib.isChunkGenerated(world, x, z)) {
switch (env) {
case NETHER:
// Nether
if (plugin.getIWM().isNetherGenerate(di.getWorld()) && plugin.getIWM().isNetherIslands(di.getWorld())) {
world = plugin.getIWM().getNetherWorld(di.getWorld());
} else {
return CompletableFuture.completedFuture(false);
}
break;
case THE_END:
// End
if (plugin.getIWM().isEndGenerate(di.getWorld()) && plugin.getIWM().isEndIslands(di.getWorld())) {
world = plugin.getIWM().getEndWorld(di.getWorld());
} else {
return CompletableFuture.completedFuture(false);
}
break;
default:
break;
}
if (PaperLib.isChunkGenerated(world, x, z)) {
CompletableFuture<Boolean> r = new CompletableFuture<>(); CompletableFuture<Boolean> r = new CompletableFuture<>();
PaperLib.getChunkAtAsync(world, x, z).thenAccept(chunk -> regenerateChunk(r, gm, chunk)); PaperLib.getChunkAtAsync(world, x, z).thenAccept(chunk -> regenerateChunk(r, gm, chunk));
return r; return r;