diff --git a/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java b/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java index f72c242..6b390bb 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java @@ -74,6 +74,7 @@ public class BooksWithoutBorders extends JavaPlugin { * * @return
The console's console sender
*/ + @NotNull public static ConsoleCommandSender getConsoleSender() { return consoleSender; } @@ -85,7 +86,8 @@ public class BooksWithoutBorders extends JavaPlugin { * @param getPublicWhether to get available public books
* @returnA list of available books
*/ - public static ListAn instance of this plugin
*/ + @NotNull public static BooksWithoutBorders getInstance() { return booksWithoutBorders; } @@ -229,7 +232,7 @@ public class BooksWithoutBorders extends JavaPlugin { * @param commandNameThe name of the command to register
* @param executorThe executor to register for the command
*/ - private void registerCommand(String commandName, CommandExecutor executor) { + private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor) { PluginCommand pluginCommand = this.getCommand(commandName); if (pluginCommand != null) { pluginCommand.setExecutor(executor); @@ -270,6 +273,7 @@ public class BooksWithoutBorders extends JavaPlugin { * * @returnThe server's item factory
*/ + @NotNull public static ItemFactory getItemFactory() { return itemFactory; } @@ -313,7 +317,7 @@ public class BooksWithoutBorders extends JavaPlugin { * @param senderThe sender to send the message to
* @param messageThe message to send
*/ - public static void sendSuccessMessage(CommandSender sender, String message) { + public static void sendSuccessMessage(@NotNull CommandSender sender, @NotNull String message) { sender.sendMessage(getSuccessColor() + message); } @@ -323,7 +327,7 @@ public class BooksWithoutBorders extends JavaPlugin { * @param senderThe sender to send the message to
* @param messageThe message to send
*/ - public static void sendErrorMessage(CommandSender sender, String message) { + public static void sendErrorMessage(@NotNull CommandSender sender, @NotNull String message) { sender.sendMessage(getErrorColor() + message); } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandBooksWithoutBorders.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandBooksWithoutBorders.java index 50cde66..24ccbc6 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandBooksWithoutBorders.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandBooksWithoutBorders.java @@ -24,7 +24,7 @@ import static net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig public class CommandBooksWithoutBorders implements TabExecutor { @Override - public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { sender.sendMessage(getCommandColor() + "[] denote optional parameters"); sender.sendMessage(getCommandColor() + "<> denote required parameters"); sender.sendMessage(getCommandColor() + "{} denote required permission"); @@ -42,7 +42,7 @@ public class CommandBooksWithoutBorders implements TabExecutor { * * @param senderThe console which sent the command
*/ - private void showConsoleCommands(CommandSender sender) { + private void showConsoleCommands(@NotNull CommandSender sender) { sender.sendMessage(getCommandColor() + "Commands:"); showCommandInfo("deletePublicBook", sender); showCommandInfo("givePublicBook", sender); @@ -54,7 +54,7 @@ public class CommandBooksWithoutBorders implements TabExecutor { * * @param senderThe player which sent the command
*/ - private void showPlayerCommands(CommandSender sender) { + private void showPlayerCommands(@NotNull CommandSender sender) { //Lists all commands Material bookPriceType = BooksWithoutBordersConfig.getBookPriceType(); double bookPriceQuantity = BooksWithoutBordersConfig.getBookPriceQuantity(); @@ -97,7 +97,7 @@ public class CommandBooksWithoutBorders implements TabExecutor { * @param commandThe command to get information about
* @param senderThe sender asking to see command info
*/ - private void showCommandInfo(String command, CommandSender sender) { + private void showCommandInfo(@NotNull String command, @NotNull CommandSender sender) { PluginCommand pluginCommand = BooksWithoutBorders.getInstance().getCommand(command); if (pluginCommand != null) { String permission = pluginCommand.getPermission(); @@ -116,7 +116,8 @@ public class CommandBooksWithoutBorders implements TabExecutor { } @Override - public ListThe book to be copied
* @returnTrue if the copying was successful
*/ - private boolean performCopy(int copies, Player player, ItemStack heldBook) { + private boolean performCopy(int copies, @NotNull Player player, @NotNull ItemStack heldBook) { //Make sure the player owns the book if authorOnlyCopy is enabled if (BooksWithoutBordersConfig.getAuthorOnlyCopy() && !player.hasPermission("bookswithoutborders.bypassAuthorOnlyCopy")) { @@ -95,7 +96,7 @@ public class CommandCopy implements TabExecutor { * @param copiesThe number of copies to create for the player
* @returnTrue if the payment failed
*/ - private boolean paymentUnSuccessful(Player player, int copies) { + private boolean paymentUnSuccessful(@NotNull Player player, int copies) { return BooksWithoutBordersConfig.booksHavePrice() && !player.hasPermission("bookswithoutborders.bypassBookPrice") && EconomyHelper.cannotPayForBookPrinting(player, copies); @@ -109,7 +110,7 @@ public class CommandCopy implements TabExecutor { * @param copiesThe number of copies requested
* @returnTrue if the book was successfully copied
*/ - private boolean copyNextGenerationBook(BookMeta bookMeta, Player player, int copies) { + private boolean copyNextGenerationBook(@NotNull BookMeta bookMeta, @NotNull Player player, int copies) { //Copy the vanilla behavior of refusing copying any further if (bookMeta.getGeneration() == BookMeta.Generation.COPY_OF_COPY || bookMeta.getGeneration() == BookMeta.Generation.TATTERED) { @@ -140,10 +141,10 @@ public class CommandCopy implements TabExecutor { @Override public ListWhether to delete a public book
* @returnTrue if the book was deleted successfully
*/ - boolean deleteBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean deletePublic) { + protected boolean deleteBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean deletePublic) { String command = deletePublic ? "deletepublicbook" : "deletebook"; if (PagedBookIndex.displayPage(arguments, sender, deletePublic, command)) { return true; @@ -69,7 +70,7 @@ public class CommandDelete implements TabExecutor { * @param fileNameThe file name of the book
* @param isPublicWhether the book to delete is public or not
*/ - public void performBookDeletion(CommandSender sender, String fileName, Boolean isPublic) { + public void performBookDeletion(@NotNull CommandSender sender, @NotNull String fileName, @NotNull Boolean isPublic) { //If the file name is an index of the load list, load the book try { int loadListIndex = Integer.parseInt(fileName); @@ -104,8 +105,9 @@ public class CommandDelete implements TabExecutor { } @Override - public ListWhether to delete a public book
* @returnA list of available arguments
*/ - protected ListThe sender trying to encrypt a book
- * @param argsThe arguments given
+ * @param argumentsThe arguments given
* @param necessaryArgumentsHow many arguments is the minimum requirement
* @param missingArgumentsErrorThe error to show if a required argument is missing
* @returnThe metadata of the book to encrypt, or null if any checks fail
*/ - BookMeta performPreChecks(CommandSender sender, String[] args, int necessaryArguments, String missingArgumentsError) { + @Nullable + protected BookMeta performPreChecks(@NotNull CommandSender sender, @NotNull String[] arguments, + int necessaryArguments, @NotNull String missingArgumentsError) { if (!(sender instanceof Player player)) { BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!"); return null; @@ -53,7 +57,7 @@ public class CommandEncrypt implements TabExecutor { return null; } - int argumentCount = args.length; + int argumentCount = arguments.length; if (argumentCount < necessaryArguments) { BooksWithoutBorders.sendErrorMessage(player, missingArgumentsError); return null; @@ -85,7 +89,8 @@ public class CommandEncrypt implements TabExecutor { * @param groupThe group to encrypt for
* @returnTrue if the book was encrypted successfully
*/ - boolean encryptBook(EncryptionStyle encryptionStyle, Player player, String key, String group) { + protected boolean encryptBook(@NotNull EncryptionStyle encryptionStyle, @NotNull Player player, @NotNull String key, + @NotNull String group) { ItemSlot heldSlot = InventoryHelper.getHeldSlotBook(player, false, false, true, true); ItemStack encryptedBook = EncryptionHelper.encryptBook(player, heldSlot == ItemSlot.MAIN_HAND, key, encryptionStyle, group); @@ -98,8 +103,10 @@ public class CommandEncrypt implements TabExecutor { } @Override - public ListWhether to auto-complete for group encryption
* @returnThe strings to auto-complete
*/ - protected ListThe folder containing the book to load
* @returnTrue if the book was given successfully
*/ - boolean giveBook(@NotNull CommandSender sender, String[] arguments, boolean givePublic, String folder) { + boolean giveBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean givePublic, + @NotNull String folder) { String command = givePublic ? "givepublicbook" : "givebook"; if (PagedBookIndex.displayPage(arguments, sender, givePublic, command)) { return true; @@ -100,8 +103,9 @@ public class CommandGive implements TabExecutor { } @Override - public ListWhether to list public files or player files
* @returnA list of available choices
*/ - protected ListThe number of copies the player wants to give
* @returnTrue if the book was successfully given
*/ - private boolean loadAndGiveBook(String bookIdentifier, CommandSender sender, Player receivingPlayer, - String isSigned, String folder, String copies) throws NumberFormatException { + private boolean loadAndGiveBook(@NotNull String bookIdentifier, @NotNull CommandSender sender, + @NotNull Player receivingPlayer, @NotNull String isSigned, @NotNull String folder, + @NotNull String copies) throws NumberFormatException { String bookToLoad = InputCleaningHelper.cleanString(bookIdentifier); ItemStack newBook = BookLoader.loadBook(sender, bookToLoad, isSigned, folder, Integer.parseInt(copies)); if (newBook != null) { diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGivePublic.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGivePublic.java index 5e48dff..0eaff68 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGivePublic.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandGivePublic.java @@ -4,6 +4,7 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; @@ -13,13 +14,16 @@ import java.util.List; public class CommandGivePublic extends CommandGive implements TabExecutor { @Override - public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] arguments) { + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, + @NotNull String[] arguments) { return giveBook(sender, arguments, true, "public"); } @Override - public ListThe sender of the command
- * @param argsThe arguments given
+ * @param argumentsThe arguments given
* @param loadPublicWhether to list public files or player files
* @returnA list of available choices
*/ - protected ListThe sender of the command
- * @param argsThe arguments given
+ * @param argumentsThe arguments given
* @param savePublicWhether to save the book in the public directory or the player directory
* @returnTrue if a book was saved successfully
*/ - boolean saveHeldBook(CommandSender sender, String[] args, boolean savePublic) { + boolean saveHeldBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean savePublic) { if (!(sender instanceof Player player)) { BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!"); return false; @@ -54,7 +54,7 @@ public class CommandSave implements TabExecutor { ItemSlot holdingSlot = InventoryHelper.getHeldSlotBook(player, false, false, false, false); if (holdingSlot != ItemSlot.NONE) { ItemStack holdingItem = InventoryHelper.getHeldItem(player, holdingSlot == ItemSlot.MAIN_HAND); - boolean duplicate = args.length == 1 && Boolean.parseBoolean(args[0]); + boolean duplicate = arguments.length == 1 && Boolean.parseBoolean(arguments[0]); saveBook(player, holdingItem, duplicate, savePublic); return true; } else { @@ -71,7 +71,7 @@ public class CommandSave implements TabExecutor { * @param overwriteWhether to overwrite any existing books
* @param saveToPublicFolderWhether to save the book to the public folder instead of the player folder
*/ - public void saveBook(Player player, ItemStack heldBook, boolean overwrite, boolean saveToPublicFolder) { + public void saveBook(@NotNull Player player, @NotNull ItemStack heldBook, boolean overwrite, boolean saveToPublicFolder) { BookMeta book = (BookMeta) heldBook.getItemMeta(); if (book == null) { BooksWithoutBorders.sendErrorMessage(player, "Unable to get metadata for your held book!"); @@ -156,8 +156,9 @@ public class CommandSave implements TabExecutor { } @Override + @NotNull public ListThe sender of the command
*/ - private void clearItemPrice(CommandSender sender) { + private void clearItemPrice(@NotNull CommandSender sender) { BooksWithoutBordersConfig.setBookPriceType(null); BooksWithoutBordersConfig.setBookPriceQuantity(0); booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", "Item type name"); @@ -85,7 +86,7 @@ public class CommandSetBookPrice implements TabExecutor { * @param priceThe new price
* @returnTrue if the price was changed successfully
*/ - private boolean setItemPrice(CommandSender sender, double price) { + private boolean setItemPrice(@NotNull CommandSender sender, double price) { if (!(sender instanceof Player player)) { BooksWithoutBorders.sendErrorMessage(sender, "[Item] price can only be used by a player!"); return false; @@ -117,7 +118,7 @@ public class CommandSetBookPrice implements TabExecutor { * @param priceThe new price
* @returnTrue if the price was changed successfully
*/ - private boolean setEconomyPrice(CommandSender sender, double price) { + private boolean setEconomyPrice(@NotNull CommandSender sender, double price) { if (EconomyHelper.setupEconomy()) { BooksWithoutBordersConfig.setBookPriceQuantity(price); BooksWithoutBordersConfig.setBookPriceType(Material.AIR); @@ -136,16 +137,17 @@ public class CommandSetBookPrice implements TabExecutor { } @Override - public ListThe books without borders object used for getting required data
*/ - public static void initialize(BooksWithoutBorders booksWithoutBorders) { + public static void initialize(@NotNull BooksWithoutBorders booksWithoutBorders) { if (isInitialized) { throw new IllegalArgumentException("Settings class initialized twice. This should not happen!"); } @@ -388,7 +389,7 @@ public class BooksWithoutBordersConfig { * @param configOptionThe configuration option to get the value for
* @returnThe value of the option
*/ - private static String getString(Configuration config, ConfigOption configOption) { + private static String getString(@NotNull Configuration config, @NotNull ConfigOption configOption) { return config.getString(configOption.getConfigNode(), (String) configOption.getDefaultValue()); } @@ -399,7 +400,7 @@ public class BooksWithoutBordersConfig { * @param configOptionThe configuration option to get the value for
* @returnThe value of the option
*/ - private static boolean getBoolean(Configuration config, ConfigOption configOption) { + private static boolean getBoolean(@NotNull Configuration config, @NotNull ConfigOption configOption) { return config.getBoolean(configOption.getConfigNode(), (Boolean) configOption.getDefaultValue()); } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java b/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java index 554990f..c72e6d6 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/config/ConfigOption.java @@ -1,5 +1,7 @@ package net.knarcraft.bookswithoutborders.config; +import org.jetbrains.annotations.NotNull; + /** * A representation of the different available config options */ @@ -90,7 +92,7 @@ public enum ConfigOption { * @param configNodeThe config node in the config file this option represents
* @param defaultValueThe default value for this config option
*/ - ConfigOption(String configNode, Object defaultValue) { + ConfigOption(@NotNull String configNode, @NotNull Object defaultValue) { this.configNode = configNode; this.defaultValue = defaultValue; } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/encryption/AES.java b/src/main/java/net/knarcraft/bookswithoutborders/encryption/AES.java index 6b3e484..e96ca74 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/encryption/AES.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/encryption/AES.java @@ -1,6 +1,8 @@ package net.knarcraft.bookswithoutborders.encryption; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; @@ -52,7 +54,8 @@ public class AES { * @param encryptWhether to encrypt or decrypt the input
* @returnThe encrypted/decrypted input, or null if anything went wrong
*/ - public String encryptDecryptText(String input, String password, boolean encrypt) { + @Nullable + public String encryptDecryptText(@NotNull String input, @NotNull String password, boolean encrypt) { //Make a key from the password SecretKeySpec secretKeySpec = getKeyFromPassword(password); //Get cipher instance @@ -102,7 +105,7 @@ public class AES { * @param encryptionWhether the input should be encrypted or decrypted
* @returnThe input in byte format
*/ - private byte[] getInputBytes(String input, boolean encryption) { + private byte[] getInputBytes(@NotNull String input, boolean encryption) { if (encryption) { return input.getBytes(); } else { @@ -117,6 +120,7 @@ public class AES { * @param encryptionWhether the output came from encryption or decryption
* @returnThe output as a string
*/ + @NotNull private String createResult(byte[] output, boolean encryption) { if (encryption) { return Base64.getEncoder().encodeToString(output); @@ -130,6 +134,7 @@ public class AES { * * @returnAn AES cipher instance, or null if something went wrong
*/ + @Nullable private Cipher getAESCipher() { Cipher aes; try { @@ -147,7 +152,8 @@ public class AES { * @param passwordA user supplied password
* @returnA secret key spec or null if something went wrong
*/ - private SecretKeySpec getKeyFromPassword(String password) { + @Nullable + private SecretKeySpec getKeyFromPassword(@NotNull String password) { PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), this.passwordSalt, 1000, 128); SecretKeyFactory keyFactory; try { diff --git a/src/main/java/net/knarcraft/bookswithoutborders/encryption/GenenCrypt.java b/src/main/java/net/knarcraft/bookswithoutborders/encryption/GenenCrypt.java index cc79e21..522e29a 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/encryption/GenenCrypt.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/encryption/GenenCrypt.java @@ -1,5 +1,7 @@ package net.knarcraft.bookswithoutborders.encryption; +import org.jetbrains.annotations.NotNull; + import java.util.ArrayList; import java.util.HashMap; import java.util.Random; @@ -24,7 +26,7 @@ public class GenenCrypt { * * @param keyThe key used to generate the codon table
*/ - public GenenCrypt(String key) { + public GenenCrypt(@NotNull String key) { // define the initial, unshuffled codon list of 4 base codons ArrayListThe input to encrypt
* @returnThe encrypted input
*/ - public String encrypt(String input) { + @NotNull + public String encrypt(@NotNull String input) { StringBuilder output = new StringBuilder(); for (int i = 0; i < input.length(); i++) { // insert junk bases @@ -147,7 +150,8 @@ public class GenenCrypt { * @param inputThe input to decrypt
* @returnThe decrypted input
*/ - public String decrypt(String input) { + @NotNull + public String decrypt(@NotNull String input) { StringBuilder output = new StringBuilder(); int keyCount = 0; int junk = key.charAt(0); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java b/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java index a243b5d..c460161 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/encryption/SubstitutionCipher.java @@ -1,5 +1,7 @@ package net.knarcraft.bookswithoutborders.encryption; +import org.jetbrains.annotations.NotNull; + import java.math.BigInteger; import java.util.StringTokenizer; @@ -17,9 +19,10 @@ public class SubstitutionCipher { // using a string for the key, it is converted // a series of offsets that each character in the // original message is offset by - public String encrypt(String in, String key) { + @NotNull + public String encrypt(@NotNull String in, @NotNull String key) { StringBuilder output = new StringBuilder(); - if (key != null && !key.isEmpty()) { + if (!key.isEmpty()) { StringTokenizer tokenizer = new StringTokenizer(key, ", "); // tokenizes the key // converts each number in the key to an integer and adds to an array int[] offsetArray = new int[tokenizer.countTokens()]; @@ -53,9 +56,10 @@ public class SubstitutionCipher { // method with a flag for encryption / decryption, but // I'm lazy. @SuppressWarnings("unused") - public String decrypt(String in, String key) { + @NotNull + public String decrypt(@NotNull String in, @NotNull String key) { StringBuilder output = new StringBuilder(); - if (key != null && !key.isEmpty()) { + if (!key.isEmpty()) { StringTokenizer tokenizer = new StringTokenizer(key, ", "); // tokenizes the key // converts each number in the key to an integer and adds to an array int[] offsetArray = new int[tokenizer.countTokens()]; @@ -81,7 +85,8 @@ public class SubstitutionCipher { // encryption works just like decryption, but is // vulnerable if the same key is used more than once. @SuppressWarnings("unused") - public String oneTimePad(String in, String key) { + @NotNull + public String oneTimePad(@NotNull String in, @NotNull String key) { StringBuilder output = new StringBuilder(); for (int i = 0; i < in.length(); i++) { output.append((char) (in.charAt(i) ^ key.charAt(i % key.length()))); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java b/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java index 057a778..1daac01 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java @@ -53,6 +53,7 @@ public class AuthorBookIndex extends BookIndex { // Display the list of books, with the next and previous buttons displayPreviousButton(componentBuilder, command + " author" + authorName, page); + componentBuilder.append("\n"); displayBookList(componentBuilder, command, page, availableBooks); displayNextButton(componentBuilder, command + " author" + authorName, page, totalPages); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java b/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java index 2846d31..f87f6a2 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java @@ -83,6 +83,7 @@ public abstract class BookIndex { */ protected static void displayAlphabetIndex(@NotNull ComponentBuilder componentBuilder, @NotNull String command, @NotNull MapWhether to send a message to the joining player
* @returnTrue if a message has yet to be sent
*/ - private boolean giveBookToNewPlayer(String bookName, Player player, boolean sendMessage) { + private boolean giveBookToNewPlayer(@NotNull String bookName, @NotNull Player player, boolean sendMessage) { if (!bookName.trim().isEmpty()) { //Give the book to the player if it exists @@ -125,7 +131,7 @@ public class PlayerEventListener implements Listener { * @param itemMetadataInformation about the held book
* @param mainHandWhether to update the book in the player's main hand
*/ - private void updateBookInHand(Player player, ItemMeta itemMetadata, boolean mainHand) { + private void updateBookInHand(@NotNull Player player, @NotNull ItemMeta itemMetadata, boolean mainHand) { PlayerInventory playerInventory = player.getInventory(); ItemStack updatedBook = updateBook(player, (BookMeta) itemMetadata); if (updatedBook != null) { @@ -144,7 +150,8 @@ public class PlayerEventListener implements Listener { * @param oldBookMetadata about the held book
* @returnAn updated book
*/ - public ItemStack updateBook(Player player, BookMeta oldBook) { + @Nullable + public ItemStack updateBook(@NotNull Player player, @NotNull BookMeta oldBook) { //handles hacked title-less books if (oldBook.getTitle() == null || oldBook.getTitle().length() < 3) { return null; diff --git a/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java b/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java index 2777f49..9247998 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/listener/SignEventListener.java @@ -25,6 +25,8 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.meta.BookMeta; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.File; @@ -40,7 +42,7 @@ public class SignEventListener implements Listener { private final String slash = getSlash(); @EventHandler - public void onSignChange(SignChangeEvent event) { + public void onSignChange(@NotNull SignChangeEvent event) { if (event.isCancelled()) { return; } @@ -80,7 +82,7 @@ public class SignEventListener implements Listener { } @EventHandler - public void onClick(PlayerInteractEvent event) { + public void onClick(@NotNull PlayerInteractEvent event) { if (event.getClickedBlock() == null) { return; } @@ -139,7 +141,8 @@ public class SignEventListener implements Listener { * @param playerThe player which clicked the sign
* @param handThe EquipmentSlot of the used hand
*/ - private void decryptHeldBookUsingSign(Sign sign, Material heldItemType, Player player, EquipmentSlot hand) { + 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(); @@ -162,7 +165,8 @@ public class SignEventListener implements Listener { * @param signThe sign to check
* @returnThe color of the sign
*/ - private ChatColor getSignLine2Color(Sign sign) { + @Nullable + private ChatColor getSignLine2Color(@NotNull Sign sign) { String line = sign.getSide(Side.FRONT).getLine(2); if (!BookFormatter.stripColor(line).equals(line)) { return ChatColor.getByChar(sign.getSide(Side.FRONT).getLine(2).substring(1, 2).charAt(0)); @@ -180,7 +184,8 @@ public class SignEventListener implements Listener { * @param colorThe color to match
* @returnTrue if the given string is what's on the sign
*/ - private boolean signLineEquals(Sign sign, int lineNumber, String compareTo, ChatColor color) { + private boolean signLineEquals(@NotNull Sign sign, int lineNumber, @NotNull String compareTo, + @NotNull ChatColor color) { String line = sign.getSide(Side.FRONT).getLine(lineNumber); return line.equalsIgnoreCase(color + compareTo); } @@ -192,7 +197,8 @@ public class SignEventListener implements Listener { * @param linesThe lines on the sign
* @param playerThe player which edited the sign
*/ - private void generateGiveSign(SignChangeEvent event, String[] lines, Player player) { + private void generateGiveSign(@NotNull SignChangeEvent event, @NotNull String[] lines, + @NotNull Player player) { if (lines[2].length() > 13 || lines[3].length() > 13) { BooksWithoutBorders.sendErrorMessage(player, "[Give] signs' 3rd and 4th lines must be 13 characters or less!"); @@ -221,7 +227,7 @@ public class SignEventListener implements Listener { * @param eventThe event causing the creation of the give sign
* @param isValidWhether the created sign is valid
*/ - private void markGiveSignValidity(SignChangeEvent event, boolean isValid) { + private void markGiveSignValidity(@NotNull SignChangeEvent event, boolean isValid) { String[] lines = event.getLines(); if (isValid) { event.setLine(2, ChatColor.DARK_GREEN + lines[2]); @@ -240,7 +246,8 @@ public class SignEventListener implements Listener { * @param heldItemThe type of the held book
* @param handThe hand the player is using to hold the book
*/ - private void decryptBook(BookMeta oldBook, Player player, ItemStack heldItem, EquipmentSlot hand) { + private void decryptBook(@NotNull BookMeta oldBook, @NotNull Player player, @NotNull ItemStack heldItem, + @NotNull EquipmentSlot hand) { ItemStack newBook; //Check if the book is encrypted by Books Without Borders @@ -286,7 +293,8 @@ public class SignEventListener implements Listener { * @param playerThe player which clicked the sign
* @param handThe EquipmentSlot of the used hand
*/ - private void encryptHeldBookUsingSign(Sign sign, Material heldItemType, Player player, EquipmentSlot hand) { + private void encryptHeldBookUsingSign(@NotNull Sign sign, @NotNull Material heldItemType, @NotNull Player player, + @NotNull EquipmentSlot hand) { ItemStack eBook; String[] lines = sign.getSide(Side.FRONT).getLines(); boolean mainHand = hand == EquipmentSlot.HAND; @@ -306,7 +314,7 @@ public class SignEventListener implements Listener { * @param signThe sign the user clicked
* @param playerThe player which clicked the sign
*/ - private void giveBook(Sign sign, Player player) { + private void giveBook(@NotNull Sign sign, @NotNull Player player) { String fileName = BookFormatter.stripColor(sign.getSide(Side.FRONT).getLine(2)); boolean isLoadListNumber = false; diff --git a/src/main/java/net/knarcraft/bookswithoutborders/state/BookDirectory.java b/src/main/java/net/knarcraft/bookswithoutborders/state/BookDirectory.java index 1d1c1d6..d8cc6ea 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/state/BookDirectory.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/state/BookDirectory.java @@ -1,5 +1,8 @@ package net.knarcraft.bookswithoutborders.state; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + /** * This enum represents the different directories books can be saved in */ @@ -26,7 +29,8 @@ public enum BookDirectory { * @param directoryThe directory to transform
* @returnA book directory, or null if the given directory is empty
*/ - public static BookDirectory getFromString(String directory) { + @Nullable + public static BookDirectory getFromString(@NotNull String directory) { if (directory.equalsIgnoreCase("public")) { return BookDirectory.PUBLIC; } else if (directory.equalsIgnoreCase("player")) { diff --git a/src/main/java/net/knarcraft/bookswithoutborders/state/EncryptionStyle.java b/src/main/java/net/knarcraft/bookswithoutborders/state/EncryptionStyle.java index 9686c5a..f0bd495 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/state/EncryptionStyle.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/state/EncryptionStyle.java @@ -1,5 +1,7 @@ package net.knarcraft.bookswithoutborders.state; +import org.jetbrains.annotations.NotNull; + /** * This enum represents the different available encryption styles */ @@ -10,7 +12,7 @@ public enum EncryptionStyle { private final String name; - EncryptionStyle(String name) { + EncryptionStyle(@NotNull String name) { this.name = name; } @@ -20,7 +22,8 @@ public enum EncryptionStyle { * @param nameThe name of the encryption style
* @returnAn encryption style or null if no match is found
*/ - public static EncryptionStyle getFromString(String name) { + @NotNull + public static EncryptionStyle getFromString(@NotNull String name) { for (EncryptionStyle style : EncryptionStyle.values()) { if (style.name.equalsIgnoreCase(name)) { return style; diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java index 87f3bb9..5c218e4 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookFormatter.java @@ -25,7 +25,7 @@ public final class BookFormatter { * * @param rawPagesA list of pages
*/ - public static void formatLastPage(ListThe max number of characters which fit on a page
* @param fitsNewlineThe max number of characters on a page which still fits a newline character
*/ - public static void formatLastPageSplitOverflow(ListThe raw pages to format
* @param maxPageTextThe max number of characters which fit on a page
*/ - public static void formatLastPageCombinePages(ListThe raw pages to format
* @param fitsNewlineThe max number of characters on a page which still fits a newline character
*/ - public static void formatLastPageAddNewline(ListThe book meta to change
* @returnThe changed book meta
*/ - public static BookMeta formatPages(BookMeta bookMeta) { + @NotNull + public static BookMeta formatPages(@NotNull BookMeta bookMeta) { ListThe command sender trying to get the directory
* @returnThe path of the directory, or null if not possible to get
*/ + @Nullable public static File getBookDirectoryPath(@NotNull BookDirectory bookDirectory, @NotNull CommandSender sender) { String bookFolderString = getBookDirectoryPathString(bookDirectory, sender); if (bookFolderString == null) { diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java index f50cafb..39af228 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java @@ -53,6 +53,10 @@ public final class BookLoader { public static ItemStack loadBook(@NotNull CommandSender sender, @NotNull String fileName, @NotNull String isSigned, @NotNull String directory, int numCopies) { BookDirectory bookDirectory = BookDirectory.getFromString(directory); + if (bookDirectory == null) { + BooksWithoutBorders.sendErrorMessage(sender, "Unrecognized book directory!"); + return null; + } //Find the filename if a book index is given try { @@ -142,7 +146,9 @@ public final class BookLoader { * @param directoryThe relative directory given
* @returnA file or null if it does not exist
*/ - private static File getFullPath(CommandSender sender, String fileName, BookDirectory bookDirectory, String directory) { + @Nullable + private static File getFullPath(@NotNull CommandSender sender, @NotNull String fileName, + @NotNull BookDirectory bookDirectory, @NotNull String directory) { File file; String slash = BooksWithoutBordersConfig.getSlash(); String bookFolder = BooksWithoutBordersConfig.getBookFolder(); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/IntegerToRomanConverter.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/IntegerToRomanConverter.java index ad2a71c..4cdbb37 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/IntegerToRomanConverter.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/IntegerToRomanConverter.java @@ -86,6 +86,7 @@ public final class IntegerToRomanConverter { * @param timesThe number of times to repeat the character
* @returnThe repeated string
*/ + @NotNull private static String repeat(char character, int times) { return String.valueOf(character).repeat(Math.max(0, times)); } diff --git a/src/test/java/net/knarcraft/bookswithoutborders/encryption/AESTest.java b/src/test/java/net/knarcraft/bookswithoutborders/encryption/AESTest.java index 3340de7..3ff608f 100644 --- a/src/test/java/net/knarcraft/bookswithoutborders/encryption/AESTest.java +++ b/src/test/java/net/knarcraft/bookswithoutborders/encryption/AESTest.java @@ -3,6 +3,7 @@ package net.knarcraft.bookswithoutborders.encryption; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; public class AESTest { @@ -16,6 +17,7 @@ public class AESTest { String encrypted = aes.encryptDecryptText(plainText, password, true); assertNotSame(encrypted, plainText); + assertNotNull(encrypted); String decrypted = aes.encryptDecryptText(encrypted, password, false); assertEquals(plainText, decrypted); }