Skip to content
Permalink
Browse files

Better save docs and support any clipboard format

  • Loading branch information...
me4502 committed Aug 6, 2019
1 parent 3734e6e commit 9d287ecd1a70c28009c1a72f5c0abdfe165841cb
@@ -22,7 +22,7 @@
public interface CLIWorld {

/**
* Saves this world back to file.
* Saves this world back to file if dirty or forced.
*
* @param force Force a save
*/
@@ -28,8 +28,8 @@
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardReader;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.biome.BiomeType;
@@ -278,26 +278,28 @@ public static void main(String[] args) {
}
if (file.getName().endsWith("level.dat")) {
throw new IllegalArgumentException("level.dat file support is unfinished.");
} else if (file.getName().endsWith(".schem")) {
ClipboardFormat format = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
ClipboardReader dataVersionReader = format
.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ));
int dataVersion = dataVersionReader.getDataVersion()
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
dataVersionReader.close();
app.platform.setDataVersion(dataVersion);
app.onStarted();
try (ClipboardReader clipboardReader = format.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ))) {
ClipboardWorld world = new ClipboardWorld(
file,
clipboardReader.read(),
file.getName()
);
app.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
}
} else {
throw new IllegalArgumentException("Unknown file provided!");
ClipboardFormat format = ClipboardFormats.findByFile(file);
if (format != null) {
ClipboardReader dataVersionReader = format
.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ));
int dataVersion = dataVersionReader.getDataVersion()
.orElseThrow(() -> new IllegalArgumentException("Failed to obtain data version from schematic."));
dataVersionReader.close();
app.platform.setDataVersion(dataVersion);
app.onStarted();
try (ClipboardReader clipboardReader = format.getReader(Files.newInputStream(file.toPath(), StandardOpenOption.READ))) {
ClipboardWorld world = new ClipboardWorld(
file,
clipboardReader.read(),
file.getName()
);
app.platform.addWorld(world);
WorldEdit.getInstance().getSessionManager().get(app.commandSender).setWorldOverride(world);
}
} else {
throw new IllegalArgumentException("Unknown file provided!");
}
}

String scriptFile = cmd.getOptionValue('s');
@@ -27,7 +27,7 @@
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
@@ -196,7 +196,7 @@ public BlockVector3 getMinimumPoint() {
@Override
public void save(boolean force) {
if (dirty || force) {
try (ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
try (ClipboardWriter writer = ClipboardFormats.findByFile(file).getWriter(new FileOutputStream(file))) {
writer.write(this);
dirty = false;
} catch (IOException e) {

0 comments on commit 9d287ec

Please sign in to comment.
You can’t perform that action at this time.