Search in sources :

Example 1 with MovementTracker

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker in project DirtMultiversion by DirtPowered.

the class ViaPlugin method tick.

@Override
public void tick() {
    for (UserData userData : api.getAllConnections()) {
        ProtocolStorage s = userData.getProtocolStorage();
        if (!s.hasObject(PlayerMovementTracker.class))
            return;
        PlayerMovementTracker movementTracker = s.get(PlayerMovementTracker.class);
        if ((System.currentTimeMillis() - movementTracker.getLastLocationUpdate()) >= 50) {
            if (userData.getUniqueId() == null)
                return;
            UserConnection userConnection = connectionManager.getConnectedClient(userData.getUniqueId());
            if (userConnection == null)
                return;
            ProtocolInfo protocolInfo = userConnection.getProtocolInfo();
            if (protocolInfo == null)
                return;
            if (protocolInfo.getPipeline().contains(Protocol1_9To1_8.class) && protocolInfo.getState() == State.PLAY) {
                PacketWrapper wrapper = new PacketWrapperImpl(0x03, null, userConnection);
                wrapper.write(Type.BOOLEAN, true);
                try {
                    wrapper.sendToServer(Protocol1_9To1_8.class, true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
Also used : ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) UserData(com.github.dirtpowered.dirtmv.data.user.UserData) PacketWrapperImpl(com.viaversion.viaversion.protocol.packet.PacketWrapperImpl) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) PlayerMovementTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker) Protocol1_9To1_8(com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)

Example 2 with MovementTracker

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker in project ViaVersion by ViaVersion.

the class PlayerMovementMapper method handle.

@Override
public void handle(PacketWrapper wrapper) throws Exception {
    MovementTracker tracker = wrapper.user().get(MovementTracker.class);
    tracker.incrementIdlePacket();
    // If packet has the ground data
    if (wrapper.is(Type.BOOLEAN, 0)) {
        tracker.setGround(wrapper.get(Type.BOOLEAN, 0));
    }
}
Also used : MovementTracker(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker)

Example 3 with MovementTracker

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker in project ViaVersion by ViaVersion.

the class ViaIdleThread method run.

@Override
public void run() {
    for (UserConnection info : Via.getManager().getConnectionManager().getConnections()) {
        ProtocolInfo protocolInfo = info.getProtocolInfo();
        if (protocolInfo == null || !protocolInfo.getPipeline().contains(Protocol1_9To1_8.class))
            continue;
        MovementTracker movementTracker = info.get(MovementTracker.class);
        if (movementTracker == null)
            continue;
        long nextIdleUpdate = movementTracker.getNextIdlePacket();
        if (nextIdleUpdate <= System.currentTimeMillis() && info.getChannel().isOpen()) {
            Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info);
        }
    }
}
Also used : MovementTransmitterProvider(com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider) ProtocolInfo(com.viaversion.viaversion.api.connection.ProtocolInfo) UserConnection(com.viaversion.viaversion.api.connection.UserConnection) MovementTracker(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker)

Example 4 with MovementTracker

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker in project ViaVersion by ViaVersion.

the class VelocityMovementTransmitter method sendPlayer.

public void sendPlayer(UserConnection userConnection) {
    if (userConnection.getProtocolInfo().getState() == State.PLAY) {
        PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, null, userConnection);
        MovementTracker tracker = userConnection.get(MovementTracker.class);
        wrapper.write(Type.BOOLEAN, tracker.isGround());
        try {
            wrapper.scheduleSendToServer(Protocol1_9To1_8.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        tracker.incrementIdlePacket();
    }
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) MovementTracker(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker)

Example 5 with MovementTracker

use of com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker in project ViaVersion by ViaVersion.

the class BungeeMovementTransmitter method sendPlayer.

public void sendPlayer(UserConnection userConnection) {
    if (userConnection.getProtocolInfo().getState() == State.PLAY) {
        PacketWrapper wrapper = PacketWrapper.create(ServerboundPackets1_8.PLAYER_MOVEMENT, null, userConnection);
        MovementTracker tracker = userConnection.get(MovementTracker.class);
        wrapper.write(Type.BOOLEAN, tracker.isGround());
        try {
            wrapper.scheduleSendToServer(Protocol1_9To1_8.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        tracker.incrementIdlePacket();
    }
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) MovementTracker(com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker)

Aggregations

MovementTracker (com.viaversion.viaversion.protocols.protocol1_9to1_8.storage.MovementTracker)4 PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)3 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)2 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)2 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)1 UserData (com.github.dirtpowered.dirtmv.data.user.UserData)1 PlayerMovementTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker)1 PacketWrapperImpl (com.viaversion.viaversion.protocol.packet.PacketWrapperImpl)1 Protocol1_9To1_8 (com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)1 MovementTransmitterProvider (com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider)1