mirror of
https://github.com/filoghost/ChestCommands.git
synced 2024-11-26 12:05:45 +01:00
Add banner options to icon
This commit is contained in:
parent
cbe2655c2b
commit
8e5bef5fd9
@ -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<Enchantment, Integer> enchantments;
|
||||
private Color color;
|
||||
private String skullOwner;
|
||||
private DyeColor bannerColor;
|
||||
private List<Pattern> 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<Pattern> getBannerPatterns() {
|
||||
return bannerPatterns;
|
||||
}
|
||||
|
||||
public void setBannerPatterns(List<Pattern> 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);
|
||||
|
||||
|
@ -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)));
|
||||
|
@ -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<Pattern> parseBannerPatternList(List<String> input) throws FormatException {
|
||||
List<Pattern> patterns = new ArrayList<Pattern>();
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user