/** * Creates an instance by copying from the given {@link ItemMeta}. If that item is another * {@link BookMeta}, its title, author, pages and generation are copied; otherwise, the new book * is blank. * @param meta the {@link ItemMeta} to copy */ public GlowMetaBook(ItemMeta meta) { super(meta); if (!(meta instanceof BookMeta)) { return; } BookMeta book = (BookMeta) meta; title = book.getTitle(); author = book.getAuthor(); if (book.hasPages()) { pages = new ArrayList<>(book instanceof GlowMetaBook ? ((GlowMetaBook) book).pages : book.getPages()); filterPages(); } if (hasGeneration()) { this.generation = book.getGeneration().ordinal(); } }
/** * @param is ItemStack that should be of type {@link Material#WRITTEN_BOOK} * @return Localized name of the generation or {@code null} if the item is not a written book */ public static String getBookGenerationName(ItemStack is) { if (is.getType() != Material.WRITTEN_BOOK) { return null; } BookMeta meta = (BookMeta) is.getItemMeta(); CustomBookMeta.Generation generation = null; if ((Utils.getMajorVersion() == 9 && Utils.getRevision() == 1) || Utils.getMajorVersion() == 8) { generation = CustomBookMeta.getGeneration(is); } else if (meta.getGeneration() != null) { generation = CustomBookMeta.Generation.valueOf(meta.getGeneration().toString()); } if (generation == null) { generation = CustomBookMeta.Generation.ORIGINAL; } for (BookGenerationName generationName : generationNames) { if (generation == generationName.getGeneration()) { return generationName.getLocalizedName(); } } return formatDefaultString(String.valueOf(generation)); }
@Override public void setGeneration(Generation generation) { if (generation == null) { this.generation = null; return; } this.generation = generation.ordinal(); }
@Override public Generation getGeneration() { if (generation == null) { return null; } return Generation.values()[generation]; }