/** * Create a new packet for the target of this packet. * * @param packetID The ID of the new packet * @return The newly created packet wrapper */ public PacketWrapper create(int packetID) { return new PacketWrapper(packetID, null, user()); }
/** * Send the current packet to the server. * (Ensure the ID is suitable for viaversion) * * @throws Exception If it failed to write */ @Deprecated public void sendToServer() throws Exception { if (!isCancelled()) { ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); writeToBuffer(output); user().sendRawPacketToServer(output, true); } }
/** * Send this packet to the associated user. * Be careful not to send packets twice. * (Sends it after current) * <b>This method is no longer used, it's favoured to use {@link #send(Class)} as it will handle the pipeline properly.</b> * * @throws Exception if it fails to write */ @Deprecated public void send() throws Exception { if (!isCancelled()) { // Send ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); writeToBuffer(output); user().sendRawPacket(output); } }
/** * Send this packet to the associated user. * Be careful not to send packets twice. * (Sends it after current) * Also returns the packets ChannelFuture * * @param packetProtocol - The protocol version of the packet. * @return The packets ChannelFuture * @throws Exception if it fails to write */ public ChannelFuture sendFuture(Class<? extends Protocol> packetProtocol) throws Exception { if (!isCancelled()) { ByteBuf output = constructPacket(packetProtocol, true, Direction.OUTGOING); return user().sendRawPacketFuture(output); } return user().getChannel().newFailedFuture(new Exception("Cancelled packet")); }
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { super.transform(direction, state, packetWrapper); if (direction == Direction.INCOMING && state == State.HANDSHAKE) { // Disable if it isn't a handshake packet. if (packetWrapper.getId() != 0) { packetWrapper.user().setActive(false); } } } }
@Override public void transform(Direction direction, State state, PacketWrapper packetWrapper) throws Exception { CompressionSendStorage compressionSendStorage = packetWrapper.user().get(CompressionSendStorage.class); if (compressionSendStorage.isCompressionSend()) { Channel channel = packetWrapper.user().getChannel(); channel.pipeline().replace("decompress", "decompress", new EmptyChannelHandler()); channel.pipeline().replace("compress", "compress", new ForwardMessageToByteEncoder()); compressionSendStorage.setCompressionSend(false); } super.transform(direction, state, packetWrapper); }
/** * Send this packet to the associated user. * Be careful not to send packets twice. * (Sends it after current) * * @param packetProtocol - The protocol version of the packet. * @param skipCurrentPipeline - Skip the current pipeline * @param currentThread - Run in the same thread * @throws Exception if it fails to write */ public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception { if (!isCancelled()) { ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.OUTGOING); user().sendRawPacket(output, currentThread); } }
/** * Send this packet to the server. * * @param packetProtocol - The protocol version of the packet. * @param skipCurrentPipeline - Skip the current pipeline * @param currentThread - Run in the same thread * @throws Exception if it fails to write */ public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) throws Exception { if (!isCancelled()) { ByteBuf output = constructPacket(packetProtocol, skipCurrentPipeline, Direction.INCOMING); user().sendRawPacketToServer(output, currentThread); } }
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); if (direction == Direction.OUTGOING) { apply(direction, user().get(ProtocolInfo.class).getState(), index, protocols); ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); writeToBuffer(output);
@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)); } } }
PacketWrapper chunkPacket = new PacketWrapper(0x21, null, wrapper.user()); chunkPacket.write(Type.INT, meta.getX()); chunkPacket.write(Type.INT, meta.getZ());
public static void transformChunk(PacketWrapper packetWrapper) throws Exception { ClientWorld world = packetWrapper.user().get(ClientWorld.class); Chunk chunk = packetWrapper.read(new Chunk1_8Type(world)); packetWrapper.write(new Chunk1_7_10WriteOnlyType(world), chunk); for (ChunkSection section : chunk.getSections()){ if (section == null) continue; for (int x = 0; x < 16; x++) { for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { int block = section.getBlock(x, y, z); BlockState state = BlockState.rawToState(block); state = ReplacementRegistry1_7_6_10to1_8.replace(state); section.setBlock(x, y, z, state.getId(), state.getData()); } } } } }
ViaPlatform platform = Via.getPlatform(); String actualUsername = packetWrapper.user().get(ProtocolInfo.class).getUsername(); String username = actualUsername != null ? actualUsername + " " : "";
public static void transformChunk(PacketWrapper packetWrapper) throws Exception { ClientWorld world = packetWrapper.user().get(ClientWorld.class); final UserConnection user = packetWrapper.user(); chunk.getBlockEntities().forEach(nbt -> { if (!nbt.contains("x") || !nbt.contains("y") || !nbt.contains("z") || !nbt.contains("id")) return;