Search in sources :

Example 1 with StructureModifier

use of com.comphenix.protocol.reflect.StructureModifier in project RayTraceAntiXray by stonar96.

the class PacketListener method onPacketSending.

@Override
public void onPacketSending(PacketEvent event) {
    if (event.getPacketType() == PacketType.Play.Server.MAP_CHUNK) {
        PlayerData playerData = plugin.getPlayerData().get(event.getPlayer().getUniqueId());
        ChunkBlocks chunkBlocks = plugin.getPacketChunkBlocksCache().get(event.getPacket().getHandle());
        if (chunkBlocks == null) {
            Location location = event.getPlayer().getEyeLocation();
            if (!location.getWorld().equals(playerData.getLocations().get(0).getWorld())) {
                playerData = new PlayerData(plugin.getLocations(event.getPlayer(), location));
                plugin.getPlayerData().put(event.getPlayer().getUniqueId(), playerData);
            }
            // Not enabled in this world.
            return;
        }
        LevelChunk chunk = chunkBlocks.getChunk();
        if (chunk == null) {
            return;
        }
        if (!chunk.getLevel().getWorld().equals(playerData.getLocations().get(0).getWorld())) {
            Location location = event.getPlayer().getEyeLocation();
            if (!chunk.getLevel().getWorld().equals(location.getWorld())) {
                // The packet can be ignored.
                return;
            }
            playerData = new PlayerData(plugin.getLocations(event.getPlayer(), location));
            plugin.getPlayerData().put(event.getPlayer().getUniqueId(), playerData);
        }
        playerData.getChunks().put(chunk.getPos(), chunkBlocks);
    } else if (event.getPacketType() == PacketType.Play.Server.UNLOAD_CHUNK) {
        StructureModifier<Integer> integers = event.getPacket().getIntegers();
        plugin.getPlayerData().get(event.getPlayer().getUniqueId()).getChunks().remove(new ChunkPos(integers.read(0), integers.read(1)));
    }
}
Also used : LevelChunk(net.minecraft.world.level.chunk.LevelChunk) StructureModifier(com.comphenix.protocol.reflect.StructureModifier) ChunkBlocks(com.vanillage.raytraceantixray.data.ChunkBlocks) ChunkPos(net.minecraft.world.level.ChunkPos) PlayerData(com.vanillage.raytraceantixray.data.PlayerData) Location(org.bukkit.Location)

Example 2 with StructureModifier

use of com.comphenix.protocol.reflect.StructureModifier in project LibsDisguises by libraryaddict.

the class PacketListenerViewSelfDisguise method onPacketSending.

