Search in sources :

Example 6 with DyeColor

use of org.bukkit.DyeColor 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)6 Material (org.bukkit.Material)2 Pattern (org.bukkit.block.banner.Pattern)2 PatternType (org.bukkit.block.banner.PatternType)2 ItemStack (org.bukkit.inventory.ItemStack)2 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Pattern (java.util.regex.Pattern)1 EntityHelper (net.aufdemrand.denizen.nms.interfaces.EntityHelper)1 PlayerProfile (net.aufdemrand.denizen.nms.util.PlayerProfile)1 Property (net.aufdemrand.denizencore.objects.properties.Property)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 Color (org.bukkit.Color)1 GrassSpecies (org.bukkit.GrassSpecies)1 Location (org.bukkit.Location)1 TreeSpecies (org.bukkit.TreeSpecies)1 Banner (org.bukkit.block.Banner)1 Block (org.bukkit.block.Block)1 Entity (org.bukkit.entity.Entity)1