Search in sources :

Example 1 with PacketOutChat_v1_11_R1

use of net.aufdemrand.denizen.nms.impl.packets.PacketOutChat_v1_11_R1 in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManager_v1_11_R1 method sendPacket.

public void sendPacket(Packet packet) {
    // If the packet sending isn't cancelled, allow normal sending
    if (packet instanceof PacketPlayOutChat) {
        if (!packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutChat_v1_11_R1((PacketPlayOutChat) packet))) {
            oldManager.sendPacket(packet);
        }
    } else if (packet instanceof PacketPlayOutNamedEntitySpawn || packet instanceof PacketPlayOutSpawnEntity || packet instanceof PacketPlayOutSpawnEntityLiving || packet instanceof PacketPlayOutSpawnEntityPainting || packet instanceof PacketPlayOutSpawnEntityExperienceOrb) {
        PacketOutSpawnEntity spawnEntity = new PacketOutSpawnEntity_v1_11_R1(player, packet);
        final Entity entity = player.getWorld().getEntity(spawnEntity.getEntityId());
        if (entity == null) {
            oldManager.sendPacket(packet);
        } else if (!NMSHandler.getInstance().getEntityHelper().isHidden(player.getBukkitEntity(), entity.getBukkitEntity())) {
            if (entity instanceof EntityFakePlayer_v1_11_R1) {
                final EntityFakePlayer_v1_11_R1 fakePlayer = (EntityFakePlayer_v1_11_R1) entity;
                sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, fakePlayer));
                Bukkit.getScheduler().runTaskLater(NMSHandler.getJavaPlugin(), new Runnable() {

                    @Override
                    public void run() {
                        sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, fakePlayer));
                    }
                }, 5);
            }
            oldManager.sendPacket(packet);
        }
    } else if (packet instanceof PacketPlayOutPlayerInfo) {
        PacketPlayOutPlayerInfo playerInfo = (PacketPlayOutPlayerInfo) packet;
        ProfileEditor_v1_11_R1.updatePlayerProfiles(playerInfo);
        oldManager.sendPacket(playerInfo);
    } else if (packet instanceof PacketPlayOutEntityMetadata) {
        if (!packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutEntityMetadata_v1_11_R1((PacketPlayOutEntityMetadata) packet))) {
            oldManager.sendPacket(packet);
        }
    } else if (packet instanceof PacketPlayOutSetSlot) {
        if (!packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutSetSlot_v1_11_R1((PacketPlayOutSetSlot) packet))) {
            oldManager.sendPacket(packet);
        }
    } else if (packet instanceof PacketPlayOutWindowItems) {
        if (!packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutWindowItems_v1_11_R1((PacketPlayOutWindowItems) packet))) {
            oldManager.sendPacket(packet);
        }
    } else if (packet instanceof PacketPlayOutCustomPayload) {
        PacketPlayOutCustomPayload payload = (PacketPlayOutCustomPayload) packet;
        PacketDataSerializer original = new PacketDataSerializer(Unpooled.buffer());
        try {
            payload.b(original);
            // Copy the data without removing it from the original
            PacketDataSerializer serializer = new PacketDataSerializer(original.getBytes(original.readerIndex(), new byte[original.readableBytes()]));
            // Write the original back to avoid odd errors
            payload.a(original);
            String name = serializer.e(20);
            if (name != null && name.equals("MC|TrList")) {
                if (!packetHandler.sendPacket(player.getBukkitEntity(), new PacketOutTradeList_v1_11_R1(payload, serializer))) {
                    oldManager.sendPacket(packet);
                }
            } else {
                oldManager.sendPacket(packet);
            }
        } catch (Exception e) {
            oldManager.sendPacket(packet);
        }
    } else {
        oldManager.sendPacket(packet);
    }
}
Also used : PacketOutSpawnEntity(net.aufdemrand.denizen.nms.interfaces.packets.PacketOutSpawnEntity) PacketOutEntityMetadata_v1_11_R1(net.aufdemrand.denizen.nms.impl.packets.PacketOutEntityMetadata_v1_11_R1) PacketOutTradeList_v1_11_R1(net.aufdemrand.denizen.nms.impl.packets.PacketOutTradeList_v1_11_R1) PacketOutChat_v1_11_R1(net.aufdemrand.denizen.nms.impl.packets.PacketOutChat_v1_11_R1) PacketOutSpawnEntity_v1_11_R1(net.aufdemrand.denizen.nms.impl.packets.PacketOutSpawnEntity_v1_11_R1) PacketOutWindowItems_v1_11_R1(net.aufdemrand.denizen.nms.impl.packets.PacketOutWindowItems_v1_11_R1) PacketOutSetSlot_v1_11_R1(net.aufdemrand.denizen.nms.impl.packets.PacketOutSetSlot_v1_11_R1) PacketOutSpawnEntity(net.aufdemrand.denizen.nms.interfaces.packets.PacketOutSpawnEntity) EntityFakePlayer_v1_11_R1(net.aufdemrand.denizen.nms.impl.entities.EntityFakePlayer_v1_11_R1)

Aggregations

EntityFakePlayer_v1_11_R1 (net.aufdemrand.denizen.nms.impl.entities.EntityFakePlayer_v1_11_R1)1 PacketOutChat_v1_11_R1 (net.aufdemrand.denizen.nms.impl.packets.PacketOutChat_v1_11_R1)1 PacketOutEntityMetadata_v1_11_R1 (net.aufdemrand.denizen.nms.impl.packets.PacketOutEntityMetadata_v1_11_R1)1 PacketOutSetSlot_v1_11_R1 (net.aufdemrand.denizen.nms.impl.packets.PacketOutSetSlot_v1_11_R1)1 PacketOutSpawnEntity_v1_11_R1 (net.aufdemrand.denizen.nms.impl.packets.PacketOutSpawnEntity_v1_11_R1)1 PacketOutTradeList_v1_11_R1 (net.aufdemrand.denizen.nms.impl.packets.PacketOutTradeList_v1_11_R1)1 PacketOutWindowItems_v1_11_R1 (net.aufdemrand.denizen.nms.impl.packets.PacketOutWindowItems_v1_11_R1)1 PacketOutSpawnEntity (net.aufdemrand.denizen.nms.interfaces.packets.PacketOutSpawnEntity)1