@Override
public void onPacketSending(final PacketEvent event) {
    if (event.isCancelled()) {
        return;
    }
    try {
        final Player observer = event.getPlayer();
        if (observer.getName().contains("UNKNOWN[")) {
            // If the player is temporary
            return;
        }
        PacketContainer packet = event.getPacket();
        // If packet isn't meant for the disguised player's self disguise
        if (packet.getIntegers().read(0) != observer.getEntityId()) {
            return;
        }
        if (!DisguiseAPI.isSelfDisguised(observer)) {
            return;
        }
        final Disguise disguise = DisguiseAPI.getDisguise(observer, observer);
        if (disguise == null) {
            return;
        }
        // Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
        LibsPackets transformed = PacketsManager.getPacketsHandler().transformPacket(packet, disguise, observer, observer);
        if (transformed.isUnhandled()) {
            transformed.addPacket(packet);
        }
        LibsPackets selfTransformed = new LibsPackets(disguise);
        for (PacketContainer newPacket : transformed.getPackets()) {
            if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY && newPacket.getIntegers().read(0) == observer.getEntityId()) {
                if (newPacket == packet) {
                    newPacket = newPacket.shallowClone();
                }
                newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
            }
            selfTransformed.addPacket(newPacket);
        }
        for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : transformed.getDelayedPacketsMap().entrySet()) {
            for (PacketContainer newPacket : entry.getValue()) {
                if (newPacket == packet) {
                    newPacket = newPacket.shallowClone();
                }
                if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY) {
                    newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
                }
                selfTransformed.addDelayedPacket(newPacket, entry.getKey());
            }
        }
        if (disguise.isPlayerDisguise()) {
            LibsDisguises.getInstance().getSkinHandler().handlePackets(observer, (PlayerDisguise) disguise, selfTransformed);
        }
        try {
            for (PacketContainer newPacket : selfTransformed.getPackets()) {
                ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false);
            }
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        selfTransformed.sendDelayed(observer);
        if (event.getPacketType() == Server.ENTITY_METADATA) {
            if (!LibsPremium.getPluginInformation().isPremium() || LibsPremium.getPaidInformation() != null || LibsPremium.getPluginInformation().getBuildNumber().matches("#[0-9]+")) {
                event.setPacket(packet = packet.deepClone());
            }
            for (WrappedWatchableObject watch : packet.getWatchableCollectionModifier().read(0)) {
                if (watch.getIndex() != 0) {
                    continue;
                }
                byte b = (byte) watch.getRawValue();
                // Add invisibility, remove glowing
                byte a = (byte) ((b | 1 << 5) & ~(1 << 6));
                watch.setValue(a);
            }
        } else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) {
            event.setCancelled(true);
            PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
            StructureModifier<Object> mods = metaPacket.getModifier();
            mods.write(0, observer.getEntityId());
            List<WrappedWatchableObject> watchableList = new ArrayList<>();
            byte b = 1 << 5;
            if (observer.isSprinting()) {
                b = (byte) (b | 1 << 3);
            }
            WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META, b);
            if (watch != null) {
                watchableList.add(watch);
            }
            metaPacket.getWatchableCollectionModifier().write(0, watchableList);
            try {
                ProtocolLibrary.getProtocolManager().sendServerPacket(observer, metaPacket);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        } else if (event.getPacketType() == Server.ANIMATION) {
            if (packet.getIntegers().read(1) != 2) {
                event.setCancelled(true);
            }
        } else if (event.getPacketType() == Server.ATTACH_ENTITY || event.getPacketType() == Server.REL_ENTITY_MOVE || event.getPacketType() == Server.REL_ENTITY_MOVE_LOOK || event.getPacketType() == Server.ENTITY_LOOK || event.getPacketType() == Server.ENTITY_TELEPORT || event.getPacketType() == Server.ENTITY_HEAD_ROTATION || event.getPacketType() == Server.ENTITY_EQUIPMENT) {
            event.setCancelled(true);
        } else if (event.getPacketType() == Server.ENTITY_STATUS) {
            if (disguise.isSelfDisguiseSoundsReplaced() && !disguise.getType().isPlayer() && packet.getBytes().read(0) == 2) {
                event.setCancelled(true);
            }
        } else if (event.getPacketType() == Server.ENTITY_VELOCITY && !DisguiseUtilities.isPlayerVelocity(observer)) {
            // The player only sees velocity changes when there is a velocity event. As the method claims there
            // was no velocity event...
            event.setCancelled(true);
            // Clear old velocity, this should only occur once.
            DisguiseUtilities.setPlayerVelocity(null);
        }
    } catch (Throwable ex) {
        event.setCancelled(true);
        ex.printStackTrace();
    }
}
Also used : Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) Disguise(me.libraryaddict.disguise.disguisetypes.Disguise) PlayerDisguise(me.libraryaddict.disguise.disguisetypes.PlayerDisguise) LibsPackets(me.libraryaddict.disguise.utilities.packets.LibsPackets) StructureModifier(com.comphenix.protocol.reflect.StructureModifier) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) WrappedWatchableObject(com.comphenix.protocol.wrappers.WrappedWatchableObject) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with StructureModifier

use of com.comphenix.protocol.reflect.StructureModifier in project LibsDisguises by libraryaddict.

the class PacketListenerInventory method onPacketReceiving.

