/** * Checks if the UUID is on the selected pipe * * @param uuid UUID Object * @return True if on pipe */ protected boolean isOnPipe(UUID uuid) { UserConnection userConnection = getUserConnection(uuid); return userConnection != null && userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline); }
@Override protected void encode(ChannelHandlerContext ctx, Object o, List list) throws Exception { // Split chunks bulk packet up in to single chunks packets before it reached the encoder. // This will prevent issues with several plugins and other protocol handlers due to the chunks being sent twice. // It also sends the chunks in the right order possible resolving some issues with added chunks/block/entity data. if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { return; } } } list.add(o); } }
@Override protected void encode(ChannelHandlerContext ctx, Object o, List list) throws Exception { // Split chunks bulk packet up in to single chunks packets before it reached the encoder. // This will prevent issues with several plugins and other protocol handlers due to the chunks being sent twice. // It also sends the chunks in the right order possible resolving some issues with added chunks/block/entity data. if (!(o instanceof ByteBuf)) { info.setLastPacket(o); /* This transformer is more for fixing issues which we find hard at packet level :) */ if (info.isActive()) { if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) { return; } } } list.add(o); } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.OUTGOING, protInfo.getState(), wrapper);
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) {
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes()); if (direction == Direction.OUTGOING) {
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@Override public void run() { for (UserConnection info : Via.getManager().getPortedPlayers().values()) { if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket(); if (nextIdleUpdate <= System.currentTimeMillis()) { if (info.getChannel().isOpen()) { Via.getManager().getProviders().get(MovementTransmitterProvider.class).sendPlayer(info); } } } } } }
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@Override public Chunk read(ByteBuf input, ClientChunks param) throws Exception { boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId();
PacketWrapper wrapper = new PacketWrapper(id, bytebuf, info); ProtocolInfo protInfo = info.get(ProtocolInfo.class); protInfo.getPipeline().transform(Direction.INCOMING, protInfo.getState(), wrapper); wrapper.writeToBuffer(newPacket);
@EventHandler public void onServerConnect(ServerConnectEvent event) { // Ignore if it doesn't exist (Like BungeeCord 1.8) if (setMainHand == null || getSettings == null) return; UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { Object settings = getSettings.invoke(event.getPlayer()); if (settings != null) { if (user.has(EntityTracker.class)) { setMainHand.invoke(settings, user.get(EntityTracker.class).getMainHand()); } } } } catch (Exception e) { e.printStackTrace(); } } }
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId();
public void transform(ByteBuf bytebuf) throws Exception { if (bytebuf.readableBytes() == 0) { return; // Someone Already Decoded It! } // Increment sent info.incrementSent(); if (info.isActive()) { // Handle ID int id = Type.VAR_INT.read(bytebuf); // Transform ByteBuf oldPacket = bytebuf.copy(); bytebuf.clear(); try { 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(); throw e; } finally { oldPacket.release(); } } }
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) {
@Subscribe(order = PostOrder.LAST) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { int entityId = user.get(EntityTracker.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9TO1_8.class); } } catch (Exception e) { e.printStackTrace(); } } }
@EventHandler(priority = EventPriority.HIGH) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { int entityId = user.get(EntityTracker.class).getProvidedEntityId(); PacketWrapper wrapper = new PacketWrapper(0x39, null, user); wrapper.write(Type.VAR_INT, entityId); wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0))); wrapper.send(Protocol1_9TO1_8.class); } } catch (Exception e) { e.printStackTrace(); } } }
@Subscribe public void onServerConnect(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null || setSettings == null) return; try { if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) { PlayerSettings settings = event.getPlayer().getPlayerSettings(); if (user.has(EntityTracker.class)) { Object clientSettings = ReflectionUtil.get(settings, "settings", Object.class); ReflectionUtil.set(clientSettings, "mainHand", user.get(EntityTracker.class).getMainHand()); setSettings.invoke(event.getPlayer(), clientSettings); } } } catch (Exception e) { e.printStackTrace(); } } }
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline(); user.clearStoredObjects(); pipeline.cleanPipes();