Re-add delchunks command (#481)

The new command now writes a json file to WorldEdit's working directory with instructions on which chunks to delete, which is read by the plugin/mod at startup and calls the ChunkDeleter.
The chunk deleter parses the json and iterates the instructions, backing up .mca files as it goes and overwriting the offset headers with 0 wherever a chunk needs to be deleted.
This allows Minecraft to reclaim the space used for that chunk, as well as forcing it to be generated from scratch next time the area is loaded.
This commit is contained in:
wizjany
2019-06-22 14:20:14 -04:00
committed by GitHub
parent 902754ce8a
commit d763ab374c
14 changed files with 650 additions and 104 deletions

View File

@ -57,6 +57,7 @@ import org.spongepowered.api.world.World;
import org.spongepowered.api.world.weather.Weather;
import java.lang.ref.WeakReference;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -116,6 +117,11 @@ public abstract class SpongeWorld extends AbstractWorld {
return getWorld().getName();
}
@Override
public Path getStoragePath() {
return getWorld().getDirectory();
}
@SuppressWarnings("WeakerAccess")
protected BlockState getBlockState(BlockStateHolder<?> block) {
if (block instanceof com.sk89q.worldedit.world.block.BlockState) {

View File

@ -20,6 +20,7 @@
package com.sk89q.worldedit.sponge;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.internal.anvil.ChunkDeleter.DELCHUNKS_FILE_NAME;
import com.google.inject.Inject;
import com.sk89q.worldedit.LocalSession;
@ -29,6 +30,7 @@ import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.internal.anvil.ChunkDeleter;
import com.sk89q.worldedit.sponge.adapter.AdapterLoadException;
import com.sk89q.worldedit.sponge.adapter.SpongeImplAdapter;
import com.sk89q.worldedit.sponge.adapter.SpongeImplLoader;
@ -62,6 +64,8 @@ import org.spongepowered.api.world.World;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@ -134,6 +138,11 @@ public class SpongeWorldEdit {
WorldEdit.getInstance().getPlatformManager().unregister(platform);
}
final Path delChunks = workingDir.toPath().resolve(DELCHUNKS_FILE_NAME);
if (Files.exists(delChunks)) {
ChunkDeleter.runFromFile(delChunks, true);
}
this.platform = new SpongePlatform(this);
this.provider = new SpongePermissionsProvider();