Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
andantet committed Dec 15, 2023
2 parents c140f84 + 21ae82e commit 51cc1f7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
5 changes: 5 additions & 0 deletions proxy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ tasks {
exclude("org/checkerframework/checker/**")

relocate("org.bstats", "com.velocitypowered.proxy.bstats")

// Include Configurate 3
val configurateBuildTask = project(":deprecated-configurate3").tasks.named("shadowJar")
dependsOn(configurateBuildTask)
from(zipTree(configurateBuildTask.map { it.outputs.files.singleFile }))
}
}

Expand Down
13 changes: 13 additions & 0 deletions proxy/deprecated/configurate3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
alias(libs.plugins.shadow)
}

dependencies {
implementation(libs.bundles.configurate3)
}

tasks.shadowJar {
exclude("com/google/**")
exclude("com/typesafe/**")
exclude("org/yaml/**")
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@
import io.netty.handler.codec.CorruptedFrameException;
import io.netty.handler.codec.DecoderException;
import io.netty.handler.codec.EncoderException;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.BinaryTag;
import net.kyori.adventure.nbt.BinaryTagIO;
import net.kyori.adventure.nbt.BinaryTagType;
import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

Expand All @@ -64,6 +65,11 @@ public enum ProtocolUtils {
.build();

public static final int DEFAULT_MAX_STRING_SIZE = 65536 * 8; // 64KiB
private static final BinaryTagType<? extends BinaryTag>[] BINARY_TAG_TYPES = new BinaryTagType[] {
BinaryTagTypes.END, BinaryTagTypes.BYTE, BinaryTagTypes.SHORT, BinaryTagTypes.INT,
BinaryTagTypes.LONG, BinaryTagTypes.FLOAT, BinaryTagTypes.DOUBLE,
BinaryTagTypes.BYTE_ARRAY, BinaryTagTypes.STRING, BinaryTagTypes.LIST,
BinaryTagTypes.COMPOUND, BinaryTagTypes.INT_ARRAY, BinaryTagTypes.LONG_ARRAY};
private static final QuietDecoderException BAD_VARINT_CACHED =
new QuietDecoderException("Bad VarInt decoded");
private static final int[] VARINT_EXACT_BYTE_LENGTHS = new int[33];
Expand Down Expand Up @@ -367,29 +373,57 @@ public static void writeUuidIntArray(ByteBuf buf, UUID uuid) {
* Reads a {@link net.kyori.adventure.nbt.CompoundBinaryTag} from the {@code buf}.
*
* @param buf the buffer to read from
* @param reader the NBT reader to use
* @param reader the {@link BinaryTagIO.Reader} to use
* @return {@link net.kyori.adventure.nbt.CompoundBinaryTag} the CompoundTag from the buffer
*/
public static CompoundBinaryTag readCompoundTag(ByteBuf buf, BinaryTagIO.Reader reader) {
public static CompoundBinaryTag readCompoundTag(ByteBuf buf, ProtocolVersion version,
BinaryTagIO.Reader reader) {
BinaryTag binaryTag = readBinaryTag(buf, version, reader);
if (binaryTag.type() != BinaryTagTypes.COMPOUND) {
throw new DecoderException(
"Expected root tag to be CompoundTag, but is " + binaryTag.getClass().getSimpleName());
}
return (CompoundBinaryTag) binaryTag;
}

/**
* Reads a {@link net.kyori.adventure.nbt.BinaryTag} from the {@code buf}.
*
* @param buf the buffer to read from
* @param reader the {@link BinaryTagIO.Reader} to use
* @return {@link net.kyori.adventure.nbt.BinaryTag} the BinaryTag from the buffer
*/
public static BinaryTag readBinaryTag(ByteBuf buf, ProtocolVersion version,
BinaryTagIO.Reader reader) {
BinaryTagType<?> type = BINARY_TAG_TYPES[buf.readByte()];
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
buf.skipBytes(buf.readUnsignedShort());
}
try {
return reader.read((DataInput) new ByteBufInputStream(buf));
return type.read(new ByteBufInputStream(buf));
} catch (IOException thrown) {
throw new DecoderException(
"Unable to parse NBT CompoundTag, full error: " + thrown.getMessage());
throw new DecoderException("Unable to parse BinaryTag, full error: " + thrown.getMessage());
}
}

/**
* Writes a CompoundTag to the {@code buf}.
* Writes a {@link net.kyori.adventure.nbt.BinaryTag} to the {@code buf}.
*
* @param buf the buffer to write to
* @param compoundTag the CompoundTag to write
* @param buf the buffer to write to
* @param tag the BinaryTag to write
*/
public static void writeCompoundTag(ByteBuf buf, CompoundBinaryTag compoundTag) {
public static <T extends BinaryTag> void writeBinaryTag(ByteBuf buf, ProtocolVersion version,
T tag) {
BinaryTagType<T> type = (BinaryTagType<T>) tag.type();
buf.writeByte(type.id());
try {
BinaryTagIO.writer().write(compoundTag, (DataOutput) new ByteBufOutputStream(buf));
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
// Empty name
buf.writeShort(0);
}
type.write(tag, new ByteBufOutputStream(buf));
} catch (IOException e) {
throw new EncoderException("Unable to encode NBT CompoundTag");
throw new EncoderException("Unable to encode BinaryTag");
}
}

Expand Down

0 comments on commit 51cc1f7

Please sign in to comment.