Search in sources :

Example 91 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project CitizensBooks by NicoNekoDev.

the class DistributionHandler method convertJsonToBook.

@Override
public ItemStack convertJsonToBook(JsonObject jsonBook) throws IllegalAccessException {
    ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
    BookMeta bookMeta = (BookMeta) newBook.getItemMeta();
    JsonPrimitive jsonAuthor = jsonBook.getAsJsonPrimitive("author");
    JsonPrimitive jsonTitle = jsonBook.getAsJsonPrimitive("title");
    JsonArray jsonPages = jsonBook.getAsJsonArray("pages");
    bookMeta.setAuthor(jsonAuthor.isString() ? jsonAuthor.getAsString() : "Server");
    bookMeta.setTitle(jsonTitle.isString() ? jsonTitle.getAsString() : "Title");
    List<IChatBaseComponent> pages = new ArrayList<>();
    for (JsonElement jsonPage : jsonPages) {
        pages.add(IChatBaseComponent.ChatSerializer.a(jsonPage.toString()));
    }
    this.pagesField.set(bookMeta, pages);
    newBook.setItemMeta(bookMeta);
    return newBook;
}
Also used : ArrayList(java.util.ArrayList) IChatBaseComponent(net.minecraft.server.v1_8_R2.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Example 92 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project TheAPI by TheDevTec.

the class v1_8_R2 method createAnvilContainer.

public Object createAnvilContainer(Inventory inv, Player player) {
    int id = ((CraftPlayer) player).getHandle().nextContainerCounter();
    ContainerAnvil anvil = new ContainerAnvil(((CraftPlayer) player).getHandle().inventory, ((CraftPlayer) player).getHandle().world, zero, ((CraftPlayer) player).getHandle());
    anvil.windowId = id;
    for (int i = 0; i < 2; ++i) anvil.setItem(i, (net.minecraft.server.v1_8_R2.ItemStack) asNMSItem(inv.getItem(i)));
    return anvil;
}
Also used : ContainerAnvil(net.minecraft.server.v1_8_R2.ContainerAnvil) CraftPlayer(org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)

Example 93 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project TheAPI by TheDevTec.

the class v1_8_R2 method openGUI.

@Override
public void openGUI(Player player, Object container, String legacy, int size, String title, ItemStack[] items) {
    EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
    int id = ((Container) container).windowId;
    net.minecraft.server.v1_8_R2.ItemStack[] nmsItems = new net.minecraft.server.v1_8_R2.ItemStack[items.length];
    for (int i = 0; i < items.length; ++i) {
        ItemStack is = items[i];
        if (is == null || is.getType() == Material.AIR)
            continue;
        net.minecraft.server.v1_8_R2.ItemStack item = null;
        ((Container) container).setItem(i, item = (net.minecraft.server.v1_8_R2.ItemStack) asNMSItem(is));
        nmsItems[i] = item;
    }
    BukkitLoader.getPacketHandler().send(player, packetOpenWindow(id, legacy, size, title));
    int i = 0;
    for (net.minecraft.server.v1_8_R2.ItemStack o : nmsItems) BukkitLoader.getPacketHandler().send(player, packetSetSlot(id, i++, o));
    nmsPlayer.activeContainer.transferTo((Container) container, (CraftPlayer) player);
    nmsPlayer.activeContainer = (Container) container;
    ((Container) container).addSlotListener(nmsPlayer);
    ((Container) container).checkReachable = false;
}
Also used : IContainer(net.minecraft.server.v1_8_R2.IContainer) CraftContainer(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftContainer) Container(net.minecraft.server.v1_8_R2.Container) EntityPlayer(net.minecraft.server.v1_8_R2.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)

Example 94 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_16_R1.Container) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound) NBTTagCompound(net.minecraft.server.v1_16_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_16_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 95 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    int containerSlotsSize = 0;
    if (is_1_12_2) {
        containerSlotsSize = container.slots.size();
    } else {
        try {
            Field slotsField = Container.class.getField("c");
            List<Slot> slots = (List<Slot>) slotsField.get(container);
            containerSlotsSize = slots.size();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    for (int slot = 0; slot < containerSlotsSize; slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) Field(java.lang.reflect.Field) Container(net.minecraft.server.v1_12_R1.Container) Slot(net.minecraft.server.v1_12_R1.Slot) List(java.util.List) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Aggregations

ItemStack (net.minecraft.server.v1_12_R1.ItemStack)28 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)27 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)21 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)20 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)17 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)16 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)14 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)13 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)12 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)12 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)11 ItemStack (org.bukkit.inventory.ItemStack)11 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)10 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)10 Location (org.bukkit.Location)10 TagCompound (de.keyle.knbt.TagCompound)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ItemStack (net.minecraft.server.v1_13_R2.ItemStack)9