--- a/net/minecraft/network/FriendlyByteBuf.java +++ b/net/minecraft/network/FriendlyByteBuf.java @@ -72,6 +72,7 @@ public static final int DEFAULT_NBT_QUOTA = 2097152; private final ByteBuf source; + @Nullable public final java.util.Locale adventure$locale; // Paper - track player's locale for server-side translations public static final short MAX_STRING_LENGTH = Short.MAX_VALUE; public static final int MAX_COMPONENT_STRING_LENGTH = 262144; private static final int PUBLIC_KEY_SIZE = 256; @@ -80,6 +81,7 @@ private static final Gson GSON = new Gson(); public FriendlyByteBuf(ByteBuf parent) { + this.adventure$locale = PacketEncoder.ADVENTURE_LOCALE.get(); // Paper - track player's locale for server-side translations this.source = parent; } @@ -120,11 +122,16 @@ } public void writeJsonWithCodec(Codec codec, T value) { + // Paper start - Adventure; add max length parameter + this.writeJsonWithCodec(codec, value, MAX_STRING_LENGTH); + } + public void writeJsonWithCodec(Codec codec, T value, int maxLength) { + // Paper end - Adventure; add max length parameter DataResult dataresult = codec.encodeStart(JsonOps.INSTANCE, value); this.writeUtf(FriendlyByteBuf.GSON.toJson((JsonElement) dataresult.getOrThrow((s) -> { return new EncoderException("Failed to encode: " + s + " " + String.valueOf(value)); - }))); + })), maxLength); // Paper - Adventure; add max length parameter } public static IntFunction limitValue(IntFunction applier, int max) { @@ -139,7 +146,7 @@ public > C readCollection(IntFunction collectionFactory, StreamDecoder reader) { int i = this.readVarInt(); - C c0 = (Collection) collectionFactory.apply(i); + C c0 = collectionFactory.apply(i); // CraftBukkit - decompile error for (int j = 0; j < i; ++j) { c0.add(reader.decode(this)); @@ -150,7 +157,7 @@ public void writeCollection(Collection collection, StreamEncoder writer) { this.writeVarInt(collection.size()); - Iterator iterator = collection.iterator(); + Iterator iterator = collection.iterator(); // CraftBukkit - decompile error while (iterator.hasNext()) { T t0 = iterator.next(); @@ -177,12 +184,12 @@ public void writeIntIdList(IntList list) { this.writeVarInt(list.size()); - list.forEach(this::writeVarInt); + list.forEach((java.util.function.IntConsumer) this::writeVarInt); // CraftBukkit - decompile error } public > M readMap(IntFunction mapFactory, StreamDecoder keyReader, StreamDecoder valueReader) { int i = this.readVarInt(); - M m0 = (Map) mapFactory.apply(i); + M m0 = mapFactory.apply(i); // CraftBukkit - decompile error for (int j = 0; j < i; ++j) { K k0 = keyReader.decode(this); @@ -216,7 +223,7 @@ } public > void writeEnumSet(EnumSet enumSet, Class type) { - E[] ae = (Enum[]) type.getEnumConstants(); + E[] ae = type.getEnumConstants(); // CraftBukkit - decompile error BitSet bitset = new BitSet(ae.length); for (int i = 0; i < ae.length; ++i) { @@ -227,7 +234,7 @@ } public > EnumSet readEnumSet(Class type) { - E[] ae = (Enum[]) type.getEnumConstants(); + E[] ae = type.getEnumConstants(); // CraftBukkit - decompile error BitSet bitset = this.readFixedBitSet(ae.length); EnumSet enumset = EnumSet.noneOf(type); @@ -498,7 +505,7 @@ } public > T readEnum(Class enumClass) { - return ((Enum[]) enumClass.getEnumConstants())[this.readVarInt()]; + return ((T[]) enumClass.getEnumConstants())[this.readVarInt()]; // CraftBukkit - fix decompile error } public FriendlyByteBuf writeEnum(Enum instance) { @@ -565,7 +572,7 @@ try { NbtIo.writeAnyTag((Tag) nbt, new ByteBufOutputStream(buf)); - } catch (IOException ioexception) { + } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception throw new EncoderException(ioexception); } }