Search in sources :

Example 46 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project CitizensAPI by CitizensDev.

the class ItemStorage method deserialiseMeta.

private static void deserialiseMeta(DataKey root, ItemStack res) {
    if (root.keyExists("flags")) {
        ItemMeta meta = ensureMeta(res);
        for (DataKey key : root.getRelative("flags").getIntegerSubKeys()) {
            meta.addItemFlags(ItemFlag.valueOf(key.getString("")));
        }
    }
    if (root.keyExists("lore")) {
        ItemMeta meta = ensureMeta(res);
        List<String> lore = Lists.newArrayList();
        for (DataKey key : root.getRelative("lore").getIntegerSubKeys()) lore.add(key.getString(""));
        meta.setLore(lore);
        res.setItemMeta(meta);
    }
    if (root.keyExists("displayname")) {
        ItemMeta meta = ensureMeta(res);
        meta.setDisplayName(root.getString("displayname"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("firework")) {
        FireworkMeta meta = ensureMeta(res);
        for (DataKey sub : root.getRelative("firework.effects").getIntegerSubKeys()) {
            meta.addEffect(deserialiseFireworkEffect(sub));
        }
        meta.setPower(root.getInt("firework.power"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("book")) {
        BookMeta meta = ensureMeta(res);
        for (DataKey sub : root.getRelative("book.pages").getIntegerSubKeys()) {
            meta.addPage(sub.getString(""));
        }
        meta.setTitle(root.getString("book.title"));
        meta.setAuthor(root.getString("book.author"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("armor")) {
        LeatherArmorMeta meta = ensureMeta(res);
        meta.setColor(Color.fromRGB(root.getInt("armor.color")));
        res.setItemMeta(meta);
    }
    if (root.keyExists("map")) {
        MapMeta meta = ensureMeta(res);
        meta.setScaling(root.getBoolean("map.scaling"));
        res.setItemMeta(meta);
    }
    if (root.keyExists("blockstate")) {
        BlockStateMeta meta = ensureMeta(res);
        if (root.keyExists("blockstate.banner")) {
            Banner banner = (Banner) meta.getBlockState();
            deserialiseBanner(root.getRelative("blockstate"), banner);
            banner.update(true);
            meta.setBlockState(banner);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("enchantmentstorage")) {
        EnchantmentStorageMeta meta = ensureMeta(res);
        for (DataKey key : root.getRelative("enchantmentstorage").getSubKeys()) {
            meta.addStoredEnchant(Enchantment.getByName(key.name()), key.getInt(""), true);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("skull")) {
        SkullMeta meta = ensureMeta(res);
        if (root.keyExists("skull.owner") && !root.getString("skull.owner").isEmpty()) {
            meta.setOwner(root.getString("skull.owner", ""));
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("banner")) {
        BannerMeta meta = ensureMeta(res);
        if (root.keyExists("banner.basecolor")) {
            meta.setBaseColor(DyeColor.valueOf(root.getString("banner.basecolor")));
        }
        if (root.keyExists("banner.patterns")) {
            for (DataKey sub : root.getRelative("banner.patterns").getIntegerSubKeys()) {
                Pattern pattern = new Pattern(DyeColor.valueOf(sub.getString("color")), PatternType.getByIdentifier(sub.getString("type")));
                meta.addPattern(pattern);
            }
        }
    }
    if (root.keyExists("potion")) {
        PotionMeta meta = ensureMeta(res);
        PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")), root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
        meta.setBasePotionData(data);
        for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
            int duration = sub.getInt("duration");
            int amplifier = sub.getInt("amplifier");
            PotionEffectType type = PotionEffectType.getByName(sub.getString("type"));
            boolean ambient = sub.getBoolean("ambient");
            meta.addCustomEffect(new PotionEffect(type, duration, amplifier, ambient), true);
        }
        res.setItemMeta(meta);
    }
    if (root.keyExists("repaircost") && res.getItemMeta() instanceof Repairable) {
        ((Repairable) res.getItemMeta()).setRepairCost(root.getInt("repaircost"));
    }
    ItemMeta meta = res.getItemMeta();
    if (meta != null) {
        try {
            meta.setUnbreakable(root.getBoolean("unbreakable", false));
        } catch (Throwable t) {
        // probably backwards-compat issue, don't log
        }
        res.setItemMeta(meta);
    }
    Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
}
Also used : Repairable(org.bukkit.inventory.meta.Repairable) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Pattern(org.bukkit.block.banner.Pattern) CitizensDeserialiseMetaEvent(net.citizensnpcs.api.event.CitizensDeserialiseMetaEvent) PotionEffect(org.bukkit.potion.PotionEffect) Banner(org.bukkit.block.Banner) PotionEffectType(org.bukkit.potion.PotionEffectType) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) PotionMeta(org.bukkit.inventory.meta.PotionMeta) BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) PotionData(org.bukkit.potion.PotionData) MapMeta(org.bukkit.inventory.meta.MapMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) BookMeta(org.bukkit.inventory.meta.BookMeta) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Example 47 with SkullMeta

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

the class TopTen method runPlayerHeadGetter.

@SuppressWarnings("deprecation")
private void runPlayerHeadGetter() {
    Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
        Iterator<Entry<UUID, String>> it = names.entrySet().iterator();
        if (it.hasNext()) {
            Entry<UUID, String> en = it.next();
            ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
            topTenHeads.put(en.getKey(), playerSkull);
            SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
            meta.setOwner(en.getValue());
            playerSkull.setItemMeta(meta);
            // Update
            topTenHeads.put(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 48 with SkullMeta

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

the class WarpPanel method runPlayerHeadGetter.

@SuppressWarnings("deprecation")
private void runPlayerHeadGetter() {
    Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> {
        if (names.size() > 0 && names.size() % 10 == 0) {
            plugin.getLogger().info("Loading player heads for warps: " + names.size() + " to go...");
        }
        Iterator<Entry<UUID, String>> it = names.entrySet().iterator();
        if (it.hasNext()) {
            Entry<UUID, String> en = it.next();
            ItemStack playerSkull = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
            cachedWarps.put(en.getKey(), playerSkull);
            SkullMeta meta = (SkullMeta) playerSkull.getItemMeta();
            meta.setOwner(en.getValue());
            meta.setDisplayName(ChatColor.WHITE + en.getValue());
            playerSkull.setItemMeta(meta);
            // Update
            cachedWarps.put(en.getKey(), playerSkull);
            Bukkit.getScheduler().runTask(plugin, () -> {
                ItemStack skull = cachedWarps.get(en.getKey());
                skull = updateText(skull, en.getKey());
                Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> plugin.getWarpPanel().updatePanel());
            });
            it.remove();
        }
    }, 200L, 20L);
}
Also used : Entry(java.util.Map.Entry) SkullMeta(org.bukkit.inventory.meta.SkullMeta) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack)

Example 49 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project MyMaid2 by jaoafa.

the class Cmd_Head method onCommand.

@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if (args.length >= 1 && args[0].equalsIgnoreCase("help")) {
        SendUsageMessage(sender, cmd);
        return true;
    }
    if (args.length == 1) {
        if (!(sender instanceof Player)) {
            SendMessage(sender, cmd, "このコマンドはゲーム内から実行してください。");
            return true;
        }
        // コマンド実行者を代入
        Player player = (Player) sender;
        OfflinePlayer offplayer = Bukkit.getOfflinePlayer(args[0]);
        String name = offplayer.getName();
        ItemStack skull = new ItemStack(Material.SKULL_ITEM);
        SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
        skull.setDurability((short) 3);
        skullMeta.setOwningPlayer(player);
        skull.setItemMeta(skullMeta);
        PlayerInventory inv = player.getInventory();
        ItemStack main = inv.getItemInMainHand();
        inv.setItemInMainHand(skull);
        SendMessage(sender, cmd, "「" + name + "の頭」をメインハンドのアイテムと置きかえました。");
        if (main != null && main.getType() != Material.AIR) {
            if (player.getInventory().firstEmpty() == -1) {
                player.getLocation().getWorld().dropItem(player.getLocation(), main);
                SendMessage(sender, cmd, "インベントリがいっぱいだったため、既に持っていたアイテムはあなたの足元にドロップしました。");
            } else {
                inv.addItem(main);
            }
        }
        return true;
    }
    if (!(sender instanceof Player)) {
        SendMessage(sender, cmd, "このコマンドはゲーム内から実行してください。");
        return true;
    }
    // コマンド実行者を代入
    Player player = (Player) sender;
    String name = player.getName();
    ItemStack skull = new ItemStack(Material.SKULL_ITEM);
    SkullMeta skullMeta = (SkullMeta) skull.getItemMeta();
    skull.setDurability((short) 3);
    skullMeta.setOwningPlayer(player);
    skull.setItemMeta(skullMeta);
    PlayerInventory inv = player.getInventory();
    ItemStack main = inv.getItemInMainHand();
    inv.setItemInMainHand(skull);
    SendMessage(sender, cmd, "「" + name + "の頭」をメインハンドのアイテムと置きかえました。");
    if (main != null && main.getType() != Material.AIR) {
        if (player.getInventory().firstEmpty() == -1) {
            player.getLocation().getWorld().dropItem(player.getLocation(), main);
            SendMessage(sender, cmd, "インベントリがいっぱいだったため、既に持っていたアイテムはあなたの足元にドロップしました。");
        } else {
            inv.addItem(main);
        }
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) OfflinePlayer(org.bukkit.OfflinePlayer) SkullMeta(org.bukkit.inventory.meta.SkullMeta) PlayerInventory(org.bukkit.inventory.PlayerInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 50 with SkullMeta

use of org.bukkit.inventory.meta.SkullMeta in project TokenManager by RealizedMC.

the class ItemUtil method applyMeta.

private static void applyMeta(final ItemStack item, final String key, final String value) {
    final ItemMeta meta = item.getItemMeta();
    if (key.equalsIgnoreCase("name")) {
        meta.setDisplayName(StringUtil.color(value.replace("_", " ")));
        item.setItemMeta(meta);
        return;
    }
    if (key.equalsIgnoreCase("lore")) {
        meta.setLore(StringUtil.color(Lists.newArrayList(value.split("\\|")), s -> s.replace("_", " ")));
        item.setItemMeta(meta);
        return;
    }
    if (key.equalsIgnoreCase("unbreakable") && value.equalsIgnoreCase("true")) {
        if (isPre1_12()) {
            meta.spigot().setUnbreakable(true);
        } else {
            meta.setUnbreakable(true);
        }
        item.setItemMeta(meta);
        return;
    }
    final Enchantment enchantment = ENCHANTMENTS.get(key);
    if (enchantment != null) {
        item.addUnsafeEnchantment(enchantment, Integer.parseInt(value));
        return;
    }
    if (item.getType().name().contains("POTION")) {
        final PotionEffectType effectType = EFFECTS.get(key);
        if (effectType != null) {
            String[] values = value.split(":");
            PotionMeta potionMeta = (PotionMeta) meta;
            potionMeta.addCustomEffect(new PotionEffect(effectType, Integer.parseInt(values[1]), Integer.parseInt(values[0])), true);
            item.setItemMeta(potionMeta);
            return;
        }
    }
    if (item.getType() == Material.SKULL_ITEM && item.getDurability() == 3 && key.equalsIgnoreCase("player") || key.equalsIgnoreCase("owner")) {
        final SkullMeta skullMeta = (SkullMeta) meta;
        skullMeta.setOwner(value);
        item.setItemMeta(skullMeta);
    }
}
Also used : NumberUtil(me.realized.tokenmanager.util.NumberUtil) Arrays(java.util.Arrays) Potions(me.realized.tokenmanager.util.compat.Potions) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) PotionType(org.bukkit.potion.PotionType) HashMap(java.util.HashMap) StringUtil(me.realized.tokenmanager.util.StringUtil) EntityType(org.bukkit.entity.EntityType) SpawnEggs(me.realized.tokenmanager.util.compat.SpawnEggs) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) PotionEffect(org.bukkit.potion.PotionEffect) Consumer(java.util.function.Consumer) OptionalLong(java.util.OptionalLong) List(java.util.List) Lists(com.google.common.collect.Lists) Map(java.util.Map) EnumUtil(me.realized.tokenmanager.util.EnumUtil) PotionMeta(org.bukkit.inventory.meta.PotionMeta) Material(org.bukkit.Material) PotionEffectType(org.bukkit.potion.PotionEffectType) Bukkit(org.bukkit.Bukkit) PotionEffect(org.bukkit.potion.PotionEffect) PotionEffectType(org.bukkit.potion.PotionEffectType) PotionMeta(org.bukkit.inventory.meta.PotionMeta) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

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