Search in sources :

Example 21 with Item

use of net.minecraft.server.v1_7_R4.Item in project MyPet by xXKeyleXx.

the class ConfigItem method load.

public void load(String data) {
    NBTBase nbtBase = null;
    if (data.contains("{")) {
        String tagString = data.substring(data.indexOf("{"));
        data = data.substring(0, data.indexOf("{"));
        try {
            nbtBase = MojangsonParser.parse(tagString);
        } catch (Exception e) {
            MyPetApi.getLogger().warning(ChatColor.RED + "Error" + ChatColor.RESET + " in config: " + ChatColor.YELLOW + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
            MyPetApi.getLogger().warning(data + tagString);
        }
    }
    String[] splitData = data.split("\\s+");
    if (splitData.length == 0) {
        return;
    }
    Item item = null;
    if (splitData.length >= 1) {
        if (Util.isInt(splitData[0])) {
            int itemId = Integer.parseInt(splitData[0]);
            item = Item.getById(itemId);
        } else {
            item = (Item) Item.REGISTRY.get(splitData[0]);
        }
    }
    if (item != null) {
        int itemDamage = 0;
        if (splitData.length >= 2) {
            if (splitData[1].startsWith("<")) {
                this.durabilityMode = DurabilityMode.Smaller;
                splitData[1] = splitData[1].substring(1);
            } else if (splitData[1].startsWith(">")) {
                this.durabilityMode = DurabilityMode.Bigger;
                splitData[1] = splitData[1].substring(1);
            } else {
                this.durabilityMode = DurabilityMode.Equal;
            }
            if (Util.isInt(splitData[1])) {
                itemDamage = Integer.parseInt(splitData[1]);
            }
        }
        net.minecraft.server.v1_7_R4.ItemStack is = new net.minecraft.server.v1_7_R4.ItemStack(item, 1, itemDamage);
        if (nbtBase != null) {
            is.setTag((NBTTagCompound) nbtBase);
        }
        this.item = CraftItemStack.asBukkitCopy(is);
    }
}
Also used : Item(net.minecraft.server.v1_7_R4.Item) NBTBase(net.minecraft.server.v1_7_R4.NBTBase) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 22 with Item

use of net.minecraft.server.v1_7_R4.Item in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
    // TODO allow items like FIRE (51)
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (Object key : vanillaTag.c()) {
            is.getTag().set(key.toString(), vanillaTag.get(key.toString()));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) NBTTagString(net.minecraft.server.v1_7_R4.NBTTagString) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_7_R4.NBTTagList) NBTTagString(net.minecraft.server.v1_7_R4.NBTTagString) ItemStack(net.minecraft.server.v1_7_R4.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)

Example 23 with Item

use of net.minecraft.server.v1_7_R4.Item in project acidisland by tastybento.

the class NMSHandler method setBook.

@Override
public ItemStack setBook(Tag item) {
    ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
    // Bukkit.getLogger().info(item.toString());
    if (((CompoundTag) item).getValue().containsKey("tag")) {
        Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
        // BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
        String author = "";
        if (contents.containsKey("author")) {
            author = ((StringTag) contents.get("author")).getValue();
        }
        // Bukkit.getLogger().info("Author: " + author);
        // bookMeta.setAuthor(author);
        String title = "";
        if (contents.containsKey("title")) {
            title = ((StringTag) contents.get("title")).getValue();
        }
        // Bukkit.getLogger().info("Title: " + title);
        // bookMeta.setTitle(title);
        List<String> lore = new ArrayList<String>();
        if (contents.containsKey("display")) {
            Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
            List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
            for (Tag s : loreTag) {
                lore.add(((StringTag) s).getValue());
            }
        }
        // Bukkit.getLogger().info("Lore: " + lore);
        net.minecraft.server.v1_7_R4.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
        // Pages
        // Create the NMS Stack's NBT (item data)
        NBTTagCompound tag = new NBTTagCompound();
        // Set the book's title
        tag.setString("title", title);
        tag.setString("author", author);
        if (contents.containsKey("pages")) {
            NBTTagList pages = new NBTTagList();
            List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
            for (Tag s : pagesTag) {
                pages.add(new NBTTagString(((StringTag) s).getValue()));
            }
            // Add the pages to the tag
            tag.set("pages", pages);
        }
        // Apply the tag to the item
        stack.setTag(tag);
        chestItem = CraftItemStack.asCraftMirror(stack);
        ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
        bookMeta.setLore(lore);
        chestItem.setItemMeta(bookMeta);
    }
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) ArrayList(java.util.ArrayList) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) NBTTagString(net.minecraft.server.v1_7_R4.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_7_R4.NBTTagList) NBTTagString(net.minecraft.server.v1_7_R4.NBTTagString) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) ListTag(com.wasteofplastic.org.jnbt.ListTag) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)18 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)5 Test (org.junit.Test)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 ArrayList (java.util.ArrayList)3 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)3 Url (org.orcid.jaxb.model.common_v2.Url)3 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2 NBTTagCompound (net.minecraft.server.v1_7_R4.NBTTagCompound)2 NBTTagList (net.minecraft.server.v1_7_R4.NBTTagList)2 NBTTagString (net.minecraft.server.v1_7_R4.NBTTagString)2 ItemStack (org.bukkit.inventory.ItemStack)2 Source (org.orcid.jaxb.model.common_v2.Source)2 SourceClientId (org.orcid.jaxb.model.common_v2.SourceClientId)2 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 NotificationAmended (org.orcid.jaxb.model.notification.amended_v2.NotificationAmended)2 AuthorizationUrl (org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl)2 NotificationPermission (org.orcid.jaxb.model.notification.permission_v2.NotificationPermission)2 NotificationAddItemsEntity (org.orcid.persistence.jpa.entities.NotificationAddItemsEntity)2