Search in sources :

Example 6 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item 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 7 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project CokesAddon by Cokes86.

the class v1_14_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_14_R1.DataWatcher.Item) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise)

Example 8 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project PublicCrafters by BananaPuncher714.

the class CustomInventoryCrafting method remove.

@Override
public void remove() {
    display.stop();
    for (ItemStack item : items) {
        org.bukkit.inventory.ItemStack is = CraftItemStack.asBukkitCopy(item);
        if (is.getType() != Material.AIR) {
            bloc.getWorld().dropItem(bloc.clone().add(.5, .9, .5), is);
        }
    }
    items.clear();
}
Also used : ItemStack(net.minecraft.server.v1_15_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)

Example 9 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project RoseStacker by Rosewood-Development.

the class NMSHandlerImpl method updateEntityNameTagForPlayer.

@Override
public void updateEntityNameTagForPlayer(Player player, org.bukkit.entity.Entity entity, String customName, boolean customNameVisible) {
    try {
        List<Item<?>> dataWatchers = new ArrayList<>();
        Optional<IChatBaseComponent> nameComponent = Optional.ofNullable(CraftChatMessage.fromStringOrNull(customName));
        dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.f.a(2), nameComponent));
        dataWatchers.add(new DataWatcher.Item<>(DataWatcherRegistry.i.a(3), customNameVisible));
        PacketPlayOutEntityMetadata packetPlayOutEntityMetadata = new PacketPlayOutEntityMetadata();
        field_PacketPlayOutEntityMetadata_a.set(packetPlayOutEntityMetadata, entity.getEntityId());
        field_PacketPlayOutEntityMetadata_b.set(packetPlayOutEntityMetadata, dataWatchers);
        ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packetPlayOutEntityMetadata);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Item(net.minecraft.server.v1_16_R2.DataWatcher.Item) ArrayList(java.util.ArrayList) PacketPlayOutEntityMetadata(net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata) IChatBaseComponent(net.minecraft.server.v1_16_R2.IChatBaseComponent) CraftPlayer(org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer) DataWatcher(net.minecraft.server.v1_16_R2.DataWatcher)

Example 10 with Item

use of net.minecraft.server.v1_15_R1.DataWatcher.Item in project SilkSpawners by timbru31.

the class NMSHandler method setNBTEntityID.

@Override
public ItemStack setNBTEntityID(final ItemStack item, final String entity) {
    if (item == null || StringUtils.isBlank(entity)) {
        Bukkit.getLogger().warning("[SilkSpawners] Skipping invalid spawner to set NBT data on.");
        return null;
    }
    String prefixedEntity;
    if (!entity.startsWith("minecraft:")) {
        prefixedEntity = "minecraft:" + entity;
    } else {
        prefixedEntity = entity;
    }
    net.minecraft.server.v1_15_R1.ItemStack itemStack = null;
    final CraftItemStack craftStack = CraftItemStack.asCraftCopy(item);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getOrCreateTag();
    // Check for SilkSpawners key
    if (!tag.hasKey("SilkSpawners")) {
        tag.set("SilkSpawners", new NBTTagCompound());
    }
    tag.getCompound("SilkSpawners").setString("entity", entity);
    // Check for Vanilla keys
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = tag.getCompound("BlockEntityTag");
    // EntityId - Deprecated in 1.9
    tag.setString("EntityId", entity);
    tag.setString("id", TileEntityTypes.a(TileEntityTypes.MOB_SPAWNER).getKey());
    // SpawnData
    if (!tag.hasKey("SpawnData")) {
        tag.set("SpawnData", new NBTTagCompound());
    }
    tag.getCompound("SpawnData").setString("id", prefixedEntity);
    if (!tag.hasKey("SpawnPotentials")) {
        tag.set("SpawnPotentials", new NBTTagCompound());
    }
    // SpawnEgg data
    if (!tag.hasKey("EntityTag")) {
        tag.set("EntityTag", new NBTTagCompound());
    }
    tag.getCompound("EntityTag").setString("id", prefixedEntity);
    return CraftItemStack.asCraftMirror(itemStack);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_15_R1.NBTTagCompound)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack)12 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)8 ChannelPromise (io.netty.channel.ChannelPromise)8 NBTTagCompound (net.minecraft.server.v1_15_R1.NBTTagCompound)8 ItemStack (org.bukkit.inventory.ItemStack)7 ArrayList (java.util.ArrayList)5 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 Container (net.minecraft.server.v1_15_R1.Container)3 CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)3 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)2 Field (java.lang.reflect.Field)2 Timestamp (java.sql.Timestamp)2 UUID (java.util.UUID)2 Nullable (javax.annotation.Nullable)2 ContainerAnvil (net.minecraft.server.v1_15_R1.ContainerAnvil)2 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)2 Item (net.minecraft.server.v1_15_R1.Item)2 ItemStack (net.minecraft.server.v1_15_R1.ItemStack)2