Search in sources :

Example 51 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project LandLord by SpatiumPrinceps.

the class AbstractManage method createSkull.

private ItemStack createSkull(String owner, String displayname, List<String> lore) {
    ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
    skullMeta.setOwner(owner);
    skullMeta.setDisplayName(displayname);
    skullMeta.setLore(lore);
    skull.setItemMeta(skullMeta);
    return skull;
}
Also used : SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack)

Example 52 with SkullMeta

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

the class ItemStackAction method setItem.

/**
 * Set the item.
 * @param item ItemStack
 * @param quantity int
 * @param enchantments Map of enchants.
 */
public void setItem(ItemStack item, int quantity, Map<Enchantment, Integer> enchantments) {
    actionData = new ItemStackActionData();
    if (enchantments != null) {
        this.enchantments = enchantments;
    }
    if (item == null || item.getAmount() <= 0) {
        this.setCanceled(true);
        return;
    }
    this.item = item;
    if (enchantments == null) {
        this.enchantments = item.getEnchantments();
    }
    // Set basics
    setMaterial(item.getType());
    actionData.durability = (short) ItemUtils.getItemDamage(item);
    if (tempDurability >= 0) {
        actionData.durability = tempDurability;
        tempDurability = -1;
    }
    actionData.amt = quantity;
    final ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null;
    if (meta != null) {
        actionData.name = meta.getDisplayName();
    }
    if (meta instanceof LeatherArmorMeta) {
        final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
        actionData.color = lam.getColor().asRGB();
    } else if (meta instanceof SkullMeta) {
        final SkullMeta skull = (SkullMeta) meta;
        if (skull.hasOwner()) {
            actionData.owner = Objects.requireNonNull(skull.getOwningPlayer()).getUniqueId().toString();
        }
    } else if (meta instanceof PotionMeta) {
        final PotionMeta potion = (PotionMeta) meta;
        actionData.potionType = potion.getBasePotionData().getType().toString().toLowerCase();
        actionData.potionExtended = potion.getBasePotionData().isExtended();
        actionData.potionUpgraded = potion.getBasePotionData().isUpgraded();
    }
    // Written books
    if (meta instanceof BookMeta) {
        final BookMeta bookMeta = (BookMeta) meta;
        actionData.by = bookMeta.getAuthor();
        actionData.title = bookMeta.getTitle();
        actionData.content = bookMeta.getPages().toArray(new String[0]);
    }
    // Lore
    if (meta != null && meta.hasLore()) {
        actionData.lore = Objects.requireNonNull(meta.getLore()).toArray(new String[0]);
    }
    // Enchantments
    if (!this.enchantments.isEmpty()) {
        final String[] enchs = new String[this.enchantments.size()];
        int i = 0;
        for (final Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
            // This is silly
            enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
            i++;
        }
        actionData.enchs = enchs;
    } else if (meta instanceof EnchantmentStorageMeta) {
        final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
        if (bookEnchantments.hasStoredEnchants()) {
            if (bookEnchantments.getStoredEnchants().size() > 0) {
                final String[] enchs = new String[bookEnchantments.getStoredEnchants().size()];
                int i = 0;
                for (final Entry<Enchantment, Integer> ench : bookEnchantments.getStoredEnchants().entrySet()) {
                    // This is absolutely silly
                    enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
                    i++;
                }
                actionData.enchs = enchs;
            }
        }
    }
    if (meta instanceof FireworkEffectMeta) {
        applyFireWorksMetaToActionData(meta);
    }
    if (meta instanceof BannerMeta) {
        List<Pattern> patterns = ((BannerMeta) meta).getPatterns();
        Map<String, String> stringyPatterns = new HashMap<>();
        patterns.forEach(pattern -> stringyPatterns.put(pattern.getPattern().getIdentifier(), pattern.getColor().name()));
        actionData.bannerMeta = stringyPatterns;
    }
}
Also used : BannerMeta(org.bukkit.inventory.meta.BannerMeta) Pattern(org.bukkit.block.banner.Pattern) HashMap(java.util.HashMap) SkullMeta(org.bukkit.inventory.meta.SkullMeta) PotionMeta(org.bukkit.inventory.meta.PotionMeta) Entry(java.util.Map.Entry) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 53 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project Denizen-For-Bukkit by DenizenScript.

the class HeadCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    Deprecations.headCommand.warn(scriptEntry);
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    ElementTag skin = scriptEntry.getElement("skin");
    MaterialTag material = scriptEntry.getObjectTag("material");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("entities", entities), skin, material);
    }
    ItemStack item = null;
    if (skin != null) {
        item = new ItemStack(Material.PLAYER_HEAD);
        ItemMeta itemMeta = item.getItemMeta();
        ((SkullMeta) itemMeta).setOwner(skin.asString());
        item.setItemMeta(itemMeta);
    } else if (material != null) {
        item = new ItemStack(material.getMaterial());
    }
    for (EntityTag entity : entities) {
        if (entity.isCitizensNPC()) {
            if (!entity.getDenizenNPC().getCitizen().hasTrait(Equipment.class)) {
                entity.getDenizenNPC().getCitizen().addTrait(Equipment.class);
            }
            Equipment trait = entity.getDenizenNPC().getCitizen().getOrAddTrait(Equipment.class);
            trait.set(1, item);
        } else if (entity.isPlayer()) {
            entity.getPlayer().getInventory().setHelmet(item);
        } else {
            if (entity.isLivingEntity() && entity.getLivingEntity().getEquipment() != null) {
                entity.getLivingEntity().getEquipment().setHelmet(item);
            } else {
                Debug.echoError(scriptEntry, entity.identify() + " is not a living entity!");
            }
        }
    }
}
Also used : MaterialTag(com.denizenscript.denizen.objects.MaterialTag) Equipment(net.citizensnpcs.api.trait.trait.Equipment) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 54 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project FunnyGuilds by FunnyGuilds.

