diff --git a/README.md b/README.md index 387c8cb..8dda65e 100644 --- a/README.md +++ b/README.md @@ -139,4 +139,4 @@ The **_decrypt_** sign must have **\[Decrypt]** on its second line. The third li | Author_Only_Save | Whether to only allow saving a player's own books with /savebook | | Format_Book_After_Signing | Whether to automatically format every book when it's signed | | Change_Generation_On_Copy | Whether to display "COPY" or "COPY_OF_COPY" instead of "ORIGINAL" when a book is copied. This also uses the vanilla behavior where a copy of a copy or tattered book cannot be copied further. | -| Enable_Book_Peeking | Whether to enable hitting a chiseled bookshelf to see the shelf's contents. Sneaking is required to destroy a bookshelf if this is enabled. | \ No newline at end of file +| Enable_Book_Peeking | Whether to enable hitting a chiseled bookshelf while sneaking to see the shelf's contents. | \ No newline at end of file diff --git a/src/main/java/net/knarcraft/bookswithoutborders/listener/BookshelfListener.java b/src/main/java/net/knarcraft/bookswithoutborders/listener/BookshelfListener.java index f14c2c0..ecb1d7f 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/listener/BookshelfListener.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/listener/BookshelfListener.java @@ -32,9 +32,9 @@ public class BookshelfListener implements Listener { public void onBookshelfClick(PlayerInteractEvent event) { Player player = event.getPlayer(); - // If left-clicking a chiseled bookshelf and not sneaking, display contents + // If left-clicking a chiseled bookshelf and sneaking, display contents if (!event.hasBlock() || !(event.getClickedBlock().getState() instanceof ChiseledBookshelf chiseledBookshelf) || - event.getAction() != Action.LEFT_CLICK_BLOCK || player.isSneaking()) { + event.getAction() != Action.LEFT_CLICK_BLOCK || !player.isSneaking()) { return; } @@ -69,11 +69,27 @@ public class BookshelfListener implements Listener { builder.append(getBookDescription(bookMeta)); } else if (meta instanceof EnchantmentStorageMeta enchantmentStorageMeta) { builder.append(getEnchantedBookDescription(enchantmentStorageMeta)); + } else if (meta != null) { + builder.append(getPlainBookDescription(meta)); } } return builder.toString(); } + /** + * Gets the description of a plain (enchant-able) book + * + * @param itemMeta
The metadata for the book to describe
+ * @returnThe description of the book
+ */ + private String getPlainBookDescription(ItemMeta itemMeta) { + String name = itemMeta.getDisplayName(); + if (name.isEmpty()) { + name = "Plain book"; + } + return name; + } + /** * Gets the description of a book * diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f8c8f4c..355b248 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -30,6 +30,5 @@ Options: # Whether to display "COPY" or "COPY_OF_COPY" instead of "ORIGINAL" when a book is copied. This also uses the # vanilla behavior where a copy of a copy cannot be copied further. Change_Generation_On_Copy: false - # Whether to enable hitting a chiseled bookshelf to see the shelf's contents. Sneaking is required to destroy a - # bookshelf if this is enabled. + # Whether to enable hitting a chiseled bookshelf while sneaking to see the shelf's contents. Enable_Book_Peeking: false \ No newline at end of file