mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-02 11:26:42 +00:00
revert some changes
This commit is contained in:
@ -479,6 +479,91 @@ public final class NBTInputStream implements Closeable {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Don't delete please
|
||||
*/
|
||||
public Object readDataPayload(int type, int depth) throws IOException {
|
||||
switch (type) {
|
||||
case NBTConstants.TYPE_END:
|
||||
if (depth == 0) {
|
||||
throw new IOException(
|
||||
"TAG_End found without a TAG_Compound/TAG_List tag preceding it.");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
case NBTConstants.TYPE_BYTE:
|
||||
return is.readByte();
|
||||
case NBTConstants.TYPE_SHORT:
|
||||
return is.readShort();
|
||||
case NBTConstants.TYPE_INT:
|
||||
return is.readInt();
|
||||
case NBTConstants.TYPE_LONG:
|
||||
return is.readLong();
|
||||
case NBTConstants.TYPE_FLOAT:
|
||||
return is.readFloat();
|
||||
case NBTConstants.TYPE_DOUBLE:
|
||||
return is.readDouble();
|
||||
case NBTConstants.TYPE_BYTE_ARRAY:
|
||||
int length = is.readInt();
|
||||
byte[] bytes = new byte[length];
|
||||
is.readFully(bytes);
|
||||
return bytes;
|
||||
case NBTConstants.TYPE_STRING:
|
||||
length = is.readShort();
|
||||
bytes = new byte[length];
|
||||
is.readFully(bytes);
|
||||
return new String(bytes, NBTConstants.CHARSET);
|
||||
case NBTConstants.TYPE_LIST:
|
||||
int childType = is.readByte();
|
||||
if (childType == NBTConstants.TYPE_LIST) {
|
||||
childType = NBTConstants.TYPE_COMPOUND;
|
||||
}
|
||||
length = is.readInt();
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
for (int i = 0; i < length; ++i) {
|
||||
Object obj = readDataPayload(childType, depth + 1);
|
||||
if (obj == null) {
|
||||
throw new IOException("TAG_End not permitted in a list.");
|
||||
}
|
||||
list.add(obj);
|
||||
}
|
||||
|
||||
return list;
|
||||
case NBTConstants.TYPE_COMPOUND:
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
while (true) {
|
||||
int newType = is.readByte();
|
||||
String name = readNamedTagName(newType);
|
||||
Object data = readDataPayload(newType, depth + 1);
|
||||
if (data == null) {
|
||||
break;
|
||||
} else {
|
||||
map.put(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
case NBTConstants.TYPE_INT_ARRAY: {
|
||||
length = is.readInt();
|
||||
int[] data = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
data[i] = is.readInt();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
case NBTConstants.TYPE_LONG_ARRAY: {
|
||||
length = is.readInt();
|
||||
long[] data = new long[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
data[i] = is.readLong();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
default:
|
||||
throw new IOException("Invalid tag type: " + type + ".");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
is.close();
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
package com.sk89q.jnbt;
|
||||
|
||||
import com.boydti.fawe.object.io.LittleEndianOutputStream;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.io.Closeable;
|
||||
@ -43,7 +45,7 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
/**
|
||||
* The output stream.
|
||||
*/
|
||||
private final DataOutputStream os;
|
||||
private final DataOutput os;
|
||||
|
||||
/**
|
||||
* Creates a new {@code NBTOutputStream}, which will write data to the
|
||||
@ -55,7 +57,17 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
* if an I/O error occurs.
|
||||
*/
|
||||
public NBTOutputStream(OutputStream os) throws IOException {
|
||||
this.os = new DataOutputStream(os);
|
||||
this(os instanceof DataOutput ? (DataOutput) os : new DataOutputStream(os));
|
||||
}
|
||||
|
||||
// Don't delete
|
||||
public NBTOutputStream(DataOutput os) throws IOException {
|
||||
this.os = os;
|
||||
}
|
||||
|
||||
// Don't delete
|
||||
public NBTOutputStream(OutputStream os, boolean littleEndian) throws IOException {
|
||||
this(littleEndian ? new LittleEndianOutputStream(os) : os);
|
||||
}
|
||||
|
||||
public DataOutput getOutputStream() {
|
||||
@ -405,7 +417,9 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
os.close();
|
||||
if (os instanceof Closeable) {
|
||||
((Closeable) os).close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -485,6 +499,8 @@ public final class NBTOutputStream extends OutputStream implements Closeable, Da
|
||||
*/
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
((Flushable) os).flush();
|
||||
if (os instanceof Flushable) {
|
||||
((Flushable) os).flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user