private static void updateBlockEntity(Position pos, short id, CompoundTag tag, UserConnection connection) throws Exception { PacketWrapper wrapper = new PacketWrapper(0x09, null, connection); wrapper.write(Type.POSITION, pos); wrapper.write(Type.UNSIGNED_BYTE, id); wrapper.write(Type.NBT, tag); wrapper.send(Protocol1_9_1_2TO1_9_3_4.class, false); } }
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception { sendToServer(packetProtocol, skipCurrentPipeline, false); }
public static void transformMultiBlockChange(PacketWrapper packetWrapper) throws Exception { packetWrapper.passthrough(Type.INT); packetWrapper.passthrough(Type.INT); int count = packetWrapper.read(Type.VAR_INT); packetWrapper.write(Type.SHORT, (short) count); packetWrapper.write(Type.INT, count * 4); for (int i = 0; i < count; i++) { packetWrapper.passthrough(Type.UNSIGNED_BYTE); packetWrapper.passthrough(Type.UNSIGNED_BYTE); int blockData = packetWrapper.read(Type.VAR_INT); BlockState state = ReplacementRegistry1_7_6_10to1_8.replace(BlockState.rawToState(blockData)); blockData = BlockState.stateToRaw(state); packetWrapper.write(Type.SHORT, (short) blockData); } } }
/** * 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()); }
/** * Take a value from the input and write to the output. * * @param type The type to read and write. * @param <T> The return type of the type you wish to pass through. * @return The type which was read/written. * @throws Exception If it failed to read or write */ public <T> T passthrough(Type<T> type) throws Exception { T value = read(type); write(type, value); return value; }
private void updateLocation() { PacketWrapper packetWrapper = new PacketWrapper(0x18, null, this.connection); packetWrapper.write(Type.VAR_INT, entityId); packetWrapper.write(Type.INT, (int) (locX * 32d)); packetWrapper.write(Type.INT, (int) (locY * 32d)); packetWrapper.write(Type.INT, (int) (locZ * 32d)); packetWrapper.write(Type.BYTE, (byte)0); packetWrapper.write(Type.BYTE, (byte)0); packetWrapper.write(Type.BOOLEAN, false); PacketUtil.sendPacket(packetWrapper, Protocol1_8TO1_9.class, true, true); }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
public void sendPlayer(UserConnection userConnection) { if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } } }
PacketWrapper wrapper = (PacketWrapper) packet; boolean skyLight = wrapper.read(Type.BOOLEAN); int count = wrapper.read(Type.VAR_INT); meta.setData(wrapper.read(customByteType)); PacketWrapper chunkPacket = new PacketWrapper(0x21, null, wrapper.user()); chunkPacket.write(Type.INT, meta.getX()); chunkPacket.write(Type.INT, meta.getZ()); chunkPacket.write(Type.BOOLEAN, true); // Always ground-up chunkPacket.write(Type.UNSIGNED_SHORT, meta.getBitMask()); chunkPacket.write(Type.VAR_INT, meta.getLength()); chunkPacket.write(customByteType, meta.getData());
/** * 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 * @throws Exception if it fails to write */ public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception { send(packetProtocol, skipCurrentPipeline, false); }
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()); } } } } }
@Override public void write(PacketWrapper output, T inputValue) { output.write(type, inputValue); } }
/** * 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); } }
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); if (direction == Direction.OUTGOING) { resetReader(); apply(direction, user().get(ProtocolInfo.class).getState(), index, protocols); ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer(); writeToBuffer(output);
return type.read(inputBuffer); } catch (Exception e) { throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Data", packetValues); } else { if (rtype == Type.NOTHING) { return read(type); // retry } else { Exception e = new IOException("Unable to read type " + type.getTypeName() + ", found " + read.getKey().getTypeName()); throw new InformativeException(e).set("Type", type.getTypeName()).set("Packet ID", getId()).set("Data", packetValues);
@Override public T read(PacketWrapper wrapper) throws Exception { return wrapper.read(type); }
/** * Take all the inputs and write them to the output. * * @throws Exception If it failed to read or write */ public void passthroughAll() throws Exception { // Copy previous objects packetValues.addAll(readableObjects); readableObjects.clear(); // If the buffer has readable bytes, copy them. if (inputBuffer.readableBytes() > 0) { passthrough(Type.REMAINING_BYTES); } }
public void updateLocation() { PacketWrapper teleport = new PacketWrapper(0x18, null, user); teleport.write(Type.VAR_INT, entityId); teleport.write(Type.INT, (int) (locX * 32.0)); teleport.write(Type.INT, (int) (locY * 32.0)); teleport.write(Type.INT, (int) (locZ * 32.0)); teleport.write(Type.BYTE, (byte) 0); teleport.write(Type.BYTE, (byte) 0); teleport.write(Type.BOOLEAN, true); PacketUtil.sendPacket(teleport, Protocol1_8TO1_9.class, true, true); }
PacketWrapper wrapper = new PacketWrapper(id, oldPacket, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper); wrapper.writeToBuffer(bytebuf); } catch (Exception e) { bytebuf.clear();
public void sendPlayer(UserConnection userConnection) { if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9TO1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } } }