use of org.bukkit.inventory.meta.ItemMeta in project SpaciousLib by anhcraft.
the class SItems method name.
/**
* Set the name for an item
*
* @param name new name for the item
*/
public void name(String name) {
ItemMeta a = this.item.getItemMeta();
a.setDisplayName(name.replace("&", "ยง"));
this.item.setItemMeta(a);
}
use of org.bukkit.inventory.meta.ItemMeta in project Prism-Bukkit by prism.
the class ItemStackAction method setItemStackFromNewDataFormat.
/**
*
*/
protected void setItemStackFromNewDataFormat() {
if (data == null || !data.startsWith("{"))
return;
actionData = gson.fromJson(data, ItemStackActionData.class);
item = new ItemStack(this.block_id, actionData.amt, (short) this.block_subid);
// Restore enchantment
if (actionData.enchs != null && actionData.enchs.length > 0) {
for (final String ench : actionData.enchs) {
final String[] enchArgs = ench.split(":");
final Enchantment enchantment = Enchantment.getById(Integer.parseInt(enchArgs[0]));
// Restore book enchantment
if (item.getType().equals(Material.ENCHANTED_BOOK)) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
item.setItemMeta(bookEnchantments);
} else // Restore item enchantment
{
item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
}
}
}
// Leather color
if (item.getType().name().contains("LEATHER_") && actionData.color > 0) {
final LeatherArmorMeta lam = (LeatherArmorMeta) item.getItemMeta();
lam.setColor(Color.fromRGB(actionData.color));
item.setItemMeta(lam);
} else // Skulls
if (item.getType().equals(Material.SKULL_ITEM) && actionData.owner != null) {
final SkullMeta meta = (SkullMeta) item.getItemMeta();
meta.setOwner(actionData.owner);
item.setItemMeta(meta);
} else // Written books
if (item.getItemMeta() instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) item.getItemMeta();
bookMeta.setAuthor(actionData.by);
bookMeta.setTitle(actionData.title);
bookMeta.setPages(actionData.content);
item.setItemMeta(bookMeta);
}
// Fireworks
if (block_id == 402 && actionData.effectColors != null && actionData.effectColors.length > 0) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) item.getItemMeta();
final Builder effect = FireworkEffect.builder();
if (actionData.effectColors != null) {
for (int i = 0; i < actionData.effectColors.length; i++) {
effect.withColor(Color.fromRGB(actionData.effectColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.fadeColors != null) {
for (int i = 0; i < actionData.fadeColors.length; i++) {
effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.hasFlicker) {
effect.flicker(true);
}
if (actionData.hasTrail) {
effect.trail(true);
}
fireworkMeta.setEffect(effect.build());
item.setItemMeta(fireworkMeta);
}
// Item display names
final ItemMeta meta = item.getItemMeta();
if (actionData.name != null) {
meta.setDisplayName(actionData.name);
}
if (actionData.lore != null) {
meta.setLore(Arrays.asList(actionData.lore));
}
item.setItemMeta(meta);
}
use of org.bukkit.inventory.meta.ItemMeta in project Prism-Bukkit by prism.
the class ItemStackAction method setItem.
/**
*
* @param action_type
* @param block
* @param player
*/
public void setItem(ItemStack item, int quantity, int slot, 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
this.block_id = item.getTypeId();
this.block_subid = item.getDurability();
actionData.amt = quantity;
if (slot >= 0) {
actionData.slot = slot;
}
// Set additional data all items may have
final ItemMeta meta = item.getItemMeta();
if (meta != null && meta.getDisplayName() != null) {
actionData.name = meta.getDisplayName();
}
// Leather Coloring
if (meta != null && item.getType().name().contains("LEATHER_")) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
if (lam.getColor() != null) {
actionData.color = lam.getColor().asRGB();
}
} else // Skull Owner
if (meta != null && item.getType().equals(Material.SKULL_ITEM)) {
final SkullMeta skull = (SkullMeta) meta;
if (skull.hasOwner()) {
actionData.owner = skull.getOwner();
}
}
// Written books
if (meta != null && 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.getLore() != null) {
actionData.lore = 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()) {
enchs[i] = ench.getKey().getId() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
} else // Book enchantments
if (meta != null && item.getType().equals(Material.ENCHANTED_BOOK)) {
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()) {
enchs[i] = ench.getKey().getId() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
}
}
}
// Fireworks
if (meta != null && block_id == 402) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
if (fireworkMeta.hasEffect()) {
final FireworkEffect effect = fireworkMeta.getEffect();
if (!effect.getColors().isEmpty()) {
final int[] effectColors = new int[effect.getColors().size()];
int i = 0;
for (final Color effectColor : effect.getColors()) {
effectColors[i] = effectColor.asRGB();
i++;
}
actionData.effectColors = effectColors;
}
if (!effect.getFadeColors().isEmpty()) {
final int[] fadeColors = new int[effect.getColors().size()];
final int i = 0;
for (final Color fadeColor : effect.getFadeColors()) {
fadeColors[i] = fadeColor.asRGB();
}
actionData.fadeColors = fadeColors;
}
if (effect.hasFlicker()) {
actionData.hasFlicker = true;
}
if (effect.hasTrail()) {
actionData.hasTrail = true;
}
}
}
}
use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.
the class DenizenPacketHandler method removeItemScriptLore.
private static ItemStack removeItemScriptLore(ItemStack itemStack) {
if (itemStack != null && itemStack.hasItemMeta() && itemStack.getItemMeta().hasLore()) {
ItemMeta meta = itemStack.getItemMeta();
List<String> lore = meta.getLore();
Iterator<String> iter = lore.iterator();
String hash = null;
while (iter.hasNext()) {
String line = iter.next();
if (line.startsWith(ItemScriptHelper.ItemScriptHashID)) {
hash = line;
iter.remove();
break;
}
}
if (hash != null) {
meta.setLore(lore);
itemStack.setItemMeta(meta);
return NMSHandler.getInstance().getItemHelper().addNbtData(itemStack, "Denizen Item Script", new StringTag(hash));
}
}
return itemStack;
}
use of org.bukkit.inventory.meta.ItemMeta in project Bukkit by Bukkit.
the class ItemStack method serialize.
@Utility
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("type", getType().name());
if (getDurability() != 0) {
result.put("damage", getDurability());
}
if (getAmount() != 1) {
result.put("amount", getAmount());
}
ItemMeta meta = getItemMeta();
if (!Bukkit.getItemFactory().equals(meta, null)) {
result.put("meta", meta);
}
return result;
}
Aggregations