Skip to content

Commit

Permalink
Book Performance
Browse files Browse the repository at this point in the history
Get itemMeta is a heavy method to use. Reduce the amount it is used for performance.
  • Loading branch information
TrueDarkLord committed Mar 23, 2024
1 parent 29a3f1b commit 7c86631
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ public boolean hasEnchantment(ItemMeta meta, CEnchantment enchantment) {
* @return If the book is a CEBook it will return the CEBook object and if not it will return null.
*/
public CEBook getCEBook(ItemStack book) {
if (!book.hasItemMeta() || !book.getItemMeta().getPersistentDataContainer().has(DataKeys.stored_enchantments.getNamespacedKey())) return null;
if (!book.hasItemMeta()) return null;
ItemMeta meta = book.getItemMeta();
if (!meta.getPersistentDataContainer().has(DataKeys.stored_enchantments.getNamespacedKey())) return null;

EnchantedBook data = this.gson.fromJson(book.getItemMeta().getPersistentDataContainer().get(DataKeys.stored_enchantments.getNamespacedKey(), PersistentDataType.STRING), EnchantedBook.class);
EnchantedBook data = this.gson.fromJson(meta.getPersistentDataContainer().get(DataKeys.stored_enchantments.getNamespacedKey(), PersistentDataType.STRING), EnchantedBook.class);

CEnchantment enchantment = null;
for (CEnchantment enchant : getRegisteredEnchantments()) {
Expand Down

0 comments on commit 7c86631

Please sign in to comment.