use of org.bukkit.block.banner.Pattern in project CitizensAPI by CitizensDev.
the class ItemStorage method serialiseBanner.
private static void serialiseBanner(DataKey root, Banner banner) {
if (banner.getBaseColor() != null) {
root.setString("basecolor", banner.getBaseColor().name());
} else {
root.removeKey("basecolor");
}
List<org.bukkit.block.banner.Pattern> patterns = banner.getPatterns();
root.removeKey("patterns");
for (int i = 0; i < patterns.size(); i++) {
org.bukkit.block.banner.Pattern pattern = patterns.get(i);
DataKey sub = root.getRelative("patterns." + i);
sub.setString("color", pattern.getColor().name());
sub.setString("type", pattern.getPattern().getIdentifier());
}
}
use of org.bukkit.block.banner.Pattern in project CitizensAPI by CitizensDev.
the class ItemStorage method deserialiseMeta.
private static void deserialiseMeta(DataKey root, ItemStack res) {
if (root.keyExists("flags")) {
ItemMeta meta = ensureMeta(res);
for (DataKey key : root.getRelative("flags").getIntegerSubKeys()) {
meta.addItemFlags(ItemFlag.valueOf(key.getString("")));
}
}
if (root.keyExists("lore")) {
ItemMeta meta = ensureMeta(res);
List<String> lore = Lists.newArrayList();
for (DataKey key : root.getRelative("lore").getIntegerSubKeys()) lore.add(key.getString(""));
meta.setLore(lore);
res.setItemMeta(meta);
}
if (root.keyExists("displayname")) {
ItemMeta meta = ensureMeta(res);
meta.setDisplayName(root.getString("displayname"));
res.setItemMeta(meta);
}
if (root.keyExists("firework")) {
FireworkMeta meta = ensureMeta(res);
for (DataKey sub : root.getRelative("firework.effects").getIntegerSubKeys()) {
meta.addEffect(deserialiseFireworkEffect(sub));
}
meta.setPower(root.getInt("firework.power"));
res.setItemMeta(meta);
}
if (root.keyExists("book")) {
BookMeta meta = ensureMeta(res);
for (DataKey sub : root.getRelative("book.pages").getIntegerSubKeys()) {
meta.addPage(sub.getString(""));
}
meta.setTitle(root.getString("book.title"));
meta.setAuthor(root.getString("book.author"));
res.setItemMeta(meta);
}
if (root.keyExists("armor")) {
LeatherArmorMeta meta = ensureMeta(res);
meta.setColor(Color.fromRGB(root.getInt("armor.color")));
res.setItemMeta(meta);
}
if (root.keyExists("map")) {
MapMeta meta = ensureMeta(res);
meta.setScaling(root.getBoolean("map.scaling"));
res.setItemMeta(meta);
}
if (root.keyExists("blockstate")) {
BlockStateMeta meta = ensureMeta(res);
if (root.keyExists("blockstate.banner")) {
Banner banner = (Banner) meta.getBlockState();
deserialiseBanner(root.getRelative("blockstate"), banner);
banner.update(true);
meta.setBlockState(banner);
}
res.setItemMeta(meta);
}
if (root.keyExists("enchantmentstorage")) {
EnchantmentStorageMeta meta = ensureMeta(res);
for (DataKey key : root.getRelative("enchantmentstorage").getSubKeys()) {
meta.addStoredEnchant(Enchantment.getByName(key.name()), key.getInt(""), true);
}
res.setItemMeta(meta);
}
if (root.keyExists("skull")) {
SkullMeta meta = ensureMeta(res);
if (root.keyExists("skull.owner") && !root.getString("skull.owner").isEmpty()) {
meta.setOwner(root.getString("skull.owner", ""));
}
res.setItemMeta(meta);
}
if (root.keyExists("banner")) {
BannerMeta meta = ensureMeta(res);
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);
}
}
}
if (root.keyExists("potion")) {
PotionMeta meta = ensureMeta(res);
PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")), root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
meta.setBasePotionData(data);
for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
int duration = sub.getInt("duration");
int amplifier = sub.getInt("amplifier");
PotionEffectType type = PotionEffectType.getByName(sub.getString("type"));
boolean ambient = sub.getBoolean("ambient");
meta.addCustomEffect(new PotionEffect(type, duration, amplifier, ambient), true);
}
res.setItemMeta(meta);
}
if (root.keyExists("repaircost") && res.getItemMeta() instanceof Repairable) {
((Repairable) res.getItemMeta()).setRepairCost(root.getInt("repaircost"));
}
ItemMeta meta = res.getItemMeta();
if (meta != null) {
try {
meta.setUnbreakable(root.getBoolean("unbreakable", false));
} catch (Throwable t) {
// probably backwards-compat issue, don't log
}
res.setItemMeta(meta);
}
Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
}
use of org.bukkit.block.banner.Pattern in project acidisland 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;
}
use of org.bukkit.block.banner.Pattern in project MassiveCore by MassiveCraft.
the class DataBannerPattern method toBukkit.
// -------------------------------------------- //
// TO BUKKIT
// -------------------------------------------- //
// Minecraft 1.7 Compatibility
@SuppressWarnings("unchecked")
public <T> T toBukkit() {
// Create
Pattern ret = WriterBannerPattern.get().createOB();
// Fill
this.write(ret, true);
// Return
return (T) ret;
}
use of org.bukkit.block.banner.Pattern in project Arcade2 by ShootGame.
the class BannerPatternParser method parsePrimitive.
@Override
protected ParserResult<Pattern> parsePrimitive(Node node, String name, String value) throws ParserException {
PatternType type = this.typeParser.parseWithDefinition(node, name, value).orFail();
DyeColor color = this.colorParser.parse(node.property("color")).orFail();
return ParserResult.fine(node, name, value, new Pattern(color, type));
}
Aggregations