Fix plotsquared schematic hook

This commit is contained in:
Jesse Boyd
2019-04-01 21:30:21 +11:00
parent 49e3102779
commit 6e6a3f9035
6 changed files with 136 additions and 31 deletions

View File

@ -27,7 +27,7 @@ import java.util.Map;
/**
* The {@code TAG_Compound} tag.
*/
public final class CompoundTag extends Tag {
public class CompoundTag extends Tag {
private final Map<String, Tag> value;
@ -57,7 +57,7 @@ public final class CompoundTag extends Tag {
* @return true if the tag contains the given key
*/
public boolean containsKey(String key) {
return value.containsKey(key);
return getValue().containsKey(key);
}
@Override
@ -94,7 +94,7 @@ public final class CompoundTag extends Tag {
* @return a byte array
*/
public byte[] getByteArray(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ByteArrayTag) {
return ((ByteArrayTag) tag).getValue();
} else {
@ -112,7 +112,7 @@ public final class CompoundTag extends Tag {
* @return a byte
*/
public byte getByte(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ByteTag) {
return ((ByteTag) tag).getValue();
} else {
@ -130,7 +130,7 @@ public final class CompoundTag extends Tag {
* @return a double
*/
public double getDouble(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof DoubleTag) {
return ((DoubleTag) tag).getValue();
} else {
@ -149,7 +149,7 @@ public final class CompoundTag extends Tag {
* @return a double
*/
public double asDouble(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ByteTag) {
return ((ByteTag) tag).getValue();
@ -183,7 +183,7 @@ public final class CompoundTag extends Tag {
* @return a float
*/
public float getFloat(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof FloatTag) {
return ((FloatTag) tag).getValue();
} else {
@ -201,7 +201,7 @@ public final class CompoundTag extends Tag {
* @return an int array
*/
public int[] getIntArray(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof IntArrayTag) {
return ((IntArrayTag) tag).getValue();
} else {
@ -219,7 +219,7 @@ public final class CompoundTag extends Tag {
* @return an int
*/
public int getInt(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof IntTag) {
return ((IntTag) tag).getValue();
} else {
@ -238,7 +238,7 @@ public final class CompoundTag extends Tag {
* @return an int
*/
public int asInt(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ByteTag) {
return ((ByteTag) tag).getValue();
@ -272,7 +272,7 @@ public final class CompoundTag extends Tag {
* @return a list of tags
*/
public List<Tag> getList(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ListTag) {
return ((ListTag) tag).getValue();
} else {
@ -290,7 +290,7 @@ public final class CompoundTag extends Tag {
* @return a tag list instance
*/
public ListTag getListTag(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ListTag) {
return (ListTag) tag;
} else {
@ -313,7 +313,7 @@ public final class CompoundTag extends Tag {
*/
@SuppressWarnings("unchecked")
public <T extends Tag> List<T> getList(String key, Class<T> listType) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ListTag) {
ListTag listTag = (ListTag) tag;
if (listTag.getType().equals(listType)) {
@ -336,7 +336,7 @@ public final class CompoundTag extends Tag {
* @return an int array
*/
public long[] getLongArray(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof LongArrayTag) {
return ((LongArrayTag) tag).getValue();
} else {
@ -354,7 +354,7 @@ public final class CompoundTag extends Tag {
* @return a long
*/
public long getLong(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof LongTag) {
return ((LongTag) tag).getValue();
} else {
@ -373,7 +373,7 @@ public final class CompoundTag extends Tag {
* @return a long
*/
public long asLong(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ByteTag) {
return ((ByteTag) tag).getValue();
@ -407,7 +407,7 @@ public final class CompoundTag extends Tag {
* @return a short
*/
public short getShort(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof ShortTag) {
return ((ShortTag) tag).getValue();
} else {
@ -425,7 +425,7 @@ public final class CompoundTag extends Tag {
* @return a string
*/
public String getString(String key) {
Tag tag = value.get(key);
Tag tag = getValue().get(key);
if (tag instanceof StringTag) {
return ((StringTag) tag).getValue();
} else {
@ -436,8 +436,8 @@ public final class CompoundTag extends Tag {
@Override
public String toString() {
StringBuilder bldr = new StringBuilder();
bldr.append("TAG_Compound").append(": ").append(value.size()).append(" entries\r\n{\r\n");
for (Map.Entry<String, Tag> entry : value.entrySet()) {
bldr.append("TAG_Compound").append(": ").append(getValue().size()).append(" entries\r\n{\r\n");
for (Map.Entry<String, Tag> entry : getValue().entrySet()) {
bldr.append(" ").append(entry.getValue().toString().replaceAll("\r\n", "\r\n ")).append("\r\n");
}
bldr.append("}");

View File

@ -0,0 +1,42 @@
package com.sk89q.jnbt;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
public abstract class CompressedCompoundTag<T> extends CompoundTag {
private T in;
public CompressedCompoundTag(T in) {
super(new HashMap<>());
this.in = in;
}
@Override
public Map<String, Tag> getValue() {
if (in != null) decompress();
return super.getValue();
}
public abstract DataInputStream adapt(T src) throws IOException;
public T getSource() {
return in;
}
private void decompress() {
try (NBTInputStream nbtIn = new NBTInputStream(adapt(in))) {
in = null;
CompoundTag tag = (CompoundTag) nbtIn.readTag();
Map<String, Tag> value = tag.getValue();
Map<String, Tag> raw = super.getValue();
for (Map.Entry<String, Tag> entry : value.entrySet()) {
raw.put(entry.getKey(), entry.getValue());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,33 @@
package com.sk89q.jnbt;
import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.object.io.FastByteArraysInputStream;
import com.boydti.fawe.object.io.PGZIPOutputStream;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicWriter;
import net.jpountz.lz4.LZ4BlockInputStream;
import net.jpountz.lz4.LZ4BlockOutputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;
public class CompressedSchematicTag extends CompressedCompoundTag<Clipboard> {
public CompressedSchematicTag(Clipboard holder) {
super(holder);
}
@Override
public DataInputStream adapt(Clipboard src) throws IOException {
System.out.println("Decompress");
FastByteArrayOutputStream blocksOut = new FastByteArrayOutputStream();
try (LZ4BlockOutputStream lz4out = new LZ4BlockOutputStream(blocksOut)) {
NBTOutputStream nbtOut = new NBTOutputStream(lz4out);
new SpongeSchematicWriter(nbtOut).write(getSource());
} catch (IOException e) {
throw new RuntimeException(e);
}
FastByteArraysInputStream in = new FastByteArraysInputStream(blocksOut.toByteArrays());
return new DataInputStream(new LZ4BlockInputStream(in));
}
}

View File

@ -216,12 +216,12 @@ public class SpongeSchematicReader extends NBTSchematicReader {
});
streamer.readFully();
if (fc == null) setupClipboard(length * width * height, uuid);
else fc.setDimensions(BlockVector3.at(width, height, length));
fc.setDimensions(BlockVector3.at(width, height, length));
BlockVector3 origin = min;
CuboidRegion region;
if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) {
origin = origin.subtract(BlockVector3.at(offsetX, offsetY, offsetZ));
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE));
} else {
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE));
}

View File

@ -91,7 +91,6 @@ public class SpongeSchematicWriter implements ClipboardWriter {
if (length > MAX_SIZE) {
throw new IllegalArgumentException("Length of region too large for a .schematic");
}
//<<<<<<< HEAD
// output
final DataOutput rawStream = outputStream.getOutputStream();
outputStream.writeLazyCompoundTag("Schematic", out -> {