Make packet send methods use the current thread by default

Defaulting to submitting to the netty event loop caused issues more often than not - this also removes the `currentThread` flag and instead provides new scheduleSend methods so it is always obvious whether the packet is sent immediately.
This commit is contained in:
KennyTV 2021-05-31 22:58:47 +02:00
parent 3fb125592b
commit 37fd69fa86
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
34 changed files with 216 additions and 147 deletions

View File

@ -52,7 +52,7 @@ public interface ViaAPI<T> {
* @return API version incremented with meaningful API changes
*/
default int apiVersion() {
return 1;
return 2;
}
/**

View File

@ -96,21 +96,18 @@ public interface UserConnection {
void clearStoredObjects();
/**
* Send a raw packet to the player.
* Sends a raw packet to the connection on the current thread.
*
* @param packet The raw packet to send
* @param currentThread Should it run in the same thread
* @param packet raw packet to send
*/
void sendRawPacket(ByteBuf packet, boolean currentThread);
void sendRawPacket(ByteBuf packet);
/**
* Send a raw packet to the player (netty thread).
* Send a raw packet to the player, submitted to the netty event loop.
*
* @param packet The packet to send
* @param packet raw packet to send
*/
default void sendRawPacket(ByteBuf packet) {
sendRawPacket(packet, false);
}
void scheduleSendRawPacket(ByteBuf packet);
/**
* Send a raw packet to the player with returning the future.
@ -135,21 +132,18 @@ public interface UserConnection {
void disconnect(String reason);
/**
* Sends a raw packet to the server.
* Sends a raw packet to the server on the current thread.
*
* @param packet Raw packet to be sent
* @param currentThread If {@code true} executes immediately, {@code false} submits a task to EventLoop
* @param packet raw packet to be sent
*/
void sendRawPacketToServer(ByteBuf packet, boolean currentThread);
void sendRawPacketToServer(ByteBuf packet);
/**
* Sends a raw packet to the server. It will submit a task to EventLoop.
* Sends a raw packet to the server, submitted to the netty event loop.
*
* @param packet Raw packet to be sent
* @param packet raw packet to be sent
*/
default void sendRawPacketToServer(ByteBuf packet) {
sendRawPacketToServer(packet, false);
}
void scheduleSendRawPacketToServer(ByteBuf packet);
/**
* Monitors serverbound packets and returns whether a packet can/should be processed.

View File

@ -168,38 +168,50 @@ public interface PacketWrapper {
void clearPacket();
/**
* Send this packet to the associated user.
* Be careful not to send packets twice.
* (Sends it after current)
* Send this packet to the connection on the current thread, skipping the current protocol.
*
* @param packetProtocol The protocol version of the packet.
* @param skipCurrentPipeline Skip the current pipeline
* @param protocol protocol to be sent through
* @throws Exception if it fails to write
*/
void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception;
default void send(Class<? extends Protocol> protocol) throws Exception {
send(protocol, true);
}
/**
* Send this packet to the associated user.
* Be careful not to send packets twice.
* (Sends it after current)
* Send this packet to the connection on the current thread.
*
* @param packetProtocol The protocol version of the packet.
* @param skipCurrentPipeline Skip the current pipeline
* @param currentThread Run in the same thread
* @param protocol protocol to be sent through
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
* @throws Exception if it fails to write
*/
void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception;
void send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
/**
* Send this packet to the associated user.
* Be careful not to send packets twice.
* (Sends it after current)
* Send this packet to the connection, submitted to netty's event loop and skipping the current protocol.
*
* @param packetProtocol The protocol version of the packet.
* @param protocol protocol to be sent through
* @throws Exception if it fails to write
*/
default void send(Class<? extends Protocol> packetProtocol) throws Exception {
send(packetProtocol, true);
default void scheduleSend(Class<? extends Protocol> protocol) throws Exception {
scheduleSend(protocol, true);
}
/**
* Send this packet to the connection, submitted to netty's event loop.
*
* @param protocol protocol to be sent through
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
* @throws Exception if it fails to write
*/
void scheduleSend(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
@Deprecated
default void send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (currentThread) {
send(protocol, skipCurrentPipeline);
} else {
scheduleSend(protocol, skipCurrentPipeline);
}
}
/**
@ -303,21 +315,50 @@ public interface PacketWrapper {
void sendToServer() throws Exception;
/**
* Send this packet to the server.
* Send this packet to the server on the current thread, skipping the current protocol.
*
* @param packetProtocol The protocol version of the packet.
* @param skipCurrentPipeline Skip the current pipeline
* @param currentThread Run in the same thread
* @param protocol protocol to be sent through
* @throws Exception if it fails to write
*/
void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception;
default void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception {
sendToServer(packetProtocol, skipCurrentPipeline, false);
default void sendToServer(Class<? extends Protocol> protocol) throws Exception {
sendToServer(protocol, true);
}
default void sendToServer(Class<? extends Protocol> packetProtocol) throws Exception {
sendToServer(packetProtocol, true);
/**
* Send this packet to the server on the current thread.
*
* @param protocol protocol to be sent through
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
* @throws Exception if it fails to write
*/
void sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
/**
* Send this packet to the server, submitted to netty's event loop and skipping the current protocol.
*
* @param protocol protocol to be sent through
* @throws Exception if it fails to write
*/
default void scheduleSendToServer(Class<? extends Protocol> protocol) throws Exception {
scheduleSendToServer(protocol, true);
}
/**
* Send this packet to the server, submitted to netty's event loop.
*
* @param protocol protocol to be sent through
* @param skipCurrentPipeline whether transformation of the current protocol should be skipped
* @throws Exception if it fails to write
*/
void scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception;
@Deprecated
default void sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (currentThread) {
sendToServer(protocol, skipCurrentPipeline);
} else {
scheduleSendToServer(protocol, skipCurrentPipeline);
}
}
/**

View File

@ -69,7 +69,7 @@ public class ArmorListener extends ViaBukkitListener {
wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -65,7 +65,7 @@ public class DeathListener extends ViaBukkitListener {
wrapper.write(Type.INT, p.getEntityId()); // Entity ID
Protocol1_9To1_8.FIX_JSON.write(wrapper, msg); // Message
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -83,7 +83,7 @@ public class EntityToggleGlideListener extends ViaBukkitListener {
// leave 0x80 as 0 to stop gliding
packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, MetaType1_14.Byte, bitmask)));
packet.send(Protocol1_15To1_14_4.class);
packet.scheduleSend(Protocol1_15To1_14_4.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -172,7 +172,7 @@ public class BungeeServerHandler implements Listener {
PacketWrapper wrapper = PacketWrapper.create(0x0C, null, user);
wrapper.write(Type.UUID, uuid);
wrapper.write(Type.VAR_INT, 1); // remove
wrapper.send(Protocol1_9To1_8.class, true, true);
wrapper.send(Protocol1_9To1_8.class);
}
}
storage.getBossbar().clear();

View File

@ -53,7 +53,7 @@ public class ElytraPatch implements Listener {
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
}
} catch (Exception e) {
e.printStackTrace();

View File

@ -41,7 +41,7 @@ public class BungeeMovementTransmitter extends MovementTransmitterProvider {
PacketWrapper wrapper = PacketWrapper.create(0x03, null, userConnection);
wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround());
try {
wrapper.sendToServer(Protocol1_9To1_8.class);
wrapper.scheduleSendToServer(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -67,7 +67,7 @@ public abstract class ViaAPIBase<T> implements ViaAPI<T> {
}
UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(uuid);
user.sendRawPacket(packet);
user.scheduleSendRawPacket(packet);
}
@Override

View File

@ -117,7 +117,16 @@ public class UserConnectionImpl implements UserConnection {
}
@Override
public void sendRawPacket(final ByteBuf packet, boolean currentThread) {
public void sendRawPacket(ByteBuf packet) {
sendRawPacket(packet, true);
}
@Override
public void scheduleSendRawPacket(ByteBuf packet) {
sendRawPacket(packet, false);
}
private void sendRawPacket(final ByteBuf packet, boolean currentThread) {
Runnable act;
if (clientSide) {
// We'll just assume that Via decoder isn't wrapping the original decoder
@ -141,22 +150,14 @@ public class UserConnectionImpl implements UserConnection {
@Override
public ChannelFuture sendRawPacketFuture(final ByteBuf packet) {
if (clientSide) {
return sendRawPacketFutureClientSide(packet);
// Assume that decoder isn't wrapping
getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(packet);
return getChannel().newSucceededFuture();
} else {
return sendRawPacketFutureServerSide(packet);
return channel.pipeline().context(Via.getManager().getInjector().getEncoderName()).writeAndFlush(packet);
}
}
private ChannelFuture sendRawPacketFutureServerSide(final ByteBuf packet) {
return channel.pipeline().context(Via.getManager().getInjector().getEncoderName()).writeAndFlush(packet);
}
private ChannelFuture sendRawPacketFutureClientSide(final ByteBuf packet) {
// Assume that decoder isn't wrapping
getChannel().pipeline().context(Via.getManager().getInjector().getDecoderName()).fireChannelRead(packet);
return getChannel().newSucceededFuture();
}
@Override
public PacketTracker getPacketTracker() {
return packetTracker;
@ -175,11 +176,20 @@ public class UserConnectionImpl implements UserConnection {
}
@Override
public void sendRawPacketToServer(final ByteBuf packet, boolean currentThread) {
public void sendRawPacketToServer(ByteBuf packet) {
if (clientSide) {
sendRawPacketToServerClientSide(packet, currentThread);
sendRawPacketToServerClientSide(packet, true);
} else {
sendRawPacketToServerServerSide(packet, currentThread);
sendRawPacketToServerServerSide(packet, true);
}
}
@Override
public void scheduleSendRawPacketToServer(ByteBuf packet) {
if (clientSide) {
sendRawPacketToServerClientSide(packet, false);
} else {
sendRawPacketToServerServerSide(packet, false);
}
}

View File

@ -227,7 +227,7 @@ public class CommonBoss implements BossBar {
return;
}
try {
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -228,20 +228,28 @@ public class PacketWrapperImpl implements PacketWrapper {
}
@Override
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception {
send(packetProtocol, skipCurrentPipeline, false);
public void send(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception {
send0(protocol, skipCurrentPipeline, true);
}
@Override
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (!isCancelled()) {
try {
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.CLIENTBOUND);
user().sendRawPacket(output, currentThread);
} catch (Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
public void scheduleSend(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception {
send0(protocol, skipCurrentPipeline, false);
}
private void send0(Class<? extends Protocol> protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (isCancelled()) return;
try {
ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.CLIENTBOUND);
if (currentThread) {
user().sendRawPacket(output);
} else {
user().scheduleSendRawPacket(output);
}
} catch (Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
}
}
@ -301,15 +309,15 @@ public class PacketWrapperImpl implements PacketWrapper {
@Override
@Deprecated
public void send() throws Exception {
if (!isCancelled()) {
// Send
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
try {
writeToBuffer(output);
user().sendRawPacket(output.retain());
} finally {
output.release();
}
if (isCancelled()) return;
// Send
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
try {
writeToBuffer(output);
user().sendRawPacket(output.retain());
} finally {
output.release();
}
}
@ -384,28 +392,40 @@ public class PacketWrapperImpl implements PacketWrapper {
@Override
@Deprecated
public void sendToServer() throws Exception {
if (!isCancelled()) {
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
try {
writeToBuffer(output);
if (isCancelled()) return;
user().sendRawPacketToServer(output.retain(), true);
} finally {
output.release();
}
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
try {
writeToBuffer(output);
user().sendRawPacketToServer(output.retain());
} finally {
output.release();
}
}
@Override
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (!isCancelled()) {
try {
ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.SERVERBOUND);
user().sendRawPacketToServer(output, currentThread);
} catch (Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
public void sendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception {
sendToServer0(protocol, skipCurrentPipeline, true);
}
@Override
public void scheduleSendToServer(Class<? extends Protocol> protocol, boolean skipCurrentPipeline) throws Exception {
sendToServer0(protocol, skipCurrentPipeline, false);
}
private void sendToServer0(Class<? extends Protocol> protocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception {
if (isCancelled()) return;
try {
ByteBuf output = constructPacket(protocol, skipCurrentPipeline, Direction.SERVERBOUND);
if (currentThread) {
user().sendRawPacketToServer(output);
} else {
user().scheduleSendRawPacketToServer(output);
}
} catch (Exception e) {
if (!PipelineUtil.containsCause(e, CancelException.class)) {
throw e;
}
}
}

View File

@ -561,7 +561,7 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol<ClientboundPackets1_1
}
}
}
}).send(Protocol1_13To1_12_2.class, true, true);
}).send(Protocol1_13To1_12_2.class);
}
}
});

View File

@ -66,7 +66,7 @@ public class ConnectionData {
blockUpdatePacket.write(Type.POSITION, pos);
blockUpdatePacket.write(Type.VAR_INT, newBlockState);
try {
blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, true);
blockUpdatePacket.send(Protocol1_13To1_12_2.class);
} catch (Exception ex) {
ex.printStackTrace();
}
@ -140,7 +140,7 @@ public class ConnectionData {
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS));
try {
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.send(Protocol1_13To1_12_2.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -169,7 +169,7 @@ public class WorldPackets {
PacketWrapper blockChange = wrapper.create(0x0B); // block change
blockChange.write(Type.POSITION, new Position(pos)); // Clone because position is mutable
blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
blockChange.send(Protocol1_13To1_12_2.class, true, true);
blockChange.send(Protocol1_13To1_12_2.class);
}
wrapper.set(Type.VAR_INT, 0, blockId);
}
@ -197,7 +197,7 @@ public class WorldPackets {
wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
if (Via.getConfig().isServersideBlockConnections()) {
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
ConnectionData.update(userConnection, position);
}
@ -250,7 +250,7 @@ public class WorldPackets {
}
}
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (BlockChangeRecord record : records) {
@ -301,7 +301,7 @@ public class WorldPackets {
}
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (int i = 0; i < recordCount; i++) {
@ -463,7 +463,7 @@ public class WorldPackets {
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.connectBlocks(wrapper.user(), chunk);
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];

View File

@ -85,7 +85,7 @@ public class BlockEntityProvider implements Provider {
wrapper.write(Type.POSITION, position);
wrapper.write(Type.VAR_INT, blockId);
wrapper.send(Protocol1_13To1_12_2.class, true, true);
wrapper.send(Protocol1_13To1_12_2.class);
}
public interface BlockEntityHandler {

View File

@ -36,7 +36,7 @@ public class TabCompleteTracker implements StorableObject {
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.OPTIONAL_POSITION, null);
try {
wrapper.sendToServer(Protocol1_13To1_12_2.class);
wrapper.scheduleSendToServer(Protocol1_13To1_12_2.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -243,7 +243,7 @@ public class InventoryPackets {
CompoundTag tag = new CompoundTag();
tag.put("force_resync", new DoubleTag(Double.NaN)); // Tags with NaN are not equal
resyncPacket.write(Type.FLAT_VAR_INT_ITEM, new Item(1, (byte) 1, (short) 0, tag)); // 5 - Clicked Item
resyncPacket.sendToServer(Protocol1_14To1_13_2.class, true, false);
resyncPacket.scheduleSendToServer(Protocol1_14To1_13_2.class);
}
});
}

View File

@ -250,12 +250,12 @@ public class WorldPackets {
PacketWrapper fakePosLook = wrapper.create(ClientboundPackets1_14.UPDATE_VIEW_POSITION); // Set center chunk
fakePosLook.write(Type.VAR_INT, chunk.getX());
fakePosLook.write(Type.VAR_INT, chunk.getZ());
fakePosLook.send(Protocol1_14To1_13_2.class, true, true);
fakePosLook.send(Protocol1_14To1_13_2.class);
entityTracker.setChunkCenterX(chunk.getX());
entityTracker.setChunkCenterZ(chunk.getZ());
}
lightPacket.send(Protocol1_14To1_13_2.class, true, true);
lightPacket.send(Protocol1_14To1_13_2.class);
// Remove light references from chunk sections
for (ChunkSection section : chunk.getSections()) {
@ -337,7 +337,7 @@ public class WorldPackets {
});
handler(wrapper -> {
// Manually send the packet
wrapper.send(Protocol1_14To1_13_2.class, true, true);
wrapper.send(Protocol1_14To1_13_2.class);
wrapper.cancel();
// View distance has to be sent after the join packet
@ -388,7 +388,7 @@ public class WorldPackets {
});
handler(wrapper -> {
// Manually send the packet and update the viewdistance after
wrapper.send(Protocol1_14To1_13_2.class, true, true);
wrapper.send(Protocol1_14To1_13_2.class);
wrapper.cancel();
sendViewDistancePacket(wrapper.user());
});
@ -406,7 +406,7 @@ public class WorldPackets {
private static void sendViewDistancePacket(UserConnection connection) throws Exception {
PacketWrapper setViewDistance = PacketWrapper.create(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE, null, connection);
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
setViewDistance.send(Protocol1_14To1_13_2.class, true, true);
setViewDistance.send(Protocol1_14To1_13_2.class);
}
private static long[] encodeHeightMap(int[] heightMap) {

View File

@ -88,7 +88,7 @@ public class EntityPackets {
List<Metadata> metadata = wrapper.read(Types1_14.METADATA_LIST);
// Send the spawn packet manually
wrapper.send(Protocol1_15To1_14_4.class, true, true);
wrapper.send(Protocol1_15To1_14_4.class);
wrapper.cancel();
// Handle meta
@ -97,7 +97,7 @@ public class EntityPackets {
PacketWrapper metadataPacket = PacketWrapper.create(ClientboundPackets1_15.ENTITY_METADATA, wrapper.user());
metadataPacket.write(Type.VAR_INT, entityId);
metadataPacket.write(Types1_14.METADATA_LIST, metadata);
metadataPacket.send(Protocol1_15To1_14_4.class, true, true);
metadataPacket.send(Protocol1_15To1_14_4.class);
}
public static int getNewEntityId(int oldId) {

View File

@ -101,7 +101,7 @@ public class WorldPackets {
newPacket.write(Type.LONG, chunkPosition | (chunkY & 0xFFFFFL));
newPacket.write(Type.BOOLEAN, false); // Ignore light updates
newPacket.write(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY, sectionRecord.toArray(EMPTY_RECORDS));
newPacket.send(Protocol1_16_2To1_16_1.class, true, true);
newPacket.send(Protocol1_16_2To1_16_1.class);
}
});
}

View File

@ -53,7 +53,7 @@ public class EntityPackets {
// Send individual remove packets
PacketWrapper newPacket = wrapper.create(ClientboundPackets1_17.REMOVE_ENTITY);
newPacket.write(Type.VAR_INT, entityId);
newPacket.send(Protocol1_17To1_16_4.class, true, true);
newPacket.send(Protocol1_17To1_16_4.class);
}
});
}

View File

@ -105,7 +105,7 @@ public class InventoryPackets {
PacketWrapper pingPacket = wrapper.create(ClientboundPackets1_17.PING);
pingPacket.write(Type.INT, id);
pingPacket.send(Protocol1_17To1_16_4.class, true, true);
pingPacket.send(Protocol1_17To1_16_4.class);
}
wrapper.cancel();
@ -128,7 +128,7 @@ public class InventoryPackets {
packet.write(Type.UNSIGNED_BYTE, (short) inventoryId);
packet.write(Type.SHORT, (short) confirmationId);
packet.write(Type.BYTE, (byte) 1); // Accept
packet.sendToServer(Protocol1_17To1_16_4.class, true, true);
packet.sendToServer(Protocol1_17To1_16_4.class);
}
wrapper.cancel();

View File

@ -231,7 +231,7 @@ public class WorldPackets {
}
blockChangePacket.write(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecords);
blockChangePacket.send(Protocol1_17To1_16_4.class, true, true);
blockChangePacket.send(Protocol1_17To1_16_4.class);
}
}

View File

@ -148,7 +148,7 @@ public class PlayerPackets {
if (mode == 4) {
// since removing add to auto team
// Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class, true, true);
wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
@ -168,7 +168,7 @@ public class PlayerPackets {
&& teamName.equals(entityTracker.getCurrentTeam())) {
// team was removed
// Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class, true, true);
wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
@ -226,7 +226,7 @@ public class PlayerPackets {
if (Via.getConfig().isAutoTeam()) {
entityTracker.setAutoTeam(true);
// Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class, true, true);
wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
@ -437,7 +437,7 @@ public class PlayerPackets {
(short) (wrapper.get(Type.UNSIGNED_BYTE, 0).intValue() | 0x80)
);
}
wrapper.sendToServer(Protocol1_9To1_8.class, true, true);
wrapper.sendToServer(Protocol1_9To1_8.class);
wrapper.cancel();
Via.getManager().getProviders().get(MainHandProvider.class).setMainHand(wrapper.user(), hand);
}

View File

@ -311,7 +311,7 @@ public class SpawnPackets {
packet.write(Type.VAR_INT, 0);
packet.write(Type.ITEM, new Item(item, (byte) 1, (short) 0, null));
try {
packet.send(Protocol1_9To1_8.class, true, true);
packet.send(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -189,7 +189,7 @@ public class WorldPackets {
// Send through this protocol again
PacketWrapper chunkPacket = PacketWrapper.create(ClientboundPackets1_8.CHUNK_DATA, buffer, wrapper.user());
chunkPacket.send(Protocol1_9To1_8.class, false, true);
chunkPacket.send(Protocol1_9To1_8.class, false);
} finally {
if (buffer != null) {
buffer.release();

View File

@ -63,7 +63,7 @@ public class CommandBlockProvider implements Provider {
wrapper.write(Type.INT, tracker.getProvidedEntityId()); // Entity ID
wrapper.write(Type.BYTE, (byte) 26); // Hardcoded op permission level
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
user.get(CommandBlockStorage.class).setPermissions(true);
}

View File

@ -93,7 +93,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
wrapper.write(Type.VAR_INT, 1); // slot
wrapper.write(Type.ITEM, this.itemInSecondHand = item);
try {
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}
@ -239,7 +239,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
wrapper.write(Type.SHORT, (short) (128D * (Via.getConfig().getHologramYOffset() * 32D)));
wrapper.write(Type.SHORT, (short) 0);
wrapper.write(Type.BOOLEAN, true);
wrapper.send(Protocol1_9To1_8.class, true, false);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception ignored) {
}
}
@ -317,7 +317,11 @@ public class EntityTracker1_9 extends EntityTrackerBase {
}
teamExists = add;
try {
wrapper.send(Protocol1_9To1_8.class, true, now);
if (now) {
wrapper.send(Protocol1_9To1_8.class);
} else {
wrapper.scheduleSend(Protocol1_9To1_8.class);
}
} catch (Exception e) {
e.printStackTrace();
}
@ -343,7 +347,7 @@ public class EntityTracker1_9 extends EntityTrackerBase {
handleMetadata(entityId, metadataList);
if (!metadataList.isEmpty()) {
try {
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -71,7 +71,7 @@ public class Sponge4ArmorListener extends ViaListener {
wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -72,7 +72,7 @@ public class DeathListener extends ViaSpongeListener {
wrapper.write(Type.INT, entityId); // Entity ID
Protocol1_9To1_8.FIX_JSON.write(wrapper, msg); // Message
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -69,7 +69,7 @@ public class Sponge5ArmorListener extends ViaSpongeListener {
wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
wrapper.send(Protocol1_9To1_8.class);
wrapper.scheduleSend(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -41,7 +41,7 @@ public class VelocityMovementTransmitter extends MovementTransmitterProvider {
PacketWrapper wrapper = PacketWrapper.create(0x03, null, userConnection);
wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround());
try {
wrapper.sendToServer(Protocol1_9To1_8.class);
wrapper.scheduleSendToServer(Protocol1_9To1_8.class);
} catch (Exception e) {
e.printStackTrace();
}