diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java b/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java index 1097c95..6d35255 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java +++ b/Plugin/src/main/java/com/gmail/filoghost/chestcommands/api/Icon.java @@ -19,13 +19,12 @@ import java.util.Map.Entry; import java.util.logging.Level; import com.gmail.filoghost.chestcommands.internal.VariableManager; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.Material; +import org.bukkit.*; +import org.bukkit.block.banner.Pattern; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.inventory.meta.SkullMeta; @@ -45,6 +44,8 @@ public class Icon { private Map enchantments; private Color color; private String skullOwner; + private DyeColor bannerColor; + private List bannerPatterns; protected boolean closeOnClick; private ClickHandler clickHandler; @@ -184,6 +185,22 @@ public class Icon { this.skullOwner = skullOwner; } + public DyeColor getBannerColor() { + return bannerColor; + } + + public void setBannerColor(DyeColor bannerColor) { + this.bannerColor = bannerColor; + } + + public List getBannerPatterns() { + return bannerPatterns; + } + + public void setBannerPatterns(List bannerPatterns) { + this.bannerPatterns = bannerPatterns; + } + public void setCloseOnClick(boolean closeOnClick) { this.closeOnClick = closeOnClick; } @@ -290,6 +307,14 @@ public class Icon { if (skullOwner != null && itemMeta instanceof SkullMeta) { ((SkullMeta) itemMeta).setOwner(skullOwner); } + + if (bannerColor != null && itemMeta instanceof BannerMeta) { + BannerMeta bannerMeta = (BannerMeta) itemMeta; + bannerMeta.setBaseColor(bannerColor); + if (bannerPatterns != null) { + ((BannerMeta) itemMeta).setPatterns(bannerPatterns); + } + } itemStack.setItemMeta(itemMeta); diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java b/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java index 1530fc9..90e2fcc 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java +++ b/Plugin/src/main/java/com/gmail/filoghost/chestcommands/serializer/IconSerializer.java @@ -47,6 +47,8 @@ public class IconSerializer { ENCHANT = "ENCHANTMENT", COLOR = "COLOR", SKULL_OWNER = "SKULL-OWNER", + BANNER_COLOR = "BANNER-COLOUR", + BANNER_PATTERNS = "BANNER-PATTERNS", COMMAND = "COMMAND", PRICE = "PRICE", EXP_LEVELS = "LEVELS", @@ -140,6 +142,22 @@ public class IconSerializer { } icon.setSkullOwner(section.getString(Nodes.SKULL_OWNER)); + + if (section.isSet(Nodes.BANNER_COLOR)) { + try { + icon.setBannerColor(Utils.parseDyeColor(section.getString(Nodes.BANNER_COLOR))); + } catch (FormatException e) { + errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid BASE-COLOUR: " + e.getMessage()); + } + } + + if (section.isSet(Nodes.BANNER_PATTERNS)) { + try { + icon.setBannerPatterns(Utils.parseBannerPatternList(section.getStringList(Nodes.BANNER_PATTERNS))); + } catch (FormatException e) { + errorLogger.addError("The icon \"" + iconName + "\" in the menu \"" + menuFileName + "\" has an invalid PATTERN-LIST: " + e.getMessage()); + } + } icon.setPermission(section.getString(Nodes.PERMISSION)); icon.setPermissionMessage(Utils.addColors(section.getString(Nodes.PERMISSION_MESSAGE))); diff --git a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java b/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java index e0e53e1..23a4769 100644 --- a/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java +++ b/Plugin/src/main/java/com/gmail/filoghost/chestcommands/util/Utils.java @@ -22,10 +22,9 @@ import java.io.IOException; import java.text.DecimalFormat; import java.util.*; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.Sound; +import org.bukkit.*; +import org.bukkit.block.banner.Pattern; +import org.bukkit.block.banner.PatternType; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryView; @@ -216,8 +215,33 @@ public class Utils { return Color.fromRGB(red, green, blue); } - - + + public static DyeColor parseDyeColor(String input) throws FormatException { + DyeColor color; + try { + color = DyeColor.valueOf(input.toUpperCase()); + } catch(IllegalArgumentException e) { + throw new FormatException("it must be a valid colour."); + } + return color; + } + + public static List parseBannerPatternList(List input) throws FormatException { + List patterns = new ArrayList(); + for(String str : input) { + String[] split = str.split(":"); + if (split.length != 2) { + throw new FormatException("it must be in the format \"pattern:colour\"."); + } + try { + patterns.add(new Pattern(parseDyeColor(split[1]), PatternType.valueOf(split[0].toUpperCase()))); + } catch(IllegalArgumentException e) { + throw new FormatException("it must be a valid pattern type."); + } + } + return patterns; + } + public static void saveResourceSafe(Plugin plugin, String name) { try { plugin.saveResource(name, false);