Search in sources :

Example 16 with Pattern

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

the class BlockBanner method toNBT.

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)

Example 17 with Pattern

use of org.bukkit.block.banner.Pattern in project CommandHelper by EngineHub.

the class BukkitMCBanner method getPatterns.

@Override
public List<MCPattern> getPatterns() {
    List<Pattern> bukkitPatterns = b.getPatterns();
    List<MCPattern> patterns = new ArrayList<>(bukkitPatterns.size());
    for (Pattern p : bukkitPatterns) {
        patterns.add(new BukkitMCPattern(p));
    }
    return patterns;
}
Also used : BukkitMCPattern(com.laytonsmith.abstraction.bukkit.BukkitMCPattern) MCPattern(com.laytonsmith.abstraction.MCPattern) BukkitMCPattern(com.laytonsmith.abstraction.bukkit.BukkitMCPattern) Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) MCPattern(com.laytonsmith.abstraction.MCPattern) BukkitMCPattern(com.laytonsmith.abstraction.bukkit.BukkitMCPattern)

Example 18 with Pattern

use of org.bukkit.block.banner.Pattern in project CommandHelper by EngineHub.

the class BukkitMCBannerMeta method setPatterns.

@Override
public void setPatterns(List<MCPattern> patterns) {
    List<Pattern> bukkitPatterns = new ArrayList<>(patterns.size());
    for (MCPattern pattern : patterns) {
        bukkitPatterns.add((Pattern) pattern.getHandle());
    }
    bm.setPatterns(bukkitPatterns);
}
Also used : MCPattern(com.laytonsmith.abstraction.MCPattern) Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) MCPattern(com.laytonsmith.abstraction.MCPattern)

Example 19 with Pattern

use of org.bukkit.block.banner.Pattern in project CommandHelper by EngineHub.

the class BukkitMCBannerMeta method getPatterns.

@Override
public List<MCPattern> getPatterns() {
    List<Pattern> bukkitPatterns = bm.getPatterns();
    List<MCPattern> patterns = new ArrayList<>(bukkitPatterns.size());
    for (Pattern p : bukkitPatterns) {
        patterns.add(new BukkitMCPattern(p));
    }
    return patterns;
}
Also used : MCPattern(com.laytonsmith.abstraction.MCPattern) Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) MCPattern(com.laytonsmith.abstraction.MCPattern)

Example 20 with Pattern

use of org.bukkit.block.banner.Pattern in project CitizensAPI by CitizensDev.

the class ItemStorage method serialiseMeta.

