From 56908a7d621646a4a6e239099dd816ba3698718f Mon Sep 17 00:00:00 2001 From: wizjany Date: Thu, 9 May 2019 16:59:06 -0400 Subject: [PATCH] Update to final Sponge schem v2 spec. Read lenient, write strict. --- .../sk89q/worldedit/command/ClipboardCommands.java | 8 +------- .../extent/clipboard/io/SpongeSchematicReader.java | 5 ++++- .../extent/clipboard/io/SpongeSchematicWriter.java | 13 ++++++------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 01d1a1fb9..c63397fb0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -61,12 +61,6 @@ import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) public class ClipboardCommands { - /** - * Create a new instance. - */ - public ClipboardCommands() { - } - @Command( name = "/copy", desc = "Copy the selection to the clipboard" @@ -78,7 +72,7 @@ public class ClipboardCommands { boolean copyEntities, @Switch(name = 'b', desc = "Also copy biomes") boolean copyBiomes, - @ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "") + @ArgFlag(name = 'm', desc = "Set the include mask, non-matching blocks become air", def = "") Mask mask) throws WorldEditException { BlockArrayClipboard clipboard = new BlockArrayClipboard(region); clipboard.setOrigin(session.getPlacementPosition(player)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java index 4d33e82b7..d42d76afd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java @@ -172,7 +172,10 @@ public class SpongeSchematicReader extends NBTSchematicReader { byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); Map> tileEntitiesMap = new HashMap<>(); - ListTag tileEntities = getTag(schematic, "TileEntities", ListTag.class); + ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class); + if (tileEntities == null) { + tileEntities = getTag(schematic, "TileEntities", ListTag.class); + } if (tileEntities != null) { List> tileEntityTags = tileEntities.getValue().stream() .map(tag -> (CompoundTag) tag) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java index f9d9248a6..2ed06cc03 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java @@ -21,7 +21,6 @@ package com.sk89q.worldedit.extent.clipboard.io; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.sk89q.jnbt.ByteArrayTag; import com.sk89q.jnbt.CompoundTag; @@ -52,6 +51,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -85,9 +85,8 @@ public class SpongeSchematicWriter implements ClipboardWriter { * * @param clipboard The clipboard * @return The schematic map - * @throws IOException If an error occurs */ - private Map write2(Clipboard clipboard) throws IOException { + private Map write2(Clipboard clipboard) { Region region = clipboard.getRegion(); BlockVector3 origin = clipboard.getOrigin(); BlockVector3 min = region.getMinimumPoint(); @@ -190,7 +189,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { schematic.put("Palette", new CompoundTag(paletteTag)); schematic.put("BlockData", new ByteArrayTag(buffer.toByteArray())); - schematic.put("TileEntities", new ListTag(CompoundTag.class, tileEntities)); + schematic.put("BlockEntities", new ListTag(CompoundTag.class, tileEntities)); // version 2 stuff if (clipboard.hasBiomes()) { @@ -265,7 +264,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { values.put("Rotation", writeRotation(e.getLocation())); return new CompoundTag(values); - }).filter(e -> e != null).collect(Collectors.toList()); + }).filter(Objects::nonNull).collect(Collectors.toList()); if (entities.isEmpty()) { return; } @@ -273,7 +272,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { } private Tag writeVector(Vector3 vector) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new DoubleTag(vector.getX())); list.add(new DoubleTag(vector.getY())); list.add(new DoubleTag(vector.getZ())); @@ -281,7 +280,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { } private Tag writeRotation(Location location) { - List list = new ArrayList(); + List list = new ArrayList<>(); list.add(new FloatTag(location.getYaw())); list.add(new FloatTag(location.getPitch())); return new ListTag(FloatTag.class, list);