Skip to content

Commit 99ea6c3

Browse files
committed
Add client and server protocol to informative exception data
1 parent cf231d9 commit 99ea6c3

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

api/src/main/java/com/viaversion/viaversion/api/minecraft/BlockChangeRecord1_16_2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public byte getSectionZ() {
5858

5959
@Override
6060
public short getY(int chunkSectionY) {
61-
Preconditions.checkArgument(chunkSectionY >= 0, "Invalid chunkSectionY: " + chunkSectionY);
61+
Preconditions.checkArgument(chunkSectionY >= 0, "Invalid chunkSectionY: %s", chunkSectionY);
6262
return (short) ((chunkSectionY << 4) + sectionY);
6363
}
6464

api/src/main/java/com/viaversion/viaversion/api/type/types/BitSetType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class BitSetType extends Type<BitSet> {
3636
public BitSetType(final int length) {
3737
super(BitSet.class);
3838
this.length = length;
39-
this.bytesLength = -Math.floorDiv(-length, 8); // Ceiled quotient
39+
this.bytesLength = (int) Math.ceil(length / 8D);
4040
}
4141

4242
@Override
@@ -48,8 +48,8 @@ public BitSet read(ByteBuf buffer) {
4848

4949
@Override
5050
public void write(ByteBuf buffer, BitSet object) {
51-
Preconditions.checkArgument(object.length() <= length, "BitSet of length " + object.length() + " larger than max length " + length);
51+
Preconditions.checkArgument(object.length() <= length, "BitSet of length %s larger than max length %s", object.length(), length);
5252
final byte[] bytes = object.toByteArray();
53-
buffer.writeBytes(Arrays.copyOf(bytes, bytesLength));
53+
buffer.writeBytes(bytes.length == bytesLength ? bytes : Arrays.copyOf(bytes, bytesLength));
5454
}
5555
}

common/src/main/java/com/viaversion/viaversion/protocol/packet/PacketWrapperImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,13 @@ public void writeProcessedValues(ByteBuf buffer) throws InformativeException {
263263
}
264264

265265
private InformativeException createInformativeException(final Exception cause, final Type<?> type, final int index) {
266+
final ProtocolInfo protocolInfo = this.user().getProtocolInfo();
266267
return new InformativeException(cause)
267268
.set("Packet Type", this.packetType)
268269
.set("Index", index)
269270
.set("Type", type.getTypeName())
271+
.set("Client Protocol", protocolInfo.protocolVersion().getName())
272+
.set("Server Protocol", protocolInfo.serverProtocolVersion().getName())
270273
.set("Data", this.packetValues)
271274
.set("Packet ID", this.id);
272275
}

0 commit comments

Comments
 (0)