From 931be7a61b1058e60a11c8f4eae11d1d0943bc71 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 2 Sep 2021 21:41:37 +0200 Subject: [PATCH] Describes the give sign in the README and fixes some bugs regarding the give sign --- README.md | 14 ++++++++++++- .../listener/SignEventListener.java | 21 ++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index ac03e37..961cb85 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,16 @@ Books without Borders has got your back! * Give first time players a single book or a set of books when they join * Configurable option to require certain items or pay via Vault compatible economy to create books via command * Add lore to any item with a simple command -* Supports adding and saving color to title, lore, and book contents \ No newline at end of file +* Supports adding and saving color to title, lore, and book contents + +### Signs + +This plugin supports several custom signs with special functionality. +Each plugin sign must have [BwB] on its first line. + +#### Give sign + +The **_give_** sign must have **[Give]** on its second line. +The third and fourth line contains the book to be loaded. +This can either be a numerical id pointing to a publicly saved book, +or the full text identifier of the book (book name, author). \ No newline at end of file diff --git a/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java b/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java index cb25a5a..3b7b667 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java @@ -58,16 +58,15 @@ public class SignEventListener implements Listener { //Mark the second line as valid event.setLine(1, ChatColor.DARK_BLUE + lines[1]); + lines = event.getLines(); //Mark valid encryption/decryption sign if (lines[1].equalsIgnoreCase(ChatColor.DARK_BLUE + "[Encrypt]") || lines[1].equalsIgnoreCase(ChatColor.DARK_BLUE + "[Decrypt]")) { event.setLine(2, ChatColor.MAGIC + lines[2]); event.setLine(3, ChatColor.DARK_BLUE + lines[3]); - } - - //Generate book giving sign - if (lines[1].equalsIgnoreCase(ChatColor.DARK_BLUE + "[Give]")) { + } else if (lines[1].equalsIgnoreCase(ChatColor.DARK_BLUE + "[Give]")) { + //Generate book giving sign generateGiveSign(event, lines, player); } } @@ -92,8 +91,7 @@ public class SignEventListener implements Listener { Tag.WALL_SIGNS.isTagged(clickedBlockType))) { //The player right-clicked a sign Sign sign = (Sign) event.getClickedBlock().getState(); - if (signLineEquals(sign, 0, "[BooksWithoutBorders]", ChatColor.DARK_GREEN)) { - + if (signLineEquals(sign, 0, "[BwB]", ChatColor.DARK_GREEN)) { if (signLineEquals(sign, 1, "[Encrypt]", ChatColor.DARK_BLUE)) { encryptHeldBookUsingSign(sign, heldItemType, player, hand); } else if (signLineEquals(sign, 1, "[Decrypt]", ChatColor.DARK_BLUE)) { @@ -101,6 +99,9 @@ public class SignEventListener implements Listener { } else if (signLineEquals(sign, 1, "[Give]", ChatColor.DARK_BLUE) && getSignLineColor(sign, 2) == ChatColor.DARK_GREEN) { giveBook(sign, player); + } else { + player.sendMessage("Sign command " + sign.getLine(1) + " " + sign.getLine(2) + " invalid"); + player.sendMessage(String.valueOf(getSignLineColor(sign, 2))); } } } else if (heldItemType == Material.WRITTEN_BOOK && (event.getAction() == Action.LEFT_CLICK_AIR @@ -147,7 +148,12 @@ public class SignEventListener implements Listener { * @return

The color of the sign

*/ private ChatColor getSignLineColor(Sign sign, int lineNumber) { - return ChatColor.getByChar(sign.getLine(lineNumber).substring(0, 2)); + String line = sign.getLine(lineNumber); + if (!ChatColor.stripColor(line).equals(line)) { + return ChatColor.getByChar(sign.getLine(lineNumber).substring(1, 2)); + } else { + return null; + } } /** @@ -182,6 +188,7 @@ public class SignEventListener implements Listener { String signFile = getBookFolder() + lines[2] + lines[3]; if (FileHelper.bookFileExists(signFile)) { markGiveSignValidity(event, true); + return; } else { if (isBookListIndex(lines[2])) { List availableFiles = FileHelper.listFiles(player, true, true);