Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ccfb6b422c | ||
|
|
2c8143ddb0 | ||
|
|
f9892c598c | ||
|
|
3eb79fd6d2 | ||
|
|
8ddceada42 | ||
|
|
a1c355d4c9 | ||
|
|
5c23459e1e | ||
|
|
af3dbc928b | ||
|
|
bd1bc7f06a | ||
|
|
7f16b992eb | ||
|
|
460884cbd8 | ||
|
|
24bf010d98 | ||
|
|
e74adedf88 | ||
|
|
a34d03f422 | ||
|
|
c0a9be3c7d | ||
|
|
8f352d9115 | ||
|
|
6ca306405c | ||
|
|
d4190b2fde | ||
|
|
30ed0bdcf3 | ||
|
|
c3e2c3ee9e | ||
|
|
155f8520d4 |
No files matched your search
@@ -1,3 +1,34 @@
|
||||
!!!!! v2.9.5
|
||||
|
||||
# PacketEvents 2.9.5 is out now! 🎉
|
||||
|
||||
This update includes critical bug fixes & minor additions to the API.
|
||||
|
||||
# Brief Announcement 📢⚠️
|
||||
|
||||
### We have our very own website: https://packetevents.com
|
||||
|
||||
### Documentation: https://docs.packetevents.com
|
||||
|
||||
### JavaDocs: https://javadocs.packetevents.com
|
||||
|
||||
## What's Changed (Summary)
|
||||
|
||||
* Injector bug fix (for Spigot)
|
||||
* WolfVariant issue fixed
|
||||
* Chunk Data error fixed
|
||||
* NBT tag issues fixed
|
||||
* Direction Y/Z axis being swapped fixed
|
||||
* Added WrappedBlockState to constructor of WrapperPlayServerBlockChange
|
||||
|
||||
**View Full Changelog**: https://github.com/retrooper/packetevents/compare/v2.9.4...v2.9.5
|
||||
|
||||
## If you want to support PacketEvents, consider sponsoring us on [GitHub Sponsors](https://github.com/sponsors/retrooper)
|
||||
|
||||
## Maven/Gradle Dependency
|
||||
|
||||
### **Check out**: https://docs.packetevents.com/getting-started
|
||||
|
||||
!!!!! v2.9.4
|
||||
|
||||
# PacketEvents 2.9.4 is out now! 🎉
|
||||
|
||||
-3
@@ -119,9 +119,6 @@ public class SingleOptionInputControl implements InputControl {
|
||||
}
|
||||
|
||||
public static NBT encode(PacketWrapper<?> wrapper, Entry entry) {
|
||||
if (entry.display == null && !entry.initial) {
|
||||
return new NBTString(entry.id);
|
||||
}
|
||||
NBTCompound compound = new NBTCompound();
|
||||
compound.setTag("id", new NBTString(entry.id));
|
||||
if (entry.display != null) {
|
||||
|
||||
+4
-2
@@ -50,14 +50,16 @@ public interface WolfVariant extends MappedEntity, CopyableEntity<WolfVariant>,
|
||||
MappedEntitySet<Biome> getBiomes();
|
||||
|
||||
static WolfVariant read(PacketWrapper<?> wrapper) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)
|
||||
|| wrapper.getServerVersion().isOlderThan(ServerVersion.V_1_21)) {
|
||||
return wrapper.readMappedEntity(WolfVariants.getRegistry());
|
||||
}
|
||||
return wrapper.readMappedEntityOrDirect(WolfVariants.getRegistry(), WolfVariant::readDirect);
|
||||
}
|
||||
|
||||
static void write(PacketWrapper<?> wrapper, WolfVariant variant) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)
|
||||
|| wrapper.getServerVersion().isOlderThan(ServerVersion.V_1_21)) {
|
||||
wrapper.writeMappedEntity(variant);
|
||||
} else {
|
||||
wrapper.writeMappedEntityOrDirect(variant, WolfVariant::writeDirect);
|
||||
|
||||
@@ -284,7 +284,7 @@ public class NBTCompound extends NBT {
|
||||
if (list == null) {
|
||||
throw new IllegalStateException(MessageFormat.format("NBT {0} does not exist", key));
|
||||
}
|
||||
return null;
|
||||
return list;
|
||||
}
|
||||
|
||||
public <T> void set(String key, T value, NbtEncoder<T> encoder, PacketWrapper<?> wrapper) {
|
||||
|
||||
@@ -18,11 +18,15 @@
|
||||
package com.github.retrooper.packetevents.protocol.nbt;
|
||||
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
@ApiStatus.NonExtendable
|
||||
public interface NBTLimiter {
|
||||
|
||||
int DEFAULT_MAX_SIZE = 2097152;
|
||||
int DEFAULT_MAX_SIZE = Integer.getInteger("packetevents.nbt.default-max-size", 1 << 20); // 2MiB
|
||||
int DEFAULT_MAX_DEPTH = Integer.getInteger("packetevents.nbt.default-max-depth", 512);
|
||||
|
||||
static NBTLimiter noop() {
|
||||
return new NBTLimiter() {
|
||||
@@ -35,27 +39,64 @@ public interface NBTLimiter {
|
||||
public void checkReadability(int length) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterDepth() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitDepth() {
|
||||
// no-op
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static NBTLimiter forBuffer(final @NotNull Object byteBuf) {
|
||||
static NBTLimiter forBuffer(Object byteBuf) {
|
||||
return forBuffer(byteBuf, DEFAULT_MAX_SIZE);
|
||||
}
|
||||
|
||||
static NBTLimiter forBuffer(final @NotNull Object byteBuf, final int max) {
|
||||
static NBTLimiter forBuffer(Object byteBuf, int maxBytes) {
|
||||
return forBuffer(byteBuf, maxBytes, DEFAULT_MAX_DEPTH);
|
||||
}
|
||||
|
||||
static NBTLimiter forBuffer(Object byteBuf, int maxBytes, int maxDepth) {
|
||||
return new NBTLimiter() {
|
||||
private int bytes;
|
||||
private int depth;
|
||||
|
||||
@Override
|
||||
public void increment(int amount) {
|
||||
bytes += amount;
|
||||
|
||||
if (bytes > max) throw new IllegalArgumentException("NBT size limit reached (" + bytes + "/" + max + ")");
|
||||
if (amount < 0) {
|
||||
throw new IllegalArgumentException("Can't increment NBT limiter by negative amount: " + amount);
|
||||
} else if (this.bytes + amount > maxBytes) {
|
||||
throw new IllegalArgumentException("NBT size limit reached (" + this.bytes + "/" + maxBytes + ")");
|
||||
}
|
||||
this.bytes += amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkReadability(int length) {
|
||||
if (length > ByteBufHelper.readableBytes(byteBuf)) throw new IllegalArgumentException("Length is too large: " + length + ", readable: " + ByteBufHelper.readableBytes(byteBuf));
|
||||
int readableBytes = ByteBufHelper.readableBytes(byteBuf);
|
||||
if (length > readableBytes) {
|
||||
throw new IllegalArgumentException("Can't read more than possible: " + length + " > " + readableBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterDepth() {
|
||||
if (this.depth >= maxDepth) {
|
||||
throw new IllegalArgumentException("NBT depth limit reached (" + this.depth + "/" + maxDepth + ")");
|
||||
}
|
||||
this.depth++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitDepth() {
|
||||
if (this.depth <= 0) {
|
||||
throw new IllegalArgumentException("Can't exit top-level depth");
|
||||
}
|
||||
this.depth--;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -64,4 +105,7 @@ public interface NBTLimiter {
|
||||
|
||||
void checkReadability(int length);
|
||||
|
||||
void enterDepth();
|
||||
|
||||
void exitDepth();
|
||||
}
|
||||
+95
-58
@@ -18,72 +18,94 @@
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.nbt.serializer;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.*;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTByte;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTByteArray;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTDouble;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTEnd;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTFloat;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTInt;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTIntArray;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLimiter;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLong;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLongArray;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTShort;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static final int OBJECT_HEADER_BYTES = 8;
|
||||
@ApiStatus.Internal
|
||||
public static final int ARRAY_HEADER_BYTES = 12;
|
||||
@ApiStatus.Internal
|
||||
public static final int OBJECT_REF_BYTES = 4;
|
||||
@ApiStatus.Internal
|
||||
public static final int STRING_SIZE_BYTES = 28;
|
||||
|
||||
public static final DefaultNBTSerializer INSTANCE = new DefaultNBTSerializer();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public DefaultNBTSerializer() {
|
||||
super(
|
||||
(limiter, dataInput) -> {
|
||||
limiter.increment(1);
|
||||
return dataInput.readByte();
|
||||
},
|
||||
(limiter, dataInput) -> dataInput.readByte(),
|
||||
DataOutput::writeByte,
|
||||
(limiter, dataInput) -> {
|
||||
String name = dataInput.readUTF();
|
||||
limiter.increment(name.length() * 2 + 28);
|
||||
return name;
|
||||
// only used for skipping strings
|
||||
dataInput.skipBytes(dataInput.readUnsignedShort());
|
||||
return "";
|
||||
},
|
||||
DataOutput::writeUTF
|
||||
);
|
||||
registerType(NBTType.END, 0, (limiter, stream) -> {
|
||||
limiter.increment(8);
|
||||
limiter.increment(OBJECT_HEADER_BYTES);
|
||||
return NBTEnd.INSTANCE;
|
||||
}, (stream, tag) -> {
|
||||
});
|
||||
registerType(NBTType.BYTE, 1, (limiter, stream) -> {
|
||||
limiter.increment(9);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Byte.BYTES);
|
||||
return new NBTByte(stream.readByte());
|
||||
}, (stream, tag) -> stream.writeByte(tag.getAsByte()));
|
||||
registerType(NBTType.SHORT, 2, (limiter, stream) -> {
|
||||
limiter.increment(10);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Short.SIZE);
|
||||
return new NBTShort(stream.readShort());
|
||||
}, (stream, tag) -> stream.writeShort(tag.getAsShort()));
|
||||
registerType(NBTType.INT, 3, (limiter, stream) -> {
|
||||
limiter.increment(12);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Integer.BYTES);
|
||||
return new NBTInt(stream.readInt());
|
||||
}, (stream, tag) -> stream.writeInt(tag.getAsInt()));
|
||||
registerType(NBTType.LONG, 4, (limiter, stream) -> {
|
||||
limiter.increment(16);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Long.BYTES);
|
||||
return new NBTLong(stream.readLong());
|
||||
}, (stream, tag) -> stream.writeLong(tag.getAsLong()));
|
||||
registerType(NBTType.FLOAT, 5, (limiter, stream) -> {
|
||||
limiter.increment(12);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Float.BYTES);
|
||||
return new NBTFloat(stream.readFloat());
|
||||
}, (stream, tag) -> stream.writeFloat(tag.getAsFloat()));
|
||||
registerType(NBTType.DOUBLE, 6, (limiter, stream) -> {
|
||||
limiter.increment(16);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Double.BYTES);
|
||||
return new NBTDouble(stream.readDouble());
|
||||
}, (stream, tag) -> stream.writeDouble(tag.getAsDouble()));
|
||||
registerType(
|
||||
NBTType.BYTE_ARRAY, 7,
|
||||
(limiter, stream) -> {
|
||||
limiter.increment(24);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int length = stream.readInt();
|
||||
|
||||
if (length >= 1 << 24)
|
||||
if (length >= 1 << 24) {
|
||||
throw new IllegalArgumentException("Byte array length is too large: " + length);
|
||||
|
||||
limiter.checkReadability(length);
|
||||
limiter.increment(length);
|
||||
}
|
||||
limiter.increment(Byte.BYTES * length);
|
||||
limiter.checkReadability(Byte.BYTES * length);
|
||||
|
||||
byte[] array = new byte[length];
|
||||
stream.readFully(array);
|
||||
@@ -96,28 +118,32 @@ public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
|
||||
}
|
||||
);
|
||||
registerType(NBTType.STRING, 8, (limiter, stream) -> {
|
||||
limiter.increment(36);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + STRING_SIZE_BYTES);
|
||||
String string = stream.readUTF();
|
||||
limiter.increment(string.length() * 2);
|
||||
limiter.increment(string.length() * Character.BYTES);
|
||||
return new NBTString(string);
|
||||
}, (stream, tag) -> stream.writeUTF(tag.getValue()));
|
||||
registerType(
|
||||
NBTType.LIST, 9,
|
||||
(limiter, stream) -> {
|
||||
limiter.increment(37);
|
||||
|
||||
NBTType<? extends NBT> valueType = readTagType(limiter, stream);
|
||||
int size = stream.readInt();
|
||||
|
||||
if ((valueType == NBTType.END) && (size > 0)) {
|
||||
throw new IllegalStateException("Missing nbt list values tag type");
|
||||
limiter.enterDepth();
|
||||
try {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + OBJECT_REF_BYTES // list tag
|
||||
+ OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES); // arraylist
|
||||
NBTType<? extends NBT> valueType = readTagType(limiter, stream);
|
||||
int size = stream.readInt();
|
||||
if (valueType == NBTType.END && size > 0) {
|
||||
throw new IllegalStateException("Missing nbt list values tag type");
|
||||
}
|
||||
limiter.increment(OBJECT_REF_BYTES * size);
|
||||
NBTList<NBT> list = new NBTList<>((NBTType<NBT>) valueType, size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
list.addTag(readTag(limiter, stream, valueType));
|
||||
}
|
||||
return list;
|
||||
} finally {
|
||||
limiter.exitDepth();
|
||||
}
|
||||
limiter.increment(4 * size);
|
||||
NBTList<NBT> list = new NBTList<>((NBTType<NBT>) valueType, size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
list.addTag(readTag(limiter, stream, valueType));
|
||||
}
|
||||
return list;
|
||||
},
|
||||
(stream, tag) -> {
|
||||
writeTagType(stream, tag.getTagsType());
|
||||
@@ -130,17 +156,24 @@ public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
|
||||
registerType(
|
||||
NBTType.COMPOUND, 10,
|
||||
(limiter, stream) -> {
|
||||
limiter.increment(48);
|
||||
|
||||
NBTCompound compound = new NBTCompound();
|
||||
NBTType<?> valueType;
|
||||
while ((valueType = readTagType(limiter, stream)) != NBTType.END) {
|
||||
String name = readTagName(limiter, stream);
|
||||
NBT nbt = readTag(limiter, stream, valueType);
|
||||
if(!compound.getTags().containsKey(name)) limiter.increment(36);
|
||||
compound.setTag(name, nbt);
|
||||
limiter.enterDepth();
|
||||
try {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + OBJECT_REF_BYTES // compound tag
|
||||
+ OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES + Integer.BYTES + Integer.BYTES + Float.BYTES); // hashmap
|
||||
NBTCompound compound = new NBTCompound();
|
||||
NBTType<?> valueType;
|
||||
while ((valueType = readTagType(limiter, stream)) != NBTType.END) {
|
||||
String name = readString(limiter, stream);
|
||||
NBT tag = readTag(limiter, stream, valueType);
|
||||
if (!compound.getTags().containsKey(name)) {
|
||||
limiter.increment(12 + OBJECT_HEADER_BYTES + Integer.BYTES + OBJECT_REF_BYTES + OBJECT_REF_BYTES + OBJECT_REF_BYTES);
|
||||
}
|
||||
compound.setTag(name, tag);
|
||||
}
|
||||
return compound;
|
||||
} finally {
|
||||
limiter.exitDepth();
|
||||
}
|
||||
return compound;
|
||||
},
|
||||
(stream, tag) -> {
|
||||
for (Entry<String, NBT> entry : tag.getTags().entrySet()) {
|
||||
@@ -155,14 +188,13 @@ public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
|
||||
registerType(
|
||||
NBTType.INT_ARRAY, 11,
|
||||
(limiter, stream) -> {
|
||||
limiter.increment(24);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int length = stream.readInt();
|
||||
|
||||
if (length >= 1 << 24)
|
||||
if (length >= 1 << 24) {
|
||||
throw new IllegalArgumentException("Int array length is too large: " + length);
|
||||
|
||||
limiter.checkReadability(length * 4);
|
||||
limiter.increment(length * 4);
|
||||
}
|
||||
limiter.increment(length * Integer.BYTES);
|
||||
limiter.checkReadability(length * Integer.BYTES);
|
||||
|
||||
int[] array = new int[length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
@@ -181,14 +213,13 @@ public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
|
||||
registerType(
|
||||
NBTType.LONG_ARRAY, 12,
|
||||
(limiter, stream) -> {
|
||||
limiter.increment(24);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int length = stream.readInt();
|
||||
|
||||
if (length >= 1 << 24)
|
||||
if (length >= 1 << 24) {
|
||||
throw new IllegalArgumentException("Long array length is too large: " + length);
|
||||
|
||||
limiter.checkReadability(length * 8);
|
||||
limiter.increment(length * 8);
|
||||
}
|
||||
limiter.increment(length * Long.BYTES);
|
||||
limiter.checkReadability(length * Long.BYTES);
|
||||
|
||||
long[] array = new long[length];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
@@ -206,4 +237,10 @@ public class DefaultNBTSerializer extends NBTSerializer<DataInput, DataOutput> {
|
||||
);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static String readString(NBTLimiter limiter, DataInput input) throws IOException {
|
||||
String string = input.readUTF();
|
||||
limiter.increment(STRING_SIZE_BYTES + Character.BYTES * string.length());
|
||||
return string;
|
||||
}
|
||||
}
|
||||
+4
@@ -21,12 +21,14 @@ package com.github.retrooper.packetevents.protocol.nbt.serializer;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLimiter;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@ApiStatus.NonExtendable
|
||||
public class NBTSerializer<IN, OUT> implements NBTReader<NBT, IN>, NBTWriter<NBT, OUT> {
|
||||
|
||||
protected final IdReader<IN> idReader;
|
||||
@@ -37,6 +39,7 @@ public class NBTSerializer<IN, OUT> implements NBTReader<NBT, IN>, NBTWriter<NBT
|
||||
protected final Map<NBTType<? extends NBT>, Integer> typeToId = new HashMap<>();
|
||||
protected final Map<NBTType<? extends NBT>, TagReader<IN, ? extends NBT>> typeReaders = new HashMap<>();
|
||||
protected final Map<NBTType<? extends NBT>, TagWriter<OUT, ? extends NBT>> typeWriters = new HashMap<>();
|
||||
|
||||
public NBTSerializer(
|
||||
IdReader<IN> idReader, IdWriter<OUT> idWriter,
|
||||
NameReader<IN> nameReader, NameWriter<OUT> nameWriter
|
||||
@@ -98,6 +101,7 @@ public class NBTSerializer<IN, OUT> implements NBTReader<NBT, IN>, NBTWriter<NBT
|
||||
return type;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
String readTagName(NBTLimiter limiter, IN from) throws IOException {
|
||||
return nameReader.readName(limiter, from);
|
||||
}
|
||||
|
||||
+157
-143
@@ -17,11 +17,30 @@
|
||||
*/
|
||||
package com.github.retrooper.packetevents.protocol.nbt.serializer;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.*;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTLimiter;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.github.retrooper.packetevents.protocol.nbt.serializer.DefaultNBTSerializer.ARRAY_HEADER_BYTES;
|
||||
import static com.github.retrooper.packetevents.protocol.nbt.serializer.DefaultNBTSerializer.OBJECT_HEADER_BYTES;
|
||||
import static com.github.retrooper.packetevents.protocol.nbt.serializer.DefaultNBTSerializer.OBJECT_REF_BYTES;
|
||||
import static com.github.retrooper.packetevents.protocol.nbt.serializer.DefaultNBTSerializer.STRING_SIZE_BYTES;
|
||||
|
||||
public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream> {
|
||||
|
||||
@@ -42,9 +61,9 @@ public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream
|
||||
|
||||
NBT nbt;
|
||||
if (type == NBTType.COMPOUND) {
|
||||
nbt = new Compound(from, limiter, () -> {});
|
||||
nbt = new Compound(from, limiter, () -> { /**/ });
|
||||
} else if (type == NBTType.LIST) {
|
||||
nbt = new List(from, limiter, () -> {});
|
||||
nbt = new List(from, limiter, () -> { /**/ });
|
||||
} else {
|
||||
nbt = DefaultNBTSerializer.INSTANCE.readTag(limiter, from, type);
|
||||
}
|
||||
@@ -120,7 +139,7 @@ public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream
|
||||
try {
|
||||
hasReadType = false;
|
||||
|
||||
String name = DefaultNBTSerializer.INSTANCE.readTagName(limiter, stream);
|
||||
String name = DefaultNBTSerializer.readString(limiter, stream);
|
||||
|
||||
if (nextType == NBTType.COMPOUND) {
|
||||
lastRead = new Compound(stream, limiter, this::runCompleted);
|
||||
@@ -209,7 +228,7 @@ public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream
|
||||
|
||||
// we have read a tag type, so we can start reading the tag
|
||||
do {
|
||||
String name = DefaultNBTSerializer.INSTANCE.readTagName(limiter, stream);
|
||||
String name = DefaultNBTSerializer.readString(limiter, stream);
|
||||
NBT nbt = DefaultNBTSerializer.INSTANCE.readTag(limiter, stream, nextType);
|
||||
limiter.increment(36);
|
||||
compound.setTag(name, nbt);
|
||||
@@ -230,7 +249,7 @@ public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream
|
||||
((Skippable) lastRead).skip();
|
||||
}
|
||||
|
||||
if (!hasNext()) return new byte[] { 10, 0 }; // empty compound
|
||||
if (!hasNext()) return new byte[]{10, 0}; // empty compound
|
||||
|
||||
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes)) {
|
||||
out.write(10); // compound type
|
||||
@@ -417,7 +436,7 @@ public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream
|
||||
((Skippable) lastRead).skip();
|
||||
}
|
||||
|
||||
if (!hasNext()) return new byte[] { 9 };
|
||||
if (!hasNext()) return new byte[]{9};
|
||||
|
||||
byte[] array = null;
|
||||
for (int i = 0; i < remaining; i++) {
|
||||
@@ -470,229 +489,224 @@ public final class SequentialNBTReader implements NBTReader<NBT, DataInputStream
|
||||
|
||||
static {
|
||||
TAG_SKIPS.put(NBTType.BYTE, (limiter, in) -> {
|
||||
limiter.increment(9);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Byte.BYTES);
|
||||
in.skipBytes(Byte.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.SHORT, (limiter, in) -> {
|
||||
limiter.increment(10);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Short.BYTES);
|
||||
in.skipBytes(Short.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.INT, (limiter, in) -> {
|
||||
limiter.increment(12);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Integer.BYTES);
|
||||
in.skipBytes(Integer.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.LONG, (limiter, in) -> {
|
||||
limiter.increment(16);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Long.BYTES);
|
||||
in.skipBytes(Long.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.FLOAT, (limiter, in) -> {
|
||||
limiter.increment(12);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Float.BYTES);
|
||||
in.skipBytes(Float.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.DOUBLE, (limiter, in) -> {
|
||||
limiter.increment(16);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Double.BYTES);
|
||||
in.skipBytes(Double.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.BYTE_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(24);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int length = in.readInt();
|
||||
|
||||
limiter.checkReadability(length);
|
||||
limiter.increment(length);
|
||||
|
||||
limiter.increment(length * Byte.BYTES);
|
||||
limiter.checkReadability(length * Byte.BYTES);
|
||||
in.skipBytes(length);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.STRING, (limiter, in) -> {
|
||||
limiter.increment(36);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + STRING_SIZE_BYTES);
|
||||
int length = in.readUnsignedShort();
|
||||
limiter.increment(length * 2);
|
||||
limiter.increment(length * Character.BYTES);
|
||||
in.skipBytes(length);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.LIST, (limiter, in) -> {
|
||||
limiter.increment(37);
|
||||
NBTType<?> listType = DefaultNBTSerializer.INSTANCE.readTagType(limiter, in);
|
||||
int length = in.readInt();
|
||||
limiter.increment(length * 4);
|
||||
for (int i = 0; i < length; i++) {
|
||||
TAG_SKIPS.get(listType).skip(limiter, in);
|
||||
limiter.enterDepth();
|
||||
try {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + OBJECT_REF_BYTES // list tag
|
||||
+ OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES); // arraylist
|
||||
NBTType<?> listType = DefaultNBTSerializer.INSTANCE.readTagType(limiter, in);
|
||||
int length = in.readInt();
|
||||
limiter.increment(length * OBJECT_REF_BYTES);
|
||||
for (int i = 0; i < length; i++) {
|
||||
TAG_SKIPS.get(listType).skip(limiter, in);
|
||||
}
|
||||
} finally {
|
||||
limiter.exitDepth();
|
||||
}
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.COMPOUND, (limiter, in) -> {
|
||||
limiter.increment(48);
|
||||
NBTType<?> valueType;
|
||||
while ((valueType = DefaultNBTSerializer.INSTANCE.readTagType(limiter, in)) != NBTType.END) {
|
||||
int utfLen = in.readUnsignedShort();
|
||||
in.skipBytes(utfLen);
|
||||
limiter.increment(36);
|
||||
TAG_SKIPS.get(valueType).skip(limiter, in);
|
||||
limiter.enterDepth();
|
||||
try {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + OBJECT_REF_BYTES // compound tag
|
||||
+ OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES + Integer.BYTES + Integer.BYTES + Float.BYTES); // hashmap
|
||||
Set<String> names = new HashSet<>();
|
||||
NBTType<?> valueType;
|
||||
while ((valueType = DefaultNBTSerializer.INSTANCE.readTagType(limiter, in)) != NBTType.END) {
|
||||
String name = DefaultNBTSerializer.readString(limiter, in);
|
||||
if (names.add(name)) {
|
||||
limiter.increment(12 + OBJECT_HEADER_BYTES + Integer.BYTES + OBJECT_REF_BYTES + OBJECT_REF_BYTES + OBJECT_REF_BYTES);
|
||||
}
|
||||
TAG_SKIPS.get(valueType).skip(limiter, in);
|
||||
}
|
||||
} finally {
|
||||
limiter.exitDepth();
|
||||
}
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.INT_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(24);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int length = in.readInt();
|
||||
|
||||
limiter.checkReadability(length * 4);
|
||||
limiter.increment(length * 4);
|
||||
|
||||
limiter.increment(length * Integer.BYTES);
|
||||
limiter.checkReadability(length * Integer.BYTES);
|
||||
in.skipBytes(length * Integer.BYTES);
|
||||
});
|
||||
TAG_SKIPS.put(NBTType.LONG_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(24);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int length = in.readInt();
|
||||
|
||||
limiter.checkReadability(length * 8);
|
||||
limiter.increment(length * 8);
|
||||
|
||||
limiter.increment(length * Long.BYTES);
|
||||
limiter.checkReadability(length * Long.BYTES);
|
||||
in.skipBytes(length * Long.BYTES);
|
||||
});
|
||||
|
||||
TAG_BINARY_READERS.put(NBTType.BYTE, (limiter, in) -> {
|
||||
limiter.increment(9);
|
||||
return new byte[] { in.readByte() };
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Byte.BYTES);
|
||||
return new byte[]{in.readByte()};
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.SHORT, (limiter, in) -> {
|
||||
limiter.increment(10);
|
||||
return new byte[] { in.readByte(), in.readByte() };
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Short.BYTES);
|
||||
return new byte[]{in.readByte(), in.readByte()};
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.INT, (limiter, in) -> {
|
||||
limiter.increment(12);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Integer.BYTES);
|
||||
byte[] bytes = new byte[Integer.BYTES];
|
||||
in.readFully(bytes);
|
||||
return bytes;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.LONG, (limiter, in) -> {
|
||||
limiter.increment(16);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Long.BYTES);
|
||||
byte[] bytes = new byte[Long.BYTES];
|
||||
in.readFully(bytes);
|
||||
return bytes;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.FLOAT, (limiter, in) -> {
|
||||
limiter.increment(12);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Float.BYTES);
|
||||
byte[] bytes = new byte[Float.BYTES];
|
||||
in.readFully(bytes);
|
||||
return bytes;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.DOUBLE, (limiter, in) -> {
|
||||
limiter.increment(16);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + Double.BYTES);
|
||||
byte[] bytes = new byte[Double.BYTES];
|
||||
in.readFully(bytes);
|
||||
return bytes;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.BYTE_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(24);
|
||||
byte[] length = new byte[Integer.BYTES];
|
||||
in.readFully(length);
|
||||
int len = bytesToInt(length);
|
||||
|
||||
if (len >= 1 << 24)
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int len = in.readInt();
|
||||
if (len >= 1 << 24) {
|
||||
throw new IllegalArgumentException("Byte array length is too large: " + len);
|
||||
|
||||
limiter.checkReadability(len);
|
||||
limiter.increment(len);
|
||||
}
|
||||
limiter.increment(len * Byte.BYTES);
|
||||
limiter.checkReadability(len * Byte.BYTES);
|
||||
|
||||
byte[] array = new byte[Integer.BYTES + len];
|
||||
System.arraycopy(length, 0, array, 0, Integer.BYTES);
|
||||
intToBytes(array, len, 0);
|
||||
in.readFully(array, Integer.BYTES, len);
|
||||
return array;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.STRING, (limiter, in) -> {
|
||||
limiter.increment(36);
|
||||
byte[] length = new byte[Short.BYTES];
|
||||
in.readFully(length);
|
||||
// read len
|
||||
short signedVal = (short) ((length[0] & 0xFF) << 8 | (length[1] & 0xFF));
|
||||
int len = signedVal >= 0 ? signedVal : 0x10000 + signedVal;
|
||||
limiter.increment(OBJECT_HEADER_BYTES + STRING_SIZE_BYTES);
|
||||
String string = in.readUTF();
|
||||
limiter.increment(string.length() * Character.BYTES);
|
||||
|
||||
limiter.increment(len * 2);
|
||||
|
||||
byte[] array = new byte[Short.BYTES + len];
|
||||
System.arraycopy(length, 0, array, 0, Short.BYTES);
|
||||
in.readFully(array, Short.BYTES, len);
|
||||
return array;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.LIST, (limiter, in) -> {
|
||||
limiter.increment(37);
|
||||
byte type = in.readByte();
|
||||
NBTType<? extends NBT> nbtType = DefaultNBTSerializer.INSTANCE.idToType.get((int) type);
|
||||
|
||||
byte[] length = new byte[Integer.BYTES];
|
||||
in.readFully(length);
|
||||
int len = bytesToInt(length);
|
||||
|
||||
limiter.increment(len * 4);
|
||||
|
||||
byte[] array = null;
|
||||
for (int i = 0; i < len; i++) {
|
||||
byte[] element = TAG_BINARY_READERS.get(nbtType).read(limiter, in);
|
||||
|
||||
if (array == null) {
|
||||
array = new byte[1 + Integer.BYTES + len * element.length]; // all the remaining child tags will be of same size
|
||||
array[0] = type;
|
||||
System.arraycopy(length, 0, array, 1, Integer.BYTES);
|
||||
}
|
||||
|
||||
System.arraycopy(element, 0, array, 1 + Integer.BYTES + i * element.length, element.length);
|
||||
}
|
||||
return array;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.COMPOUND, (limiter, in) -> {
|
||||
limiter.increment(48);
|
||||
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bytes)) {
|
||||
byte type;
|
||||
while ((type = in.readByte()) != 0) {
|
||||
out.writeByte(type);
|
||||
|
||||
// name
|
||||
byte[] name = TAG_BINARY_READERS.get(NBTType.STRING).read(NBTLimiter.noop(), in);
|
||||
limiter.increment(name.length * 2 + 28);
|
||||
out.write(name);
|
||||
|
||||
// nbt
|
||||
byte[] nbt = TAG_BINARY_READERS.get(DefaultNBTSerializer.INSTANCE.idToType.get((int) type)).read(limiter, in);
|
||||
limiter.increment(36);
|
||||
|
||||
out.write(nbt);
|
||||
}
|
||||
|
||||
out.write(0); // end
|
||||
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(bytes)) {
|
||||
out.writeUTF(string);
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.INT_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(24);
|
||||
byte[] length = new byte[Integer.BYTES];
|
||||
in.readFully(length);
|
||||
int len = bytesToInt(length);
|
||||
TAG_BINARY_READERS.put(NBTType.LIST, (limiter, in) -> {
|
||||
limiter.enterDepth();
|
||||
try {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + OBJECT_REF_BYTES // list tag
|
||||
+ OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES); // arraylist
|
||||
byte type = in.readByte();
|
||||
NBTType<? extends NBT> nbtType = DefaultNBTSerializer.INSTANCE.idToType.get((int) type);
|
||||
|
||||
limiter.checkReadability(len * 4);
|
||||
limiter.increment(len * 4);
|
||||
int len = in.readInt();
|
||||
limiter.increment(len * OBJECT_REF_BYTES);
|
||||
|
||||
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(bytes)) {
|
||||
out.write(type);
|
||||
out.writeInt(len);
|
||||
for (int i = 0; i < len; i++) {
|
||||
out.write(TAG_BINARY_READERS.get(nbtType).read(limiter, in));
|
||||
}
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
} finally {
|
||||
limiter.exitDepth();
|
||||
}
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.COMPOUND, (limiter, in) -> {
|
||||
limiter.enterDepth();
|
||||
try {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + OBJECT_REF_BYTES // compound tag
|
||||
+ OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES + Integer.BYTES + Integer.BYTES + Float.BYTES); // hashmap
|
||||
try (ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(bytes)) {
|
||||
Set<String> names = new HashSet<>();
|
||||
byte type;
|
||||
while ((type = in.readByte()) != 0) {
|
||||
out.write(type);
|
||||
String name = DefaultNBTSerializer.readString(limiter, in);
|
||||
out.writeUTF(name);
|
||||
out.write(TAG_BINARY_READERS.get(DefaultNBTSerializer.INSTANCE.idToType.get((int) type)).read(limiter, in));
|
||||
if (names.add(name)) {
|
||||
limiter.increment(12 + OBJECT_HEADER_BYTES + Integer.BYTES + OBJECT_REF_BYTES + OBJECT_REF_BYTES + OBJECT_REF_BYTES);
|
||||
}
|
||||
}
|
||||
out.write(type);
|
||||
return bytes.toByteArray();
|
||||
}
|
||||
} finally {
|
||||
limiter.exitDepth();
|
||||
}
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.INT_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int len = in.readInt();
|
||||
limiter.increment(len * Integer.BYTES);
|
||||
limiter.checkReadability(len * Integer.BYTES);
|
||||
|
||||
byte[] array = new byte[Integer.BYTES + len * Integer.BYTES];
|
||||
System.arraycopy(length, 0, array, 0, Integer.BYTES);
|
||||
intToBytes(array, len, 0);
|
||||
in.readFully(array, Integer.BYTES, len * Integer.BYTES);
|
||||
return array;
|
||||
});
|
||||
TAG_BINARY_READERS.put(NBTType.LONG_ARRAY, (limiter, in) -> {
|
||||
limiter.increment(24);
|
||||
byte[] length = new byte[Integer.BYTES];
|
||||
in.readFully(length);
|
||||
int len = bytesToInt(length);
|
||||
|
||||
limiter.checkReadability(len * 8);
|
||||
limiter.increment(len * 8);
|
||||
limiter.increment(OBJECT_HEADER_BYTES + ARRAY_HEADER_BYTES + Integer.BYTES);
|
||||
int len = in.readInt();
|
||||
limiter.increment(len * Long.BYTES);
|
||||
limiter.checkReadability(len * Long.BYTES);
|
||||
|
||||
byte[] array = new byte[Integer.BYTES + len * Long.BYTES];
|
||||
System.arraycopy(length, 0, array, 0, Integer.BYTES);
|
||||
intToBytes(array, len, 0);
|
||||
in.readFully(array, Integer.BYTES, len * Long.BYTES);
|
||||
return array;
|
||||
});
|
||||
}
|
||||
|
||||
private static int bytesToInt(byte[] bytes) {
|
||||
return ((bytes[0] & 0xFF) << 24) |
|
||||
((bytes[1] & 0xFF) << 16) |
|
||||
((bytes[2] & 0xFF) << 8 ) |
|
||||
((bytes[3] & 0xFF));
|
||||
public static void intToBytes(byte[] array, int val, int offset) {
|
||||
array[offset] = (byte) ((val >>> 24) & 0xFF);
|
||||
array[offset + 1] = (byte) ((val >>> 16) & 0xFF);
|
||||
array[offset + 2] = (byte) ((val >>> 8) & 0xFF);
|
||||
array[offset + 3] = (byte) (val & 0xFF);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,16 +19,16 @@
|
||||
package com.github.retrooper.packetevents.protocol.world;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.world.states.enums.Axis;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.github.retrooper.packetevents.util.Vector3i;
|
||||
|
||||
// From MCProtocolLib
|
||||
public enum Direction {
|
||||
DOWN(-1, Axis.Z, new Vector3i(0 , -1, 0)),
|
||||
UP(-1, Axis.Z, new Vector3i(0, 1, 0)),
|
||||
NORTH(0, Axis.Y, new Vector3i(0 , 0, -1)),
|
||||
SOUTH(1, Axis.Y, new Vector3i(0 ,0 ,1)),
|
||||
WEST(2, Axis.X, new Vector3i(-1, 0 ,0)),
|
||||
|
||||
DOWN(-1, Axis.Y, new Vector3i(0, -1, 0)),
|
||||
UP(-1, Axis.Y, new Vector3i(0, 1, 0)),
|
||||
NORTH(0, Axis.Z, new Vector3i(0, 0, -1)),
|
||||
SOUTH(1, Axis.Z, new Vector3i(0, 0, 1)),
|
||||
WEST(2, Axis.X, new Vector3i(-1, 0, 0)),
|
||||
EAST(3, Axis.X, new Vector3i(1, 0, 0));
|
||||
|
||||
private final int horizontalIndex;
|
||||
@@ -63,4 +63,4 @@ public enum Direction {
|
||||
public Axis getAxis() {
|
||||
return this.axis;
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -33,6 +33,10 @@ public class WrapperPlayServerBlockChange extends PacketWrapper<WrapperPlayServe
|
||||
super(event);
|
||||
}
|
||||
|
||||
public WrapperPlayServerBlockChange(Vector3i blockPosition, WrappedBlockState state) {
|
||||
this(blockPosition, state.getGlobalId());
|
||||
}
|
||||
|
||||
public WrapperPlayServerBlockChange(Vector3i blockPosition, int blockID) {
|
||||
super(PacketType.Play.Server.BLOCK_CHANGE);
|
||||
this.blockPosition = blockPosition;
|
||||
|
||||
+7
-2
@@ -194,8 +194,13 @@ public class WrapperPlayServerChunkData extends PacketWrapper<WrapperPlayServerC
|
||||
// verify the full chunk has been read
|
||||
int readerIndex = ByteBufHelper.readerIndex(this.buffer);
|
||||
if (expectedReaderIndex != readerIndex) {
|
||||
throw new RuntimeException("Error while decoding chunk at " + chunkX + " " + chunkZ
|
||||
+ "; expected reader index " + expectedReaderIndex + ", got " + readerIndex);
|
||||
if (expectedReaderIndex < readerIndex) {
|
||||
// we advanced too far, error
|
||||
throw new RuntimeException("Error while decoding chunk at " + chunkX + " " + chunkZ
|
||||
+ "; expected reader index " + expectedReaderIndex + ", got " + readerIndex);
|
||||
}
|
||||
// we didn't read the whole buffer, skip the rest
|
||||
ByteBufHelper.readerIndex(this.buffer, expectedReaderIndex);
|
||||
}
|
||||
} finally {
|
||||
// change buffer back if it has been switched
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.github.retrooper.packetevents.test.base;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.MockPlugin;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.mockbukkit.mockbukkit.MockBukkit;
|
||||
import org.mockbukkit.mockbukkit.ServerMock;
|
||||
import org.mockbukkit.mockbukkit.plugin.PluginMock;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public abstract class BaseDummyAPITest {
|
||||
@@ -13,7 +13,7 @@ public abstract class BaseDummyAPITest {
|
||||
public static final Logger LOGGER = TestPacketEventsBuilder.LOGGER;
|
||||
|
||||
private ServerMock server;
|
||||
private MockPlugin plugin;
|
||||
private PluginMock plugin;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
[versions]
|
||||
shadow = "8.3.3"
|
||||
shadow = "8.3.8"
|
||||
jetbrains-annotations = "23.0.0"
|
||||
via-nbt = "4.1.0"
|
||||
via-nbt = "5.1.2"
|
||||
fast-util = "8.5.6"
|
||||
gson = "2.8.9"
|
||||
java-diff-utils = "4.12"
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
package com.github.retrooper.compression
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag
|
||||
import com.github.steveice10.opennbt.tag.io.NBTIO
|
||||
import com.github.steveice10.opennbt.tag.io.TagWriter
|
||||
import com.viaversion.nbt.tag.Tag
|
||||
import com.viaversion.nbt.io.NBTIO
|
||||
import com.viaversion.nbt.io.TagWriter
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonArray
|
||||
import com.google.gson.JsonElement
|
||||
|
||||
+6
-6
@@ -23,12 +23,12 @@ import com.github.difflib.patch.ChangeDelta
|
||||
import com.github.difflib.patch.DeleteDelta
|
||||
import com.github.difflib.patch.InsertDelta
|
||||
import com.github.retrooper.compression.asStringList
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag
|
||||
import com.viaversion.nbt.tag.ByteTag
|
||||
import com.viaversion.nbt.tag.CompoundTag
|
||||
import com.viaversion.nbt.tag.IntTag
|
||||
import com.viaversion.nbt.tag.ListTag
|
||||
import com.viaversion.nbt.tag.StringTag
|
||||
import com.viaversion.nbt.tag.Tag
|
||||
import com.google.gson.JsonElement
|
||||
|
||||
object JsonArrayCompressionStrategy : JsonCompressionStrategy() {
|
||||
|
||||
+4
-4
@@ -18,10 +18,10 @@
|
||||
|
||||
package com.github.retrooper.compression.strategy.json
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag
|
||||
import com.viaversion.nbt.tag.ByteArrayTag
|
||||
import com.viaversion.nbt.tag.ByteTag
|
||||
import com.viaversion.nbt.tag.CompoundTag
|
||||
import com.viaversion.nbt.tag.Tag
|
||||
import com.google.gson.JsonElement
|
||||
import java.util.*
|
||||
|
||||
|
||||
+3
-3
@@ -20,9 +20,9 @@ package com.github.retrooper.compression.strategy.json
|
||||
import com.github.retrooper.compression.CompressionUtil
|
||||
import com.github.retrooper.compression.EntryVersion
|
||||
import com.github.retrooper.compression.strategy.CompressionStrategy
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag
|
||||
import com.viaversion.nbt.tag.ByteTag
|
||||
import com.viaversion.nbt.tag.CompoundTag
|
||||
import com.viaversion.nbt.tag.Tag
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonObject
|
||||
import java.nio.file.Path
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ import com.github.difflib.patch.ChangeDelta
|
||||
import com.github.difflib.patch.DeleteDelta
|
||||
import com.github.difflib.patch.InsertDelta
|
||||
import com.github.retrooper.compression.asPrimitiveMap
|
||||
import com.github.steveice10.opennbt.tag.builtin.*
|
||||
import com.viaversion.nbt.tag.*
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.JsonPrimitive
|
||||
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
package com.github.retrooper.compression.strategy.json
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.*
|
||||
import com.viaversion.nbt.tag.*
|
||||
import com.google.gson.JsonElement
|
||||
import com.google.gson.internal.LazilyParsedNumber
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
org.gradle.jvmargs=-Xmx2000m
|
||||
|
||||
# TODO UPDATE
|
||||
fullVersion=2.9.4
|
||||
fullVersion=2.9.5
|
||||
snapshot=false
|
||||
|
||||
publishing.display_name=PacketEvents
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ bungeecord = "1.21-R0.1-SNAPSHOT"
|
||||
velocity = "3.4.0-SNAPSHOT"
|
||||
run-paper = "2.3.1"
|
||||
fabric-loom = "1.11.4"
|
||||
spongeGradle = "2.2.0"
|
||||
spongeGradle = "2.3.0"
|
||||
classgraph = "4.8.179"
|
||||
|
||||
[libraries]
|
||||
|
||||
+2
-1
@@ -20,6 +20,7 @@ package io.github.retrooper.packetevents.bukkit;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.PacketEventsAPI;
|
||||
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.util.FakeChannelUtil;
|
||||
import io.github.retrooper.packetevents.injector.SpigotChannelInjector;
|
||||
@@ -103,7 +104,7 @@ public class InternalBukkitListener implements Listener {
|
||||
// delay by a tick
|
||||
FoliaScheduler.getEntityScheduler().runDelayed(player, this.plugin, __ -> {
|
||||
// only kick if the player is actually still connected
|
||||
if (player.isConnected()) {
|
||||
if (channel != null ? ChannelHelper.isOpen(channel) : player.isOnline()) {
|
||||
player.kickPlayer(KICK_MESSAGE);
|
||||
}
|
||||
}, null, 0);
|
||||
|
||||
+11
-4
@@ -35,6 +35,7 @@ import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -58,10 +59,10 @@ public class SpigotChannelInjector implements ChannelInjector {
|
||||
public boolean isPlayerSet(Object channel) {
|
||||
if (channel == null) return false;
|
||||
PacketEventsEncoder encoder = getEncoder((Channel) channel);
|
||||
if (encoder.player != null) return true;
|
||||
if (encoder != null && encoder.player != null) return true;
|
||||
|
||||
PacketEventsDecoder decoder = getDecoder((Channel) channel);
|
||||
return decoder.player != null;
|
||||
return decoder != null && decoder.player != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,11 +228,17 @@ public class SpigotChannelInjector implements ChannelInjector {
|
||||
}
|
||||
}
|
||||
|
||||
private PacketEventsEncoder getEncoder(Channel channel) {
|
||||
/**
|
||||
* @return may return null if the channel is closed already or not initialized yet
|
||||
*/
|
||||
private @Nullable PacketEventsEncoder getEncoder(Channel channel) {
|
||||
return (PacketEventsEncoder) channel.pipeline().get(PacketEvents.ENCODER_NAME);
|
||||
}
|
||||
|
||||
private PacketEventsDecoder getDecoder(Channel channel) {
|
||||
/**
|
||||
* @return may return null if the channel is closed already or not initialized yet
|
||||
*/
|
||||
private @Nullable PacketEventsDecoder getDecoder(Channel channel) {
|
||||
return (PacketEventsDecoder) channel.pipeline().get(PacketEvents.DECODER_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
[versions]
|
||||
mockbukkit = "3.131.0"
|
||||
mockbukkit = "4.72.2"
|
||||
slf4j = "2.0.16"
|
||||
junit = "5.11.2"
|
||||
|
||||
[libraries]
|
||||
mockbukkit = { group = "com.github.seeseemelk", name = "MockBukkit-v1.21", version.ref = "mockbukkit" }
|
||||
mockbukkit = { group = "org.mockbukkit.mockbukkit", name = "mockbukkit-v1.21", version.ref = "mockbukkit" }
|
||||
slf4j = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
|
||||
junit-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit" }
|
||||
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit" }
|
||||
|
||||
Reference in new issue
Block a user