Search in sources :

Example 21 with SkullMeta

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

the class BlockSkull method getDrops.

@NotNull
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    GlowSkull skull = (GlowSkull) block.getState();
    Material skullMaterial = SKULL_MATERIALS.get(skull.getSkullType());
    ItemStack drop = new ItemStack(skullMaterial, 1);
    if (skull.hasOwner()) {
        SkullMeta meta = (SkullMeta) drop.getItemMeta();
        meta.setOwner(skull.getOwner());
        drop.setItemMeta(meta);
    }
    drop.setDurability((short) skull.getSkullType().ordinal());
    return Arrays.asList(drop);
}
Also used : GlowSkull(net.glowstone.block.entity.state.GlowSkull) Material(org.bukkit.Material) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project EliteMobs by MagmaGuy.

the class PlayerHeads method exclamation.

public static ItemStack exclamation() {
    ItemStack exclamation;
    exclamation = new ItemStack(Material.PLAYER_HEAD);
    SkullMeta exclamationMeta = (SkullMeta) exclamation.getItemMeta();
    exclamationMeta.setOwner("MHF_Exclamation");
    exclamation.setItemMeta(exclamationMeta);
    return exclamation;
}
Also used : SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack)

Example 23 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Prism-Bukkit by prism.

the class ItemStackAction method deserialize.

@Override
public void deserialize(String data) {
    if (data == null || !data.startsWith("{")) {
        return;
    }
    actionData = gson().fromJson(data, ItemStackActionData.class);
    item = new ItemStack(getMaterial(), actionData.amt);
    MaterialState.setItemDamage(item, actionData.durability);
    // Restore enchantment
    if (actionData.enchs != null && actionData.enchs.length > 0) {
        for (final String ench : actionData.enchs) {
            final String[] enchArgs = ench.split(":");
            Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchArgs[0]));
            // Restore book enchantment
            if (enchantment != null) {
                if (item.getType() == Material.ENCHANTED_BOOK) {
                    final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
                    bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
                    item.setItemMeta(bookEnchantments);
                } else {
                    item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
                }
            }
        }
    }
    ItemMeta meta = item.getItemMeta();
    // Leather color
    if (meta instanceof LeatherArmorMeta && actionData.color > 0) {
        final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
        lam.setColor(Color.fromRGB(actionData.color));
        item.setItemMeta(lam);
    } else if (meta instanceof SkullMeta && actionData.owner != null) {
        final SkullMeta skull = (SkullMeta) meta;
        skull.setOwningPlayer(Bukkit.getOfflinePlayer(EntityUtils.uuidOf(actionData.owner)));
        item.setItemMeta(skull);
    } else if (meta instanceof BookMeta) {
        final BookMeta bookMeta = (BookMeta) meta;
        bookMeta.setAuthor(actionData.by);
        bookMeta.setTitle(actionData.title);
        bookMeta.setPages(actionData.content);
        item.setItemMeta(bookMeta);
    } else if (meta instanceof PotionMeta) {
        final PotionType potionType = PotionType.valueOf(actionData.potionType.toUpperCase());
        final PotionMeta potionMeta = (PotionMeta) meta;
        potionMeta.setBasePotionData(new PotionData(potionType, actionData.potionExtended, actionData.potionUpgraded));
    }
    if (meta instanceof FireworkEffectMeta && actionData.effectColors != null && actionData.effectColors.length > 0) {
        item = deserializeFireWorksMeta(item, meta, actionData);
    }
    if (meta instanceof BannerMeta && actionData.bannerMeta != null) {
        Map<String, String> stringStringMap = actionData.bannerMeta;
        List<Pattern> patterns = new ArrayList<>();
        stringStringMap.forEach((patternIdentifier, dyeName) -> {
            PatternType type = PatternType.getByIdentifier(patternIdentifier);
            DyeColor color = DyeColor.valueOf(dyeName);
            if (type != null && color != null) {
                Pattern p = new Pattern(color, type);
                patterns.add(p);
            }
        });
        ((BannerMeta) meta).setPatterns(patterns);
    }
    if (actionData.name != null) {
        if (meta == null) {
            meta = item.getItemMeta();
        }
        if (meta != null) {
            meta.setDisplayName(actionData.name);
        }
    }
    if (actionData.lore != null) {
        if (meta == null) {
            meta = item.getItemMeta();
        }
        if (meta != null) {
            meta.setLore(Arrays.asList(actionData.lore));
        }
    }
    if (meta != null) {
        item.setItemMeta(meta);
    }
}
Also used : PatternType(org.bukkit.block.banner.PatternType) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) SkullMeta(org.bukkit.inventory.meta.SkullMeta) PotionMeta(org.bukkit.inventory.meta.PotionMeta) DyeColor(org.bukkit.DyeColor) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) PotionData(org.bukkit.potion.PotionData) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) PotionType(org.bukkit.potion.PotionType) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 24 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Prism-Bukkit by prism.

the class ItemUtils method getItemFullNiceName.

/**
 * Returns a proper full name for an item, which includes meta content as well.
 *
 * @return string
 */
