Search in sources :

Example 41 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project Glowstone by GlowstoneMC.

the class PluginMessageHandler method handleInternal.

private void handleInternal(GlowSession session, String channel, byte... data) {
    /*
        MC|Brand
            entire data: string of client's brand (e.g. "vanilla")
        MC|BEdit
            item stack: new book item (should be verified)
        MC|BSign
            item stack: new book item (should be verified)
        MC|TrSel
            int: villager trade to select
        MC|AdvCdm
            byte: mode
            if 0:
                int x, int y, int z (command block in world)
            if 1:
                int entity (command block minecart)
            string: command to set
        MC|Beacon
            two ints, presumably the selected enchants
        MC|ItemName
            entire data: name to apply to item in anvil
         */
    ByteBuf buf = Unpooled.wrappedBuffer(data);
    switch(channel) {
        case "MC|Brand":
            // vanilla server doesn't handle this, for now just log it
            String brand = null;
            try {
                brand = ByteBufUtils.readUTF8(buf);
            } catch (IOException e) {
                GlowServer.logger.log(Level.WARNING, "Error reading client brand of " + session, e);
            }
            if (brand != null && !brand.equals("vanilla")) {
                GlowServer.logger.info("Client brand of " + session.getPlayer().getName() + " is: " + brand);
            }
            break;
        case "MC|BEdit":
            {
                // read and verify stack
                ItemStack item = GlowBufUtils.readSlot(buf);
                //GlowServer.logger.info("BookEdit [" + session.getPlayer().getName() + "]: " + item);
                if (item == null || item.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta meta = item.getItemMeta();
                if (!(meta instanceof BookMeta)) {
                    return;
                }
                BookMeta book = (BookMeta) meta;
                if (!book.hasPages()) {
                    return;
                }
                // verify item in hand
                ItemStack inHand = session.getPlayer().getItemInHand();
                if (inHand == null || inHand.getType() != Material.BOOK_AND_QUILL) {
                    return;
                }
                ItemMeta handMeta = inHand.getItemMeta();
                if (!(handMeta instanceof BookMeta)) {
                    return;
                }
                BookMeta handBook = (BookMeta) handMeta;
                // apply pages to book
                handBook.setPages(book.getPages());
                inHand.setItemMeta(handBook);
                session.getPlayer().setItemInHand(inHand);
                break;
            }
        case "MC|BSign":
            // read and verify stack
            ItemStack item = GlowBufUtils.readSlot(buf);
            //GlowServer.logger.info("BookSign [" + session.getPlayer().getName() + "]: " + item);
            if (item == null || item.getType() != Material.WRITTEN_BOOK) {
                return;
            }
            ItemMeta meta = item.getItemMeta();
            if (!(meta instanceof BookMeta)) {
                return;
            }
            BookMeta book = (BookMeta) meta;
            if (!book.hasPages() || !book.hasTitle()) {
                return;
            }
            // verify item in hand
            ItemStack inHand = session.getPlayer().getItemInHand();
            if (inHand == null || inHand.getType() != Material.BOOK_AND_QUILL) {
                return;
            }
            ItemMeta handMeta = inHand.getItemMeta();
            if (!(handMeta instanceof BookMeta)) {
                return;
            }
            BookMeta handBook = (BookMeta) handMeta;
            // apply pages, title, and author to book
            handBook.setAuthor(session.getPlayer().getName());
            handBook.setTitle(book.getTitle());
            handBook.setPages(book.getPages());
            inHand.setType(Material.WRITTEN_BOOK);
            inHand.setItemMeta(handBook);
            session.getPlayer().setItemInHand(inHand);
            break;
        case "MC|ItemName":
            if (session.getPlayer().getOpenInventory() == null) {
                break;
            }
            // check if player is in an anvil inventory
            if (session.getPlayer().getOpenInventory().getType() != InventoryType.ANVIL) {
                break;
            }
            // get the new name for the item
            String name;
            try {
                name = ByteBufUtils.readUTF8(buf);
            } catch (IOException e) {
                GlowServer.logger.log(Level.WARNING, "Error reading anvil item name by " + session, e);
                break;
            }
            ((GlowAnvilInventory) session.getPlayer().getOpenInventory().getTopInventory()).setRenameText(name);
            break;
        default:
            GlowServer.logger.info(session + " used unknown Minecraft channel: " + channel);
            break;
    }
    buf.release();
}
Also used : GlowAnvilInventory(net.glowstone.inventory.GlowAnvilInventory) IOException(java.io.IOException) ByteBuf(io.netty.buffer.ByteBuf) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 42 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project SpaciousLib by anhcraft.

the class SItems method removeLore.

/**
     * Remove lore of an item
     *
     * @param order numerical order of row
     */
public void removeLore(int order) {
    ItemMeta a = this.item.getItemMeta();
    List<String> lores = a.getLore();
    lores.remove(order);
    a.setLore(lores);
    this.item.setItemMeta(a);
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 43 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project SpaciousLib by anhcraft.

the class SItems method addEnchant.

/**
     * Add an echantment for an item
     *
     * @param enchant the enchant name
     * @param level   the enchant level
     */
public void addEnchant(Enchantment enchant, int level) {
    ItemMeta a = this.item.getItemMeta();
    a.addEnchant(enchant, level, true);
    this.item.setItemMeta(a);
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 44 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project SpaciousLib by anhcraft.

the class SItems method removeFlag.

/**
     * Remove flags for an item
     *
     * @param flag the flag
     */
public void removeFlag(ItemFlag flag) {
    ItemMeta a = this.item.getItemMeta();
    a.removeItemFlags(flag);
    this.item.setItemMeta(a);
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 45 with ItemMeta

use of org.bukkit.inventory.meta.ItemMeta in project SpaciousLib by anhcraft.

the class SItems method addLores.

/**
     * Add lores for an item
     *
     * @param texts the lores
     */
public void addLores(List<String> texts) {
    ItemMeta a = this.item.getItemMeta();
    List<String> lores;
    if (a.hasLore()) {
        lores = a.getLore();
    } else {
        lores = new ArrayList<>();
    }
    for (String b : texts) {
        lores.add(b.replace("&", "ยง"));
    }
    a.setLore(lores);
    this.item.setItemMeta(a);
}
Also used : ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ItemMeta (org.bukkit.inventory.meta.ItemMeta)47 ItemStack (org.bukkit.inventory.ItemStack)17 ArrayList (java.util.ArrayList)5 Enchantment (org.bukkit.enchantments.Enchantment)5 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)4 BookMeta (org.bukkit.inventory.meta.BookMeta)3 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)3 SkullMeta (org.bukkit.inventory.meta.SkullMeta)3 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 StringTag (net.aufdemrand.denizen.nms.util.jnbt.StringTag)2 Element (net.aufdemrand.denizencore.objects.Element)2 FireworkEffect (org.bukkit.FireworkEffect)2 Material (org.bukkit.Material)2 Banner (org.bukkit.block.Banner)2 BannerMeta (org.bukkit.inventory.meta.BannerMeta)2 BlockStateMeta (org.bukkit.inventory.meta.BlockStateMeta)2 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)2 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)2 RewardType (au.com.mineauz.minigames.minigame.reward.RewardType)1