use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.
the class AcidInventory method onInventoryOpen.
/**
* This covers items in a chest, etc. inventory, then change the name then
*
* @param e - event
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent e) {
if (DEBUG)
plugin.getLogger().info("DEBUG: " + e.getEventName());
// plugin.getLogger().info("Inventory open event called");
if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName)) {
Inventory inventory = e.getInventory();
if (Settings.acidDamage == 0D || !Settings.acidBottle) {
return;
}
// If this is the minishop - forget it
if (inventory.getName() != null && inventory.getName().equalsIgnoreCase(plugin.myLocale(e.getPlayer().getUniqueId()).islandMiniShopTitle)) {
return;
}
if (inventory.contains(Material.WATER_BUCKET)) {
if (DEBUG)
plugin.getLogger().info("Inventory contains water bucket");
ItemStack[] inv = inventory.getContents();
for (ItemStack item : inv) {
if (item != null) {
// plugin.getLogger().info(item.toString());
if (item.getType() == Material.WATER_BUCKET) {
if (DEBUG)
plugin.getLogger().info("Found it!");
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBucket);
lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
meta.setLore(lore);
item.setItemMeta(meta);
}
}
}
} else if (inventory.contains(Material.POTION)) {
if (DEBUG)
plugin.getLogger().info("Inventory contains water bottle");
ItemStack[] inv = inventory.getContents();
for (ItemStack item : inv) {
if (item != null) {
// plugin.getLogger().info(item.toString());
if (item.getType() == Material.POTION) {
NMSAbstraction nms = null;
try {
nms = Util.checkVersion();
} catch (Exception ex) {
return;
}
if (!nms.isPotion(item)) {
if (DEBUG)
plugin.getLogger().info("Found it!");
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(plugin.myLocale(e.getPlayer().getUniqueId()).acidBottle);
lore = Arrays.asList(plugin.myLocale(e.getPlayer().getUniqueId()).acidLore.split("\n"));
meta.setLore(lore);
item.setItemMeta(meta);
}
}
}
}
}
}
}
use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_8_R1.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.
the class NMSHandler method setBook.
@Override
public ItemStack setBook(Tag item) {
ItemStack chestItem = new ItemStack(Material.WRITTEN_BOOK);
// Bukkit.getLogger().info(item.toString());
if (((CompoundTag) item).getValue().containsKey("tag")) {
Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) item).getValue().get("tag").getValue();
// BookMeta bookMeta = (BookMeta) chestItem.getItemMeta();
String author = "";
if (contents.containsKey("author")) {
author = ((StringTag) contents.get("author")).getValue();
}
// Bukkit.getLogger().info("Author: " + author);
// bookMeta.setAuthor(author);
String title = "";
if (contents.containsKey("title")) {
title = ((StringTag) contents.get("title")).getValue();
}
// Bukkit.getLogger().info("Title: " + title);
// bookMeta.setTitle(title);
List<String> lore = new ArrayList<String>();
if (contents.containsKey("display")) {
Map<String, Tag> display = (Map<String, Tag>) (contents.get("display")).getValue();
List<Tag> loreTag = ((ListTag) display.get("Lore")).getValue();
for (Tag s : loreTag) {
lore.add(((StringTag) s).getValue());
}
}
// Bukkit.getLogger().info("Lore: " + lore);
net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
// Pages
// Create the NMS Stack's NBT (item data)
NBTTagCompound tag = new NBTTagCompound();
// Set the book's title
tag.setString("title", title);
tag.setString("author", author);
if (contents.containsKey("pages")) {
NBTTagList pages = new NBTTagList();
List<Tag> pagesTag = ((ListTag) contents.get("pages")).getValue();
for (Tag s : pagesTag) {
pages.add(new NBTTagString(((StringTag) s).getValue()));
}
// Add the pages to the tag
tag.set("pages", pages);
}
// Apply the tag to the item
stack.setTag(tag);
chestItem = CraftItemStack.asCraftMirror(stack);
ItemMeta bookMeta = (ItemMeta) chestItem.getItemMeta();
bookMeta.setLore(lore);
chestItem.setItemMeta(bookMeta);
}
return chestItem;
}
use of org.bukkit.inventory.meta.ItemMeta in project acidisland by tastybento.
the class CPItem method setLore.
public void setLore(List<String> lore) {
ItemMeta meta = item.getItemMeta();
meta.setLore(lore);
item.setItemMeta(meta);
}
Aggregations