public static String getItemFullNiceName(ItemStack item) {
    StringBuilder itemName = new StringBuilder(item.getType().name().toLowerCase(Locale.ENGLISH).replace('_', ' '));
    ItemMeta meta = null;
    if (item.hasItemMeta()) {
        meta = item.getItemMeta();
    }
    // Leather Coloring
    if (meta instanceof LeatherArmorMeta) {
        LeatherArmorMeta lam = (LeatherArmorMeta) meta;
        if (lam.getColor() != Bukkit.getItemFactory().getDefaultLeatherColor()) {
            itemName.append(" dyed");
        }
    } else if (meta instanceof SkullMeta) {
        SkullMeta skull = (SkullMeta) meta;
        if (skull.hasOwner()) {
            itemName.append(Objects.requireNonNull(skull.getOwningPlayer()).getName()).append("'s ");
        }
    } else if (meta instanceof BookMeta) {
        BookMeta book = (BookMeta) meta;
        itemName.append(" '").append(book.getTitle()).append("' by ").append(book.getAuthor());
    }
    if (meta instanceof EnchantmentStorageMeta) {
        EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
        if (bookEnchantments.hasStoredEnchants()) {
            Map<Enchantment, Integer> enchs = bookEnchantments.getStoredEnchants();
            applyEnchantments(enchs, itemName);
        }
    }
    // Enchantments
    Map<Enchantment, Integer> enchs = item.getEnchantments();
    applyEnchantments(enchs, itemName);
    // Fireworks
    if (meta instanceof FireworkEffectMeta) {
        FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
        if (fireworkMeta.hasEffect()) {
            FireworkEffect effect = fireworkMeta.getEffect();
            if (effect != null) {
                if (!effect.getColors().isEmpty()) {
                    itemName.append(" ").append(effect.getColors().size()).append(" colors");
                }
                if (!effect.getFadeColors().isEmpty()) {
                    itemName.append(" ").append(effect.getFadeColors().size()).append(" fade colors");
                }
                if (effect.hasFlicker()) {
                    itemName.append(" flickering");
                }
                if (effect.hasTrail()) {
                    itemName.append(" with trail");
                }
            }
        }
    }
    // Custom item names
    if (meta != null) {
        // TODO: API fail here, report and check later
        if (meta.hasDisplayName() && meta.getDisplayName().length() > 0) {
            itemName.append(" named \"").append(meta.getDisplayName()).append("\"");
        }
    }
    return itemName.toString();
}
Also used : EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) FireworkEffect(org.bukkit.FireworkEffect) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 25 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Prism-Bukkit by prism.

the class ItemUtils method equals.

/**
 * Check if an ItemStack is equal.
 * 1. Type
 * 2. Display name
 * 3. If leather check the colour.
 * 4. Lore
 * 5. Enchants.
 * 6. SkullMeta is checked if appropriate.
 * 7. Bookmeta - title , page count and author
 * 8. PotionMeta - checked
 * 9 FireworkMeta including effect meta.
 *
 * @param a Itemstack
 * @param b ItemStack
 * @return bool
 */
