Fixes sign decryption using the wrong key
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
This commit is contained in:
@@ -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;
|
||||
|
@@ -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,31 +94,45 @@ 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())))) {
|
||||
//The player right-clicked a sign
|
||||
Sign sign = (Sign) event.getClickedBlock().getState();
|
||||
if (SignType.fromString(sign.getSide(Side.FRONT).getLine(0)) != SignType.BOOKS_WITHOUT_BORDERS) {
|
||||
return;
|
||||
}
|
||||
if (event.getClickedBlock() == null || (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
||||
(!Tag.SIGNS.isTagged(event.getClickedBlock().getType()) &&
|
||||
!Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())))) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
//The player right-clicked a sign
|
||||
checkSign(event, (Sign) event.getClickedBlock().getState(), heldItemType, hand);
|
||||
}
|
||||
|
||||
SignType signType = SignType.fromString(sign.getSide(Side.FRONT).getLine(1));
|
||||
if (signType == SignType.ENCRYPT) {
|
||||
encryptHeldBookUsingSign(sign, heldItemType, player, hand);
|
||||
} else if (signType == SignType.DECRYPT) {
|
||||
decryptHeldBookUsingSign(sign, heldItemType, player, hand);
|
||||
} else if (signType == SignType.GIVE && getSignLine2Color(sign) == ChatColor.DARK_GREEN) {
|
||||
giveBook(sign, player);
|
||||
} else {
|
||||
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)));
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
|
||||
SignType signType = SignType.fromString(sign.getSide(Side.FRONT).getLine(1));
|
||||
if (signType == SignType.ENCRYPT) {
|
||||
encryptHeldBookUsingSign(sign, heldItemType, player, hand);
|
||||
} else if (signType == SignType.DECRYPT) {
|
||||
decryptHeldBookUsingSign(sign, heldItemType, player, hand);
|
||||
} else if (signType == SignType.GIVE && getSignLine2Color(sign) == ChatColor.DARK_GREEN) {
|
||||
giveBook(sign, player);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
player.closeInventory();
|
||||
if (heldItemType != Material.WRITTEN_BOOK) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Converts user supplied key into integer form
|
||||
String lineText = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||
String key = EncryptionUtil.getNumberKeyFromStringKey(lineText);
|
||||
player.closeInventory();
|
||||
|
||||
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, key, false, false);
|
||||
if (book == null) {
|
||||
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, key, false);
|
||||
}
|
||||
//Converts user supplied key into integer form
|
||||
String lineText = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||
|
||||
if (book != null) {
|
||||
player.getInventory().setItem(hand, book);
|
||||
player.sendMessage(ChatColor.GREEN + "Book decrypted!");
|
||||
}
|
||||
|
||||
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, lineText, false, false);
|
||||
if (book == null) {
|
||||
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, lineText, false);
|
||||
}
|
||||
|
||||
if (book != null) {
|
||||
player.getInventory().setItem(hand, book);
|
||||
new FormatBuilder(Translatable.SUCCESS_DECRYPTED).success(player);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user