use of org.bukkit.block.banner.Pattern in project Prism-Bukkit by prism.
the class ItemStackAction method deserialize.
@Override
public void deserialize(String data) {
if (data == null || !data.startsWith("{")) {
return;
}
actionData = gson().fromJson(data, ItemStackActionData.class);
item = new ItemStack(getMaterial(), actionData.amt);
MaterialState.setItemDamage(item, actionData.durability);
// Restore enchantment
if (actionData.enchs != null && actionData.enchs.length > 0) {
for (final String ench : actionData.enchs) {
final String[] enchArgs = ench.split(":");
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(enchArgs[0]));
// Restore book enchantment
if (enchantment != null) {
if (item.getType() == Material.ENCHANTED_BOOK) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
item.setItemMeta(bookEnchantments);
} else {
item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
}
}
}
}
ItemMeta meta = item.getItemMeta();
// Leather color
if (meta instanceof LeatherArmorMeta && actionData.color > 0) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
lam.setColor(Color.fromRGB(actionData.color));
item.setItemMeta(lam);
} else if (meta instanceof SkullMeta && actionData.owner != null) {
final SkullMeta skull = (SkullMeta) meta;
skull.setOwningPlayer(Bukkit.getOfflinePlayer(EntityUtils.uuidOf(actionData.owner)));
item.setItemMeta(skull);
} else if (meta instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) meta;
bookMeta.setAuthor(actionData.by);
bookMeta.setTitle(actionData.title);
bookMeta.setPages(actionData.content);
item.setItemMeta(bookMeta);
} else if (meta instanceof PotionMeta) {
final PotionType potionType = PotionType.valueOf(actionData.potionType.toUpperCase());
final PotionMeta potionMeta = (PotionMeta) meta;
potionMeta.setBasePotionData(new PotionData(potionType, actionData.potionExtended, actionData.potionUpgraded));
}
if (meta instanceof FireworkEffectMeta && actionData.effectColors != null && actionData.effectColors.length > 0) {
item = deserializeFireWorksMeta(item, meta, actionData);
}
if (meta instanceof BannerMeta && actionData.bannerMeta != null) {
Map<String, String> stringStringMap = actionData.bannerMeta;
List<Pattern> patterns = new ArrayList<>();
stringStringMap.forEach((patternIdentifier, dyeName) -> {
PatternType type = PatternType.getByIdentifier(patternIdentifier);
DyeColor color = DyeColor.valueOf(dyeName);
if (type != null && color != null) {
Pattern p = new Pattern(color, type);
patterns.add(p);
}
});
((BannerMeta) meta).setPatterns(patterns);
}
if (actionData.name != null) {
if (meta == null) {
meta = item.getItemMeta();
}
if (meta != null) {
meta.setDisplayName(actionData.name);
}
}
if (actionData.lore != null) {
if (meta == null) {
meta = item.getItemMeta();
}
if (meta != null) {
meta.setLore(Arrays.asList(actionData.lore));
}
}
if (meta != null) {
item.setItemMeta(meta);
}
}
use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.
the class ItemPatterns method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("patterns")) {
List<Pattern> patterns = new ArrayList<>();
ListTag list = mechanism.valueAsType(ListTag.class);
List<String> split;
for (String string : list) {
try {
split = CoreUtilities.split(string, '/', 2);
patterns.add(new Pattern(DyeColor.valueOf(split.get(0).toUpperCase()), PatternType.valueOf(split.get(1).toUpperCase())));
} catch (Exception e) {
Debug.echoError("Could not apply pattern to banner: " + string);
}
}
setPatterns(patterns);
}
}
use of org.bukkit.block.banner.Pattern in project Glowstone by GlowstoneMC.
the class BlockBanner method fromNbt.
/**
* Converts NBT tags to banner patterns.
*
* @param tag a list of banner patterns as NBT tags
* @return the patterns as Pattern instances
*/
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;
}
use of org.bukkit.block.banner.Pattern in project Glowstone by GlowstoneMC.
the class BlockCauldron method bleachBanner.
private boolean bleachBanner(GlowPlayer player, GlowBlock block) {
// fired when a player bleaches a banner using the cauldron
if (player.getGameMode() == GameMode.CREATIVE) {
return false;
}
if (block.getData() > LEVEL_EMPTY) {
ItemStack inHand = player.getItemInHand();
BannerMeta meta = (BannerMeta) inHand.getItemMeta();
List<Pattern> layers = meta.getPatterns();
if (layers.isEmpty()) {
return false;
}
if (!setCauldronLevel(block, block.getData() - 1, player, CauldronLevelChangeEvent.ChangeReason.BANNER_WASH)) {
return false;
}
meta.setPatterns(layers);
inHand.setItemMeta(meta);
return true;
} else {
return false;
}
}
use of org.bukkit.block.banner.Pattern in project Glowstone by GlowstoneMC.
the class GlowMetaShield method serialize.
@Override
@NotNull
public Map<String, Object> serialize() {
Map<String, Object> result = super.serialize();
result.put("meta-type", "SHIELD");
List<Map<String, String>> patternsList = new ArrayList<>();
for (Pattern pattern : patterns) {
patternsList.add(ImmutableMap.of(pattern.getPattern().toString(), pattern.getColor().toString()));
}
result.put("pattern", patternsList);
if (baseColor != null) {
result.put("baseColor", baseColor);
}
return result;
}
Aggregations