Skip to content

Commit f95ec49

Browse files
committed
Properly pass on packet type in PacketWrapper.create
1 parent 1be574b commit f95ec49

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

api/src/main/java/com/viaversion/viaversion/api/protocol/packet/PacketWrapper.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ default void scheduleSend(Class<? extends Protocol> protocol) throws Informative
258258
* @param packetType packet type of the new packet
259259
* @return The newly created packet wrapper
260260
*/
261-
default PacketWrapper create(PacketType packetType) {
262-
return create(packetType.getId());
263-
}
261+
PacketWrapper create(PacketType packetType);
264262

265263
/**
266264
* Creates a new packet with values.
@@ -269,9 +267,7 @@ default PacketWrapper create(PacketType packetType) {
269267
* @param handler handler to write to the packet
270268
* @return newly created packet wrapper
271269
*/
272-
default PacketWrapper create(PacketType packetType, PacketHandler handler) throws InformativeException {
273-
return create(packetType.getId(), handler);
274-
}
270+
PacketWrapper create(PacketType packetType, PacketHandler handler) throws InformativeException;
275271

276272
/**
277273
* Creates a new packet for the target of this packet.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,18 @@ public PacketWrapperImpl create(int packetId, PacketHandler handler) throws Info
429429
return wrapper;
430430
}
431431

432+
@Override
433+
public PacketWrapperImpl create(final PacketType packetType) {
434+
return new PacketWrapperImpl(packetType, null, user());
435+
}
436+
437+
@Override
438+
public PacketWrapperImpl create(final PacketType packetType, final PacketHandler handler) throws InformativeException {
439+
PacketWrapperImpl wrapper = create(packetType);
440+
handler.handle(wrapper);
441+
return wrapper;
442+
}
443+
432444
@Override
433445
public void apply(Direction direction, State state, List<Protocol> pipeline) throws InformativeException, CancelException {
434446
// Indexed loop to allow additions to the tail

common/src/main/java/com/viaversion/viaversion/protocols/v1_20to1_20_2/storage/ConfigurationState.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ public void sendQueuedPackets(final UserConnection connection) {
113113
packetQueue.add(hasJoinGamePacket ? 1 : 0, toQueuedPacket(clientInformationPacket, false, true));
114114
}
115115

116-
final ConfigurationState.QueuedPacket[] queuedPackets = packetQueue.toArray(EMPTY_PACKET_ARRAY);
116+
final QueuedPacket[] queuedPackets = packetQueue.toArray(EMPTY_PACKET_ARRAY);
117117
packetQueue.clear();
118118

119-
for (final ConfigurationState.QueuedPacket packet : queuedPackets) {
119+
for (final QueuedPacket packet : queuedPackets) {
120120
final PacketWrapper queuedWrapper;
121121
try {
122122
if (packet.packetType() != null) {
@@ -176,7 +176,7 @@ public static final class QueuedPacket {
176176
private final int packetId;
177177
private final boolean skipCurrentPipeline;
178178

179-
private QueuedPacket(final ByteBuf buf, final boolean clientbound, final PacketType packetType,
179+
private QueuedPacket(final ByteBuf buf, final boolean clientbound, @Nullable final PacketType packetType,
180180
final int packetId, final boolean skipCurrentPipeline) {
181181
this.buf = buf;
182182
this.clientbound = clientbound;

0 commit comments

Comments
 (0)