/** * 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. * @throws Exception if it fails to write */ public void send(Class<? extends Protocol> packetProtocol) throws Exception { send(packetProtocol, true); }
@Override public void write(PacketWrapper output, T inputValue) { output.write(type, inputValue); } }
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); } }
/** * 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 BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) { Arrays.fill(oldToNew, (short) -1); mapIdentifiers(oldToNew, mapping1_12, mapping1_13); // Map minecraft:snow[layers=1] of 1.12 to minecraft:snow[layers=2] in 1.13 if (Via.getConfig().isSnowCollisionFix()) { oldToNew[1248] = 3416; } }
@Override public void registerMap() { if (Via.getConfig().isServersideBlockConnections()) { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { int x = wrapper.passthrough(Type.INT); int z = wrapper.passthrough(Type.INT); ConnectionData.getProvider().unloadChunk(wrapper.user(), x, z); } }); } } });
@Override public String description() { return "Forces ViaVersion to scan server protocol versions " + (((VelocityViaConfig) Via.getConfig()).getVelocityPingInterval() == -1 ? "" : "(Also happens at an interval)"); }
public static boolean isBaseProtocol(Protocol protocol) { for (Pair<Range<Integer>, Protocol> p : baseProtocols) { if (p.getValue() == protocol) { return true; } } return false; }
@Override public void onEnable() { // Inject Via.getManager().init(); }
public void sendToServer(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception { sendToServer(packetProtocol, skipCurrentPipeline, false); }
/** * Map a type using a basic ValueReader to a ValueWriter * * @param inputReader The reader to read with. * @param outputWriter The writer to write with * @param <T> The return type */ public <T> void map(ValueReader<T> inputReader, ValueWriter<T> outputWriter) { valueRemappers.add(new Pair<ValueReader, ValueWriter>(inputReader, outputWriter)); }
@Override public T read(PacketWrapper wrapper) throws Exception { return wrapper.read(type); }
/** * Clear the packet, used if you have to change the packet completely */ public void clearPacket() { clearInputBuffer(); packetValues.clear(); }
private void sendBlockChange(UserConnection user, Position position, int blockId) throws Exception { PacketWrapper wrapper = new PacketWrapper(0x0B, null, user); wrapper.write(Type.POSITION, position); wrapper.write(Type.VAR_INT, blockId); wrapper.send(Protocol1_13To1_12_2.class, true, true); }
/** * 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); }
@Override public String description() { return "Forces ViaVersion to scan server protocol versions " + (((BungeeViaConfig) Via.getConfig()).getBungeePingInterval() == -1 ? "" : "(Also happens at an interval)"); }
public void sendToServer(Class<? extends Protocol> packetProtocol) throws Exception { sendToServer(packetProtocol, true); }