Search in sources :

Example 21 with Pattern

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

the class ItemStorage method serialiseBanner.

private static void serialiseBanner(DataKey root, Banner 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());
    }
}
Also used : Pattern(org.bukkit.block.banner.Pattern) Pattern(org.bukkit.block.banner.Pattern)

Example 22 with Pattern

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

use of org.bukkit.block.banner.Pattern in project acidisland by tastybento.

the class BannerBlock method prep.

@SuppressWarnings("deprecation")
public boolean prep(Map<String, Tag> tileData) {
    // x = Int
    try {
        // Do the base color
        int baseColor = 15 - ((IntTag) tileData.get("Base")).getValue();
        // //ASkyBlock.getPlugin().getLogger().info("Base value = " +
        // baseColor);
        // baseColor green = 10
        bannerBaseColor = DyeColor.getByDyeData((byte) baseColor);
        // Do the patterns (no idea if this will work or not)
        bannerPattern = new ArrayList<Pattern>();
        ListTag patterns = (ListTag) tileData.get("Patterns");
        if (patterns != null) {
            for (Tag pattern : patterns.getValue()) {
                // Translate pattern to PatternType
                if (pattern instanceof CompoundTag) {
                    CompoundTag patternColor = (CompoundTag) pattern;
                    // The tag is made up of pattern (String) and color
                    // (int)
                    Map<String, Tag> patternValue = patternColor.getValue();
                    StringTag mark = (StringTag) patternValue.get("Pattern");
                    Integer markColor = 15 - ((IntTag) patternValue.get("Color")).getValue();
                    // ASkyBlock.getPlugin().getLogger().info("mark = " +
                    // mark.getValue());
                    // ASkyBlock.getPlugin().getLogger().info("color = " +
                    // markColor);
                    DyeColor dColor = DyeColor.getByDyeData(markColor.byteValue());
                    // + dColor.toString());
                    if (patternKey.containsKey(mark.getValue())) {
                        Pattern newPattern = new Pattern(dColor, patternKey.get(mark.getValue()));
                        bannerPattern.add(newPattern);
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) Pattern(org.bukkit.block.banner.Pattern) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) IntTag(com.wasteofplastic.org.jnbt.IntTag) Tag(com.wasteofplastic.org.jnbt.Tag) DyeColor(org.bukkit.DyeColor) ListTag(com.wasteofplastic.org.jnbt.ListTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag)

Example 24 with Pattern

use of org.bukkit.block.banner.Pattern in project MassiveCore by MassiveCraft.

the class DataBannerPattern method toBukkit.

// -------------------------------------------- //
// TO BUKKIT
// -------------------------------------------- //
// Minecraft 1.7 Compatibility
@SuppressWarnings("unchecked")
public <T> T toBukkit() {
    // Create
    Pattern ret = WriterBannerPattern.get().createOB();
    // Fill
    this.write(ret, true);
    // Return
    return (T) ret;
}
Also used : Pattern(org.bukkit.block.banner.Pattern)

Example 25 with Pattern

use of org.bukkit.block.banner.Pattern in project Arcade2 by ShootGame.

the class BannerPatternParser method parsePrimitive.

@Override
protected ParserResult<Pattern> parsePrimitive(Node node, String name, String value) throws ParserException {
    PatternType type = this.typeParser.parseWithDefinition(node, name, value).orFail();
    DyeColor color = this.colorParser.parse(node.property("color")).orFail();
    return ParserResult.fine(node, name, value, new Pattern(color, type));
}
Also used : PatternType(org.bukkit.block.banner.PatternType) Pattern(org.bukkit.block.banner.Pattern) DyeColor(org.bukkit.DyeColor)

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