Search in sources :

Example 51 with NBTTagList

use of net.minecraft.server.v1_16_R3.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 52 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project RoseStacker by Rosewood-Development.

the class NBTStackedEntityDataStorage method stripAttributeUuids.

private void stripAttributeUuids(NBTTagCompound compoundTag) {
    NBTTagList attributes = compoundTag.getList("Attributes", 10);
    for (int i = 0; i < attributes.size(); i++) {
        NBTTagCompound attribute = attributes.getCompound(i);
        attribute.remove("UUID");
        NBTTagList modifiers = attribute.getList("Modifiers", 10);
        for (int j = 0; j < modifiers.size(); j++) {
            NBTTagCompound modifier = modifiers.getCompound(j);
            if (modifier.getString("Name").equals("Random spawn bonus")) {
                modifiers.remove(j);
                j--;
            } else {
                modifier.remove("UUID");
            }
        }
    }
}
Also used : NBTTagList(net.minecraft.server.v1_16_R2.NBTTagList) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound)

Example 53 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project RoseStacker by Rosewood-Development.

the class NBTStackedEntityDataStorage method fillAttributeUuids.

private void fillAttributeUuids(NBTTagCompound compoundTag) {
    NBTTagList attributes = compoundTag.getList("Attributes", 10);
    for (int i = 0; i < attributes.size(); i++) {
        NBTTagCompound attribute = attributes.getCompound(i);
        attribute.a("UUID", UUID.randomUUID());
        NBTTagList modifiers = attribute.getList("Modifiers", 10);
        for (int j = 0; j < modifiers.size(); j++) {
            NBTTagCompound modifier = modifiers.getCompound(j);
            modifier.a("UUID", UUID.randomUUID());
        }
        if (modifiers.size() == 0)
            attribute.remove("Modifiers");
    }
}
Also used : NBTTagList(net.minecraft.server.v1_16_R2.NBTTagList) NBTTagCompound(net.minecraft.server.v1_16_R2.NBTTagCompound)

Example 54 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method getPlayerSkull.

@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
    ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
    NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
    NBTTagCompound properties = new NBTTagCompound();
    NBTTagList textures = new NBTTagList();
    NBTTagCompound signature = new NBTTagCompound();
    signature.setString("Value", texture);
    textures.add(signature);
    properties.set("textures", textures);
    skullOwner.set("Properties", properties);
    skullOwner.setString("Id", UUID.randomUUID().toString());
    nbtTagCompound.set("SkullOwner", skullOwner);
    nmsItem.setTag(nbtTagCompound);
    return CraftItemStack.asBukkitCopy(nmsItem);
}
Also used : NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Example 55 with NBTTagList

use of net.minecraft.server.v1_16_R3.NBTTagList in project WildLoaders by BG-Software-LLC.

the class NMSAdapter_v1_7_R4 method getPlayerSkull.

@Override
public org.bukkit.inventory.ItemStack getPlayerSkull(org.bukkit.inventory.ItemStack itemStack, String texture) {
    ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound nbtTagCompound = nmsItem.hasTag() ? nmsItem.getTag() : new NBTTagCompound();
    NBTTagCompound skullOwner = nbtTagCompound.hasKey("SkullOwner") ? nbtTagCompound.getCompound("SkullOwner") : new NBTTagCompound();
    NBTTagCompound properties = new NBTTagCompound();
    NBTTagList textures = new NBTTagList();
    NBTTagCompound signature = new NBTTagCompound();
    signature.setString("Value", texture);
    textures.add(signature);
    properties.set("textures", textures);
    skullOwner.set("Properties", properties);
    skullOwner.setString("Id", UUID.randomUUID().toString());
    nbtTagCompound.set("SkullOwner", skullOwner);
    nmsItem.setTag(nbtTagCompound);
    return CraftItemStack.asBukkitCopy(nmsItem);
}
Also used : NBTTagList(net.minecraft.server.v1_7_R4.NBTTagList) NBTTagCompound(net.minecraft.server.v1_7_R4.NBTTagCompound) ItemStack(net.minecraft.server.v1_7_R4.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)24 ArrayList (java.util.ArrayList)22 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 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 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)17 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)17 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)8 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)6 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)6 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_16_R3.NBTTagList)5 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)5 NBTTagList (net.minecraft.server.v1_9_R2.NBTTagList)5