Search in sources :

Example 1 with PatternType

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

the class BlockBanner method fromNBT.

public static List<Pattern> fromNBT(List<CompoundTag> tag) {
    List<Pattern> banner = new ArrayList<>();
    for (CompoundTag layer : tag) {
        PatternType patternType = PatternType.getByIdentifier(layer.getString("Pattern"));
        DyeColor color = DyeColor.getByDyeData((byte) layer.getInt("Color"));
        banner.add(new Pattern(color, patternType));
    }
    return banner;
}
Also used : PatternType(org.bukkit.block.banner.PatternType) Pattern(org.bukkit.block.banner.Pattern) ArrayList(java.util.ArrayList) DyeColor(org.bukkit.DyeColor) CompoundTag(net.glowstone.util.nbt.CompoundTag)

Example 2 with PatternType

use of org.bukkit.block.banner.PatternType in project Essentials by drtshock.

the class MetaItemStack method addBannerMeta.

public void addBannerMeta(final CommandSource sender, final boolean allowShortName, final String string, final IEssentials ess) throws Exception {
    if (stack.getType() == Material.BANNER && string != null) {
        final String[] split = splitPattern.split(string, 2);
        if (split.length < 2) {
            throw new Exception(tl("invalidBanner", split[1]));
        }
        PatternType patternType = null;
        try {
            patternType = PatternType.valueOf(split[0]);
        } catch (Exception ignored) {
        }
        final BannerMeta meta = (BannerMeta) stack.getItemMeta();
        if (split[0].equalsIgnoreCase("basecolor")) {
            Color color = Color.fromRGB(Integer.valueOf(split[1]));
            meta.setBaseColor(DyeColor.getByColor(color));
        } else if (patternType != null) {
            PatternType type = PatternType.valueOf(split[0]);
            DyeColor color = DyeColor.getByColor(Color.fromRGB(Integer.valueOf(split[1])));
            org.bukkit.block.banner.Pattern pattern = new org.bukkit.block.banner.Pattern(color, type);
            meta.addPattern(pattern);
        }
        stack.setItemMeta(meta);
    } else if (stack.getType() == Material.SHIELD && string != null) {
        final String[] split = splitPattern.split(string, 2);
        if (split.length < 2) {
            throw new Exception(tl("invalidBanner", split[1]));
        }
        PatternType patternType = null;
        try {
            patternType = PatternType.valueOf(split[0]);
        } catch (Exception ignored) {
        }
        // Hacky fix for accessing Shield meta - https://github.com/drtshock/Essentials/pull/745#issuecomment-234843795
        BlockStateMeta meta = (BlockStateMeta) stack.getItemMeta();
        Banner banner = (Banner) meta.getBlockState();
        if (split[0].equalsIgnoreCase("basecolor")) {
            Color color = Color.fromRGB(Integer.valueOf(split[1]));
            banner.setBaseColor(DyeColor.getByColor(color));
        } else if (patternType != null) {
            PatternType type = PatternType.valueOf(split[0]);
            DyeColor color = DyeColor.getByColor(Color.fromRGB(Integer.valueOf(split[1])));
            org.bukkit.block.banner.Pattern pattern = new org.bukkit.block.banner.Pattern(color, type);
            banner.addPattern(pattern);
        }
        banner.update();
        meta.setBlockState(banner);
        stack.setItemMeta(meta);
    }
}
Also used : PatternType(org.bukkit.block.banner.PatternType) Pattern(java.util.regex.Pattern) Banner(org.bukkit.block.Banner) DyeColor(org.bukkit.DyeColor) Color(org.bukkit.Color) DyeColor(org.bukkit.DyeColor)

Aggregations

DyeColor (org.bukkit.DyeColor)2 PatternType (org.bukkit.block.banner.PatternType)2 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 Color (org.bukkit.Color)1 Banner (org.bukkit.block.Banner)1 Pattern (org.bukkit.block.banner.Pattern)1