the class Parser method parseItem.

public static ItemStack parseItem(String string) {
    String[] split = string.split(" ");
    String[] typeSplit = split[1].split(":");
    String subtype = typeSplit.length > 1 ? typeSplit[1] : "0";
    Material mat = parseMaterial(typeSplit[0], false);
    int stack;
    int data;
    try {
        stack = Integer.parseInt(split[0]);
        data = Integer.parseInt(subtype);
    } catch (NumberFormatException e) {
        FunnyLogger.parser("Unknown size: " + split[0]);
        stack = 1;
        data = 0;
    }
    ItemBuilder item = new ItemBuilder(mat, stack, data);
    for (int i = 2; i < split.length; i++) {
        String str = split[i];
        if (str.contains("name")) {
            String[] splitName = str.split(":");
            item.setName(StringUtils.replace(StringUtils.colored(String.join(":", Arrays.copyOfRange(splitName, 1, splitName.length))), "_", " "), true);
        } else if (str.contains("lore")) {
            String[] splitLore = str.split(":");
            String loreArgs = String.join(":", Arrays.copyOfRange(splitLore, 1, splitLore.length));
            String[] lores = loreArgs.split("#");
            List<String> lore = new ArrayList<>();
            for (String s : lores) {
                lore.add(StringUtils.replace(StringUtils.replace(StringUtils.colored(s), "_", " "), "{HASH}", "#"));
            }
            item.setLore(lore);
        } else if (str.contains("enchant")) {
            String[] parse = str.split(":");
            String enchantName = parse[1];
            int level;
            try {
                level = Integer.parseInt(parse[2]);
            } catch (NumberFormatException e) {
                FunnyLogger.parser("Unknown enchant level: " + split[2]);
                level = 1;
            }
            Enchantment enchant = Enchantment.getByName(enchantName.toUpperCase());
            if (enchant == null) {
                FunnyLogger.parser("Unknown enchant: " + parse[1]);
            }
            item.addEnchant(enchant, level);
        } else if (str.contains("skullowner")) {
            if (item.getMeta() instanceof SkullMeta) {
                ((SkullMeta) item.getMeta()).setOwner(str.split(":")[1]);
                item.refreshMeta();
            }
        } else if (str.contains("armorcolor")) {
            if (item.getMeta() instanceof LeatherArmorMeta) {
                String[] color = str.split(":")[1].split("_");
                try {
                    ((LeatherArmorMeta) item.getMeta()).setColor(Color.fromRGB(Integer.parseInt(color[0]), Integer.parseInt(color[1]), Integer.parseInt(color[2])));
                    item.refreshMeta();
                } catch (NumberFormatException e) {
                    FunnyLogger.parser("Unknown armor color: " + str.split(":")[1]);
                }
            }
        } else if (str.contains("eggtype")) {
            if (EggTypeChanger.needsSpawnEggMeta()) {
                EntityType type = null;
                try {
                    type = EntityType.valueOf(str.split(":")[1].toUpperCase());
                } catch (Exception e) {
                    FunnyLogger.parser("Unknown entity type: " + str.split(":")[1].toUpperCase());
                }
                if (type != null) {
                    EggTypeChanger.applyChanges(item.getMeta(), type);
                    item.refreshMeta();
                }
            } else {
                FunnyLogger.info("This MC version supports metadata for spawn egg type, no need to use eggtype in item creation!");
            }
        }
    }
    return item.getItem();
}
Also used : Material(org.bukkit.Material) SkullMeta(org.bukkit.inventory.meta.SkullMeta) EntityType(org.bukkit.entity.EntityType) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ArrayList(java.util.ArrayList) List(java.util.List) Enchantment(org.bukkit.enchantments.Enchantment)

Example 55 with SkullMeta

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

the class ItemStackGenerator method generateSkullItemStack.

public static ItemStack generateSkullItemStack(String owner, String name, List<String> lore) {
    ItemStack itemStack = new ItemStack(Material.PLAYER_HEAD);
    SkullMeta skullMeta = (SkullMeta) itemStack.getItemMeta();
    skullMeta.setOwner(owner);
    skullMeta.setDisplayName(name);
    skullMeta.setLore(lore);
    itemStack.setItemMeta(skullMeta);
    return itemStack;
}
Also used : SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

SkullMeta (org.bukkit.inventory.meta.SkullMeta)57 ItemStack (org.bukkit.inventory.ItemStack)40 ItemMeta (org.bukkit.inventory.meta.ItemMeta)21 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 Player (org.bukkit.entity.Player)8 UUID (java.util.UUID)7 BookMeta (org.bukkit.inventory.meta.BookMeta)7 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)7 Inventory (org.bukkit.inventory.Inventory)5 FireworkEffectMeta (org.bukkit.inventory.meta.FireworkEffectMeta)5 PotionEffect (org.bukkit.potion.PotionEffect)5 HashMap (java.util.HashMap)4 List (java.util.List)4 Entry (java.util.Map.Entry)4 Pattern (org.bukkit.block.banner.Pattern)4 EventHandler (org.bukkit.event.EventHandler)4 BannerMeta (org.bukkit.inventory.meta.BannerMeta)4