@Override
public void onPacketReceiving(final PacketEvent event) {
    if (event.isCancelled() || event.isPlayerTemporary()) {
        return;
    }
    final Player player = event.getPlayer();
    if (player == null || player.getVehicle() != null) {
        return;
    }
    if (event.isAsync()) {
        new BukkitRunnable() {

            @Override
            public void run() {
                onPacketReceiving(event);
            }
        }.runTask(LibsDisguises.getInstance());
        return;
    }
    if (!DisguiseConfig.isHidingCreativeEquipmentFromSelf() && player.getGameMode() == GameMode.CREATIVE) {
        return;
    }
    Disguise disguise = DisguiseAPI.getDisguise(player, player);
    // If player is disguised, views self disguises and has a inventory modifier
    if (disguise == null || !DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId()) || (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
        return;
    }
    // If they are in creative and clicked on a slot
    if (event.getPacketType() == PacketType.Play.Client.SET_CREATIVE_SLOT) {
        int slot = event.getPacket().getIntegers().read(0);
        if (slot >= 5 && slot <= 8) {
            if (disguise.isHidingArmorFromSelf()) {
                int armorSlot = Math.abs((slot - 5) - 3);
                org.bukkit.inventory.ItemStack item = player.getInventory().getArmorContents()[armorSlot];
                if (item != null && item.getType() != Material.AIR && item.getType() != Material.ELYTRA) {
                    PacketContainer packet = new PacketContainer(Server.SET_SLOT);
                    StructureModifier<Object> mods = packet.getModifier();
                    mods.write(0, 0);
                    mods.write(NmsVersion.v1_17.isSupported() ? 2 : 1, slot);
                    if (NmsVersion.v1_17.isSupported()) {
                        mods.write(1, ReflectionManager.getIncrementedStateId(player));
                    }
                    packet.getItemModifier().write(0, new ItemStack(Material.AIR));
                    try {
                        ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            }
        } else if (slot >= 36 && slot <= 45) {
            if (disguise.isHidingHeldItemFromSelf()) {
                int currentSlot = player.getInventory().getHeldItemSlot();
                if (slot + 36 == currentSlot || slot == 45) {
                    org.bukkit.inventory.ItemStack item = player.getInventory().getItemInMainHand();
                    if (item != null && item.getType() != Material.AIR) {
                        PacketContainer packet = new PacketContainer(Server.SET_SLOT);
                        StructureModifier<Object> mods = packet.getModifier();
                        mods.write(0, 0);
                        mods.write(NmsVersion.v1_17.isSupported() ? 2 : 1, slot);
                        if (NmsVersion.v1_17.isSupported()) {
                            mods.write(1, ReflectionManager.getIncrementedStateId(player));
                        }
                        packet.getItemModifier().write(0, new ItemStack(Material.AIR));
                        try {
                            ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
                        } catch (InvocationTargetException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    } else if (event.getPacketType() == PacketType.Play.Client.WINDOW_CLICK) {
        int slot = event.getPacket().getIntegers().read(NmsVersion.v1_17.isSupported() ? 2 : 1);
        org.bukkit.inventory.ItemStack clickedItem;
        int type;
        if (NmsVersion.v1_17.isSupported()) {
            type = event.getPacket().getIntegers().read(3);
        } else {
            type = event.getPacket().getShorts().read(0);
        }
        if (type == 1) {
            // Its a shift click
            clickedItem = event.getPacket().getItemModifier().read(0);
            if (clickedItem != null && clickedItem.getType() != Material.AIR) {
                // Rather than predict the clients actions
                // Lets just update the entire inventory..
                Bukkit.getScheduler().runTask(libsDisguises, new Runnable() {

                    public void run() {
                        player.updateInventory();
                    }
                });
            }
            return;
        } else {
            // Shift clicking is exempted for the item in hand..
            if (event.getPacket().getIntegers().read(0) != 0) {
                return;
            }
            clickedItem = player.getItemOnCursor();
        }
        if (clickedItem != null && clickedItem.getType() != Material.AIR && clickedItem.getType() != Material.ELYTRA) {
            // If the slot is a armor slot
            if (slot >= 5 && slot <= 8) {
                if (disguise.isHidingArmorFromSelf()) {
                    PacketContainer packet = new PacketContainer(Server.SET_SLOT);
                    StructureModifier<Object> mods = packet.getModifier();
                    mods.write(0, 0);
                    mods.write(NmsVersion.v1_17.isSupported() ? 2 : 1, slot);
                    if (NmsVersion.v1_17.isSupported()) {
                        mods.write(1, ReflectionManager.getIncrementedStateId(player));
                    }
                    packet.getItemModifier().write(0, new ItemStack(Material.AIR));
                    try {
                        ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                }
            // Else if its a hotbar slot
            } else if (slot >= 36 && slot <= 45) {
                if (disguise.isHidingHeldItemFromSelf()) {
                    int currentSlot = player.getInventory().getHeldItemSlot();
                    // Check if the player is on the same slot as the slot that its setting
                    if (slot == currentSlot + 36 || slot == 45) {
                        PacketContainer packet = new PacketContainer(Server.SET_SLOT);
                        StructureModifier<Object> mods = packet.getModifier();
                        mods.write(0, 0);
                        mods.write(NmsVersion.v1_17.isSupported() ? 2 : 1, slot);
                        if (NmsVersion.v1_17.isSupported()) {
                            mods.write(1, ReflectionManager.getIncrementedStateId(player));
                        }
                        try {
                            ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
                        } catch (InvocationTargetException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Disguise(me.libraryaddict.disguise.disguisetypes.Disguise) PacketContainer(com.comphenix.protocol.events.PacketContainer) StructureModifier(com.comphenix.protocol.reflect.StructureModifier) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) InvocationTargetException(java.lang.reflect.InvocationTargetException) ItemStack(org.bukkit.inventory.ItemStack) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with StructureModifier

use of com.comphenix.protocol.reflect.StructureModifier in project LibsDisguises by libraryaddict.

the class PacketListenerInventory method onPacketSending.

@Override
public void onPacketSending(PacketEvent event) {
    Player player = event.getPlayer();
    // If the inventory is the players inventory
    if (event.isPlayerTemporary() || player.getVehicle() != null || event.getPacket().getIntegers().read(0) != 0) {
        return;
    }
    if (!DisguiseConfig.isHidingCreativeEquipmentFromSelf() && player.getGameMode() == GameMode.CREATIVE) {
        return;
    }
    Disguise disguise = DisguiseAPI.getDisguise(player, player);
    if (disguise == null || !DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId()) || (!disguise.isHidingArmorFromSelf() && !disguise.isHidingHeldItemFromSelf())) {
        return;
    }
    // Things such as picking up a item, spawned in item. Plugin sets the item. etc. Will fire this
    if (event.getPacketType() == Server.SET_SLOT) {
        // The raw slot
        // nms code has the start of the hotbar being 36.
        int slot = event.getPacket().getIntegers().read(NmsVersion.v1_17.isSupported() ? 2 : 1);
        // If the slot is a armor slot
        if (slot >= 5 && slot <= 8) {
            if (disguise.isHidingArmorFromSelf()) {
                // Get the bukkit armor slot!
                int armorSlot = Math.abs((slot - 5) - 3);
                org.bukkit.inventory.ItemStack item = player.getInventory().getArmorContents()[armorSlot];
                if (item != null && item.getType() != Material.AIR && item.getType() != Material.ELYTRA) {
                    event.setPacket(event.getPacket().shallowClone());
                    event.getPacket().getItemModifier().write(0, new ItemStack(Material.AIR));
                }
            }
        // Else if its a hotbar slot
        } else if (slot >= 36 && slot <= 45) {
            if (disguise.isHidingHeldItemFromSelf()) {
                int currentSlot = player.getInventory().getHeldItemSlot();
                // Check if the player is on the same slot as the slot that its setting
                if (slot == currentSlot + 36 || slot == 45) {
                    org.bukkit.inventory.ItemStack item = player.getInventory().getItemInMainHand();
                    if (item != null && item.getType() != Material.AIR) {
                        event.setPacket(event.getPacket().shallowClone());
                        event.getPacket().getItemModifier().write(0, new ItemStack(Material.AIR));
                    }
                }
            }
        }
    } else if (event.getPacketType() == Server.WINDOW_ITEMS) {
        event.setPacket(event.getPacket().shallowClone());
        StructureModifier<List<ItemStack>> mods = event.getPacket().getItemListModifier();
        List<ItemStack> items = new ArrayList<>(mods.read(0));
        for (int slot = 0; slot < items.size(); slot++) {
            if (slot >= 5 && slot <= 8) {
                if (disguise.isHidingArmorFromSelf()) {
                    // Get the bukkit armor slot!
                    int armorSlot = Math.abs((slot - 5) - 3);
                    ItemStack item = player.getInventory().getArmorContents()[armorSlot];
                    if (item != null && item.getType() != Material.AIR && item.getType() != Material.ELYTRA) {
                        items.set(slot, new ItemStack(Material.AIR));
                    }
                }
            // Else if its a hotbar slot
            } else if (slot >= 36 && slot <= 45) {
                if (disguise.isHidingHeldItemFromSelf()) {
                    int currentSlot = player.getInventory().getHeldItemSlot();
                    // Check if the player is on the same slot as the slot that its setting
                    if (slot == currentSlot + 36 || slot == 45) {
                        ItemStack item = player.getInventory().getItemInMainHand();
                        if (item != null && item.getType() != Material.AIR) {
                            items.set(slot, new ItemStack(Material.AIR));
                        }
                    }
                }
            }
        }
        mods.write(0, items);
    }
}
Also used : Player(org.bukkit.entity.Player) Disguise(me.libraryaddict.disguise.disguisetypes.Disguise) StructureModifier(com.comphenix.protocol.reflect.StructureModifier) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 5 with StructureModifier

use of com.comphenix.protocol.reflect.StructureModifier in project LibsDisguises by libraryaddict.

the class PacketHandlerMovement method handle2.

public void handle2(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
    if (invalid && RandomUtils.nextDouble() < 0.1) {
        packets.clear();
        return;
    }
    double yMod = DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier();
    // If falling block should be appearing in center of blocks
    if (disguise.getType() == DisguiseType.FALLING_BLOCK && ((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) {
        packets.clear();
        if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK) {
            return;
        }
        PacketContainer movePacket = sentPacket.shallowClone();
        Location loc = entity.getLocation();
        // If not relational movement
        if (movePacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
            StructureModifier<Double> doubles = movePacket.getDoubles();
            // Center the block
            doubles.write(0, loc.getBlockX() + 0.5);
            double y = loc.getBlockY();
            y += (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0);
            doubles.write(1, y + yMod);
            doubles.write(2, loc.getBlockZ() + 0.5);
        } else {
            int x;
            int y;
            int z;
            if (NmsVersion.v1_14.isSupported()) {
                StructureModifier<Short> shorts = movePacket.getShorts();
                x = shorts.read(0);
                y = shorts.read(1);
                z = shorts.read(2);
            } else {
                StructureModifier<Integer> ints = movePacket.getIntegers();
                x = ints.read(0);
                y = ints.read(1);
                z = ints.read(2);
            }
            Vector diff = new Vector(x / 4096D, y / 4096D, z / 4096D);
            Location newLoc = loc.clone().subtract(diff);
            double origY = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0);
            double newY = newLoc.getBlockY() + (newLoc.getY() % 1 >= 0.85 ? 1 : newLoc.getY() % 1 >= 0.35 ? .5 : 0);
            boolean sameBlock = loc.getBlockX() == newLoc.getBlockX() && newY == origY && loc.getBlockZ() == newLoc.getBlockZ();
            if (sameBlock) {
                // Make no modifications but don't send anything
                return;
            } else {
                x = conRel(loc.getBlockX(), newLoc.getBlockX());
                y = conRel(origY, newY);
                z = conRel(loc.getBlockZ(), newLoc.getBlockZ());
                if (NmsVersion.v1_14.isSupported()) {
                    StructureModifier<Short> shorts = movePacket.getShorts();
                    shorts.write(0, (short) x);
                    shorts.write(1, (short) y);
                    shorts.write(2, (short) z);
                } else {
                    StructureModifier<Integer> ints = movePacket.getIntegers();
                    ints.write(0, x);
                    ints.write(1, y);
                    ints.write(2, z);
                }
            }
        }
        packets.addPacket(movePacket);
        return;
    } else if (disguise.getType() == DisguiseType.RABBIT && (sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE || sentPacket.getType() == PacketType.Play.Server.REL_ENTITY_MOVE_LOOK)) {
        // When did the rabbit disguise last hop
        long lastHop = 999999;
        // If hop meta exists, set the last hop time
        if (!entity.getMetadata("LibsRabbitHop").isEmpty()) {
            // Last hop was 3 minutes ago, so subtract current time with the last hop time and get 3
            // minutes ago in milliseconds
            lastHop = System.currentTimeMillis() - entity.getMetadata("LibsRabbitHop").get(0).asLong();
        }
        // If last hop was less than 0.1 or more than 0.5 seconds ago
        if (lastHop < 100 || lastHop > 500) {
            if (lastHop > 500) {
                entity.removeMetadata("LibsRabbitHop", LibsDisguises.getInstance());
                entity.setMetadata("LibsRabbitHop", new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis()));
            }
            PacketContainer statusPacket = new PacketContainer(PacketType.Play.Server.ENTITY_STATUS);
            packets.addPacket(statusPacket);
            statusPacket.getIntegers().write(0, entity.getEntityId());
            statusPacket.getBytes().write(0, (byte) 1);
        }
    }
    if (sentPacket.getType() == PacketType.Play.Server.ENTITY_LOOK && disguise.getType() == DisguiseType.WITHER_SKULL) {
        // Stop wither skulls from looking
        packets.clear();
    } else {
        if (sentPacket.getType() != PacketType.Play.Server.REL_ENTITY_MOVE) {
            packets.clear();
            PacketContainer movePacket = sentPacket.shallowClone();
            packets.addPacket(movePacket);
            StructureModifier<Byte> bytes = movePacket.getBytes();
            byte yawValue = bytes.read(0);
            byte pitchValue = bytes.read(1);
            Float pitchLock = disguise.getWatcher().getPitchLock();
            Float yawLock = disguise.getWatcher().getYawLock();
            if (pitchLock != null) {
                pitchValue = (byte) (int) (pitchLock * 256.0F / 360.0F);
                pitchValue = DisguiseUtilities.getPitch(disguise.getType(), pitchValue);
            } else {
                pitchValue = DisguiseUtilities.getPitch(disguise.getType(), entity.getType(), pitchValue);
            }
            if (yawLock != null) {
                yawValue = (byte) (int) (yawLock * 256.0F / 360.0F);
                yawValue = DisguiseUtilities.getYaw(disguise.getType(), yawValue);
            } else {
                yawValue = DisguiseUtilities.getYaw(disguise.getType(), entity.getType(), yawValue);
            }
            bytes.write(0, yawValue);
            bytes.write(1, pitchValue);
            if (entity == observer.getVehicle() && AbstractHorse.class.isAssignableFrom(disguise.getType().getEntityClass())) {
                PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_LOOK);
                packet.getIntegers().write(0, DisguiseAPI.getEntityAttachmentId());
                packet.getBytes().write(0, yawValue);
                packet.getBytes().write(1, pitchValue);
                packets.addPacket(packet);
            } else if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
                StructureModifier<Double> doubles = movePacket.getDoubles();
                Location loc = entity.getLocation();
                double data = (((loc.getYaw() % 360) + 720 + 45) / 90) % 4;
                if (data % 2 == 0) {
                    if (data % 2 == 0) {
                        doubles.write(3, loc.getZ());
                    } else {
                        doubles.write(1, loc.getZ());
                    }
                }
                double y = DisguiseUtilities.getYModifier(disguise);
                if (y != 0) {
                    doubles.write(2, doubles.read(2) + y);
                }
            } else if (disguise.getType() == DisguiseType.DOLPHIN) {
                movePacket.getBooleans().write(0, false);
            }
        } else if (disguise.getType() == DisguiseType.DOLPHIN) {
            // Dolphins act funny on the ground, so lets not tell the clients they are on the ground
            packets.clear();
            PacketContainer movePacket = sentPacket.shallowClone();
            packets.addPacket(movePacket);
            movePacket.getBooleans().write(0, false);
        }
        if (yMod != 0 && sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
            PacketContainer packet = packets.getPackets().get(0);
            if (packet == sentPacket) {
                packet = packet.shallowClone();
                packets.clear();
                packets.addPacket(packet);
            }
            StructureModifier<Double> doubles = packet.getDoubles();
            doubles.write(1, doubles.read(1) + yMod);
        }
    }
}
Also used : AbstractHorse(org.bukkit.entity.AbstractHorse) PacketContainer(com.comphenix.protocol.events.PacketContainer) StructureModifier(com.comphenix.protocol.reflect.StructureModifier) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

StructureModifier (com.comphenix.protocol.reflect.StructureModifier)6 PacketContainer (com.comphenix.protocol.events.PacketContainer)4 Disguise (me.libraryaddict.disguise.disguisetypes.Disguise)4 Player (org.bukkit.entity.Player)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Location (org.bukkit.Location)3 ItemStack (org.bukkit.inventory.ItemStack)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PlayerDisguise (me.libraryaddict.disguise.disguisetypes.PlayerDisguise)2 LibsPackets (me.libraryaddict.disguise.utilities.packets.LibsPackets)2 Vector (org.bukkit.util.Vector)2 PacketType (com.comphenix.protocol.PacketType)1 ProtocolLibrary (com.comphenix.protocol.ProtocolLibrary)1 WrappedAttribute (com.comphenix.protocol.wrappers.WrappedAttribute)1 WrappedDataWatcher (com.comphenix.protocol.wrappers.WrappedDataWatcher)1 WrappedWatchableObject (com.comphenix.protocol.wrappers.WrappedWatchableObject)1 Pair (com.mojang.datafixers.util.Pair)1 ChunkBlocks (com.vanillage.raytraceantixray.data.ChunkBlocks)1 PlayerData (com.vanillage.raytraceantixray.data.PlayerData)1