Fixes a lot of nullability issues
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:
@@ -74,6 +74,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
*
|
||||
* @return <p>The console's console sender</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static ConsoleCommandSender getConsoleSender() {
|
||||
return consoleSender;
|
||||
}
|
||||
@@ -85,7 +86,8 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
* @param getPublic <p>Whether to get available public books</p>
|
||||
* @return <p>A list of available books</p>
|
||||
*/
|
||||
public static List<String> getAvailableBooks(CommandSender sender, boolean getPublic) {
|
||||
@NotNull
|
||||
public static List<String> getAvailableBooks(@NotNull CommandSender sender, boolean getPublic) {
|
||||
if (getPublic) {
|
||||
return new ArrayList<>(publicBooksList);
|
||||
} else if (sender instanceof Player player) {
|
||||
@@ -191,6 +193,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
*
|
||||
* @return <p>An instance of this plugin</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static BooksWithoutBorders getInstance() {
|
||||
return booksWithoutBorders;
|
||||
}
|
||||
@@ -229,7 +232,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
* @param commandName <p>The name of the command to register</p>
|
||||
* @param executor <p>The executor to register for the command</p>
|
||||
*/
|
||||
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 {
|
||||
*
|
||||
* @return <p>The server's item factory</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static ItemFactory getItemFactory() {
|
||||
return itemFactory;
|
||||
}
|
||||
@@ -313,7 +317,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
* @param sender <p>The sender to send the message to</p>
|
||||
* @param message <p>The message to send</p>
|
||||
*/
|
||||
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 sender <p>The sender to send the message to</p>
|
||||
* @param message <p>The message to send</p>
|
||||
*/
|
||||
public static void sendErrorMessage(CommandSender sender, String message) {
|
||||
public static void sendErrorMessage(@NotNull CommandSender sender, @NotNull String message) {
|
||||
sender.sendMessage(getErrorColor() + message);
|
||||
}
|
||||
|
||||
|
@@ -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 sender <p>The console which sent the command</p>
|
||||
*/
|
||||
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 sender <p>The player which sent the command</p>
|
||||
*/
|
||||
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 command <p>The command to get information about</p>
|
||||
* @param sender <p>The sender asking to see command info</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,7 @@ public class CommandClear implements TabExecutor {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@@ -26,7 +26,8 @@ import java.util.Objects;
|
||||
public class CommandCopy implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull 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[] arguments) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
@@ -37,14 +38,14 @@ public class CommandCopy implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
if (arguments.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specify the number of copies to be made!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
int copies = Integer.parseInt(args[0]);
|
||||
int copies = Integer.parseInt(arguments[0]);
|
||||
if (copies <= 0) {
|
||||
throw new NumberFormatException("Number of copies must be larger than 0");
|
||||
}
|
||||
@@ -64,7 +65,7 @@ public class CommandCopy implements TabExecutor {
|
||||
* @param heldBook <p>The book to be copied</p>
|
||||
* @return <p>True if the copying was successful</p>
|
||||
*/
|
||||
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 copies <p>The number of copies to create for the player</p>
|
||||
* @return <p>True if the payment failed</p>
|
||||
*/
|
||||
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 copies <p>The number of copies requested</p>
|
||||
* @return <p>True if the book was successfully copied</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
int argumentCount = args.length;
|
||||
@NotNull String[] arguments) {
|
||||
int argumentCount = arguments.length;
|
||||
if (argumentCount == 1) {
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getNumbers(1, 20), args[0]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getNumbers(1, 20), arguments[0]);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@@ -99,8 +99,9 @@ public class CommandDecrypt implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
int argumentCount = args.length;
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
int argumentCount = arguments.length;
|
||||
if (argumentCount == 1) {
|
||||
List<String> info = new ArrayList<>();
|
||||
info.add("<password>");
|
||||
|
@@ -22,7 +22,8 @@ import java.util.List;
|
||||
public class CommandDelete implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] arguments) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(sender instanceof Player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
@@ -39,7 +40,7 @@ public class CommandDelete implements TabExecutor {
|
||||
* @param deletePublic <p>Whether to delete a public book</p>
|
||||
* @return <p>True if the book was deleted successfully</p>
|
||||
*/
|
||||
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 fileName <p>The file name of the book</p>
|
||||
* @param isPublic <p>Whether the book to delete is public or not</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
return doTabCompletion(sender, args, false);
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return doTabCompletion(sender, arguments, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,7 +118,8 @@ public class CommandDelete implements TabExecutor {
|
||||
* @param deletePublic <p>Whether to delete a public book</p>
|
||||
* @return <p>A list of available arguments</p>
|
||||
*/
|
||||
protected List<String> doTabCompletion(CommandSender sender, String[] args, boolean deletePublic) {
|
||||
@NotNull
|
||||
protected List<String> doTabCompletion(@NotNull CommandSender sender, @NotNull String[] args, boolean deletePublic) {
|
||||
int argumentCount = args.length;
|
||||
if (argumentCount == 1) {
|
||||
return TabCompletionHelper.filterMatchingContains(BooksWithoutBorders.getAvailableBooks(sender, deletePublic),
|
||||
|
@@ -18,8 +18,8 @@ public class CommandDeletePublic extends CommandDelete implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
return doTabCompletion(sender, args, true);
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] arguments) {
|
||||
return doTabCompletion(sender, arguments, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -23,25 +24,28 @@ import java.util.List;
|
||||
public class CommandEncrypt implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (performPreChecks(sender, args, 1, "You must specify a key to encrypt a book!") == null) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
if (performPreChecks(sender, arguments, 1, "You must specify a key to encrypt a book!") == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
EncryptionStyle encryptionStyle = args.length == 2 ? EncryptionStyle.getFromString(args[1]) : EncryptionStyle.SUBSTITUTION;
|
||||
return encryptBook(encryptionStyle, (Player) sender, args[0], "");
|
||||
EncryptionStyle encryptionStyle = arguments.length == 2 ? EncryptionStyle.getFromString(arguments[1]) : EncryptionStyle.SUBSTITUTION;
|
||||
return encryptBook(encryptionStyle, (Player) sender, arguments[0], "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs necessary pre-checks before going through with the encryption
|
||||
*
|
||||
* @param sender <p>The sender trying to encrypt a book</p>
|
||||
* @param args <p>The arguments given</p>
|
||||
* @param arguments <p>The arguments given</p>
|
||||
* @param necessaryArguments <p>How many arguments is the minimum requirement</p>
|
||||
* @param missingArgumentsError <p>The error to show if a required argument is missing</p>
|
||||
* @return <p>The metadata of the book to encrypt, or null if any checks fail</p>
|
||||
*/
|
||||
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 group <p>The group to encrypt for</p>
|
||||
* @return <p>True if the book was encrypted successfully</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
return doTabCompletion(args, false);
|
||||
@NotNull
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return doTabCompletion(arguments, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +116,8 @@ public class CommandEncrypt implements TabExecutor {
|
||||
* @param groupEncrypt <p>Whether to auto-complete for group encryption</p>
|
||||
* @return <p>The strings to auto-complete</p>
|
||||
*/
|
||||
protected List<String> doTabCompletion(String[] args, boolean groupEncrypt) {
|
||||
@NotNull
|
||||
protected List<String> doTabCompletion(@NotNull String[] args, boolean groupEncrypt) {
|
||||
int argumentsCount = args.length;
|
||||
|
||||
List<String> encryptionStyles = new ArrayList<>();
|
||||
|
@@ -20,7 +20,8 @@ import java.util.List;
|
||||
public class CommandFormat implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull 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[] arguments) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
@@ -32,7 +33,14 @@ public class CommandFormat implements TabExecutor {
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
heldBook.setItemMeta(BookFormatter.formatPages((BookMeta) heldBook.getItemMeta()));
|
||||
BookMeta meta = (BookMeta) heldBook.getItemMeta();
|
||||
|
||||
if (meta == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "Unable to get metadata from the held book!");
|
||||
return false;
|
||||
}
|
||||
|
||||
heldBook.setItemMeta(BookFormatter.formatPages(meta));
|
||||
|
||||
BooksWithoutBorders.sendSuccessMessage(sender, "Book formatted!");
|
||||
|
||||
@@ -40,7 +48,8 @@ public class CommandFormat implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@@ -13,6 +13,7 @@ import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -25,7 +26,8 @@ public class CommandGive implements TabExecutor {
|
||||
private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] arguments) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
if (!(sender instanceof Player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
@@ -43,7 +45,8 @@ public class CommandGive implements TabExecutor {
|
||||
* @param folder <p>The folder containing the book to load</p>
|
||||
* @return <p>True if the book was given successfully</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
return doTabCompletion(sender, args, false);
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return doTabCompletion(sender, arguments, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +116,8 @@ public class CommandGive implements TabExecutor {
|
||||
* @param listPublic <p>Whether to list public files or player files</p>
|
||||
* @return <p>A list of available choices</p>
|
||||
*/
|
||||
protected List<String> doTabCompletion(CommandSender sender, String[] args, boolean listPublic) {
|
||||
@Nullable
|
||||
protected List<String> doTabCompletion(@NotNull CommandSender sender, @NotNull String[] args, boolean listPublic) {
|
||||
Server server = booksWithoutBorders.getServer();
|
||||
|
||||
int argumentCount = args.length;
|
||||
@@ -157,8 +162,9 @@ public class CommandGive implements TabExecutor {
|
||||
* @param copies <p>The number of copies the player wants to give</p>
|
||||
* @return <p>True if the book was successfully given</p>
|
||||
*/
|
||||
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) {
|
||||
|
@@ -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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
return doTabCompletion(sender, args, true);
|
||||
@Nullable
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return doTabCompletion(sender, arguments, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -17,8 +17,9 @@ import java.util.List;
|
||||
public class CommandGroupEncrypt extends CommandEncrypt implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
BookMeta bookMetadata = performPreChecks(sender, args, 2,
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
BookMeta bookMetadata = performPreChecks(sender, arguments, 2,
|
||||
"You must specify a group name and key to encrypt a book!");
|
||||
|
||||
if (bookMetadata == null) {
|
||||
@@ -32,13 +33,14 @@ public class CommandGroupEncrypt extends CommandEncrypt implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
EncryptionStyle encryptionStyle = args.length == 3 ? EncryptionStyle.getFromString(args[2]) : EncryptionStyle.SUBSTITUTION;
|
||||
return encryptBook(encryptionStyle, (Player) sender, args[1], args[0]);
|
||||
EncryptionStyle encryptionStyle = arguments.length == 3 ? EncryptionStyle.getFromString(arguments[2]) : EncryptionStyle.SUBSTITUTION;
|
||||
return encryptBook(encryptionStyle, (Player) sender, arguments[1], arguments[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
return doTabCompletion(args, true);
|
||||
public @NotNull List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String alias, @NotNull String[] arguments) {
|
||||
return doTabCompletion(arguments, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,7 +22,8 @@ import java.util.List;
|
||||
public class CommandLoad implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] arguments) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
return loadBook(sender, arguments, "player", false);
|
||||
}
|
||||
|
||||
@@ -95,32 +96,34 @@ public class CommandLoad implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
return doTabCompletion(sender, args, false);
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return doTabCompletion(sender, arguments, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the actual tab completion
|
||||
*
|
||||
* @param sender <p>The sender of the command</p>
|
||||
* @param args <p>The arguments given</p>
|
||||
* @param arguments <p>The arguments given</p>
|
||||
* @param loadPublic <p>Whether to list public files or player files</p>
|
||||
* @return <p>A list of available choices</p>
|
||||
*/
|
||||
protected List<String> doTabCompletion(CommandSender sender, String[] args, boolean loadPublic) {
|
||||
int argumentCount = args.length;
|
||||
@NotNull
|
||||
protected List<String> doTabCompletion(@NotNull CommandSender sender, @NotNull String[] arguments, boolean loadPublic) {
|
||||
int argumentCount = arguments.length;
|
||||
if (argumentCount == 1) {
|
||||
//Return list of books
|
||||
return TabCompletionHelper.filterMatchingContains(BooksWithoutBorders.getAvailableBooks(sender, loadPublic),
|
||||
args[0]);
|
||||
arguments[0]);
|
||||
} else if (argumentCount == 2) {
|
||||
//Number of copies
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getBooleansAndNumbers(1, 3), args[1]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getBooleansAndNumbers(1, 3), arguments[1]);
|
||||
} else if (argumentCount == 3) {
|
||||
//Signed
|
||||
try {
|
||||
Integer.parseInt(args[1]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getBooleans(), args[2]);
|
||||
Integer.parseInt(arguments[1]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getBooleans(), arguments[2]);
|
||||
} catch (NumberFormatException e) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@@ -13,13 +13,15 @@ import java.util.List;
|
||||
public class CommandLoadPublic extends CommandLoad implements CommandExecutor {
|
||||
|
||||
@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 loadBook(sender, arguments, "public", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
return doTabCompletion(sender, args, true);
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return doTabCompletion(sender, arguments, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,7 +16,8 @@ import java.util.List;
|
||||
public class CommandReload implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull 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[] arguments) {
|
||||
if (BooksWithoutBordersConfig.loadConfig()) {
|
||||
BooksWithoutBorders.sendSuccessMessage(sender, "BooksWithoutBorders configuration reloaded!");
|
||||
} else {
|
||||
@@ -31,7 +32,8 @@ public class CommandReload implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@@ -33,19 +33,19 @@ import static net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig
|
||||
public class CommandSave implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
return saveHeldBook(sender, args, false);
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] arguments) {
|
||||
return saveHeldBook(sender, arguments, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the player's held book if it exists
|
||||
*
|
||||
* @param sender <p>The sender of the command</p>
|
||||
* @param args <p>The arguments given</p>
|
||||
* @param arguments <p>The arguments given</p>
|
||||
* @param savePublic <p>Whether to save the book in the public directory or the player directory</p>
|
||||
* @return <p>True if a book was saved successfully</p>
|
||||
*/
|
||||
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 overwrite <p>Whether to overwrite any existing books</p>
|
||||
* @param saveToPublicFolder <p>Whether to save the book to the public folder instead of the player folder</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@@ -11,8 +11,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class CommandSavePublic extends CommandSave implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
return saveHeldBook(sender, args, true);
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
return saveHeldBook(sender, arguments, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -22,13 +23,14 @@ import java.util.List;
|
||||
public class CommandSetAuthor implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull 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[] arguments) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
if (arguments.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Too few command arguments!");
|
||||
return false;
|
||||
}
|
||||
@@ -48,7 +50,7 @@ public class CommandSetAuthor implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
String author = ColorHelper.translateColorCodes(String.join(" ", args), ColorConversion.RGB);
|
||||
String author = ColorHelper.translateColorCodes(String.join(" ", arguments), ColorConversion.RGB);
|
||||
bookMetaData.setAuthor(author);
|
||||
heldBook.setItemMeta(bookMetaData);
|
||||
BooksWithoutBorders.sendSuccessMessage(player, "Book author set to " + author + "!");
|
||||
@@ -56,8 +58,10 @@ public class CommandSetAuthor implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
if (args.length == 1) {
|
||||
@Nullable
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
return null;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
|
@@ -26,35 +26,36 @@ public class CommandSetBookPrice implements TabExecutor {
|
||||
private List<String> paymentTypes;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] arguments) {
|
||||
//Clear the current price
|
||||
if (args.length == 0) {
|
||||
if (arguments.length == 0) {
|
||||
clearItemPrice(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
//Warn about missing arguments
|
||||
if (args.length < 2) {
|
||||
if (arguments.length < 2) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "[Item/Eco] and [quantity] must be specified!");
|
||||
return false;
|
||||
}
|
||||
|
||||
//Warn about invalid argument
|
||||
if (!args[0].equalsIgnoreCase("Item") && !args[0].equalsIgnoreCase("Eco")) {
|
||||
if (!arguments[0].equalsIgnoreCase("Item") && !arguments[0].equalsIgnoreCase("Eco")) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "Price type must be \"Item\" or \"Eco\"!");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
double price = Double.parseDouble(args[1]);
|
||||
double price = Double.parseDouble(arguments[1]);
|
||||
if (price <= 0) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "[quantity] must be greater than 0!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("Item")) {
|
||||
if (arguments[0].equalsIgnoreCase("Item")) {
|
||||
return setItemPrice(sender, price);
|
||||
} else if (args[0].equalsIgnoreCase("Eco")) {
|
||||
} else if (arguments[0].equalsIgnoreCase("Eco")) {
|
||||
return setEconomyPrice(sender, price);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -68,7 +69,7 @@ public class CommandSetBookPrice implements TabExecutor {
|
||||
*
|
||||
* @param sender <p>The sender of the command</p>
|
||||
*/
|
||||
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 price <p>The new price</p>
|
||||
* @return <p>True if the price was changed successfully</p>
|
||||
*/
|
||||
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 price <p>The new price</p>
|
||||
* @return <p>True if the price was changed successfully</p>
|
||||
*/
|
||||
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 List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
if (paymentTypes == null) {
|
||||
initializeTabCompleteLists();
|
||||
}
|
||||
|
||||
int argumentCount = args.length;
|
||||
int argumentCount = arguments.length;
|
||||
if (argumentCount == 1) {
|
||||
return TabCompletionHelper.filterMatchingStartsWith(paymentTypes, args[0]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(paymentTypes, arguments[0]);
|
||||
} else if (argumentCount == 2) {
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getNumbers(1, 3), args[1]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getNumbers(1, 3), arguments[1]);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ public class CommandSetGeneration implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
@NotNull String[] arguments) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
@@ -32,14 +32,14 @@ public class CommandSetGeneration implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
if (arguments.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "You must specify the new generation for your book!");
|
||||
return false;
|
||||
}
|
||||
|
||||
BookMeta.Generation generation;
|
||||
try {
|
||||
generation = BookMeta.Generation.valueOf(args[0]);
|
||||
generation = BookMeta.Generation.valueOf(arguments[0]);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Invalid book generation specified!");
|
||||
return false;
|
||||
@@ -60,8 +60,8 @@ public class CommandSetGeneration implements TabExecutor {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
List<String> generations = new ArrayList<>();
|
||||
for (BookMeta.Generation generation : BookMeta.Generation.values()) {
|
||||
generations.add(generation.name());
|
||||
|
@@ -24,13 +24,14 @@ import java.util.List;
|
||||
public class CommandSetLore implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull 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[] arguments) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
if (arguments.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Missing a command argument!");
|
||||
return false;
|
||||
}
|
||||
@@ -42,7 +43,7 @@ public class CommandSetLore implements TabExecutor {
|
||||
}
|
||||
|
||||
//Treat all arguments as lore input
|
||||
String rawLore = String.join(" ", args);
|
||||
String rawLore = String.join(" ", arguments);
|
||||
|
||||
//Format lore
|
||||
rawLore = ColorHelper.translateColorCodes(rawLore, ColorConversion.RGB);
|
||||
@@ -62,7 +63,8 @@ public class CommandSetLore implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, String[] args) {
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] arguments) {
|
||||
//TODO: Figure out if there is a better way to display that an argument is required
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("<new lore>");
|
||||
|
@@ -24,13 +24,13 @@ public class CommandSetTitle implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
@NotNull String[] arguments) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.length < 1) {
|
||||
if (arguments.length < 1) {
|
||||
BooksWithoutBorders.sendErrorMessage(player, "Too few command arguments!");
|
||||
return false;
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public class CommandSetTitle implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
String title = String.join(" ", args);
|
||||
String title = String.join(" ", arguments);
|
||||
title = ColorHelper.translateColorCodes(title, ColorConversion.RGB);
|
||||
|
||||
ItemMeta itemMetadata = heldItem.getItemMeta();
|
||||
@@ -69,7 +69,7 @@ public class CommandSetTitle implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
@NotNull String[] arguments) {
|
||||
List<String> options = new ArrayList<>();
|
||||
options.add("<new title>");
|
||||
return options;
|
||||
|
@@ -90,8 +90,9 @@ public class CommandUnSign implements TabExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
|
||||
@NotNull String[] args) {
|
||||
@NotNull String[] arguments) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@ import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.file.FileSystems;
|
||||
import java.util.ArrayList;
|
||||
@@ -48,7 +49,7 @@ public class BooksWithoutBordersConfig {
|
||||
*
|
||||
* @param booksWithoutBorders <p>The books without borders object used for getting required data</p>
|
||||
*/
|
||||
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 configOption <p>The configuration option to get the value for</p>
|
||||
* @return <p>The value of the option</p>
|
||||
*/
|
||||
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 configOption <p>The configuration option to get the value for</p>
|
||||
* @return <p>The value of the option</p>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
|
||||
|
@@ -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 configNode <p>The config node in the config file this option represents</p>
|
||||
* @param defaultValue <p>The default value for this config option</p>
|
||||
*/
|
||||
ConfigOption(String configNode, Object defaultValue) {
|
||||
ConfigOption(@NotNull String configNode, @NotNull Object defaultValue) {
|
||||
this.configNode = configNode;
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
@@ -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 encrypt <p>Whether to encrypt or decrypt the input</p>
|
||||
* @return <p>The encrypted/decrypted input, or null if anything went wrong</p>
|
||||
*/
|
||||
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 encryption <p>Whether the input should be encrypted or decrypted</p>
|
||||
* @return <p>The input in byte format</p>
|
||||
*/
|
||||
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 encryption <p>Whether the output came from encryption or decryption</p>
|
||||
* @return <p>The output as a string</p>
|
||||
*/
|
||||
@NotNull
|
||||
private String createResult(byte[] output, boolean encryption) {
|
||||
if (encryption) {
|
||||
return Base64.getEncoder().encodeToString(output);
|
||||
@@ -130,6 +134,7 @@ public class AES {
|
||||
*
|
||||
* @return <p>An AES cipher instance, or null if something went wrong</p>
|
||||
*/
|
||||
@Nullable
|
||||
private Cipher getAESCipher() {
|
||||
Cipher aes;
|
||||
try {
|
||||
@@ -147,7 +152,8 @@ public class AES {
|
||||
* @param password <p>A user supplied password</p>
|
||||
* @return <p>A secret key spec or null if something went wrong</p>
|
||||
*/
|
||||
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 {
|
||||
|
@@ -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 key <p>The key used to generate the codon table</p>
|
||||
*/
|
||||
public GenenCrypt(String key) {
|
||||
public GenenCrypt(@NotNull String key) {
|
||||
|
||||
// define the initial, unshuffled codon list of 4 base codons
|
||||
ArrayList<String> originalCodonList = new ArrayList<>();
|
||||
@@ -114,7 +116,8 @@ public class GenenCrypt {
|
||||
* @param input <p>The input to encrypt</p>
|
||||
* @return <p>The encrypted input</p>
|
||||
*/
|
||||
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 input <p>The input to decrypt</p>
|
||||
* @return <p>The decrypted input</p>
|
||||
*/
|
||||
public String decrypt(String input) {
|
||||
@NotNull
|
||||
public String decrypt(@NotNull String input) {
|
||||
StringBuilder output = new StringBuilder();
|
||||
int keyCount = 0;
|
||||
int junk = key.charAt(0);
|
||||
|
@@ -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())));
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -83,6 +83,7 @@ public abstract class BookIndex {
|
||||
*/
|
||||
protected static void displayAlphabetIndex(@NotNull ComponentBuilder componentBuilder,
|
||||
@NotNull String command, @NotNull Map<Character, Integer> firstInstances) {
|
||||
componentBuilder.append("[index] <", ComponentBuilder.FormatRetention.NONE);
|
||||
for (int characterIndex = 0; characterIndex <= 25; characterIndex++) {
|
||||
char character = (char) ('a' + characterIndex);
|
||||
if (firstInstances.containsKey(character)) {
|
||||
@@ -95,7 +96,7 @@ public abstract class BookIndex {
|
||||
componentBuilder.append(character + "", ComponentBuilder.FormatRetention.NONE).color(ChatColor.GRAY);
|
||||
}
|
||||
}
|
||||
componentBuilder.append("\n");
|
||||
componentBuilder.append(">", ComponentBuilder.FormatRetention.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,7 +116,6 @@ public abstract class BookIndex {
|
||||
} else {
|
||||
componentBuilder.append("Previous [<]", ComponentBuilder.FormatRetention.NONE).color(ChatColor.GRAY);
|
||||
}
|
||||
componentBuilder.append("\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -63,11 +63,9 @@ public class PagedBookIndex extends BookIndex {
|
||||
@NotNull Map<Character, Integer> firstInstances) {
|
||||
ComponentBuilder componentBuilder = new ComponentBuilder();
|
||||
|
||||
// Display the alphabet index as the header
|
||||
displayAlphabetIndex(componentBuilder, command, firstInstances);
|
||||
|
||||
// Display the list of books, with the next and previous buttons
|
||||
displayPreviousButton(componentBuilder, command, page);
|
||||
componentBuilder.append("\n");
|
||||
displayBookList(componentBuilder, command, page, availableBooks);
|
||||
displayNextButton(componentBuilder, command, page, totalPages);
|
||||
|
||||
@@ -76,6 +74,10 @@ public class PagedBookIndex extends BookIndex {
|
||||
displayTotalPages(componentBuilder, page, totalPages);
|
||||
componentBuilder.append(" ", ComponentBuilder.FormatRetention.NONE);
|
||||
displayPageCommand(componentBuilder, command, page);
|
||||
componentBuilder.append("\n");
|
||||
|
||||
// Display the alphabet index as the header
|
||||
displayAlphabetIndex(componentBuilder, command, firstInstances);
|
||||
sender.spigot().sendMessage(componentBuilder.create());
|
||||
}
|
||||
|
||||
|
@@ -5,6 +5,7 @@ import net.knarcraft.bookswithoutborders.utility.BookFormatter;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A listener for listening to book events
|
||||
@@ -14,7 +15,7 @@ import org.bukkit.event.player.PlayerEditBookEvent;
|
||||
public class BookEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onBookSign(PlayerEditBookEvent event) {
|
||||
public void onBookSign(@NotNull PlayerEditBookEvent event) {
|
||||
if (event.isCancelled() || !event.isSigning() || !BooksWithoutBordersConfig.formatBooks()) {
|
||||
return;
|
||||
}
|
||||
|
@@ -17,6 +17,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
@@ -29,7 +31,7 @@ public class PlayerEventListener implements Listener {
|
||||
private final BooksWithoutBorders booksWithoutBorders = BooksWithoutBorders.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onHold(PlayerItemHeldEvent event) {
|
||||
public void onHold(@NotNull PlayerItemHeldEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
@@ -54,7 +56,7 @@ public class PlayerEventListener implements Listener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
public void onPlayerJoin(@NotNull PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
//If a book directory exists with this player's name, move it to this player's UUID
|
||||
@@ -82,11 +84,15 @@ public class PlayerEventListener implements Listener {
|
||||
ItemStack offHandItem = InventoryHelper.getHeldItem(player, false);
|
||||
if (mainHandItem.getType() == Material.WRITTEN_BOOK) {
|
||||
ItemMeta itemMetadata = mainHandItem.getItemMeta();
|
||||
updateBookInHand(player, itemMetadata, true);
|
||||
if (itemMetadata != null) {
|
||||
updateBookInHand(player, itemMetadata, true);
|
||||
}
|
||||
}
|
||||
if (offHandItem.getType() == Material.WRITTEN_BOOK) {
|
||||
ItemMeta itemMetadata = offHandItem.getItemMeta();
|
||||
updateBookInHand(player, itemMetadata, false);
|
||||
if (itemMetadata != null) {
|
||||
updateBookInHand(player, itemMetadata, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +104,7 @@ public class PlayerEventListener implements Listener {
|
||||
* @param sendMessage <p>Whether to send a message to the joining player</p>
|
||||
* @return <p>True if a message has yet to be sent</p>
|
||||
*/
|
||||
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 itemMetadata <p>Information about the held book</p>
|
||||
* @param mainHand <p>Whether to update the book in the player's main hand</p>
|
||||
*/
|
||||
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 oldBook <p>Metadata about the held book</p>
|
||||
* @return <p>An updated book</p>
|
||||
*/
|
||||
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;
|
||||
|
@@ -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 player <p>The player which clicked the sign</p>
|
||||
* @param hand <p>The EquipmentSlot of the used hand</p>
|
||||
*/
|
||||
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 sign <p>The sign to check</p>
|
||||
* @return <p>The color of the sign</p>
|
||||
*/
|
||||
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 color <p>The color to match</p>
|
||||
* @return <p>True if the given string is what's on the sign</p>
|
||||
*/
|
||||
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 lines <p>The lines on the sign</p>
|
||||
* @param player <p>The player which edited the sign</p>
|
||||
*/
|
||||
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 event <p>The event causing the creation of the give sign</p>
|
||||
* @param isValid <p>Whether the created sign is valid</p>
|
||||
*/
|
||||
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 heldItem <p>The type of the held book</p>
|
||||
* @param hand <p>The hand the player is using to hold the book</p>
|
||||
*/
|
||||
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 player <p>The player which clicked the sign</p>
|
||||
* @param hand <p>The EquipmentSlot of the used hand</p>
|
||||
*/
|
||||
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 sign <p>The sign the user clicked</p>
|
||||
* @param player <p>The player which clicked the sign</p>
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@@ -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 directory <p>The directory to transform</p>
|
||||
* @return <p>A book directory, or null if the given directory is empty</p>
|
||||
*/
|
||||
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")) {
|
||||
|
@@ -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 name <p>The name of the encryption style</p>
|
||||
* @return <p>An encryption style or null if no match is found</p>
|
||||
*/
|
||||
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;
|
||||
|
@@ -25,7 +25,7 @@ public final class BookFormatter {
|
||||
*
|
||||
* @param rawPages <p>A list of pages</p>
|
||||
*/
|
||||
public static void formatLastPage(List<String> rawPages) {
|
||||
public static void formatLastPage(@NotNull List<String> rawPages) {
|
||||
int maxPageText = 256;
|
||||
int fitsNewline = maxPageText - 2;
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class BookFormatter {
|
||||
* @param maxPageText <p>The max number of characters which fit on a page</p>
|
||||
* @param fitsNewline <p>The max number of characters on a page which still fits a newline character</p>
|
||||
*/
|
||||
public static void formatLastPageSplitOverflow(List<String> rawPages, int maxPageText, int fitsNewline) {
|
||||
public static void formatLastPageSplitOverflow(@NotNull List<String> rawPages, int maxPageText, int fitsNewline) {
|
||||
while (rawPages.get(rawPages.size() - 1).length() > maxPageText) {
|
||||
int splitPosition;
|
||||
String fittingText = rawPages.get(rawPages.size() - 1).substring(0, maxPageText);
|
||||
@@ -78,7 +78,7 @@ public final class BookFormatter {
|
||||
* @param rawPages <p>The raw pages to format</p>
|
||||
* @param maxPageText <p>The max number of characters which fit on a page</p>
|
||||
*/
|
||||
public static void formatLastPageCombinePages(List<String> rawPages, int maxPageText) {
|
||||
public static void formatLastPageCombinePages(@NotNull List<String> rawPages, int maxPageText) {
|
||||
int lastPageIndex = rawPages.size() - 1;
|
||||
int nextToLastIndex = rawPages.size() - 2;
|
||||
if (rawPages.get(nextToLastIndex).length() + rawPages.get(lastPageIndex).length() <= maxPageText) {
|
||||
@@ -93,7 +93,7 @@ public final class BookFormatter {
|
||||
* @param rawPages <p>The raw pages to format</p>
|
||||
* @param fitsNewline <p>The max number of characters on a page which still fits a newline character</p>
|
||||
*/
|
||||
public static void formatLastPageAddNewline(List<String> rawPages, int fitsNewline) {
|
||||
public static void formatLastPageAddNewline(@NotNull List<String> rawPages, int fitsNewline) {
|
||||
int pageIndex = rawPages.size() - 1;
|
||||
if (rawPages.get(pageIndex).length() <= fitsNewline && !rawPages.get(pageIndex).isEmpty()) {
|
||||
rawPages.set(pageIndex, (rawPages.get(pageIndex)) + "\n");
|
||||
@@ -106,7 +106,8 @@ public final class BookFormatter {
|
||||
* @param bookMeta <p>The book meta to change</p>
|
||||
* @return <p>The changed book meta</p>
|
||||
*/
|
||||
public static BookMeta formatPages(BookMeta bookMeta) {
|
||||
@NotNull
|
||||
public static BookMeta formatPages(@NotNull BookMeta bookMeta) {
|
||||
List<String> formattedPages = new ArrayList<>(Objects.requireNonNull(bookMeta).getPageCount());
|
||||
for (String page : bookMeta.getPages()) {
|
||||
formattedPages.add(ColorHelper.translateColorCodes(page, ColorConversion.RGB));
|
||||
|
@@ -53,6 +53,7 @@ public final class BookHelper {
|
||||
* @param sender <p>The command sender trying to get the directory</p>
|
||||
* @return <p>The path of the directory, or null if not possible to get</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static File getBookDirectoryPath(@NotNull BookDirectory bookDirectory, @NotNull CommandSender sender) {
|
||||
String bookFolderString = getBookDirectoryPathString(bookDirectory, sender);
|
||||
if (bookFolderString == null) {
|
||||
|
@@ -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 directory <p>The relative directory given</p>
|
||||
* @return <p>A file or null if it does not exist</p>
|
||||
*/
|
||||
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();
|
||||
|
@@ -86,6 +86,7 @@ public final class IntegerToRomanConverter {
|
||||
* @param times <p>The number of times to repeat the character</p>
|
||||
* @return <p>The repeated string</p>
|
||||
*/
|
||||
@NotNull
|
||||
private static String repeat(char character, int times) {
|
||||
return String.valueOf(character).repeat(Math.max(0, times));
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user