diff --git a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java index dc915bcf4..37a004268 100644 --- a/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java +++ b/PlotSquared/src/com/intellectualcrafters/jnbt/NBTOutputStream.java @@ -7,12 +7,19 @@ import java.io.OutputStream; import java.util.List; /** + *

* This class writes NBT, or Named Binary Tag - * {@code Tag} objects to an underlying {@code OutputStream}. + * Tag objects to an underlying OutputStream. + *

* - *

The NBT format was created by Markus Persson, and the specification may be + *

+ * The NBT format was created by Markus Persson, and the specification may be * found at - * http://www.minecraft.net/docs/NBT.txt.

+ * http://www.minecraft.net/docs/NBT.txt. + *

+ * + * @author Graham Edgecombe + * */ public final class NBTOutputStream implements Closeable { @@ -22,7 +29,7 @@ public final class NBTOutputStream implements Closeable { private final DataOutputStream os; /** - * Creates a new {@code NBTOutputStream}, which will write data to the + * Creates a new NBTOutputStream, which will write data to the * specified underlying output stream. * * @param os @@ -111,7 +118,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Byte} tag. + * Writes a TAG_Byte tag. * * @param tag * The tag. @@ -123,7 +130,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Byte_Array} tag. + * Writes a TAG_Byte_Array tag. * * @param tag * The tag. @@ -137,7 +144,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Compound} tag. + * Writes a TAG_Compound tag. * * @param tag * The tag. @@ -152,7 +159,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_List} tag. + * Writes a TAG_List tag. * * @param tag * The tag. @@ -166,13 +173,13 @@ public final class NBTOutputStream implements Closeable { os.writeByte(NBTUtils.getTypeCode(clazz)); os.writeInt(size); - for (Tag tag1 : tags) { - writeTagPayload(tag1); + for (int i = 0; i < size; ++i) { + writeTagPayload(tags.get(i)); } } /** - * Writes a {@code TAG_String} tag. + * Writes a TAG_String tag. * * @param tag * The tag. @@ -186,7 +193,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Double} tag. + * Writes a TAG_Double tag. * * @param tag * The tag. @@ -198,7 +205,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Float} tag. + * Writes a TAG_Float tag. * * @param tag * The tag. @@ -210,7 +217,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Long} tag. + * Writes a TAG_Long tag. * * @param tag * The tag. @@ -222,7 +229,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Int} tag. + * Writes a TAG_Int tag. * * @param tag * The tag. @@ -234,7 +241,7 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Short} tag. + * Writes a TAG_Short tag. * * @param tag * The tag. @@ -246,9 +253,12 @@ public final class NBTOutputStream implements Closeable { } /** - * Writes a {@code TAG_Empty} tag. + * Writes a TAG_Empty tag. * - * @param tag the tag + * @param tag + * The tag. + * @throws IOException + * if an I/O error occurs. */ private void writeEndTagPayload(EndTag tag) { /* empty */ @@ -257,14 +267,13 @@ public final class NBTOutputStream implements Closeable { private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { int[] data = tag.getValue(); os.writeInt(data.length); - for (int aData : data) { - os.writeInt(aData); + for (int i = 0; i < data.length; i++) { + os.writeInt(data[i]); } } - @Override public void close() throws IOException { os.close(); } -} +} \ No newline at end of file diff --git a/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java b/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java index 2280d0e8d..dcdee26f5 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/SchematicHandler.java @@ -14,9 +14,11 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; /** * Created by Citymonstret on 2014-09-15. @@ -202,7 +204,7 @@ public class SchematicHandler { try { OutputStream stream = new FileOutputStream(path); - NBTOutputStream output = new NBTOutputStream(stream); + NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream)); output.writeTag(tag); output.close(); stream.close(); @@ -265,20 +267,27 @@ public class SchematicHandler { schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0)); schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0)); + System.out.print("WHL "+width+" | "+height+ " | "+length); + byte[] blocks = new byte[width * height * length]; byte[] addBlocks = null; byte[] blockData = new byte[width * height * length]; + int count = 0; + for (int x = 0; x < width; x++) { for (int z = 0; z < length; z++) { for (int y = 0; y < height; y++) { int index = y * width * length + z * width + x; + count++; + Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, 0 + y, pos1.getBlockZ() + z)); int id2 = block.getTypeId(); if (id2 > 255) { + System.out.print("GREATER "+id2); if (addBlocks == null) { addBlocks = new byte[(blocks.length >> 1) + 1]; } @@ -297,9 +306,14 @@ public class SchematicHandler { } } } + + System.out.print("COUNT "+count); + schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); schematic.put("Data", new ByteArrayTag("Data", blockData)); - + schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList())); + schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, new ArrayList())); + if (addBlocks != null) { schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks)); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java index 981dbb663..335e918ca 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Schematic.java @@ -159,9 +159,8 @@ public class Schematic extends SubCommand { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { @Override public void run() { - counter++; PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); - boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+","+owner+".schematic"); + boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+worldname+", "+owner+".schematic"); if (!result) { PlayerFunctions.sendMessage(plr, "&7 - Failed to save &c"+plot.id); @@ -251,7 +250,6 @@ public class Schematic extends SubCommand { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { @Override public void run() { - counter++; PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+world+","+owner+".schematic");