use of org.bukkit.block.banner.Pattern in project Prism-Bukkit by prism.
the class ItemStackAction method setItem.
/**
* Set the item.
* @param item ItemStack
* @param quantity int
* @param enchantments Map of enchants.
*/
public void setItem(ItemStack item, int quantity, Map<Enchantment, Integer> enchantments) {
actionData = new ItemStackActionData();
if (enchantments != null) {
this.enchantments = enchantments;
}
if (item == null || item.getAmount() <= 0) {
this.setCanceled(true);
return;
}
this.item = item;
if (enchantments == null) {
this.enchantments = item.getEnchantments();
}
// Set basics
setMaterial(item.getType());
actionData.durability = (short) ItemUtils.getItemDamage(item);
if (tempDurability >= 0) {
actionData.durability = tempDurability;
tempDurability = -1;
}
actionData.amt = quantity;
final ItemMeta meta = item.hasItemMeta() ? item.getItemMeta() : null;
if (meta != null) {
actionData.name = meta.getDisplayName();
}
if (meta instanceof LeatherArmorMeta) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
actionData.color = lam.getColor().asRGB();
} else if (meta instanceof SkullMeta) {
final SkullMeta skull = (SkullMeta) meta;
if (skull.hasOwner()) {
actionData.owner = Objects.requireNonNull(skull.getOwningPlayer()).getUniqueId().toString();
}
} else if (meta instanceof PotionMeta) {
final PotionMeta potion = (PotionMeta) meta;
actionData.potionType = potion.getBasePotionData().getType().toString().toLowerCase();
actionData.potionExtended = potion.getBasePotionData().isExtended();
actionData.potionUpgraded = potion.getBasePotionData().isUpgraded();
}
// Written books
if (meta instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) meta;
actionData.by = bookMeta.getAuthor();
actionData.title = bookMeta.getTitle();
actionData.content = bookMeta.getPages().toArray(new String[0]);
}
// Lore
if (meta != null && meta.hasLore()) {
actionData.lore = Objects.requireNonNull(meta.getLore()).toArray(new String[0]);
}
// Enchantments
if (!this.enchantments.isEmpty()) {
final String[] enchs = new String[this.enchantments.size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
// This is silly
enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
} else if (meta instanceof EnchantmentStorageMeta) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
if (bookEnchantments.hasStoredEnchants()) {
if (bookEnchantments.getStoredEnchants().size() > 0) {
final String[] enchs = new String[bookEnchantments.getStoredEnchants().size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : bookEnchantments.getStoredEnchants().entrySet()) {
// This is absolutely silly
enchs[i] = ench.getKey().getKey().getKey() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
}
}
}
if (meta instanceof FireworkEffectMeta) {
applyFireWorksMetaToActionData(meta);
}
if (meta instanceof BannerMeta) {
List<Pattern> patterns = ((BannerMeta) meta).getPatterns();
Map<String, String> stringyPatterns = new HashMap<>();
patterns.forEach(pattern -> stringyPatterns.put(pattern.getPattern().getIdentifier(), pattern.getColor().name()));
actionData.bannerMeta = stringyPatterns;
}
}
use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showBannerUpdate.
@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
List<CompoundTag> nbtPatterns = new ArrayList<>();
for (Pattern pattern : patterns) {
nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
}
CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
showTileEntityData(player, location, 3, compoundTag);
}
use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showBannerUpdate.
@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
List<CompoundTag> nbtPatterns = new ArrayList<>();
for (Pattern pattern : patterns) {
nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
}
CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
showTileEntityData(player, location, 3, compoundTag);
}
use of org.bukkit.block.banner.Pattern in project Denizen-For-Bukkit by DenizenScript.
the class PacketHelperImpl method showBannerUpdate.
@Override
public void showBannerUpdate(Player player, Location location, DyeColor base, List<Pattern> patterns) {
List<CompoundTag> nbtPatterns = new ArrayList<>();
for (Pattern pattern : patterns) {
nbtPatterns.add(NMSHandler.getInstance().createCompoundTag(new HashMap<>()).createBuilder().putInt("Color", pattern.getColor().getDyeData()).putString("Pattern", pattern.getPattern().getIdentifier()).build());
}
CompoundTag compoundTag = NMSHandler.getBlockHelper().getNbtData(location.getBlock()).createBuilder().put("Patterns", new JNBTListTag(CompoundTag.class, nbtPatterns)).build();
showTileEntityData(player, location, 3, compoundTag);
}
use of org.bukkit.block.banner.Pattern in project Glowstone by GlowstoneMC.
the class BlockBanner method toNbt.
/**
* Converts banner patterns to NBT tags.
*
* @param banner a list of banner patterns
* @return the patterns as NBT tags
*/
public static List<CompoundTag> toNbt(List<Pattern> banner) {
List<CompoundTag> patterns = new ArrayList<>();
for (Pattern pattern : banner) {
CompoundTag layerTag = new CompoundTag();
layerTag.putString("Pattern", pattern.getPattern().getIdentifier());
layerTag.putInt("Color", pattern.getColor().getDyeData());
patterns.add(layerTag);
}
return patterns;
}
Aggregations