|
25 | 25 | import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
26 | 26 | import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
27 | 27 | import com.viaversion.viaversion.api.protocol.packet.State;
|
28 |
| -import com.viaversion.viaversion.protocol.ProtocolRunnable; |
| 28 | +import com.viaversion.viaversion.connection.StorableObjectTask; |
29 | 29 | import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
|
30 | 30 | import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage;
|
31 |
| -import io.netty.channel.Channel; |
32 | 31 | import java.util.logging.Level;
|
33 | 32 |
|
34 |
| -public final class PlayerPacketsTickTask extends ProtocolRunnable { |
| 33 | +public final class PlayerPacketsTickTask extends StorableObjectTask<PlayerStorage> { |
35 | 34 |
|
36 | 35 | public PlayerPacketsTickTask() {
|
37 |
| - super(Protocol1_21_2To1_21.class); |
| 36 | + super(PlayerStorage.class); |
38 | 37 | }
|
39 | 38 |
|
40 | 39 | @Override
|
41 |
| - public void run(final UserConnection connection) { |
| 40 | + public void run(final UserConnection connection, final PlayerStorage storableObject) { |
42 | 41 | final ProtocolInfo protocolInfo = connection.getProtocolInfo();
|
| 42 | + if (protocolInfo.getClientState() != State.PLAY || protocolInfo.getServerState() != State.PLAY) { |
| 43 | + return; |
| 44 | + } |
| 45 | + |
43 | 46 | final EntityTracker entityTracker = connection.getEntityTracker(Protocol1_21_2To1_21.class);
|
44 |
| - if (protocolInfo.getClientState() != State.PLAY || protocolInfo.getServerState() != State.PLAY || !entityTracker.hasClientEntityId()) { |
| 47 | + if (!entityTracker.hasClientEntityId()) { |
45 | 48 | return;
|
46 | 49 | }
|
47 | 50 |
|
48 |
| - final Channel channel = connection.getChannel(); |
49 |
| - channel.eventLoop().submit(() -> { |
50 |
| - if (!channel.isActive() || protocolInfo.getClientState() != State.PLAY || protocolInfo.getServerState() != State.PLAY || !entityTracker.hasClientEntityId()) { |
51 |
| - return; |
52 |
| - } |
53 |
| - try { |
54 |
| - if (!connection.has(ClientVehicleStorage.class)) { |
55 |
| - final PlayerStorage playerStorage = connection.get(PlayerStorage.class); |
56 |
| - playerStorage.tick(connection); |
57 |
| - } |
58 |
| - } catch (final Throwable t) { |
59 |
| - ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending player input packet.", t); |
| 51 | + try { |
| 52 | + if (!connection.has(ClientVehicleStorage.class)) { |
| 53 | + storableObject.tick(connection); |
60 | 54 | }
|
61 |
| - try { |
62 |
| - final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, connection); |
63 |
| - clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class); |
64 |
| - } catch (final Throwable t) { |
65 |
| - ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t); |
66 |
| - } |
67 |
| - }); |
| 55 | + } catch (final Throwable t) { |
| 56 | + ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending player input packet.", t); |
| 57 | + } |
| 58 | + |
| 59 | + try { |
| 60 | + final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, connection); |
| 61 | + clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class); |
| 62 | + } catch (final Throwable t) { |
| 63 | + ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t); |
| 64 | + } |
68 | 65 | }
|
69 | 66 | }
|
0 commit comments