Search in sources :

Example 26 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project acidisland by tastybento.

the class HeadGetter method runPlayerHeadGetter.

@SuppressWarnings("deprecation")
private void runPlayerHeadGetter() {
    plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, () -> {
        synchronized (names) {
            Iterator<Entry<UUID, String>> it = names.entrySet().iterator();
            if (it.hasNext()) {
                Entry<UUID, String> en = it.next();
                // Bukkit.getLogger().info("DEBUG: getting " + en.getValue());
                ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
                meta.setOwner(en.getValue());
                meta.setDisplayName(ChatColor.WHITE + en.getValue());
                playerSkull.setItemMeta(meta);
                // Bukkit.getLogger().info("DEBUG: Got it!");
                // Save in cache
                cachedHeads.put(en.getKey(), new HeadInfo(en.getValue(), en.getKey(), playerSkull));
                // Tell requesters the head came in
                if (headRequesters.containsKey(en.getKey())) {
                    for (Requester req : headRequesters.get(en.getKey())) {
                        // Bukkit.getLogger().info("DEBUG: Telling requester");
                        plugin.getServer().getScheduler().runTask(plugin, () -> req.setHead(new HeadInfo(en.getValue(), en.getKey(), playerSkull)));
                    }
                }
                it.remove();
            }
        }
    }, 0L, 20L);
}
Also used : Entry(java.util.Map.Entry) SkullMeta(org.bukkit.inventory.meta.SkullMeta) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack)

Example 27 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project acidisland by tastybento.

the class TopTen method topTenAddEntry.

/**
 * Adds a player to the top ten, if the level is good enough
 *
 * @param ownerUUID
 * @param l
 */
public void topTenAddEntry(UUID ownerUUID, long l) {
    if (DEBUG) {
        plugin.getLogger().info("DEBUG: adding top ten entry " + ownerUUID + " " + l);
    }
    // needs to be removed from the list
    if (l < 1) {
        topTenList.remove(ownerUUID);
        return;
    }
    // Try and see if the player is online
    Player player = plugin.getServer().getPlayer(ownerUUID);
    if (player != null) {
        // Online
        if (!player.hasPermission(Settings.PERMPREFIX + "intopten")) {
            topTenList.remove(ownerUUID);
            return;
        }
    }
    topTenList.put(ownerUUID, l);
    topTenList = topTenList.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).limit(10).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
    // Add head to cache
    if (Settings.warpHeads) {
        if (topTenList.containsKey(ownerUUID) && !topTenHeads.containsKey(ownerUUID)) {
            String name = plugin.getPlayers().getName(ownerUUID);
            if (name != null && !name.isEmpty()) {
                ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
                SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
                meta.setDisplayName(name);
                playerSkull.setItemMeta(meta);
                topTenHeads.put(ownerUUID, playerSkull);
                // Get skull async
                plugin.getHeadGetter().getHead(ownerUUID, this);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) Entry(java.util.Map.Entry) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with SkullMeta

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

the class ItemStackAction method setItemStackFromNewDataFormat.

/**
	 * 
	 */
protected void setItemStackFromNewDataFormat() {
    if (data == null || !data.startsWith("{"))
        return;
    actionData = gson.fromJson(data, ItemStackActionData.class);
    item = new ItemStack(this.block_id, actionData.amt, (short) this.block_subid);
    // Restore enchantment
    if (actionData.enchs != null && actionData.enchs.length > 0) {
        for (final String ench : actionData.enchs) {
            final String[] enchArgs = ench.split(":");
            final Enchantment enchantment = Enchantment.getById(Integer.parseInt(enchArgs[0]));
            // Restore book enchantment
            if (item.getType().equals(Material.ENCHANTED_BOOK)) {
                final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
                bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
                item.setItemMeta(bookEnchantments);
            } else // Restore item enchantment
            {
                item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
            }
        }
    }
    // Leather color
    if (item.getType().name().contains("LEATHER_") && actionData.color > 0) {
        final LeatherArmorMeta lam = (LeatherArmorMeta) item.getItemMeta();
        lam.setColor(Color.fromRGB(actionData.color));
        item.setItemMeta(lam);
    } else // Skulls
    if (item.getType().equals(Material.SKULL_ITEM) && actionData.owner != null) {
        final SkullMeta meta = (SkullMeta) item.getItemMeta();
        meta.setOwner(actionData.owner);
        item.setItemMeta(meta);
    } else // Written books
    if (item.getItemMeta() instanceof BookMeta) {
        final BookMeta bookMeta = (BookMeta) item.getItemMeta();
        bookMeta.setAuthor(actionData.by);
        bookMeta.setTitle(actionData.title);
        bookMeta.setPages(actionData.content);
        item.setItemMeta(bookMeta);
    }
    // Fireworks
    if (block_id == 402 && actionData.effectColors != null && actionData.effectColors.length > 0) {
        final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) item.getItemMeta();
        final Builder effect = FireworkEffect.builder();
        if (actionData.effectColors != null) {
            for (int i = 0; i < actionData.effectColors.length; i++) {
                effect.withColor(Color.fromRGB(actionData.effectColors[i]));
            }
            fireworkMeta.setEffect(effect.build());
        }
        if (actionData.fadeColors != null) {
            for (int i = 0; i < actionData.fadeColors.length; i++) {
                effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
            }
            fireworkMeta.setEffect(effect.build());
        }
        if (actionData.hasFlicker) {
            effect.flicker(true);
        }
        if (actionData.hasTrail) {
            effect.trail(true);
        }
        fireworkMeta.setEffect(effect.build());
        item.setItemMeta(fireworkMeta);
    }
    // Item display names
    final ItemMeta meta = item.getItemMeta();
    if (actionData.name != null) {
        meta.setDisplayName(actionData.name);
    }
    if (actionData.lore != null) {
        meta.setLore(Arrays.asList(actionData.lore));
    }
    item.setItemMeta(meta);
}
Also used : Builder(org.bukkit.FireworkEffect.Builder) SkullMeta(org.bukkit.inventory.meta.SkullMeta) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) FireworkEffectMeta(org.bukkit.inventory.meta.FireworkEffectMeta) ItemStack(org.bukkit.inventory.ItemStack) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 29 with SkullMeta

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

