Search in sources :

Example 1 with Pattern

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

the class ItemPatterns method adjust.

@Override
public void adjust(Mechanism mechanism) {
    if (mechanism.matches("patterns")) {
        List<Pattern> patterns = new ArrayList<Pattern>();
        dList list = mechanism.getValue().asType(dList.class);
        List<String> split;
        for (String string : list) {
            try {
                split = CoreUtilities.split(string, '/', 2);
                patterns.add(new Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
            } catch (Exception e) {
                dB.echoError("Could not apply pattern to banner: " + string);
            }
        }
        setPatterns(patterns);
    }
}
Also used : Pattern(org.bukkit.block.banner.Pattern) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) ArrayList(java.util.ArrayList)

Example 2 with Pattern

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

the class PacketHelper_v1_10_R1 method showBannerUpdate.

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

Example 3 with Pattern

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

the class ItemStorage method deserialiseBanner.

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

Example 4 with Pattern

use of org.bukkit.block.banner.Pattern in project askyblock 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 5 with Pattern

use of org.bukkit.block.banner.Pattern in project Prism-Bukkit by prism.

the class BlockAction method handleBanners.

private ChangeResultImpl handleBanners(Block block, BlockActionData blockActionData, BlockState originalBlock) {
    block.setType(getMaterial());
    BlockState state = block.getState();
    final BannerActionData actionData = (BannerActionData) blockActionData;
    setBlockRotatable(state, actionData);
    state = block.getState();
    if (!actionData.patterns.isEmpty()) {
        final Banner banner = (Banner) state;
        List<Pattern> patternsList = new ArrayList<>();
        actionData.patterns.forEach((s, s2) -> {
            PatternType type = PatternType.valueOf(s);
            DyeColor color = DyeColor.valueOf(s2.toUpperCase());
            Pattern p = new Pattern(color, type);
            patternsList.add(p);
        });
        banner.setPatterns(patternsList);
        banner.update();
    }
    BlockStateChangeImpl stateChange = new BlockStateChangeImpl(originalBlock, state);
    return new ChangeResultImpl(ChangeResultType.APPLIED, stateChange);
}
Also used : PatternType(org.bukkit.block.banner.PatternType) Pattern(org.bukkit.block.banner.Pattern) BlockState(org.bukkit.block.BlockState) BlockStateChangeImpl(me.botsko.prism.events.BlockStateChangeImpl) Banner(org.bukkit.block.Banner) ArrayList(java.util.ArrayList) DyeColor(org.bukkit.DyeColor) ChangeResultImpl(me.botsko.prism.appliers.ChangeResultImpl)

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