public static boolean equals(ItemStack a, ItemStack b) {
    ItemMeta metaA = a.getItemMeta();
    ItemMeta metaB = b.getItemMeta();
    // Type/dura
    if (!isSameType(a, b)) {
        return false;
    }
    if (metaA == null && metaB == null) {
        return true;
    } else if (metaA == null || metaB == null) {
        return false;
    }
    if (!metaA.getDisplayName().equals(metaB.getDisplayName())) {
        return false;
    }
    // Coloring
    if (metaA instanceof LeatherArmorMeta) {
        if (!(metaB instanceof LeatherArmorMeta)) {
            return false;
        }
        LeatherArmorMeta colorA = (LeatherArmorMeta) metaA;
        LeatherArmorMeta colorB = (LeatherArmorMeta) metaB;
        if (!colorA.getColor().equals(colorB.getColor())) {
            return false;
        }
    }
    // Lore
    if (metaA.getLore() != null && metaA.getLore() != null) {
        for (String lore : metaA.getLore()) {
            if (!Objects.requireNonNull(metaB.getLore()).contains(lore)) {
                return false;
            }
        }
    } else if (!(metaA.getLore() == null && metaB.getLore() == null)) {
        return false;
    }
    // Enchants
    if (enchantsUnEqual(a.getEnchantments(), b.getEnchantments())) {
        return false;
    }
    // Books
    if (metaA instanceof BookMeta) {
        if (!(metaB instanceof BookMeta)) {
            return false;
        }
        BookMeta bookA = (BookMeta) metaA;
        BookMeta bookB = (BookMeta) metaB;
        // Author
        if (bookA.getAuthor() != null) {
            if (!bookA.getAuthor().equals(bookB.getAuthor())) {
                return false;
            }
        }
        if (bookA.getTitle() != null) {
            if (!bookA.getTitle().equals(bookB.getTitle())) {
                return false;
            }
        }
        // Pages
        if (bookA.getPageCount() != bookB.getPageCount()) {
            return false;
        }
        for (int page = 0; page < bookA.getPages().size(); page++) {
            String pageContentA = bookA.getPages().get(page);
            if (pageContentA != null && !pageContentA.equals(bookB.getPages().get(page))) {
                return false;
            }
        }
    }
    // Enchanted books
    if (metaA instanceof EnchantmentStorageMeta) {
        if (!(metaB instanceof EnchantmentStorageMeta)) {
            return false;
        }
        EnchantmentStorageMeta enchA = (EnchantmentStorageMeta) metaA;
        EnchantmentStorageMeta enchB = (EnchantmentStorageMeta) metaB;
        if (enchA.hasStoredEnchants() != enchB.hasStoredEnchants()) {
            return false;
        }
        if (enchantsUnEqual(enchA.getStoredEnchants(), enchB.getStoredEnchants())) {
            return false;
        }
    }
    // Skulls
    if (metaA instanceof SkullMeta) {
        if (!(metaB instanceof SkullMeta)) {
            return false;
        }
        SkullMeta skullA = (SkullMeta) metaA;
        SkullMeta skullB = (SkullMeta) metaB;
        if (skullA.hasOwner() != skullB.hasOwner()) {
            return false;
        }
        return skullA.hasOwner() && Objects.requireNonNull(skullA.getOwningPlayer()).getUniqueId().equals(Objects.requireNonNull(skullB.getOwningPlayer()).getUniqueId());
    }
    // Potions
    if (metaA instanceof PotionMeta) {
        if (!(metaB instanceof PotionMeta)) {
            return false;
        }
        PotionMeta potA = (PotionMeta) metaA;
        PotionMeta potB = (PotionMeta) metaB;
        for (int c = 0; c < potA.getCustomEffects().size(); c++) {
            PotionEffect e = potA.getCustomEffects().get(c);
            if (!e.equals(potB.getCustomEffects().get(c))) {
                return true;
            }
        }
    }
    // Fireworks
    if (metaA instanceof FireworkMeta) {
        if (!(metaB instanceof FireworkMeta)) {
            return false;
        }
        FireworkMeta fwA = (FireworkMeta) metaA;
        FireworkMeta fwB = (FireworkMeta) metaB;
        if (fwA.getPower() != fwB.getPower()) {
            return false;
        }
        for (int e = 0; e < fwA.getEffects().size(); e++) {
            if (!fwA.getEffects().get(e).equals(fwB.getEffects().get(e))) {
                return false;
            }
        }
    }
    // Firework Effects
    if (metaA instanceof FireworkEffectMeta) {
        if (!(metaB instanceof FireworkEffectMeta)) {
            return false;
        }
        FireworkEffectMeta fwA = (FireworkEffectMeta) metaA;
        FireworkEffectMeta fwB = (FireworkEffectMeta) metaB;
        FireworkEffect effectA = fwA.getEffect();
        FireworkEffect effectB = fwB.getEffect();
        if (effectA == null && effectB == null) {
            return true;
        }
        if (effectA == null) {
            return false;
        }
        if (effectB == null) {
            return false;
        }
        if (!effectA.getType().equals(effectB.getType())) {
            return false;
        }
        if (effectA.getColors().size() != effectB.getColors().size()) {
            return false;
        }
        // Colors
        for (int c = 0; c < effectA.getColors().size(); c++) {
            if (!effectA.getColors().get(c).equals(effectB.getColors().get(c))) {
                return false;
            }
        }
        if (effectA.getFadeColors().size() != effectB.getFadeColors().size()) {
            return false;
        }
        // Fade colors
        for (int c = 0; c < effectA.getFadeColors().size(); c++) {
            if (!effectA.getFadeColors().get(c).equals(effectB.getFadeColors().get(c))) {
                return false;
            }
        }
        if (effectA.hasFlicker() != effectB.hasFlicker()) {
            return false;
        }
        return effectA.hasTrail() == effectB.hasTrail();
    }
    return true;
}
Also used : EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) PotionEffect(org.bukkit.potion.PotionEffect) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) PotionMeta(org.bukkit.inventory.meta.PotionMeta) BookMeta(org.bukkit.inventory.meta.BookMeta) FireworkEffect(org.bukkit.FireworkEffect) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

SkullMeta (org.bukkit.inventory.meta.SkullMeta)59 ItemStack (org.bukkit.inventory.ItemStack)43 ItemMeta (org.bukkit.inventory.meta.ItemMeta)22 Enchantment (org.bukkit.enchantments.Enchantment)10 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)10 ArrayList (java.util.ArrayList)9 PotionMeta (org.bukkit.inventory.meta.PotionMeta)9 UUID (java.util.UUID)8 Player (org.bukkit.entity.Player)8 BookMeta (org.bukkit.inventory.meta.BookMeta)7 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)7 Entry (java.util.Map.Entry)6 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)5 PotionEffect (org.bukkit.potion.PotionEffect)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Pattern (org.bukkit.block.banner.Pattern)4 Inventory (org.bukkit.inventory.Inventory)4 BannerMeta (org.bukkit.inventory.meta.BannerMeta)4 Property (com.mojang.authlib.properties.Property)3