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();
}
}
}
}
}
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();
}
}
Aggregations