org.bukkit.inventory.meta.BookMeta Java Examples
The following examples show how to use
org.bukkit.inventory.meta.BookMeta.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommandHandler.java From NyaaUtils with MIT License | 7 votes |
@SubCommand(value = "setbookauthor", permission = "nu.setbook") public void setbookauthor(CommandSender sender, Arguments args) { if (!(args.length() > 1)) { msg(sender, "manual.setbookauthor.usage"); return; } String author = args.next(); Player p = asPlayer(sender); author = ChatColor.translateAlternateColorCodes('&', author); ItemStack item = p.getInventory().getItemInMainHand(); if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) { msg(sender, "user.setbook.no_book"); return; } BookMeta meta = (BookMeta) item.getItemMeta(); meta.setAuthor(author); item.setItemMeta(meta); msg(sender, "user.setbook.success"); }
Example #2
Source File: LecternInteractListener.java From ViaBackwards with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onLecternInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if (!isOnPipe(player)) return; Block block = event.getClickedBlock(); if (block == null || block.getType() != Material.LECTERN) return; Lectern lectern = (Lectern) block.getState(); ItemStack book = lectern.getInventory().getItem(0); if (book == null) return; BookMeta meta = (BookMeta) book.getItemMeta(); // Open a book with the text of the lectern's writable book ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK); BookMeta newBookMeta = (BookMeta) newBook.getItemMeta(); newBookMeta.setPages(meta.getPages()); newBookMeta.setAuthor("an upsidedown person"); newBookMeta.setTitle("buk"); newBook.setItemMeta(newBookMeta); player.openBook(newBook); event.setCancelled(true); }
Example #3
Source File: CustomItem.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
protected void applyConfig(ConfigurationSection section) { _enabled = section.getBoolean("enabled"); _name = section.getString("name"); ItemMeta meta = _item.getItemMeta(); if (meta instanceof BookMeta) { ((BookMeta) meta).setTitle(_name); } else { meta.setDisplayName(_name); } meta.setLore(section.getStringList("lore")); _item.setItemMeta(meta); List<String> allowedWorlds = section.getStringList("allowed-worlds"); if (allowedWorlds == null || allowedWorlds.size() == 0) { List<String> blockedWorlds = section.getStringList("blocked-worlds"); _blockedWorlds = (blockedWorlds.size() > 0 ? new HashSet<String>(blockedWorlds) : null); _allowedWorlds = null; } else { _allowedWorlds = new HashSet<String>(allowedWorlds); } }
Example #4
Source File: CustomBookOverlay.java From CS-CoreLib with GNU General Public License v3.0 | 6 votes |
public CustomBookOverlay(String title, String author, TellRawMessage... pages) { this.book = new ItemStack(Material.WRITTEN_BOOK); BookMeta meta = (BookMeta) this.book.getItemMeta(); meta.setTitle(title); meta.setAuthor(author); for (TellRawMessage page: pages) { try { addPage(meta, page); } catch (Exception e) { e.printStackTrace(); } } this.book.setItemMeta(meta); }
Example #5
Source File: BookSerialize.java From NBTEditor with GNU General Public License v3.0 | 6 votes |
public static String loadData(BookMeta meta, String dataTitle) { int pageCount = meta.getPageCount(); if (pageCount == 0) { return null; } StringBuilder dataSB = new StringBuilder(); for (int i = 1; i <= pageCount; ++i) { String page = meta.getPage(i); if (page.startsWith(dataTitle)) { dataSB.append(page.substring(dataTitle.length() + _dataPre.length())); for (++i; i <= pageCount; ++i) { page = meta.getPage(i); if (page.startsWith(_dataPre)) { dataSB.append(page.substring(_dataPre.length())); } else { break; } } return dataSB.toString(); } } return null; }
Example #6
Source File: CommandHandler.java From NyaaUtils with MIT License | 6 votes |
@SubCommand(value = "setbooktitle", permission = "nu.setbook") public void setbooktitle(CommandSender sender, Arguments args) { if (!(args.length() > 1)) { msg(sender, "manual.setbooktitle.usage"); return; } String title = args.next(); Player p = asPlayer(sender); title = ChatColor.translateAlternateColorCodes('&', title); ItemStack item = p.getInventory().getItemInMainHand(); if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) { msg(sender, "user.setbook.no_book"); return; } BookMeta meta = (BookMeta) item.getItemMeta(); meta.setTitle(title); item.setItemMeta(meta); msg(sender, "user.setbook.success"); }
Example #7
Source File: CommandHandler.java From NyaaUtils with MIT License | 6 votes |
@SubCommand(value = "setbookunsigned", permission = "nu.setbook") public void setbookunsigned(CommandSender sender, Arguments args) { Player p = asPlayer(sender); ItemStack item = p.getInventory().getItemInMainHand(); if (item == null || !item.getType().equals(Material.WRITTEN_BOOK)) { msg(sender, "user.setbook.no_book"); return; } BookMeta meta = (BookMeta) item.getItemMeta(); ItemStack newbook = new ItemStack(Material.WRITABLE_BOOK, 1); BookMeta newbookMeta = (BookMeta) newbook.getItemMeta(); newbookMeta.setPages(meta.getPages()); newbook.setItemMeta(newbookMeta); p.getInventory().setItemInMainHand(newbook); msg(sender, "user.setbook.success"); }
Example #8
Source File: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 6 votes |
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) { int itemInHandIndex = player.inventory.currentItem; PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book); player.worldObj.getServer().getPluginManager().callEvent(editBookEvent); net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex); // If they've got the same item in their hand, it'll need to be updated. if (itemInHand != null && itemInHand.getItem() == net.minecraft.init.Items.writable_book) { if (!editBookEvent.isCancelled()) { CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta()); if (editBookEvent.isSigning()) { itemInHand.func_150996_a(net.minecraft.init.Items.written_book); } } // Client will have updated its idea of the book item; we need to overwrite that net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex); player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand)); } }
Example #9
Source File: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 6 votes |
public static void handleEditBookEvent(EntityPlayerMP player, ItemStack newBookItem) { int itemInHandIndex = player.inventory.currentItem; PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK); player.world.getServer().getPluginManager().callEvent(editBookEvent); ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex); // If they've got the same item in their hand, it'll need to be updated. if (itemInHand != null && itemInHand.getItem() == Items.WRITABLE_BOOK) { if (!editBookEvent.isCancelled()) { if (editBookEvent.isSigning()) { itemInHand.setItem(Items.WRITTEN_BOOK); } CraftMetaBook meta = (CraftMetaBook) editBookEvent.getNewBookMeta(); List<ITextComponent> pages = meta.pages; for (int i = 0; i < pages.size(); i++) { pages.set(i, stripEvents(pages.get(i))); } CraftItemStack.setItemMeta(itemInHand, meta); } // Client will have updated its idea of the book item; we need to overwrite that Slot slot = player.openContainer.getSlotFromInventory(player.inventory, itemInHandIndex); player.connection.sendPacket(new SPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand)); } }
Example #10
Source File: BookUtil.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static void linePageinate(BookMeta meta, ArrayList<String> lines) { /* * 13 writeable lines per page, iterate through each line * and place into the page, when the line count equals 14 * set it back to 0 and add page. */ int count = 0; String page = ""; for (String line : lines) { count++; if (count > LINES_PER_PAGE) { meta.addPage(page); count = 0; page = ""; } page += line+"\n"; } meta.addPage(page); }
Example #11
Source File: BookUtil.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static void paginate(BookMeta meta, String longString) { /* Break page into lines and pass into longString. */ int count = 0; ArrayList<String> lines = new ArrayList<String>(); String line = ""; for (char c : longString.toCharArray()) { count++; if (c == '\n' || count > CHARS_PER_LINE) { lines.add(line); line = ""; count = 0; } if (c != '\n') { line += c; } } linePageinate(meta, lines); }
Example #12
Source File: Spy.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onPlayerDeath(EntityDeathEvent event, ItemStack stack) { Player player = (Player)event.getEntity(); Resident resident = CivGlobal.getResident(player); if (resident == null || !resident.hasTown()) { return; } ArrayList<String> bookout = MissionLogger.getMissionLogs(resident.getTown()); ItemStack book = new ItemStack(Material.WRITTEN_BOOK, 1); BookMeta meta = (BookMeta) book.getItemMeta(); ArrayList<String> lore = new ArrayList<String>(); lore.add("Mission Report"); meta.setAuthor("Mission Reports"); meta.setTitle("Missions From "+resident.getTown().getName()); String out = ""; for (String str : bookout) { out += str+"\n"; } BookUtil.paginate(meta, out); meta.setLore(lore); book.setItemMeta(meta); player.getWorld().dropItem(player.getLocation(), book); }
Example #13
Source File: CustomBookOverlay.java From CS-CoreLib with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) private void addPage(BookMeta meta, TellRawMessage page) throws Exception { Field field = ReflectionUtils.getField(ReflectionUtils.getClass(PackageName.OBC, "inventory.CraftMetaBook"), "pages"); field.setAccessible(true); List pages = (List) field.get(meta); pages.add(ReflectionUtils.getClass(PackageName.NMS, "IChatBaseComponent").cast(page.getSerializedString())); field.setAccessible(false); }
Example #14
Source File: Utils.java From ShopChest with MIT License | 5 votes |
/** * Check if two items are similar to each other * @param itemStack1 The first item * @param itemStack2 The second item * @return {@code true} if the given items are similar or {@code false} if not */ public static boolean isItemSimilar(ItemStack itemStack1, ItemStack itemStack2) { if (itemStack1 == null || itemStack2 == null) { return false; } ItemMeta itemMeta1 = itemStack1.getItemMeta(); ItemMeta itemMeta2 = itemStack2.getItemMeta(); if (itemMeta1 instanceof BookMeta && itemMeta2 instanceof BookMeta) { BookMeta bookMeta1 = (BookMeta) itemStack1.getItemMeta(); BookMeta bookMeta2 = (BookMeta) itemStack2.getItemMeta(); if ((getMajorVersion() == 9 && getRevision() == 1) || getMajorVersion() == 8) { CustomBookMeta.Generation generation1 = CustomBookMeta.getGeneration(itemStack1); CustomBookMeta.Generation generation2 = CustomBookMeta.getGeneration(itemStack2); if (generation1 == null) CustomBookMeta.setGeneration(itemStack1, CustomBookMeta.Generation.ORIGINAL); if (generation2 == null) CustomBookMeta.setGeneration(itemStack2, CustomBookMeta.Generation.ORIGINAL); } else { if (bookMeta1.getGeneration() == null) bookMeta1.setGeneration(BookMeta.Generation.ORIGINAL); if (bookMeta2.getGeneration() == null) bookMeta2.setGeneration(BookMeta.Generation.ORIGINAL); } itemStack1.setItemMeta(bookMeta1); itemStack2.setItemMeta(bookMeta2); itemStack1 = decode(encode(itemStack1)); itemStack2 = decode(encode(itemStack2)); } return itemStack1.isSimilar(itemStack2); }
Example #15
Source File: Journal.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
/** * Checks if the item is journal * * @param playerID ID of the player * @param item ItemStack to check against being the journal * @return true if the ItemStack is the journal, false otherwise */ public static boolean isJournal(String playerID, ItemStack item) { // if there is no item then it's not a journal if (item == null) { return false; } // get language String playerLang = BetonQuest.getInstance().getPlayerData(playerID).getLanguage(); // check all properties of the item and return the result return (item.getType().equals(Material.WRITTEN_BOOK) && ((BookMeta) item.getItemMeta()).hasTitle() && ((BookMeta) item.getItemMeta()).getTitle().equals(Config.getMessage(playerLang, "journal_title")) && item.getItemMeta().hasLore() && item.getItemMeta().getLore().contains(Config.getMessage(playerLang, "journal_lore"))); }
Example #16
Source File: BookPlayerShopkeeper.java From Shopkeepers with GNU General Public License v3.0 | 5 votes |
private static String getTitleOfBook(ItemStack book) { if (book.getType() == Material.WRITTEN_BOOK && book.hasItemMeta()) { BookMeta meta = (BookMeta) book.getItemMeta(); return meta.getTitle(); } return null; }
Example #17
Source File: SchematicUtil.java From PlotMe-Core with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private Item getItem(ItemStack is, Byte slot) { byte count = (byte) is.getAmount(); short damage = (short) is.getData().getData(); short itemid = (short) is.getTypeId(); ItemTag itemtag = null; if (is.hasItemMeta()) { List<Ench> enchants = null; ItemMeta im = is.getItemMeta(); Map<Enchantment, Integer> isEnchants = im.getEnchants(); if (isEnchants != null) { enchants = new ArrayList<>(); for (Enchantment ench : isEnchants.keySet()) { enchants.add(new Ench((short) ench.getId(), isEnchants.get(ench).shortValue())); } } List<String> lore = im.getLore(); String name = im.getDisplayName(); Display display = new Display(name, lore); String author = null; String title = null; List<String> pages = null; if (im instanceof BookMeta) { BookMeta bm = (BookMeta) im; author = bm.getAuthor(); title = bm.getTitle(); pages = bm.getPages(); } itemtag = new ItemTag(0, enchants, display, author, title, pages); } return new Item(count, slot, damage, itemid, itemtag); }
Example #18
Source File: SchematicUtil.java From PlotMe-Core with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") private void setTag(ItemStack is, ItemTag itemtag) { List<Ench> enchants = itemtag.getEnchants(); //Integer repaircost = itemtag.getRepairCost(); List<String> pages = itemtag.getPages(); String author = itemtag.getAuthor(); String title = itemtag.getTitle(); Display display = itemtag.getDisplay(); ItemMeta itemmeta = is.getItemMeta(); if (display != null) { List<String> lores = display.getLore(); String name = display.getName(); itemmeta.setLore(lores); itemmeta.setDisplayName(name); } if (itemmeta instanceof BookMeta) { BookMeta bookmeta = (BookMeta) itemmeta; bookmeta.setAuthor(author); bookmeta.setTitle(title); bookmeta.setPages(pages); } if (itemmeta instanceof EnchantmentStorageMeta) { EnchantmentStorageMeta enchantmentstoragemeta = (EnchantmentStorageMeta) itemmeta; for (Ench enchant : enchants) { enchantmentstoragemeta.addEnchant(Enchantment.getById(enchant.getId()), enchant.getLvl(), true); } } is.setItemMeta(itemmeta); }
Example #19
Source File: Items.java From CardinalPGM with MIT License | 5 votes |
public static ItemStack createBook(Material material, int amount, String name, String author) { ItemStack item = createItem(material, amount, (short) 0, name); BookMeta meta = (BookMeta) item.getItemMeta(); meta.setAuthor(author); meta.setPages(Collections.singletonList("")); item.setItemMeta(meta); return item; }
Example #20
Source File: BookOfSouls.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public static EntityNBT bookToEntityNBT(ItemStack book) { if (isValidBook(book)) { try { String data = BookSerialize.loadData((BookMeta) book.getItemMeta(), _dataTitle); if (data == null) { // This is not a BoS v0.2, is BoS v0.1? data = BookSerialize.loadData((BookMeta) book.getItemMeta(), _dataTitleOLD); if (data != null) { // Yes, it is v0.1, do a dirty conversion. int i = data.indexOf(','); NBTTagCompound nbtData = NBTTagCompound.unserialize(Base64.decode(data.substring(i + 1))); nbtData.setString("id", data.substring(0, i)); data = Base64.encodeBytes(nbtData.serialize(), Base64.GZIP); } } if (data != null) { if (data.startsWith("§k")) { // Dirty fix, for some reason 'data' can sometimes start with §k. // Remove it!!! data = data.substring(2); } return EntityNBT.unserialize(data); } } catch (Exception e) { _plugin.getLogger().log(Level.WARNING, "Corrupt Book of Souls.", e); return null; } } return null; }
Example #21
Source File: BookOfSouls.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public static boolean isValidBook(ItemStack book) { if (book != null && book.getType() == Material.WRITTEN_BOOK) { ItemMeta meta = book.getItemMeta(); String title = ((BookMeta) meta).getTitle(); if (meta != null && title != null && title.equals(_bosCustomItem.getName())) { return true; } } return false; }
Example #22
Source File: UtilsMc.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public static ItemStack newWrittenBook(String title, String author) { ItemStack book = new ItemStack(Material.WRITTEN_BOOK); BookMeta meta = (BookMeta) book.getItemMeta(); meta.setTitle(title); meta.setAuthor(author); book.setItemMeta(meta); return book; }
Example #23
Source File: BookSerialize.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
public static void saveToBook(BookMeta meta, String data, String dataTitle) { int max; int pageMax = 255 - _dataPre.length(); for (int i = 0, l = data.length(); i < l; i += max) { max = (i == 0 ? pageMax - dataTitle.length() : pageMax); meta.addPage((i == 0 ? dataTitle : "") + _dataPre + data.substring(i, (i + max > l ? l : i + max))); } }
Example #24
Source File: CustomItem.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
static String getItemName(ItemStack item) { if (item != null) { ItemMeta meta = item.getItemMeta(); if (meta != null) { if (meta instanceof BookMeta) { return ((BookMeta) meta).getTitle(); } else { return meta.getDisplayName(); } } } return null; }
Example #25
Source File: ExprBookAuthor.java From Skript with GNU General Public License v3.0 | 5 votes |
@Nullable @Override public String convert(ItemType item) { if (!book.isOfType(item.getMaterial())) return null; return ((BookMeta) item.getItemMeta()).getAuthor(); }
Example #26
Source File: ExploitFixerPostProcessListener.java From ExploitFixer with GNU General Public License v3.0 | 5 votes |
private int getBookLength(final ExploitPlayer exploitPlayer, final HamsterPlayer hamsterPlayer, final ItemMeta itemMeta) { final Player player = hamsterPlayer.getPlayer(); final Logger logger = plugin.getLogger(); final BookMeta bookMeta = (BookMeta) itemMeta; final double dataVls = packetsModule.getDataVls(); final int pageCount = bookMeta.getPageCount(), dataBytesBook = packetsModule.getDataBytesBook(); int bookTotalBytes = 0; if (pageCount > 50) { if (notificationsModule.isDebug()) { logger.info(player.getName() + " has sent a packet with a book with too many pages! (" + pageCount + "/" + 50 + ") Added vls: " + dataVls); } exploitPlayer.addVls(plugin, null, hamsterPlayer, packetsModule, dataVls); } else { for (final String page : bookMeta.getPages()) { final int pageBytes = page.getBytes(StandardCharsets.UTF_8).length; bookTotalBytes += pageBytes; if (pageBytes > dataBytesBook) { if (notificationsModule.isDebug()) { logger.info( player.getName() + " has sent a packet with a book with too many characters per page! (" + pageBytes + "/" + dataBytesBook + ") Added vls: " + dataVls); } exploitPlayer.addVls(plugin, null, hamsterPlayer, packetsModule, dataVls); break; } } return bookTotalBytes; } return itemMeta.toString().getBytes(StandardCharsets.UTF_8).length; }
Example #27
Source File: KitParser.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public ItemStack parseBook(Element el) throws InvalidXMLException { ItemStack itemStack = parseItem(el, Material.WRITTEN_BOOK); BookMeta meta = (BookMeta) itemStack.getItemMeta(); meta.setTitle(BukkitUtils.colorize(XMLUtils.getRequiredUniqueChild(el, "title").getText())); meta.setAuthor(BukkitUtils.colorize(XMLUtils.getRequiredUniqueChild(el, "author").getText())); Element elPages = el.getChild("pages"); if (elPages != null) { for (Element elPage : elPages.getChildren("page")) { String text = elPage.getText(); text = text.trim(); // Remove leading and trailing whitespace text = Pattern.compile("^[ \\t]+", Pattern.MULTILINE) .matcher(text) .replaceAll(""); // Remove indentation on each line text = Pattern.compile("^\\n", Pattern.MULTILINE) .matcher(text) .replaceAll( " \n"); // Add a space to blank lines, otherwise they vanish for unknown reasons text = BukkitUtils.colorize(text); // Color codes meta.addPage(text); } } itemStack.setItemMeta(meta); return itemStack; }
Example #28
Source File: MapPoll.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public void sendBook(MatchPlayer viewer, boolean forceOpen) { String title = ChatColor.GOLD + "" + ChatColor.BOLD; title += TextTranslations.translate("vote.title.map", viewer.getBukkit()); ItemStack is = new ItemStack(Material.WRITTEN_BOOK); BookMeta meta = (BookMeta) is.getItemMeta(); meta.setAuthor("PGM"); meta.setTitle(title); TextComponent.Builder content = TextComponent.builder(); content.append(TranslatableComponent.of("vote.header.map", TextColor.DARK_PURPLE)); content.append(TextComponent.of("\n\n")); for (MapInfo pgmMap : votes.keySet()) content.append(getMapBookComponent(viewer, pgmMap)); NMSHacks.setBookPages( meta, TextTranslations.toBaseComponent(content.build(), viewer.getBukkit())); is.setItemMeta(meta); ItemStack held = viewer.getInventory().getItemInHand(); if (held.getType() != Material.WRITTEN_BOOK || !title.equals(((BookMeta) is.getItemMeta()).getTitle())) { viewer.getInventory().setHeldItemSlot(2); } viewer.getInventory().setItemInHand(is); if (forceOpen || viewer.getSettings().getValue(SettingKey.VOTE) == SettingValue.VOTE_ON) NMSHacks.openBook(is, viewer.getBukkit()); }
Example #29
Source File: PlayerEditBookEvent.java From Kettle with GNU General Public License v3.0 | 5 votes |
public PlayerEditBookEvent(Player who, int slot, BookMeta previousBookMeta, BookMeta newBookMeta, boolean isSigning) { super(who); Validate.isTrue(slot >= 0 && slot <= 8, "Slot must be in range 0-8 inclusive"); Validate.notNull(previousBookMeta, "Previous book meta must not be null"); Validate.notNull(newBookMeta, "New book meta must not be null"); Bukkit.getItemFactory().equals(previousBookMeta, newBookMeta); this.previousBookMeta = previousBookMeta; this.newBookMeta = newBookMeta; this.slot = slot; this.isSigning = isSigning; this.cancel = false; }
Example #30
Source File: I18nOrigin.java From TabooLib with MIT License | 5 votes |
@Override public String getName(Player player, ItemStack itemStack) { if (itemStack == null) { return "-"; } ItemMeta itemMeta = itemStack.getItemMeta(); if (itemMeta instanceof BookMeta && ((BookMeta) itemMeta).getTitle() != null) { return ((BookMeta) itemMeta).getTitle(); } if (!Version.isAfter(Version.v1_11)) { if (itemStack.getType().name().equals("MONSTER_EGG")) { NBTCompound nbtCompound = NMS.handle().loadNBT(itemStack); if (nbtCompound.containsKey("EntityTag")) { return lang.getString("item_monsterPlacer_name") + " " + lang.getString("entity_" + nbtCompound.get("EntityTag").asCompound().get("id").asString() + "_name"); } return lang.getString("item_monsterPlacer_name"); } } else if (!Version.isAfter(Version.v1_13)) { if (itemMeta instanceof SpawnEggMeta) { String spawnEggType = lang.getString("entity_" + ((SpawnEggMeta) itemMeta).getSpawnedType().getEntityClass().getSimpleName().replace(".", "_") + "_name"); if (spawnEggType != null) { return lang.getString(NMS.handle().getName(itemStack).replace(".", "_"), itemStack.getType().name().toLowerCase().replace("_", "")) + " " + spawnEggType; } } } return lang.getString(NMS.handle().getName(itemStack).replace(".", "_"), itemStack.getType().name().toLowerCase().replace("_", "")); }