Search in sources :

Example 36 with CraftPlayer

use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.

the class v1_13_R1 method injectPlayer.

public void injectPlayer(Player player) {
    CraftPlayer player1 = (CraftPlayer) player;
    if (!player.isValid())
        return;
    if (channelHandlers.containsKey(player.getUniqueId())) {
        final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
        if (!pair.getLeft().isValid()) {
            try {
                pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
            } catch (NoSuchElementException ignored) {
            }
        } else
            return;
    }
    final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {

        @Override
        public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
            if (packet instanceof PacketPlayOutEntityEquipment) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
                }
            } else if (packet instanceof PacketPlayOutEntityMetadata) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
                    if (items.size() != 0) {
                        Item<?> item = items.get(0);
                        if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
                            Item<Byte> byteItem = (Item<Byte>) item;
                            byteItem.a((byte) (byteItem.b() | 1 << 5));
                            ((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
                        }
                    }
                }
            }
            super.write(ctx, packet, promise);
        }
    };
    channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
    player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
Also used : Item(net.minecraft.server.v1_13_R1.DataWatcher.Item) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) CraftPlayer(org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise)

Example 37 with CraftPlayer

use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.

the class v1_13_R1 method hide.

public void hide() {
    getParticipant().attributes().TARGETABLE.setValue(false);
    final CraftPlayer craftPlayer = (CraftPlayer) getPlayer();
    craftPlayer.getHandle().getDataWatcher().set(new DataWatcherObject<>(10, DataWatcherRegistry.b), 0);
    craftPlayer.getHandle().setInvisible(true);
    final PacketPlayOutEntityEquipment[] packets = { new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.MAINHAND, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.OFFHAND, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.HEAD, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.CHEST, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.LEGS, ItemStack.a), new PacketPlayOutEntityEquipment(getPlayer().getEntityId(), EnumItemSlot.FEET, ItemStack.a) };
    for (CraftPlayer player : ((CraftServer) Bukkit.getServer()).getOnlinePlayers()) {
        if (player.equals(getPlayer()))
            continue;
        for (PacketPlayOutEntityEquipment packet : packets) {
            player.getHandle().playerConnection.sendPacket(packet);
        }
        injectPlayer(player);
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_13_R1.entity.CraftPlayer) CraftServer(org.bukkit.craftbukkit.v1_13_R1.CraftServer)

Example 38 with CraftPlayer

use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.

the class v1_16_R2 method changeSkin.

@Override
public void changeSkin(Player player, UUID uuid) {
    if (origin.containsKey(uuid)) {
        CraftPlayer cp = (CraftPlayer) player;
        cp.getProfile().getProperties().removeAll("textures");
        cp.getProfile().getProperties().put("textures", origin.get(uuid).getRight());
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer)

Example 39 with CraftPlayer

use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.

the class v1_16_R2 method saveData.

@Override
public void saveData() {
    for (Player pl : Bukkit.getOnlinePlayers()) {
        if (origin.containsKey(pl.getUniqueId()))
            continue;
        if (pl.getName().isEmpty())
            continue;
        CraftPlayer cp = (CraftPlayer) pl;
        Iterator<Property> iterator = cp.getProfile().getProperties().get("textures").iterator();
        if (iterator.hasNext()) {
            origin.put(pl.getUniqueId(), Pair.of(pl.getName(), iterator.next()));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) Property(com.mojang.authlib.properties.Property)

Example 40 with CraftPlayer

use of org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer in project CokesAddon by Cokes86.

the class v1_16_R2 method addData.

@Override
public void addData(UUID uuid) {
    if (origin.containsKey(uuid))
        return;
    Player pl = Bukkit.getPlayer(uuid);
    if (pl == null)
        return;
    CraftPlayer cp = (CraftPlayer) pl;
    Iterator<Property> iterator = cp.getProfile().getProperties().get("textures").iterator();
    if (iterator.hasNext()) {
        origin.put(uuid, Pair.of(pl.getName(), iterator.next()));
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_16_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) Property(com.mojang.authlib.properties.Property)

Aggregations

Player (org.bukkit.entity.Player)234 ServerPlayer (net.minecraft.server.level.ServerPlayer)128 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)122 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)106 CraftPlayer (org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer)101 CraftPlayer (org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer)91 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)90 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)81 ItemStack (org.bukkit.inventory.ItemStack)78 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)75 EntityPlayer (net.minecraft.server.level.EntityPlayer)68 Property (com.mojang.authlib.properties.Property)67 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)66 Location (org.bukkit.Location)60 GameProfile (com.mojang.authlib.GameProfile)59 CraftPlayer (org.bukkit.craftbukkit.v1_13_R2.entity.CraftPlayer)58 CraftPlayer (org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer)55 CraftPlayer (org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer)54 CraftPlayer (org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer)49 CraftPlayer (org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer)48