3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-26 00:00:33 +01:00

Check for client state in event loop in PlayerPacketsTickTask

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-12-05 22:46:19 +01:00
Ursprung 5f0cb34e64
Commit 8ec7c27153
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 6 neuen und 4 gelöschten Zeilen

BIN
.DS_Store vendored Normale Datei

Binäre Datei nicht angezeigt.

Datei anzeigen

@ -21,6 +21,7 @@ import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage; import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
@ -34,13 +35,14 @@ public final class PlayerPacketsTickTask implements Runnable {
@Override @Override
public void run() { public void run() {
for (final UserConnection user : Via.getManager().getConnectionManager().getConnections()) { for (final UserConnection user : Via.getManager().getConnectionManager().getConnections()) {
if (user.getProtocolInfo().getClientState() != State.PLAY || !user.getProtocolInfo().getPipeline().contains(Protocol1_21_2To1_21.class)) { final ProtocolInfo protocolInfo = user.getProtocolInfo();
if (protocolInfo.getClientState() != State.PLAY || protocolInfo.getServerState() != State.PLAY || !protocolInfo.getPipeline().contains(Protocol1_21_2To1_21.class)) {
continue; continue;
} }
final Channel channel = user.getChannel(); final Channel channel = user.getChannel();
channel.eventLoop().submit(() -> { channel.eventLoop().submit(() -> {
if (!channel.isActive()) { if (!channel.isActive() || protocolInfo.getClientState() != State.PLAY || protocolInfo.getServerState() != State.PLAY) {
return; return;
} }
try { try {
@ -48,13 +50,13 @@ public final class PlayerPacketsTickTask implements Runnable {
final PlayerStorage playerStorage = user.get(PlayerStorage.class); final PlayerStorage playerStorage = user.get(PlayerStorage.class);
playerStorage.tick(user); playerStorage.tick(user);
} }
} catch (Throwable t) { } catch (final Throwable t) {
ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending player input packet.", t); ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending player input packet.", t);
} }
try { try {
final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, user); final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, user);
clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class); clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class);
} catch (Throwable t) { } catch (final Throwable t) {
ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t); ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t);
} }
}); });