From 6b7a1032bb7f62231367f785795425c7f747db86 Mon Sep 17 00:00:00 2001 From: Tom Martin Date: Fri, 13 Jan 2023 23:04:14 +0000 Subject: [PATCH] Remove usage of deprecated methods + minor reformat --- .../state/vanilla/VanillaWorldState.java | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/github/notstirred/chunkyeditor/state/vanilla/VanillaWorldState.java b/src/main/java/io/github/notstirred/chunkyeditor/state/vanilla/VanillaWorldState.java index d03860d..224991f 100644 --- a/src/main/java/io/github/notstirred/chunkyeditor/state/vanilla/VanillaWorldState.java +++ b/src/main/java/io/github/notstirred/chunkyeditor/state/vanilla/VanillaWorldState.java @@ -40,7 +40,7 @@ public VanillaWorldState(World world, WorldLock worldLock) throws FileNotFoundEx public CompletableFuture> deleteChunks(Executor taskExecutor, Collection chunks) { Map> regionSelection = new HashMap<>(); for (ChunkPosition chunkPosition : chunks) { - ChunkPosition asRegionPos = chunkPosition.regionPosition(); + ChunkPosition asRegionPos = chunkPosition.getRegionPosition(); regionSelection.computeIfAbsent(new VanillaRegionPos(asRegionPos.x, asRegionPos.z), pos -> new ArrayList<>()) .add(chunkPosition); @@ -116,31 +116,31 @@ private CompletableFuture> deleteChunks(Executor taskExecu return Optional.ofNullable(suppressed); }, taskExecutor); - deletionFuture.whenCompleteAsync((optionalException, throwable) -> { - regionSelection.forEach((regionPos, chunkPositions) -> { - Region region = world.getRegion(new ChunkPosition(regionPos.x, regionPos.z)); - for (ChunkPosition chunkPos : chunkPositions) { - Chunk chunk = world.getChunk(chunkPos); - if (!chunk.isEmpty()) { - chunk.reset(); - Accessor.invoke_MCRegion$setChunk((MCRegion) region, chunkPos, EmptyChunk.INSTANCE); - world.chunkUpdated(chunkPos); - world.chunkDeleted(chunkPos); + deletionFuture.whenCompleteAsync((optionalException, throwable) -> + regionSelection.forEach((regionPos, chunkPositions) -> { + Region region = world.getRegion(new ChunkPosition(regionPos.x, regionPos.z)); + for (ChunkPosition chunkPos : chunkPositions) { + Chunk chunk = world.getChunk(chunkPos); + if (!chunk.isEmpty()) { + chunk.reset(); + Accessor.invoke_MCRegion$setChunk((MCRegion) region, chunkPos, EmptyChunk.INSTANCE); + world.chunkUpdated(chunkPos); + world.chunkDeleted(chunkPos); + } } - } - }); - }, Platform::runLater); + }), Platform::runLater + ); return deletionFuture; } public CompletableFuture> undo(Executor taskExecutor) { if(!this.stateTracker.hasPreviousState()) { - return CompletableFuture.completedFuture(null); + return CompletableFuture.completedFuture(Optional.empty()); } if (!worldLock.tryLock()) - return CompletableFuture.completedFuture(null); + return CompletableFuture.completedFuture(Optional.empty()); List writtenRegions = new ArrayList<>(); @@ -164,10 +164,9 @@ public CompletableFuture> undo(Executor taskExecutor) { return Optional.ofNullable(suppressed); }, taskExecutor); - undoFuture.whenCompleteAsync((v, throwable) -> { - writtenRegions.forEach(regionPos -> - Editor.INSTANCE.mapLoader().regionUpdated(new ChunkPosition(regionPos.x, regionPos.z))); - }, Platform::runLater); + undoFuture.whenCompleteAsync((v, throwable) -> + writtenRegions.forEach(regionPos -> + Editor.INSTANCE.mapLoader().regionUpdated(new ChunkPosition(regionPos.x, regionPos.z))), Platform::runLater); return undoFuture; }