private static void serialiseMeta(DataKey key, ItemMeta meta) {
    key.removeKey("flags");
    try {
        key.setBoolean("unbreakable", meta.isUnbreakable());
    } catch (Throwable t) {
    // probably backwards-compat issue, don't log
    }
    int j = 0;
    for (ItemFlag flag : ItemFlag.values()) {
        if (meta.hasItemFlag(flag)) {
            key.setString("flags." + j++, flag.name());
        }
    }
    if (meta instanceof Repairable) {
        Repairable rep = (Repairable) meta;
        key.setInt("repaircost", rep.getRepairCost());
    } else {
        key.removeKey("repaircost");
    }
    if (meta.hasLore()) {
        List<String> lore = meta.getLore();
        DataKey root = key.getRelative("lore");
        for (int i = 0; i < lore.size(); i++) {
            root.setString(Integer.toString(i), lore.get(i));
        }
    } else {
        key.removeKey("lore");
    }
    if (meta.hasDisplayName()) {
        key.setString("displayname", meta.getDisplayName());
    } else {
        key.removeKey("displayname");
    }
    if (meta instanceof BookMeta) {
        BookMeta book = (BookMeta) meta;
        DataKey pages = key.getRelative("book.pages");
        for (int i = 1; i <= book.getPageCount(); i++) {
            pages.setString(Integer.toString(i), book.getPage(i));
        }
        key.setString("book.title", book.getTitle());
        key.setString("book.author", book.getAuthor());
        serialiseEnchantments(key.getRelative("book.enchantments"), book.getEnchants());
    } else {
        key.removeKey("book");
    }
    if (meta instanceof SkullMeta) {
        SkullMeta skull = (SkullMeta) meta;
        key.setString("skull.owner", skull.getOwner());
    } else {
        key.removeKey("skull");
    }
    if (meta instanceof FireworkMeta) {
        FireworkMeta firework = (FireworkMeta) meta;
        int i = 0;
        for (FireworkEffect effect : firework.getEffects()) {
            serialiseFireworkEffect(key.getRelative("firework.effects." + i), effect);
            i++;
        }
        key.setInt("firework.power", firework.getPower());
    } else {
        key.removeKey("firework");
    }
    if (meta instanceof MapMeta) {
        MapMeta map = (MapMeta) meta;
        key.setBoolean("map.scaling", map.isScaling());
    } else {
        key.removeKey("map");
    }
    if (meta instanceof LeatherArmorMeta) {
        LeatherArmorMeta armor = (LeatherArmorMeta) meta;
        Color color = armor.getColor();
        key.setInt("armor.color", color.asRGB());
    } else {
        key.removeKey("armor");
    }
    if (meta instanceof EnchantmentStorageMeta) {
        EnchantmentStorageMeta ench = (EnchantmentStorageMeta) meta;
        for (Map.Entry<Enchantment, Integer> e : ench.getStoredEnchants().entrySet()) {
            key.getRelative("enchantmentstorage").setInt(e.getKey().getName(), e.getValue());
        }
    } else {
        key.removeKey("enchantmentstorage");
    }
    if (meta instanceof PotionMeta) {
        PotionMeta potion = (PotionMeta) meta;
        PotionData data = potion.getBasePotionData();
        List<PotionEffect> effects = potion.getCustomEffects();
        key.setBoolean("potion.data.extended", data.isExtended());
        key.setBoolean("potion.data.upgraded", data.isUpgraded());
        key.setString("potion.data.type", data.getType().name());
        key.removeKey("potion.effects");
        DataKey effectKey = key.getRelative("potion.effects");
        for (int i = 0; i < effects.size(); i++) {
            PotionEffect effect = effects.get(i);
            DataKey sub = effectKey.getRelative(Integer.toString(i));
            sub.setBoolean("ambient", effect.isAmbient());
            sub.setInt("amplifier", effect.getAmplifier());
            sub.setInt("duration", effect.getDuration());
            sub.setString("type", effect.getType().getName());
        }
    } else {
        key.removeKey("potion");
    }
    key.removeKey("blockstate");
    if (meta instanceof BlockStateMeta) {
        BlockStateMeta state = (BlockStateMeta) meta;
        if (state.hasBlockState()) {
            DataKey root = key.getRelative("blockstate");
            BlockState blockstate = state.getBlockState();
            if (blockstate instanceof Banner) {
                Banner banner = (Banner) blockstate;
                serialiseBanner(root.getRelative("banner"), banner);
            } else {
                root.removeKey("banner");
            }
        }
    }
    if (meta instanceof BannerMeta) {
        BannerMeta banner = (BannerMeta) meta;
        DataKey root = key.getRelative("banner");
        if (banner.getBaseColor() != null) {
            root.setString("basecolor", banner.getBaseColor().name());
        } else {
            root.removeKey("basecolor");
        }
        List<org.bukkit.block.banner.Pattern> patterns = banner.getPatterns();
        root.removeKey("patterns");
        for (int i = 0; i < patterns.size(); i++) {
            org.bukkit.block.banner.Pattern pattern = patterns.get(i);
            DataKey sub = root.getRelative("patterns." + i);
            sub.setString("color", pattern.getColor().name());
            sub.setString("type", pattern.getPattern().getIdentifier());
        }
    } else {
        key.removeKey("banner");
    }
    Bukkit.getPluginManager().callEvent(new CitizensSerialiseMetaEvent(key, meta));
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) Pattern(org.bukkit.block.banner.Pattern) SkullMeta(org.bukkit.inventory.meta.SkullMeta) FireworkEffect(org.bukkit.FireworkEffect) CitizensSerialiseMetaEvent(net.citizensnpcs.api.event.CitizensSerialiseMetaEvent) PotionData(org.bukkit.potion.PotionData) Repairable(org.bukkit.inventory.meta.Repairable) BannerMeta(org.bukkit.inventory.meta.BannerMeta) Pattern(org.bukkit.block.banner.Pattern) Banner(org.bukkit.block.Banner) Color(org.bukkit.Color) DyeColor(org.bukkit.DyeColor) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) PotionMeta(org.bukkit.inventory.meta.PotionMeta) BlockStateMeta(org.bukkit.inventory.meta.BlockStateMeta) EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) BlockState(org.bukkit.block.BlockState) MapMeta(org.bukkit.inventory.meta.MapMeta) LeatherArmorMeta(org.bukkit.inventory.meta.LeatherArmorMeta) ItemFlag(org.bukkit.inventory.ItemFlag) Enchantment(org.bukkit.enchantments.Enchantment) BookMeta(org.bukkit.inventory.meta.BookMeta) HashMap(java.util.HashMap) Map(java.util.Map)

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