Search in sources :

Example 26 with Pattern

use of org.bukkit.block.banner.Pattern 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 27 with Pattern

use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) JNBTListTag(com.denizenscript.denizen.nms.util.jnbt.JNBTListTag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag)

Example 28 with Pattern

use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) JNBTListTag(com.denizenscript.denizen.nms.util.jnbt.JNBTListTag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag)

Example 29 with Pattern

use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method showBannerUpdate.

@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
    List<CompoundTag> nbtPatterns = new ArrayList<>();
    for (Pattern pattern : patterns) {
        nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
    }
    CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
    showTileEntityData(player, location, 3, compoundTag);
}
Also used : Pattern(org.bukkit.block.banner.Pattern) JNBTListTag(com.denizenscript.denizen.nms.util.jnbt.JNBTListTag) CompoundTag(com.denizenscript.denizen.nms.util.jnbt.CompoundTag)

Example 30 with Pattern

use of org.bukkit.block.banner.Pattern in project Glowstone by GlowstoneMC.

the class BlockBanner method toNbt.

/**
 * Converts banner patterns to NBT tags.
 *
 * @param banner a list of banner patterns
 * @return the patterns as NBT tags
 */
public static List<CompoundTag> toNbt(List<Pattern> banner) {
    List<CompoundTag> patterns = new ArrayList<>();
    for (Pattern pattern : banner) {
        CompoundTag layerTag = new CompoundTag();
        layerTag.putString("Pattern", pattern.getPattern().getIdentifier());
        layerTag.putInt("Color", pattern.getColor().getDyeData());
        patterns.add(layerTag);
    }
    return patterns;
}
Also used : Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Aggregations

Pattern (org.bukkit.block.banner.Pattern)31 ArrayList (java.util.ArrayList)17 DyeColor (org.bukkit.DyeColor)9 HashMap (java.util.HashMap)6 BannerMeta (org.bukkit.inventory.meta.BannerMeta)6 PatternType (org.bukkit.block.banner.PatternType)5 CompoundTag (net.aufdemrand.denizen.nms.util.jnbt.CompoundTag)4 ListTag (net.aufdemrand.denizen.nms.util.jnbt.ListTag)4 CompoundTag (net.glowstone.util.nbt.CompoundTag)4 BookMeta (org.bukkit.inventory.meta.BookMeta)4 EnchantmentStorageMeta (org.bukkit.inventory.meta.EnchantmentStorageMeta)4 LeatherArmorMeta (org.bukkit.inventory.meta.LeatherArmorMeta)4 PotionMeta (org.bukkit.inventory.meta.PotionMeta)4 SkullMeta (org.bukkit.inventory.meta.SkullMeta)4 CompoundTag (com.denizenscript.denizen.nms.util.jnbt.CompoundTag)3 JNBTListTag (com.denizenscript.denizen.nms.util.jnbt.JNBTListTag)3 MCPattern (com.laytonsmith.abstraction.MCPattern)3 Map (java.util.Map)3 Banner (org.bukkit.block.Banner)3 Enchantment (org.bukkit.enchantments.Enchantment)3