Search in sources :

Example 56 with SkullMeta

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

the class CustomConfigFields method processItemStack.

public ItemStack processItemStack(String path, ItemStack value, ItemStack pluginDefault, boolean forceWriteDefault) {
    if (!configHas(path)) {
        if (forceWriteDefault || value != pluginDefault)
            processString(path, itemStackDeserializer(value), itemStackDeserializer(pluginDefault), forceWriteDefault);
        return value;
    }
    try {
        String materialString = processString(path, itemStackDeserializer(value), itemStackDeserializer(pluginDefault), forceWriteDefault);
        if (materialString == null)
            return null;
        if (materialString.matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}")) {
            ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
            SkullMeta skullMeta = (SkullMeta) playerHead.getItemMeta();
            skullMeta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(materialString)));
            playerHead.setItemMeta(skullMeta);
            return playerHead;
        }
        if (materialString.contains(":")) {
            ItemStack itemStack = ItemStackGenerator.generateItemStack(Material.getMaterial(materialString.split(":")[0]));
            if (materialString.split(":")[1].contains("leather_") || materialString.split(":")[1].contains("LEATHER_")) {
                LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemStack.getItemMeta();
                leatherArmorMeta.setColor(Color.fromRGB(Integer.parseInt(materialString.split(":")[1])));
                itemStack.setItemMeta(leatherArmorMeta);
            } else {
                ItemMeta itemMeta = itemStack.getItemMeta();
                itemMeta.setCustomModelData(Integer.parseInt(materialString.split(":")[1]));
                itemStack.setItemMeta(itemMeta);
            }
            return itemStack;
        } else
            return ItemStackGenerator.generateItemStack(Material.getMaterial(materialString));
    } catch (Exception ex) {
        new WarningMessage("File " + filename + " has an incorrect entry for " + path);
        new WarningMessage("Entry: " + value);
    }
    return value;
}
Also used : WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 57 with SkullMeta

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

the class BlockSkull method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    GlowSkull skull = (GlowSkull) block.getState();
    skull.setSkullType(getType(holding.getDurability()));
    if (skull.getSkullType() == SkullType.PLAYER) {
        SkullMeta meta = (SkullMeta) holding.getItemMeta();
        if (meta != null) {
            skull.setOwner(meta.getOwner());
        }
    }
    MaterialData data = skull.getData();
    if (!(data instanceof Skull)) {
        warnMaterialData(Skull.class, data);
        return;
    }
    Skull skullData = (Skull) data;
    if (canRotate(skullData)) {
        // Can be rotated
        skull.setRotation(player.getFacing().getOppositeFace());
    }
    skull.update();
    // Wither
    for (int i = 0; i < 3; i++) {
        if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) {
            block.getWorld().spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER);
            break;
        }
    }
}
Also used : GlowSkull(net.glowstone.block.entity.state.GlowSkull) GlowSkull(net.glowstone.block.entity.state.GlowSkull) Skull(org.bukkit.material.Skull) SkullMeta(org.bukkit.inventory.meta.SkullMeta) MaterialData(org.bukkit.material.MaterialData)

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