Fixes sign decryption using the wrong key
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good

This commit is contained in:
2025-08-27 14:21:37 +02:00
parent 2bb676758d
commit 4fc201276f
2 changed files with 54 additions and 38 deletions

View File

@@ -70,7 +70,7 @@ public class PlayerEventListener implements Listener {
if (!welcomeMessage.trim().isEmpty() && newBook != null && sendMessage) {
sendMessage = false;
booksWithoutBorders.getServer().getScheduler().scheduleSyncDelayedTask(booksWithoutBorders,
() -> player.sendMessage(welcomeMessage), 40L);
() -> new FormatBuilder(welcomeMessage).neutral(player), 40L);
}
}
return sendMessage;

View File

@@ -4,13 +4,13 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.Permission;
import net.knarcraft.bookswithoutborders.config.translation.GiveMessage;
import net.knarcraft.bookswithoutborders.config.translation.SignText;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.encryption.EncryptionStyle;
import net.knarcraft.bookswithoutborders.state.BookDirectory;
import net.knarcraft.bookswithoutborders.state.SignType;
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
import net.knarcraft.bookswithoutborders.utility.EncryptedBookUtil;
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
import net.knarcraft.knarlib.formatting.FormatBuilder;
import net.md_5.bungee.api.ChatColor;
@@ -94,11 +94,27 @@ public class SignEventListener implements Listener {
}
Material heldItemType = heldItem.getType();
if (event.getClickedBlock() != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK &&
(Tag.SIGNS.isTagged(event.getClickedBlock().getType()) ||
Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())))) {
if (event.getClickedBlock() == null || (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
(!Tag.SIGNS.isTagged(event.getClickedBlock().getType()) &&
!Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())))) {
return;
}
//The player right-clicked a sign
Sign sign = (Sign) event.getClickedBlock().getState();
checkSign(event, (Sign) event.getClickedBlock().getState(), heldItemType, hand);
}
/**
* Checks if the clicked sign is a BwB sign, and which action to take
*
* @param event <p>The triggered interact event</p>
* @param sign <p>The clicked sign</p>
* @param heldItemType <p>The type of the held item</p>
* @param hand <p>The hand the held item is in</p>
*/
private void checkSign(@NotNull PlayerInteractEvent event, @NotNull Sign sign, @NotNull Material heldItemType,
@NotNull EquipmentSlot hand) {
Player player = event.getPlayer();
if (SignType.fromString(sign.getSide(Side.FRONT).getLine(0)) != SignType.BOOKS_WITHOUT_BORDERS) {
return;
}
@@ -117,8 +133,6 @@ public class SignEventListener implements Listener {
SignSide front = sign.getSide(Side.FRONT);
new FormatBuilder(SignText.ERROR_SIGN_COMMAND_INVALID).replace("{action}", front.getLine(1)).
replace("{data}", front.getLine(2)).error(player);
player.sendMessage(String.valueOf(getSignLine2Color(sign)));
}
}
}
@@ -133,22 +147,24 @@ public class SignEventListener implements Listener {
private void decryptHeldBookUsingSign(@NotNull Sign sign, @NotNull Material heldItemType, @NotNull Player player,
@NotNull EquipmentSlot hand) {
//Decrypt the held book and replace it
if (heldItemType == Material.WRITTEN_BOOK) {
if (heldItemType != Material.WRITTEN_BOOK) {
return;
}
player.closeInventory();
//Converts user supplied key into integer form
String lineText = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
String key = EncryptionUtil.getNumberKeyFromStringKey(lineText);
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, key, false, false);
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, lineText, false, false);
if (book == null) {
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, key, false);
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, lineText, false);
}
if (book != null) {
player.getInventory().setItem(hand, book);
player.sendMessage(ChatColor.GREEN + "Book decrypted!");
}
new FormatBuilder(Translatable.SUCCESS_DECRYPTED).success(player);
}
}