Search in sources :

Example 21 with NBTTagList

use of net.minecraft.server.v1_10_R1.NBTTagList in project solinia3-core by mixxit.

the class ItemStackAdapter method Adapt.

public static ItemStack Adapt(ISoliniaItem soliniaItem) {
    ItemStack stack = new ItemStack(Material.valueOf(soliniaItem.getBasename().toUpperCase()), 1, soliniaItem.getColor());
    if (soliniaItem.getDamage() > 0) {
        if (soliniaItem.getBasename().equals("WOOD_SWORD") || soliniaItem.getBasename().equals("STONE_SWORD") || soliniaItem.getBasename().equals("IRON_SWORD") || soliniaItem.getBasename().equals("GOLD_SWORD") || soliniaItem.getBasename().equals("DIAMOND_SWORD") || soliniaItem.getBasename().equals("WOOD_AXE") || soliniaItem.getBasename().equals("STONE_AXE") || soliniaItem.getBasename().equals("IRON_AXE") || soliniaItem.getBasename().equals("GOLD_AXE") || soliniaItem.getBasename().equals("DIAMOND_AXE") || soliniaItem.getBasename().equals("WOOD_SPADE") || soliniaItem.getBasename().equals("STONE_SPADE") || soliniaItem.getBasename().equals("IRON_SPADE") || soliniaItem.getBasename().equals("GOLD_SPADE") || soliniaItem.getBasename().equals("DIAMOND_SPADE")) {
            net.minecraft.server.v1_12_R1.ItemStack nmsStack = CraftItemStack.asNMSCopy(stack);
            NBTTagCompound compound = (nmsStack.hasTag()) ? nmsStack.getTag() : new NBTTagCompound();
            NBTTagList modifiers = new NBTTagList();
            NBTTagCompound damagecompound = new NBTTagCompound();
            damagecompound.set("AttributeName", new NBTTagString("generic.attackDamage"));
            damagecompound.set("Name", new NBTTagString("generic.attackDamage"));
            damagecompound.set("Amount", new NBTTagInt(soliniaItem.getDamage()));
            damagecompound.set("Operation", new NBTTagInt(0));
            damagecompound.set("UUIDLeast", new NBTTagInt(894654));
            damagecompound.set("UUIDMost", new NBTTagInt(2872));
            damagecompound.set("Slot", new NBTTagString("mainhand"));
            modifiers.add(damagecompound);
            compound.set("AttributeModifiers", modifiers);
            nmsStack.setTag(compound);
            stack = CraftItemStack.asBukkitCopy(nmsStack);
        }
    }
    ItemMeta i = stack.getItemMeta();
    if (soliniaItem.getBasename().equals("POTION") || soliniaItem.getBasename().equals("SPLASH_POTION") || soliniaItem.getBasename().equals("LINGERING_POTION")) {
        i = (PotionMeta) stack.getItemMeta();
        PotionData data = new PotionData(PotionType.INSTANT_HEAL);
        ((PotionMeta) i).setBasePotionData(data);
    }
    if (soliniaItem.getTexturebase64() != null && !soliniaItem.getTexturebase64().equals("") && soliniaItem.getBasename().equals("SKULL_ITEM")) {
        UUID skinuuid = getUUIDFromString(soliniaItem.getTexturebase64());
        i = buildSkull((SkullMeta) i, skinuuid, soliniaItem.getTexturebase64(), null);
    }
    i.setUnbreakable(true);
    i.setDisplayName(soliniaItem.getDisplayname());
    List<String> loretxt = new ArrayList<String>();
    if (soliniaItem.getLore() != null) {
        String[] lorestr = soliniaItem.getLore().split("(?<=\\G.{34})");
        loretxt.addAll(Arrays.asList(lorestr));
    }
    if (soliniaItem.isArtifact() == true) {
        loretxt.add(ChatColor.GREEN + "This item is a unique artifact!" + ChatColor.RESET);
    }
    if (soliniaItem.isQuest() == true) {
        loretxt.add(ChatColor.YELLOW + "This item is part of a quest line" + ChatColor.RESET);
    }
    if (soliniaItem.isCrafting() == true) {
        loretxt.add(ChatColor.GOLD + "This looks like it could be crafted" + ChatColor.RESET);
        loretxt.add(ChatColor.GOLD + "into something useful" + ChatColor.RESET);
    }
    if (soliniaItem.isExperienceBonus() == true) {
        loretxt.add(ChatColor.GOLD + "Grant XP Experience!" + ChatColor.RESET);
    }
    if (soliniaItem.isFingersItem()) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : FINGERS" + ChatColor.RESET);
    }
    if (soliniaItem.isNeckItem()) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : NECK" + ChatColor.RESET);
    }
    if (soliniaItem.isShouldersItem()) {
        loretxt.add(ChatColor.AQUA + "/EQUIP : SHOULDERS" + ChatColor.RESET);
    }
    if (soliniaItem.isAugmentation() == true) {
        loretxt.add(ChatColor.AQUA + "This looks like it could augment " + ChatColor.RESET);
        loretxt.add(ChatColor.AQUA + "weapon or armour" + ChatColor.RESET);
        loretxt.add(ChatColor.AQUA + "Augments Item Slots: " + soliniaItem.getAugmentationFitsSlotType().name() + ChatColor.RESET);
    }
    if (soliniaItem.getDamage() > 0) {
        if (soliniaItem.getBasename().equals("BOW")) {
            loretxt.add("Modifies Arrow Dmg: " + ChatColor.GREEN + soliniaItem.getDamage() + ChatColor.RESET);
        }
    }
    if (soliniaItem.getBaneUndead() > 0) {
        loretxt.add("Bane UNDEAD: " + ChatColor.GREEN + soliniaItem.getBaneUndead() + ChatColor.RESET);
    }
    if (soliniaItem.getAC() > 0) {
        loretxt.add("Armour Class: " + ChatColor.GREEN + soliniaItem.getAC() + ChatColor.RESET);
    }
    String classtxt = "";
    if (soliniaItem.getAllowedClassNames().size() > 0) {
        classtxt = "Usable By: ";
        for (String classname : soliniaItem.getAllowedClassNames()) {
            classtxt += ChatColor.YELLOW + classname + ChatColor.RESET + " ";
        }
    }
    if (!classtxt.equals("")) {
        loretxt.add(classtxt);
    }
    if (soliniaItem.getMinLevel() > 0) {
        loretxt.add("Minimum Level: " + ChatColor.YELLOW + soliniaItem.getMinLevel() + ChatColor.RESET);
    }
    String stattxt = "";
    if (soliniaItem.getStrength() > 0) {
        stattxt = "STR: " + ChatColor.GREEN + soliniaItem.getStrength() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getStamina() > 0) {
        stattxt += "STA: " + ChatColor.GREEN + soliniaItem.getStamina() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getAgility() > 0) {
        stattxt += "AGI: " + ChatColor.GREEN + soliniaItem.getAgility() + ChatColor.RESET + " ";
    }
    if (!stattxt.equals("")) {
        loretxt.add(stattxt);
    }
    stattxt = "";
    if (soliniaItem.getDexterity() > 0) {
        stattxt = "DEX: " + ChatColor.GREEN + soliniaItem.getDexterity() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getIntelligence() > 0) {
        stattxt += "INT: " + ChatColor.GREEN + soliniaItem.getIntelligence() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getWisdom() > 0) {
        stattxt += "WIS: " + ChatColor.GREEN + soliniaItem.getWisdom() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getCharisma() > 0) {
        stattxt += "CHA: " + ChatColor.GREEN + soliniaItem.getCharisma() + ChatColor.RESET + " ";
    }
    if (!stattxt.equals("")) {
        loretxt.add(stattxt);
    }
    String resisttxt = "";
    if (soliniaItem.getFireResist() > 0) {
        resisttxt += "FR: " + ChatColor.AQUA + soliniaItem.getFireResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getColdResist() > 0) {
        resisttxt += "CR: " + ChatColor.AQUA + soliniaItem.getColdResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getMagicResist() > 0) {
        resisttxt += "MR: " + ChatColor.AQUA + soliniaItem.getMagicResist() + ChatColor.RESET + " ";
    }
    if (soliniaItem.getPoisonResist() > 0) {
        resisttxt += "PR: " + ChatColor.AQUA + soliniaItem.getPoisonResist() + ChatColor.RESET + " ";
    }
    if (!resisttxt.equals("")) {
        loretxt.add(resisttxt);
    }
    String regentxt = "";
    if (soliniaItem.getHpregen() > 0 || soliniaItem.getMpregen() > 0) {
        if (soliniaItem.getHpregen() > 0) {
            regentxt = ChatColor.WHITE + "HPRegen: " + ChatColor.YELLOW + soliniaItem.getHpregen() + ChatColor.RESET;
        }
        if (soliniaItem.getMpregen() > 0) {
            if (!regentxt.equals(""))
                regentxt += " ";
            regentxt += ChatColor.WHITE + "MPRegen: " + ChatColor.YELLOW + soliniaItem.getMpregen() + ChatColor.RESET;
        }
    }
    if (!(soliniaItem.getSkillModType().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType().toString() + "  +(" + soliniaItem.getSkillModValue() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType2().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType2().toString() + "  +(" + soliniaItem.getSkillModValue2() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType3().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType3().toString() + "  +(" + soliniaItem.getSkillModValue3() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getSkillModType4().equals(SkillType.None))) {
        loretxt.add(ChatColor.WHITE + "Modifies skill checks for: " + ChatColor.YELLOW + soliniaItem.getSkillModType4().toString() + "  +(" + soliniaItem.getSkillModValue4() + ")" + ChatColor.RESET);
    }
    if (!(soliniaItem.getAcceptsAugmentationSlotType().equals(AugmentationSlotType.NONE))) {
        loretxt.add(ChatColor.WHITE + "Augmentation Slot Types: " + ChatColor.YELLOW + soliniaItem.getAcceptsAugmentationSlotType().name() + ChatColor.RESET);
    }
    if (!regentxt.equals("")) {
        loretxt.add(regentxt);
    }
    String hpmanatxt = "";
    if (soliniaItem.getHp() > 0 || soliniaItem.getMana() > 0) {
        if (soliniaItem.getHp() > 0) {
            hpmanatxt = ChatColor.WHITE + "HP: " + ChatColor.YELLOW + soliniaItem.getHp() + ChatColor.RESET;
        }
        if (soliniaItem.getMana() > 0) {
            if (!hpmanatxt.equals(""))
                hpmanatxt += " ";
            hpmanatxt += ChatColor.WHITE + "Mana: " + ChatColor.YELLOW + soliniaItem.getMana() + ChatColor.RESET;
        }
    }
    if (!hpmanatxt.equals("")) {
        loretxt.add(hpmanatxt);
    }
    if (soliniaItem.getAbilityid() > 0 && soliniaItem.isSpellscroll()) {
        loretxt.addAll(generateSpellLoreText(soliniaItem));
    }
    if (soliniaItem.getAbilityid() > 0 && !soliniaItem.isSpellscroll()) {
        loretxt.addAll(generateConsumableAbilityLoreText(soliniaItem));
    }
    if (soliniaItem.getWeaponabilityid() > 0 && !soliniaItem.isSpellscroll()) {
        loretxt.addAll(generateWeaponAbilityLoreText(soliniaItem));
    }
    loretxt.add("Discovered By: " + soliniaItem.getDiscoverer());
    if (soliniaItem.getWorth() > 0) {
        loretxt.add(ChatColor.WHITE + "Worth: " + ChatColor.YELLOW + soliniaItem.getWorth() + ChatColor.RESET);
    }
    if (soliniaItem.isTemporary()) {
        loretxt.add("Temporary: " + StateManager.getInstance().getInstanceGuid());
    }
    i.setLore(loretxt);
    stack.setItemMeta(i);
    stack.addUnsafeEnchantment(Enchantment.DURABILITY, 1000 + soliniaItem.getId());
    if (soliniaItem.getEnchantment1() != null) {
        if (soliniaItem.getEnchantment1val() > 0) {
            try {
                Enchantment enchantment = Utils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment1());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment1val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getEnchantment2() != null) {
        if (soliniaItem.getEnchantment2val() > 0) {
            try {
                Enchantment enchantment = Utils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment2());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment2val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getEnchantment3() != null) {
        if (soliniaItem.getEnchantment3val() > 0) {
            try {
                Enchantment enchantment = Utils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment3());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment3val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getEnchantment4() != null) {
        if (soliniaItem.getEnchantment4val() > 0) {
            try {
                Enchantment enchantment = Utils.getEnchantmentFromEnchantmentName(soliniaItem.getEnchantment4());
                stack.addUnsafeEnchantment(enchantment, soliniaItem.getEnchantment4val());
            } catch (Exception e) {
                System.out.println("WARNING: Invalid Enchantment Item on SoliniaItem: " + soliniaItem.getId());
            }
        }
    }
    if (soliniaItem.getTexturebase64() != null && !soliniaItem.getTexturebase64().equals("") && soliniaItem.getBasename().equals("SKULL_ITEM")) {
        stack.setDurability((short) 3);
    }
    return stack;
}
Also used : NBTTagInt(net.minecraft.server.v1_12_R1.NBTTagInt) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ArrayList(java.util.ArrayList) PotionMeta(org.bukkit.inventory.meta.PotionMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) PotionData(org.bukkit.potion.PotionData) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) UUID(java.util.UUID) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 22 with NBTTagList

use of net.minecraft.server.v1_10_R1.NBTTagList in project askyblock 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_10_R1.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_10_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_10_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 23 with NBTTagList

use of net.minecraft.server.v1_10_R1.NBTTagList in project askyblock 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_8_R1.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_8_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_8_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_8_R1.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) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 24 with NBTTagList

use of net.minecraft.server.v1_10_R1.NBTTagList in project askyblock 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_9_R1.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_9_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_9_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 25 with NBTTagList

use of net.minecraft.server.v1_10_R1.NBTTagList 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_10_R1.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_10_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) NBTTagList(net.minecraft.server.v1_10_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

ArrayList (java.util.ArrayList)21 ItemStack (org.bukkit.inventory.ItemStack)21 ItemMeta (org.bukkit.inventory.meta.ItemMeta)21 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)20 ListTag (com.wasteofplastic.org.jnbt.ListTag)20 StringTag (com.wasteofplastic.org.jnbt.StringTag)20 Tag (com.wasteofplastic.org.jnbt.Tag)20 Map (java.util.Map)20 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)5 HashMap (java.util.HashMap)4 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)4 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)4 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)3 NBTTagList (net.minecraft.server.v1_10_R1.NBTTagList)3 NBTTagString (net.minecraft.server.v1_10_R1.NBTTagString)3 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)3 NBTTagCompound (net.minecraft.server.v1_7_R4.NBTTagCompound)3