mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 11:26:42 +00:00
Upstream
This commit is contained in:
@ -41,15 +41,6 @@ public class CompoundTag extends Tag {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRaw() {
|
||||
HashMap<String, Object> raw = new HashMap<>();
|
||||
for (Map.Entry<String, Tag> entry : value.entrySet()) {
|
||||
raw.put(entry.getKey(), entry.getValue().getRaw());
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this compound tag contains the given key.
|
||||
*
|
||||
|
@ -34,7 +34,7 @@ public class CompoundTagBuilder {
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public CompoundTagBuilder() {
|
||||
CompoundTagBuilder() {
|
||||
this.entries = new HashMap<>();
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public class CompoundTagBuilder {
|
||||
*
|
||||
* @param value the value
|
||||
*/
|
||||
public CompoundTagBuilder(Map<String, Tag> value) {
|
||||
CompoundTagBuilder(Map<String, Tag> value) {
|
||||
checkNotNull(value);
|
||||
this.entries = value;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public final class ListTag extends Tag {
|
||||
|
||||
/**
|
||||
* Get the tag if it exists at the given index.
|
||||
*
|
||||
*
|
||||
* @param index the index
|
||||
* @return the tag or null
|
||||
*/
|
||||
@ -82,7 +82,7 @@ public final class ListTag extends Tag {
|
||||
if (index >= value.size()) {
|
||||
return null;
|
||||
}
|
||||
return value.get(index);
|
||||
return value.get(index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,16 +20,12 @@
|
||||
package com.sk89q.jnbt;
|
||||
|
||||
import com.boydti.fawe.jnbt.NBTStreamer;
|
||||
import com.boydti.fawe.object.RunnableVal2;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -40,7 +36,7 @@ import java.util.function.Function;
|
||||
* This class reads <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* streams, and produces an object graph of subclasses of the {@code Tag}
|
||||
* object.
|
||||
*
|
||||
*
|
||||
* <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">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||
@ -52,7 +48,7 @@ public final class NBTInputStream implements Closeable {
|
||||
/**
|
||||
* Creates a new {@code NBTInputStream}, which will source its data
|
||||
* from the specified input stream.
|
||||
*
|
||||
*
|
||||
* @param is the input stream
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
@ -64,13 +60,9 @@ public final class NBTInputStream implements Closeable {
|
||||
this.is = dis;
|
||||
}
|
||||
|
||||
public DataInputStream getInputStream() {
|
||||
return is;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT tag from the stream.
|
||||
*
|
||||
*
|
||||
* @return The tag that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
@ -78,19 +70,9 @@ public final class NBTInputStream implements Closeable {
|
||||
return readNamedTag(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT map from the stream.
|
||||
*
|
||||
* @return The map that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public NamedData readNamedData() throws IOException {
|
||||
return readNamedData(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an NBT from the stream.
|
||||
*
|
||||
*
|
||||
* @param depth the depth of this tag
|
||||
* @return The tag that was read.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
@ -100,21 +82,11 @@ public final class NBTInputStream implements Closeable {
|
||||
return new NamedTag(readNamedTagName(type), readTagPayload(type, depth));
|
||||
}
|
||||
|
||||
private NamedData readNamedData(int depth) throws IOException {
|
||||
int type = is.readByte();
|
||||
return new NamedData(readNamedTagName(type), readDataPayload(type, depth));
|
||||
}
|
||||
|
||||
public Tag readTag() throws IOException {
|
||||
int type = is.readByte();
|
||||
return readTagPayload(type, 0);
|
||||
}
|
||||
|
||||
public Object readData() throws IOException {
|
||||
int type = is.readByte();
|
||||
return readDataPayload(type, 0);
|
||||
}
|
||||
|
||||
public void readNamedTagLazy(Function<String, BiConsumer> getReader) throws IOException {
|
||||
int type = is.readByte();
|
||||
String name = readNamedTagName(type);
|
||||
@ -522,13 +494,13 @@ public final class NBTInputStream implements Closeable {
|
||||
|
||||
/**
|
||||
* Reads the payload of a tag given the type.
|
||||
*
|
||||
*
|
||||
* @param type the type
|
||||
* @param depth the depth
|
||||
* @return the tag
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public Tag readTagPayload(int type, int depth) throws IOException {
|
||||
private Tag readTagPayload(int type, int depth) throws IOException {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
if (depth == 0) {
|
||||
@ -598,11 +570,11 @@ public final class NBTInputStream implements Closeable {
|
||||
}
|
||||
case NBTConstants.TYPE_LONG_ARRAY: {
|
||||
length = is.readInt();
|
||||
long[] data = new long[length];
|
||||
long[] longData = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
data[i] = is.readLong();
|
||||
longData[i] = is.readLong();
|
||||
}
|
||||
return new LongArrayTag(data);
|
||||
return new LongArrayTag(longData);
|
||||
}
|
||||
default:
|
||||
throw new IOException("Invalid tag type: " + type + ".");
|
||||
|
@ -21,7 +21,6 @@ package com.sk89q.jnbt;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.object.io.LittleEndianOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
@ -34,7 +33,7 @@ import java.util.Map;
|
||||
/**
|
||||
* This class writes <strong>NBT</strong>, or <strong>Named Binary Tag</strong>
|
||||
* {@code Tag} objects to an underlying {@code OutputStream}.
|
||||
*
|
||||
*
|
||||
* <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">
|
||||
* http://www.minecraft.net/docs/NBT.txt</a>.</p>
|
||||
@ -49,7 +48,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
/**
|
||||
* Creates a new {@code NBTOutputStream}, which will write data to the
|
||||
* specified underlying output stream.
|
||||
*
|
||||
*
|
||||
* @param os
|
||||
* The output stream.
|
||||
* @throws IOException
|
||||
@ -67,15 +66,9 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
return os;
|
||||
}
|
||||
|
||||
public void setLittleEndian() {
|
||||
if (!(os instanceof LittleEndianOutputStream)) {
|
||||
this.os = new LittleEndianOutputStream((OutputStream) os);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag to write.
|
||||
* @throws IOException
|
||||
@ -86,10 +79,16 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
checkNotNull(tag);
|
||||
|
||||
int type = NBTUtils.getTypeCode(tag.getClass());
|
||||
writeNamedTagName(name, type);
|
||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||
|
||||
os.writeByte(type);
|
||||
os.writeShort(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
|
||||
if (type == NBTConstants.TYPE_END) {
|
||||
throw new IOException("Named TAG_End not permitted.");
|
||||
}
|
||||
|
||||
writeTagPayload(tag);
|
||||
}
|
||||
|
||||
@ -149,16 +148,6 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNamedTag(String name, long[] data) throws IOException {
|
||||
checkNotNull(name);
|
||||
int type = NBTConstants.TYPE_LONG_ARRAY;
|
||||
writeNamedTagName(name, type);
|
||||
os.writeInt(data.length);
|
||||
for (long aData : data) {
|
||||
os.writeLong(aData);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNamedEmptyList(String name) throws IOException {
|
||||
writeNamedEmptyList(name, NBTConstants.TYPE_COMPOUND);
|
||||
}
|
||||
@ -171,6 +160,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
public void writeNamedTagName(String name, int type) throws IOException {
|
||||
byte[] nameBytes = name.getBytes(NBTConstants.CHARSET);
|
||||
|
||||
os.writeByte(type);
|
||||
os.writeShort(nameBytes.length);
|
||||
os.write(nameBytes);
|
||||
@ -201,7 +191,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes tag payload.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -256,7 +246,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Byte} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -268,7 +258,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Byte_Array} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -282,7 +272,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Compound} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -292,12 +282,12 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
for (Map.Entry<String, Tag> entry : tag.getValue().entrySet()) {
|
||||
writeNamedTag(entry.getKey(), entry.getValue());
|
||||
}
|
||||
os.writeByte(NBTConstants.TYPE_END); // end tag - better way?
|
||||
os.writeByte((byte) 0); // end tag - better way?
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_List} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -324,7 +314,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_String} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -338,7 +328,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Double} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -350,7 +340,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Float} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -362,7 +352,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Long} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -374,7 +364,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Int} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -386,7 +376,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Short} tag.
|
||||
*
|
||||
*
|
||||
* @param tag
|
||||
* The tag.
|
||||
* @throws IOException
|
||||
@ -398,19 +388,19 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
/**
|
||||
* Writes a {@code TAG_Empty} tag.
|
||||
*
|
||||
*
|
||||
* @param tag the tag
|
||||
*/
|
||||
private void writeEndTagPayload(EndTag tag) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
|
||||
private void writeIntArrayTagPayload(IntArrayTag tag) throws IOException {
|
||||
int[] data = tag.getValue();
|
||||
os.writeInt(data.length);
|
||||
for (int aData : data) {
|
||||
os.writeInt(aData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLongArrayTagPayload(LongArrayTag tag) throws IOException {
|
||||
@ -505,4 +495,4 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
public void flush() throws IOException {
|
||||
if (os instanceof Flushable) ((Flushable) os).flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,12 +26,9 @@ public abstract class Tag {
|
||||
|
||||
/**
|
||||
* Gets the value of this tag.
|
||||
*
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public abstract Object getValue();
|
||||
|
||||
public Object getRaw() {
|
||||
return getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user