Skip to content

Commit

Permalink
Remove usage of deprecated methods + minor reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
NotStirred committed Jan 13, 2023
1 parent 94663ef commit 6b7a103
Showing 1 changed file with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public VanillaWorldState(World world, WorldLock worldLock) throws FileNotFoundEx
public CompletableFuture<Optional<IOException>> deleteChunks(Executor taskExecutor, Collection<ChunkPosition> chunks) {
Map<VanillaRegionPos, List<ChunkPosition>> 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);
Expand Down Expand Up @@ -116,31 +116,31 @@ private CompletableFuture<Optional<IOException>> 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<Optional<IOException>> 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<VanillaRegionPos> writtenRegions = new ArrayList<>();

Expand All @@ -164,10 +164,9 @@ public CompletableFuture<Optional<IOException>> 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;
}

Expand Down

0 comments on commit 6b7a103

Please # to comment.