the class HeadCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
    Element skin = scriptEntry.getElement("skin");
    dMaterial material = scriptEntry.getdObject("material");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("entities", entities.toString()) + (skin != null ? skin.debug() : "") + (material != null ? material.debug() : ""));
    ItemStack item = null;
    // Create head item with chosen skin, or item/skin
    if (skin != null) {
        item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
        ItemMeta itemMeta = item.getItemMeta();
        ((SkullMeta) itemMeta).setOwner(skin.asString().replaceAll("[pP]@", ""));
        item.setItemMeta(itemMeta);
    } else if (material != null) {
        item = new ItemStack(material.getMaterial());
    }
    for (dEntity entity : entities) {
        if (entity.isCitizensNPC()) {
            if (!entity.getDenizenNPC().getCitizen().hasTrait(Equipment.class)) {
                entity.getDenizenNPC().getCitizen().addTrait(Equipment.class);
            }
            Equipment trait = entity.getDenizenNPC().getCitizen().getTrait(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 {
                dB.echoError(scriptEntry.getResidingQueue(), entity.identify() + " is not a living entity!");
            }
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Equipment(net.citizensnpcs.api.trait.trait.Equipment) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 30 with SkullMeta

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

the class LootGUI method headerConstructor.

private void headerConstructor(Inventory inventory) {
    ItemStack arrowLeft = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    SkullMeta arrowLeftSkullMeta = (SkullMeta) arrowLeft.getItemMeta();
    arrowLeftSkullMeta.setOwner("MHF_ArrowLeft");
    arrowLeftSkullMeta.setDisplayName("Previous Item Ranks");
    arrowLeft.setItemMeta(arrowLeftSkullMeta);
    inventory.setItem(0, arrowLeft);
    ItemStack arrowRight = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    SkullMeta arrowRightSkullMeta = (SkullMeta) arrowRight.getItemMeta();
    arrowRightSkullMeta.setOwner("MHF_ArrowRight");
    arrowRightSkullMeta.setDisplayName("Next Item Ranks");
    arrowRight.setItemMeta(arrowRightSkullMeta);
    inventory.setItem(8, arrowRight);
    ItemStack signature = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
    SkullMeta signatureSkullMeta = (SkullMeta) signature.getItemMeta();
    signatureSkullMeta.setOwner("magmaguy");
    signatureSkullMeta.setDisplayName("EliteMobs by MagmaGuy");
    List<String> signatureList = new ArrayList<>();
    signatureList.add("Support the plugins you enjoy!");
    signatureSkullMeta.setLore(signatureList);
    signature.setItemMeta(signatureSkullMeta);
    inventory.setItem(4, signature);
}
Also used : ArrayList(java.util.ArrayList) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack)

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