Search in sources :

Example 1 with PacketWrapperImpl

use of com.viaversion.viaversion.protocol.packet.PacketWrapperImpl 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 PacketWrapperImpl

use of com.viaversion.viaversion.protocol.packet.PacketWrapperImpl in project ViaVersion by ViaVersion.

the class UserConnectionImpl method transform.

private void transform(ByteBuf buf, Direction direction, Function<Throwable, Exception> cancelSupplier) throws Exception {
    if (!buf.isReadable())
        return;
    int id = Type.VAR_INT.readPrimitive(buf);
    if (id == PacketWrapper.PASSTHROUGH_ID) {
        if (!passthroughTokens.remove(Type.UUID.read(buf))) {
            throw new IllegalArgumentException("Invalid token");
        }
        return;
    }
    PacketWrapper wrapper = new PacketWrapperImpl(id, buf, this);
    try {
        protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper);
    } catch (CancelException ex) {
        throw cancelSupplier.apply(ex);
    }
    ByteBuf transformed = buf.alloc().buffer();
    try {
        wrapper.writeToBuffer(transformed);
        buf.clear().writeBytes(transformed);
    } finally {
        transformed.release();
    }
}
Also used : PacketWrapper(com.viaversion.viaversion.api.protocol.packet.PacketWrapper) PacketWrapperImpl(com.viaversion.viaversion.protocol.packet.PacketWrapperImpl) CancelException(com.viaversion.viaversion.exception.CancelException) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

PacketWrapper (com.viaversion.viaversion.api.protocol.packet.PacketWrapper)2 PacketWrapperImpl (com.viaversion.viaversion.protocol.packet.PacketWrapperImpl)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 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)1 UserConnection (com.viaversion.viaversion.api.connection.UserConnection)1 CancelException (com.viaversion.viaversion.exception.CancelException)1 Protocol1_9To1_8 (com.viaversion.viaversion.protocols.protocol1_9to1_8.Protocol1_9To1_8)1 ByteBuf (io.netty.buffer.ByteBuf)1