forgot to export schematic in GZIP format. Whoops.

This commit is contained in:
boy0001 2014-10-26 11:05:54 +11:00
parent 768cb8b293
commit d4e0397187
3 changed files with 48 additions and 27 deletions

View File

@ -7,12 +7,19 @@ import java.io.OutputStream;
import java.util.List; import java.util.List;
/** /**
* <p>
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong> * This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
* {@code Tag} objects to an underlying {@code OutputStream}. * <code>Tag</code> objects to an underlying <code>OutputStream</code>.
* </p>
* *
* <p>The NBT format was created by Markus Persson, and the specification may be * <p>
* The NBT format was created by Markus Persson, and the specification may be
* found at <a href="http://www.minecraft.net/docs/NBT.txt"> * found at <a href="http://www.minecraft.net/docs/NBT.txt">
* http://www.minecraft.net/docs/NBT.txt</a>.</p> * http://www.minecraft.net/docs/NBT.txt</a>.
* </p>
*
* @author Graham Edgecombe
*
*/ */
public final class NBTOutputStream implements Closeable { public final class NBTOutputStream implements Closeable {
@ -22,7 +29,7 @@ public final class NBTOutputStream implements Closeable {
private final DataOutputStream os; private final DataOutputStream os;
/** /**
* Creates a new {@code NBTOutputStream}, which will write data to the * Creates a new <code>NBTOutputStream</code>, which will write data to the
* specified underlying output stream. * specified underlying output stream.
* *
* @param os * @param os
@ -111,7 +118,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Byte} tag. * Writes a <code>TAG_Byte</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -123,7 +130,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Byte_Array} tag. * Writes a <code>TAG_Byte_Array</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -137,7 +144,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Compound} tag. * Writes a <code>TAG_Compound</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -152,7 +159,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_List} tag. * Writes a <code>TAG_List</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -166,13 +173,13 @@ public final class NBTOutputStream implements Closeable {
os.writeByte(NBTUtils.getTypeCode(clazz)); os.writeByte(NBTUtils.getTypeCode(clazz));
os.writeInt(size); os.writeInt(size);
for (Tag tag1 : tags) { for (int i = 0; i < size; ++i) {
writeTagPayload(tag1); writeTagPayload(tags.get(i));
} }
} }
/** /**
* Writes a {@code TAG_String} tag. * Writes a <code>TAG_String</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -186,7 +193,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Double} tag. * Writes a <code>TAG_Double</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -198,7 +205,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Float} tag. * Writes a <code>TAG_Float</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -210,7 +217,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Long} tag. * Writes a <code>TAG_Long</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -222,7 +229,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Int} tag. * Writes a <code>TAG_Int</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -234,7 +241,7 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Short} tag. * Writes a <code>TAG_Short</code> tag.
* *
* @param tag * @param tag
* The tag. * The tag.
@ -246,9 +253,12 @@ public final class NBTOutputStream implements Closeable {
} }
/** /**
* Writes a {@code TAG_Empty} tag. * Writes a <code>TAG_Empty</code> tag.
* *
* @param tag the tag * @param tag
* The tag.
* @throws IOException
* if an I/O error occurs.
*/ */
private void writeEndTagPayload(EndTag tag) { private void writeEndTagPayload(EndTag tag) {
/* empty */ /* empty */
@ -257,12 +267,11 @@ public final class NBTOutputStream implements Closeable {
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException { private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
int[] data = tag.getValue(); int[] data = tag.getValue();
os.writeInt(data.length); os.writeInt(data.length);
for (int aData : data) { for (int i = 0; i < data.length; i++) {
os.writeInt(aData); os.writeInt(data[i]);
} }
} }
@Override
public void close() throws IOException { public void close() throws IOException {
os.close(); os.close();
} }

View File

@ -14,9 +14,11 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/** /**
* Created by Citymonstret on 2014-09-15. * Created by Citymonstret on 2014-09-15.
@ -202,7 +204,7 @@ public class SchematicHandler {
try { try {
OutputStream stream = new FileOutputStream(path); OutputStream stream = new FileOutputStream(path);
NBTOutputStream output = new NBTOutputStream(stream); NBTOutputStream output = new NBTOutputStream(new GZIPOutputStream(stream));
output.writeTag(tag); output.writeTag(tag);
output.close(); output.close();
stream.close(); stream.close();
@ -265,20 +267,27 @@ public class SchematicHandler {
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0)); schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0)); schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
System.out.print("WHL "+width+" | "+height+ " | "+length);
byte[] blocks = new byte[width * height * length]; byte[] blocks = new byte[width * height * length];
byte[] addBlocks = null; byte[] addBlocks = null;
byte[] blockData = new byte[width * height * length]; byte[] blockData = new byte[width * height * length];
int count = 0;
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
for (int z = 0; z < length; z++) { for (int z = 0; z < length; z++) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
int index = y * width * length + z * width + x; int index = y * width * length + z * width + x;
count++;
Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, 0 + y, pos1.getBlockZ() + z)); Block block = world.getBlockAt(new Location(world, pos1.getBlockX() + x, 0 + y, pos1.getBlockZ() + z));
int id2 = block.getTypeId(); int id2 = block.getTypeId();
if (id2 > 255) { if (id2 > 255) {
System.out.print("GREATER "+id2);
if (addBlocks == null) { if (addBlocks == null) {
addBlocks = new byte[(blocks.length >> 1) + 1]; addBlocks = new byte[(blocks.length >> 1) + 1];
} }
@ -297,8 +306,13 @@ public class SchematicHandler {
} }
} }
} }
System.out.print("COUNT "+count);
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks)); schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData)); schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, new ArrayList<Tag>()));
if (addBlocks != null) { if (addBlocks != null) {
schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks)); schematic.put("AddBlocks", new ByteArrayTag("AddBlocks", addBlocks));

View File

@ -159,7 +159,6 @@ public class Schematic extends SubCommand {
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
@Override @Override
public void run() { public void run() {
counter++;
PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); 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");
@ -251,7 +250,6 @@ public class Schematic extends SubCommand {
Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() { Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getServer().getPluginManager().getPlugin("PlotSquared"), new Runnable() {
@Override @Override
public void run() { public void run() {
counter++;
PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id); PlayerFunctions.sendMessage(plr, "&6ID: "+plot.id);
boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+world+","+owner+".schematic"); boolean result = SchematicHandler.save(sch, Settings.Web.PATH+"/"+plot.id.x+","+plot.id.y+","+world+","+owner+".schematic");