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) {
|
if (!welcomeMessage.trim().isEmpty() && newBook != null && sendMessage) {
|
||||||
sendMessage = false;
|
sendMessage = false;
|
||||||
booksWithoutBorders.getServer().getScheduler().scheduleSyncDelayedTask(booksWithoutBorders,
|
booksWithoutBorders.getServer().getScheduler().scheduleSyncDelayedTask(booksWithoutBorders,
|
||||||
() -> player.sendMessage(welcomeMessage), 40L);
|
() -> new FormatBuilder(welcomeMessage).neutral(player), 40L);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return sendMessage;
|
return sendMessage;
|
||||||
|
@@ -4,13 +4,13 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
|||||||
import net.knarcraft.bookswithoutborders.config.Permission;
|
import net.knarcraft.bookswithoutborders.config.Permission;
|
||||||
import net.knarcraft.bookswithoutborders.config.translation.GiveMessage;
|
import net.knarcraft.bookswithoutborders.config.translation.GiveMessage;
|
||||||
import net.knarcraft.bookswithoutborders.config.translation.SignText;
|
import net.knarcraft.bookswithoutborders.config.translation.SignText;
|
||||||
|
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||||
import net.knarcraft.bookswithoutborders.encryption.EncryptionStyle;
|
import net.knarcraft.bookswithoutborders.encryption.EncryptionStyle;
|
||||||
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
||||||
import net.knarcraft.bookswithoutborders.state.SignType;
|
import net.knarcraft.bookswithoutborders.state.SignType;
|
||||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||||
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
||||||
import net.knarcraft.bookswithoutborders.utility.EncryptedBookUtil;
|
import net.knarcraft.bookswithoutborders.utility.EncryptedBookUtil;
|
||||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
|
||||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
@@ -94,31 +94,45 @@ public class SignEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
Material heldItemType = heldItem.getType();
|
Material heldItemType = heldItem.getType();
|
||||||
|
|
||||||
if (event.getClickedBlock() != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK &&
|
if (event.getClickedBlock() == null || (event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
||||||
(Tag.SIGNS.isTagged(event.getClickedBlock().getType()) ||
|
(!Tag.SIGNS.isTagged(event.getClickedBlock().getType()) &&
|
||||||
Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())))) {
|
!Tag.WALL_SIGNS.isTagged(event.getClickedBlock().getType())))) {
|
||||||
//The player right-clicked a sign
|
return;
|
||||||
Sign sign = (Sign) event.getClickedBlock().getState();
|
}
|
||||||
if (SignType.fromString(sign.getSide(Side.FRONT).getLine(0)) != SignType.BOOKS_WITHOUT_BORDERS) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setUseItemInHand(Event.Result.DENY);
|
//The player right-clicked a sign
|
||||||
event.setCancelled(true);
|
checkSign(event, (Sign) event.getClickedBlock().getState(), heldItemType, hand);
|
||||||
|
}
|
||||||
|
|
||||||
SignType signType = SignType.fromString(sign.getSide(Side.FRONT).getLine(1));
|
/**
|
||||||
if (signType == SignType.ENCRYPT) {
|
* Checks if the clicked sign is a BwB sign, and which action to take
|
||||||
encryptHeldBookUsingSign(sign, heldItemType, player, hand);
|
*
|
||||||
} else if (signType == SignType.DECRYPT) {
|
* @param event <p>The triggered interact event</p>
|
||||||
decryptHeldBookUsingSign(sign, heldItemType, player, hand);
|
* @param sign <p>The clicked sign</p>
|
||||||
} else if (signType == SignType.GIVE && getSignLine2Color(sign) == ChatColor.DARK_GREEN) {
|
* @param heldItemType <p>The type of the held item</p>
|
||||||
giveBook(sign, player);
|
* @param hand <p>The hand the held item is in</p>
|
||||||
} else {
|
*/
|
||||||
SignSide front = sign.getSide(Side.FRONT);
|
private void checkSign(@NotNull PlayerInteractEvent event, @NotNull Sign sign, @NotNull Material heldItemType,
|
||||||
new FormatBuilder(SignText.ERROR_SIGN_COMMAND_INVALID).replace("{action}", front.getLine(1)).
|
@NotNull EquipmentSlot hand) {
|
||||||
replace("{data}", front.getLine(2)).error(player);
|
Player player = event.getPlayer();
|
||||||
player.sendMessage(String.valueOf(getSignLine2Color(sign)));
|
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,
|
private void decryptHeldBookUsingSign(@NotNull Sign sign, @NotNull Material heldItemType, @NotNull Player player,
|
||||||
@NotNull EquipmentSlot hand) {
|
@NotNull EquipmentSlot hand) {
|
||||||
//Decrypt the held book and replace it
|
//Decrypt the held book and replace it
|
||||||
if (heldItemType == Material.WRITTEN_BOOK) {
|
if (heldItemType != Material.WRITTEN_BOOK) {
|
||||||
player.closeInventory();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//Converts user supplied key into integer form
|
player.closeInventory();
|
||||||
String lineText = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
|
||||||
String key = EncryptionUtil.getNumberKeyFromStringKey(lineText);
|
|
||||||
|
|
||||||
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, key, false, false);
|
//Converts user supplied key into integer form
|
||||||
if (book == null) {
|
String lineText = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||||
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, key, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (book != null) {
|
|
||||||
player.getInventory().setItem(hand, book);
|
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, lineText, false, false);
|
||||||
player.sendMessage(ChatColor.GREEN + "Book decrypted!");
|
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