diff --git a/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java b/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java index 7a214d8..71d2135 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBorders.java @@ -54,6 +54,9 @@ public class BooksWithoutBorders extends JavaPlugin { protected static BooksWithoutBordersListener bL; protected static ConsoleCommandSender consoleSender; protected static String bookFolder; + protected static ChatColor errorColor = ChatColor.RED; + protected static ChatColor successColor = ChatColor.GREEN; + protected static ChatColor commandColor = ChatColor.YELLOW; @Override public void onEnable() { @@ -76,9 +79,9 @@ public class BooksWithoutBorders extends JavaPlugin { { iF = this.getServer().getItemFactory(); } catch (java.lang.NoSuchMethodError nsmE) { - consoleSender.sendMessage(ChatColor.RED + "Warning! [BooksWithoutBorders] failed to initialize!"); - consoleSender.sendMessage(ChatColor.RED + "Please confirm the correct version of [BooksWithoutBorders] is"); - consoleSender.sendMessage(ChatColor.RED + "being run for this version of bukkit!"); + consoleSender.sendMessage(errorColor + "Warning! [BooksWithoutBorders] failed to initialize!"); + consoleSender.sendMessage(errorColor + "Please confirm the correct version of [BooksWithoutBorders] is"); + consoleSender.sendMessage(errorColor + "being run for this version of bukkit!"); return false; } @@ -106,8 +109,8 @@ public class BooksWithoutBorders extends JavaPlugin { //Handles old book and quill settings if (this.getConfig().contains("Options.Require_book_and_quill_to_create_book")) { - consoleSender.sendMessage(ChatColor.GREEN + "[BooksWithoutBorders] Found old config setting \"Require_book_and_quill_to_create_book\""); - consoleSender.sendMessage(ChatColor.GREEN + "Updating to \"Price_to_create_book\" settings"); + consoleSender.sendMessage(successColor + "[BooksWithoutBorders] Found old config setting \"Require_book_and_quill_to_create_book\""); + consoleSender.sendMessage(successColor + "Updating to \"Price_to_create_book\" settings"); if (this.getConfig().getBoolean("Options.Require_book_and_quill_to_create_book")) { bookPriceType = Material.WRITABLE_BOOK; @@ -127,7 +130,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (!fTest.exists()) { try { if (!fTest.mkdir()) { - consoleSender.sendMessage(ChatColor.RED + "Saving failed! Aborting..."); + consoleSender.sendMessage(errorColor + "Saving failed! Aborting..."); return false; } } catch (Exception e) { @@ -138,7 +141,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (!efTest.exists()) { try { if (!efTest.mkdir()) { - consoleSender.sendMessage(ChatColor.RED + "Saving failed! Aborting..."); + consoleSender.sendMessage(errorColor + "Saving failed! Aborting..."); return false; } } catch (Exception e) { @@ -174,7 +177,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (setupEconomy()) bookPriceType = Material.AIR; else { - consoleSender.sendMessage(ChatColor.RED + "BooksWithoutBorders failed to hook into Vault! Book price not set!"); + consoleSender.sendMessage(errorColor + "BooksWithoutBorders failed to hook into Vault! Book price not set!"); bookPriceType = null; } } else if (!sMaterial.equalsIgnoreCase(" ")) { @@ -188,14 +191,14 @@ public class BooksWithoutBorders extends JavaPlugin { //makes sure TsepA is a valid value titleAuthorSeparator = cleanString(titleAuthorSeparator); if (titleAuthorSeparator.length() != 1) { - consoleSender.sendMessage(ChatColor.RED + "Title-Author_Separator is set to an invalid value!"); - consoleSender.sendMessage(ChatColor.RED + "Reverting to default value of \",\""); + consoleSender.sendMessage(errorColor + "Title-Author_Separator is set to an invalid value!"); + consoleSender.sendMessage(errorColor + "Reverting to default value of \",\""); titleAuthorSeparator = ","; this.getConfig().set("Options.Title-Author_Separator", titleAuthorSeparator); } } catch (Exception e) { - consoleSender.sendMessage(ChatColor.RED + "Warning! Config.yml failed to load!"); - consoleSender.sendMessage(ChatColor.RED + "Try Looking for settings that are missing values!"); + consoleSender.sendMessage(errorColor + "Warning! Config.yml failed to load!"); + consoleSender.sendMessage(errorColor + "Try Looking for settings that are missing values!"); return false; } @@ -222,7 +225,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (!fTest.exists()) { try { if (!fTest.createNewFile()) { - consoleSender.sendMessage(ChatColor.RED + "Could not create Existing Players file! Aborting..."); + consoleSender.sendMessage(errorColor + "Could not create Existing Players file! Aborting..."); return false; } PrintWriter pw = new PrintWriter(new FileWriter(fTest)); @@ -266,7 +269,7 @@ public class BooksWithoutBorders extends JavaPlugin { pw.println(playerName); pw.close(); } catch (IOException e) { - consoleSender.sendMessage(ChatColor.RED + "Failed to add " + playerName + " to Existing Players list"); + consoleSender.sendMessage(errorColor + "Failed to add " + playerName + " to Existing Players list"); } } @@ -285,85 +288,85 @@ public class BooksWithoutBorders extends JavaPlugin { if ((command.getName().equalsIgnoreCase("BooksWithoutBorders") || command.getName().equalsIgnoreCase("bwb"))) { if (args.length == 0 && sender instanceof Player) { //lists commands - sender.sendMessage(ChatColor.YELLOW + "Use: /bwb [Command]"); - sender.sendMessage(ChatColor.YELLOW + "[] denote parameters"); + sender.sendMessage(commandColor + "Use: /bwb [Command]"); + sender.sendMessage(commandColor + "[] denote parameters"); if (booksHavePrice()) { if (bookPriceType != Material.AIR) - sender.sendMessage(ChatColor.RED + "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]"); + sender.sendMessage(errorColor + "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]"); else - sender.sendMessage(ChatColor.RED + "[" + BooksWithoutBorders.eco.format(bookPriceQuantity) + " is required to create a book]"); + sender.sendMessage(errorColor + "[" + BooksWithoutBorders.eco.format(bookPriceQuantity) + " is required to create a book]"); } - sender.sendMessage(ChatColor.YELLOW + "Commands:"); + sender.sendMessage(commandColor + "Commands:"); if (sender.hasPermission("bookswithoutborders.load")) { - sender.sendMessage(ChatColor.YELLOW + "\nLoad [file name or number] [# of copies] [true/false]:"); - sender.sendMessage(ChatColor.GREEN + "Creates a book from the specified file and gives it to the player"); - sender.sendMessage(ChatColor.GREEN + "If no file is specified, a list of available files is returned"); - sender.sendMessage(ChatColor.GREEN + "If true is specified the book will be signed, if false it will be"); - sender.sendMessage(ChatColor.GREEN + "unsigned"); + sender.sendMessage(commandColor + "\nLoad [file name or number] [# of copies] [true/false]:"); + sender.sendMessage(successColor + "Creates a book from the specified file and gives it to the player"); + sender.sendMessage(successColor + "If no file is specified, a list of available files is returned"); + sender.sendMessage(successColor + "If true is specified the book will be signed, if false it will be"); + sender.sendMessage(successColor + "unsigned"); } if (sender.hasPermission("bookswithoutborders.loadpublic")) { - sender.sendMessage(ChatColor.YELLOW + "loadPublic [file name or number] [# of copies] [true/false]:"); - sender.sendMessage(ChatColor.GREEN + "Same as Load, but views files in the public directory"); + sender.sendMessage(commandColor + "loadPublic [file name or number] [# of copies] [true/false]:"); + sender.sendMessage(successColor + "Same as Load, but views files in the public directory"); } if (sender.hasPermission("bookswithoutborders.save")) { - sender.sendMessage("\n" + ChatColor.YELLOW + "Save [true/false]: " + ChatColor.GREEN + "Saves the book the player is"); - sender.sendMessage(ChatColor.GREEN + "holding to a text file in a private directory"); - sender.sendMessage(ChatColor.GREEN + "If true is specified, a book of the same name by the same"); - sender.sendMessage(ChatColor.GREEN + "author will be overwritten by the new book"); + sender.sendMessage("\n" + commandColor + "Save [true/false]: " + successColor + "Saves the book the player is"); + sender.sendMessage(successColor + "holding to a text file in a private directory"); + sender.sendMessage(successColor + "If true is specified, a book of the same name by the same"); + sender.sendMessage(successColor + "author will be overwritten by the new book"); } if (sender.hasPermission("bookswithoutborders.savepublic")) { - sender.sendMessage(ChatColor.YELLOW + "savePublic [true/false]: " + ChatColor.GREEN + "Same as Save,"); - sender.sendMessage(ChatColor.GREEN + "but saves files in the public directory"); + sender.sendMessage(commandColor + "savePublic [true/false]: " + successColor + "Same as Save,"); + sender.sendMessage(successColor + "but saves files in the public directory"); } if (sender.hasPermission("bookswithoutborders.give")) { - sender.sendMessage("\n" + ChatColor.YELLOW + "Give [file name or number] [playername] [# of copies] [true/false]:"); - sender.sendMessage(ChatColor.GREEN + "Gives the selected player a book from your personal directory"); + sender.sendMessage("\n" + commandColor + "Give [file name or number] [playername] [# of copies] [true/false]:"); + sender.sendMessage(successColor + "Gives the selected player a book from your personal directory"); } if (sender.hasPermission("bookswithoutborders.givepublic")) { - sender.sendMessage(ChatColor.YELLOW + "givePublic [file name or number] [playername] [# of copies] [true/false]:"); - sender.sendMessage(ChatColor.GREEN + "Same as give, but uses books from the public directory"); + sender.sendMessage(commandColor + "givePublic [file name or number] [playername] [# of copies] [true/false]:"); + sender.sendMessage(successColor + "Same as give, but uses books from the public directory"); } if (sender.hasPermission("bookswithoutborders.delete")) { - sender.sendMessage(ChatColor.YELLOW + "\nDelete [file name or number]: " + ChatColor.GREEN + "Deletes the specified"); - sender.sendMessage(ChatColor.GREEN + "file in the player's directory"); - sender.sendMessage(ChatColor.GREEN + "If no file is specified, a list of available files is returned"); + sender.sendMessage(commandColor + "\nDelete [file name or number]: " + successColor + "Deletes the specified"); + sender.sendMessage(successColor + "file in the player's directory"); + sender.sendMessage(successColor + "If no file is specified, a list of available files is returned"); } if (sender.hasPermission("bookswithoutborders.admin")) { - sender.sendMessage(ChatColor.YELLOW + "deletePublic [file name or number]: " + ChatColor.GREEN + "Same as Delete,"); - sender.sendMessage(ChatColor.GREEN + "but deletes files in the public directory"); - sender.sendMessage(ChatColor.YELLOW + "\nReload:" + ChatColor.GREEN + " Reloads BwB's configuration file"); + sender.sendMessage(commandColor + "deletePublic [file name or number]: " + successColor + "Same as Delete,"); + sender.sendMessage(successColor + "but deletes files in the public directory"); + sender.sendMessage(commandColor + "\nReload:" + successColor + " Reloads BwB's configuration file"); } if (sender.hasPermission("bookswithoutborders.unsign")) - sender.sendMessage("\n" + ChatColor.YELLOW + "Unsign: " + ChatColor.GREEN + "Unsigns the book the player is holding"); + sender.sendMessage("\n" + commandColor + "Unsign: " + successColor + "Unsigns the book the player is holding"); if (sender.hasPermission("bookswithoutborders.copy")) - sender.sendMessage("\n" + ChatColor.YELLOW + "Copy [number of copies]: " + ChatColor.GREEN + "Copies the book the player is holding"); + sender.sendMessage("\n" + commandColor + "Copy [number of copies]: " + successColor + "Copies the book the player is holding"); if (sender.hasPermission("bookswithoutborders.encrypt")) { - sender.sendMessage("\n" + ChatColor.YELLOW + "Encrypt [key] [style]: " + ChatColor.GREEN + "Encrypts the book the player is holding"); - sender.sendMessage(ChatColor.YELLOW + "[key]" + ChatColor.GREEN + " is required and can be any phrase or number excluding spaces"); - sender.sendMessage(ChatColor.YELLOW + "[style]" + ChatColor.GREEN + " is not required. Possible values are \"DNA\" or \"Magic\""); + sender.sendMessage("\n" + commandColor + "Encrypt [key] [style]: " + successColor + "Encrypts the book the player is holding"); + sender.sendMessage(commandColor + "[key]" + successColor + " is required and can be any phrase or number excluding spaces"); + sender.sendMessage(commandColor + "[style]" + successColor + " is not required. Possible values are \"DNA\" or \"Magic\""); } if (sender.hasPermission("bookswithoutborders.groupencrypt")) { - sender.sendMessage("\n" + ChatColor.YELLOW + "groupEncrypt [group name] [key] [style]: " + ChatColor.GREEN + "Encrypts book so that only players with the" + - "\n bookswithoutborders.decrypt." + ChatColor.YELLOW + "[group name]" + ChatColor.GREEN + " permission may decrypt the book by holding and left clicking the book"); + sender.sendMessage("\n" + commandColor + "groupEncrypt [group name] [key] [style]: " + successColor + "Encrypts book so that only players with the" + + "\n bookswithoutborders.decrypt." + commandColor + "[group name]" + successColor + " permission may decrypt the book by holding and left clicking the book"); } if (sender.hasPermission("bookswithoutborders.decrypt")) { - sender.sendMessage("\n" + ChatColor.YELLOW + "Decrypt [key]: " + ChatColor.GREEN + "Decrypts the book the player is holding"); - sender.sendMessage(ChatColor.YELLOW + "[key]" + ChatColor.GREEN + " is required and MUST be IDENTICAL to the key used to encrypt held book"); + sender.sendMessage("\n" + commandColor + "Decrypt [key]: " + successColor + "Decrypts the book the player is holding"); + sender.sendMessage(commandColor + "[key]" + successColor + " is required and MUST be IDENTICAL to the key used to encrypt held book"); } if (sender.hasPermission("bookswithoutborders.settitle")) - sender.sendMessage("\n" + ChatColor.YELLOW + "setTitle [title]: " + ChatColor.GREEN + "Sets the title of the book/item the player is holding"); + sender.sendMessage("\n" + commandColor + "setTitle [title]: " + successColor + "Sets the title of the book/item the player is holding"); if (sender.hasPermission("bookswithoutborders.setauthor")) - sender.sendMessage("\n" + ChatColor.YELLOW + "setAuthor [author]: " + ChatColor.GREEN + "Sets the author of the book the player is holding"); + sender.sendMessage("\n" + commandColor + "setAuthor [author]: " + successColor + "Sets the author of the book the player is holding"); if (sender.hasPermission("bookswithoutborders.setlore")) { - sender.sendMessage("\n" + ChatColor.YELLOW + "setLore [lore]: " + ChatColor.GREEN + "Sets the lore of the item the player is holding"); - sender.sendMessage(ChatColor.GREEN + "Insert the lore_line_separator character to force a new line\n[\"~\" by default]"); + sender.sendMessage("\n" + commandColor + "setLore [lore]: " + successColor + "Sets the lore of the item the player is holding"); + sender.sendMessage(successColor + "Insert the lore_line_separator character to force a new line\n[\"~\" by default]"); } if (sender.hasPermission("bookswithoutborders.setbookprice")) - sender.sendMessage("\n" + ChatColor.YELLOW + "setBookPrice [Item/Eco] [quantity]: " + ChatColor.GREEN + "Sets the per-book-price to create a book via commands." + + sender.sendMessage("\n" + commandColor + "setBookPrice [Item/Eco] [quantity]: " + successColor + "Sets the per-book-price to create a book via commands." + "\nIf [Item], the item in the player's hand in the amount of [quanity] will be the price.\nIf [Eco], a Vault based economy will be used for price." + "\nIf neither [Item/Eco] or [quantity] are specified the current price to create books will be removed."); return true; @@ -371,16 +374,16 @@ public class BooksWithoutBorders extends JavaPlugin { if (args.length == 0) { //lists commands from console - sender.sendMessage(ChatColor.YELLOW + "Use: /bwb [Command]"); - sender.sendMessage(ChatColor.YELLOW + "[] denote parameters"); - sender.sendMessage(ChatColor.YELLOW + "Commands:"); - sender.sendMessage(ChatColor.YELLOW + "\nReload:" + ChatColor.GREEN + " Reloads BwB's config file"); - sender.sendMessage(ChatColor.YELLOW + "givePublic [file name or number] [playername] [true/false]: " + ChatColor.GREEN); - sender.sendMessage(ChatColor.GREEN + "Gives the selected player a book from the public directory"); - sender.sendMessage(ChatColor.GREEN + "If no file is specified, a list of available files is returned"); - sender.sendMessage(ChatColor.YELLOW + "deletePublic [file name or number]: " + ChatColor.GREEN + "Deletes the specified"); - sender.sendMessage(ChatColor.GREEN + "file in the public directory"); - sender.sendMessage(ChatColor.GREEN + "If no file is specified, a list of available files is returned"); + sender.sendMessage(commandColor + "Use: /bwb [Command]"); + sender.sendMessage(commandColor + "[] denote parameters"); + sender.sendMessage(commandColor + "Commands:"); + sender.sendMessage(commandColor + "\nReload:" + successColor + " Reloads BwB's config file"); + sender.sendMessage(commandColor + "givePublic [file name or number] [playername] [true/false]: " + successColor); + sender.sendMessage(successColor + "Gives the selected player a book from the public directory"); + sender.sendMessage(successColor + "If no file is specified, a list of available files is returned"); + sender.sendMessage(commandColor + "deletePublic [file name or number]: " + successColor + "Deletes the specified"); + sender.sendMessage(successColor + "file in the public directory"); + sender.sendMessage(successColor + "If no file is specified, a list of available files is returned"); return true; } @@ -388,16 +391,16 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("reload")) { if (sender instanceof Player) { if (!sender.hasPermission("bookswithoutborders.admin") && !sender.hasPermission("*")) { - sender.sendMessage(ChatColor.RED + "You don't have permission to use this command!"); + sender.sendMessage(errorColor + "You don't have permission to use this command!"); return false; } } if (loadConfig() && loadExistingPlayers()) - sender.sendMessage(ChatColor.GREEN + "BooksWithoutBorders configuration reloaded!"); + sender.sendMessage(successColor + "BooksWithoutBorders configuration reloaded!"); else { - sender.sendMessage(ChatColor.RED + "Reload Failed!"); - sender.sendMessage(ChatColor.RED + "See console for details"); + sender.sendMessage(errorColor + "Reload Failed!"); + sender.sendMessage(errorColor + "See console for details"); } return true; } @@ -407,7 +410,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("savePublic")) { if (!sender.hasPermission("bookswithoutborders.savepublic")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } @@ -419,14 +422,14 @@ public class BooksWithoutBorders extends JavaPlugin { } return true; } else { - sender.sendMessage(ChatColor.RED + "You must be holding a written book or book and quill to save it!"); + sender.sendMessage(errorColor + "You must be holding a written book or book and quill to save it!"); return false; } } if (args[0].equalsIgnoreCase("save")) { if (!sender.hasPermission("bookswithoutborders.save")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } @@ -438,19 +441,19 @@ public class BooksWithoutBorders extends JavaPlugin { } return true; } else { - sender.sendMessage(ChatColor.RED + "You must be holding a written book or book and quill to save it!"); + sender.sendMessage(errorColor + "You must be holding a written book or book and quill to save it!"); return false; } } if (args[0].equalsIgnoreCase("loadPublic")) { if (!sender.hasPermission("bookswithoutborders.loadpublic")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (((Player) sender).getInventory().firstEmpty() == -1) { - sender.sendMessage(ChatColor.RED + "You must have space in your inventory to load books!"); + sender.sendMessage(errorColor + "You must have space in your inventory to load books!"); return false; } @@ -480,26 +483,26 @@ public class BooksWithoutBorders extends JavaPlugin { if (newBook != null) { ((Player) sender).getInventory().addItem(newBook); - sender.sendMessage(ChatColor.GREEN + "Book created!"); + sender.sendMessage(successColor + "Book created!"); return true; } else { - sender.sendMessage(ChatColor.RED + "Book failed to load!"); + sender.sendMessage(errorColor + "Book failed to load!"); return false; } } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Invalid number of book copies specified!"); + sender.sendMessage(errorColor + "Invalid number of book copies specified!"); return false; } } if (args[0].equalsIgnoreCase("load")) { if (!sender.hasPermission("bookswithoutborders.load")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (((Player) sender).getInventory().firstEmpty() == -1) { - sender.sendMessage(ChatColor.RED + "You must have space in your inventory to load books!"); + sender.sendMessage(errorColor + "You must have space in your inventory to load books!"); return false; } @@ -530,26 +533,26 @@ public class BooksWithoutBorders extends JavaPlugin { if (newBook != null) { ((Player) sender).getInventory().addItem(newBook); - sender.sendMessage(ChatColor.GREEN + "Book created!"); + sender.sendMessage(successColor + "Book created!"); return true; } else { - sender.sendMessage(ChatColor.RED + "Book failed to load!"); + sender.sendMessage(errorColor + "Book failed to load!"); return false; } } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Invalid number of book copies specified!"); + sender.sendMessage(errorColor + "Invalid number of book copies specified!"); return false; } } if (args[0].equalsIgnoreCase("give")) { if (!sender.hasPermission("bookswithoutborders.give")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (!(args.length == 1 || args.length == 3 || args.length == 4 || args.length == 5)) { - sender.sendMessage(ChatColor.RED + "Incorrect number of arguments for this command!"); + sender.sendMessage(errorColor + "Incorrect number of arguments for this command!"); return false; } @@ -568,12 +571,12 @@ public class BooksWithoutBorders extends JavaPlugin { ItemStack newBook; Player receivingPlayer = this.getServer().getPlayer(args[2]); if (receivingPlayer == null) { - sender.sendMessage(ChatColor.RED + "Player not found!"); + sender.sendMessage(errorColor + "Player not found!"); return false; } if (receivingPlayer.getInventory().firstEmpty() == -1) { - sender.sendMessage(ChatColor.RED + "Receiving player must have space in their inventory to receive books!"); + sender.sendMessage(errorColor + "Receiving player must have space in their inventory to receive books!"); return false; } @@ -592,22 +595,22 @@ public class BooksWithoutBorders extends JavaPlugin { if (newBook != null) { receivingPlayer.getInventory().addItem(newBook); - sender.sendMessage(ChatColor.GREEN + "Book sent!"); - receivingPlayer.sendMessage(ChatColor.GREEN + "Book received!"); + sender.sendMessage(successColor + "Book sent!"); + receivingPlayer.sendMessage(successColor + "Book received!"); return true; } else { - sender.sendMessage(ChatColor.RED + "Book failed to load!"); + sender.sendMessage(errorColor + "Book failed to load!"); return false; } } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Invalid number of book copies specified!"); + sender.sendMessage(errorColor + "Invalid number of book copies specified!"); return false; } } if (args[0].equalsIgnoreCase("delete")) { if (!sender.hasPermission("bookswithoutborders.delete")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } @@ -619,14 +622,14 @@ public class BooksWithoutBorders extends JavaPlugin { //actual deletion if (args.length == 2) { if (!loadList.containsKey(sender.getName())) { - sender.sendMessage(ChatColor.RED + "You must first use /bwb delete to create a list of delete-able files!"); + sender.sendMessage(errorColor + "You must first use /bwb delete to create a list of delete-able files!"); return false; } else { if (!loadList.get(sender.getName()).isEmpty()) { deleteBook(sender, args[1], false); return true; } else { - sender.sendMessage(ChatColor.RED + "No files available to delete!"); + sender.sendMessage(errorColor + "No files available to delete!"); return false; } } @@ -635,12 +638,12 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("unsign")) { if (!sender.hasPermission("bookswithoutborders.unsign")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { - sender.sendMessage(ChatColor.RED + "You must be holding a written book to unsign it!"); + sender.sendMessage(errorColor + "You must be holding a written book to unsign it!"); return false; } @@ -649,7 +652,7 @@ public class BooksWithoutBorders extends JavaPlugin { //Find which hand the player is using to hold the book. If holding one in each, throw an error if (hasBookInMainHand && hasBookInOffHand) { - sender.sendMessage(ChatColor.RED + "You cannot un-sign two books at once. Please un-equip one " + + sender.sendMessage(errorColor + "You cannot un-sign two books at once. Please un-equip one " + "of the books you're holding!"); } else if (hasBookInMainHand) { unSignHeldBook(player, true); @@ -661,17 +664,17 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("copy")) { if (!sender.hasPermission("bookswithoutborders.copy")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { - sender.sendMessage(ChatColor.RED + "You must be holding a written book to copy it!"); + sender.sendMessage(errorColor + "You must be holding a written book to copy it!"); return false; } if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "You must specifiy the number of copies to be made!"); + sender.sendMessage(errorColor + "You must specifiy the number of copies to be made!"); return false; } @@ -689,15 +692,15 @@ public class BooksWithoutBorders extends JavaPlugin { } ((Player) sender).getItemInHand().setAmount(((Player) sender).getItemInHand().getAmount() + Integer.parseInt(args[1])); - sender.sendMessage(ChatColor.GREEN + "Book copied!"); + sender.sendMessage(successColor + "Book copied!"); } else { - sender.sendMessage(ChatColor.RED + "Book not copied!"); - sender.sendMessage(ChatColor.RED + "Number specified was invalid!"); + sender.sendMessage(errorColor + "Book not copied!"); + sender.sendMessage(errorColor + "Number specified was invalid!"); return false; } } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Book not copied!"); - sender.sendMessage(ChatColor.RED + "Number specified was invalid!"); + sender.sendMessage(errorColor + "Book not copied!"); + sender.sendMessage(errorColor + "Number specified was invalid!"); return false; } return true; @@ -705,35 +708,35 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("encrypt")) { if (!sender.hasPermission("bookswithoutborders.encrypt")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { - sender.sendMessage(ChatColor.RED + "You must be holding a written book to encrypt it!"); + sender.sendMessage(errorColor + "You must be holding a written book to encrypt it!"); return false; } if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "You must specify a key to encrypt a book!"); + sender.sendMessage(errorColor + "You must specify a key to encrypt a book!"); return false; } if (args.length > 3) { - sender.sendMessage(ChatColor.RED + "Too many command options specified!"); + sender.sendMessage(errorColor + "Too many command options specified!"); return false; } if (!((BookMeta) ((Player) sender).getItemInHand().getItemMeta()).hasPages()) { - sender.sendMessage(ChatColor.RED + "Book must have contents to encrypt!"); + sender.sendMessage(errorColor + "Book must have contents to encrypt!"); return false; } ItemStack eBook; if (args.length == 3) { - eBook = encryptBook((Player) sender, true, args[1], args[2], ""); + eBook = encryptBook((Player) sender, true, args[1], EncryptionStyle.getFromString(args[2]), ""); } else { - eBook = encryptBook((Player) sender, true, args[1], "", ""); + eBook = encryptBook((Player) sender, true, args[1], EncryptionStyle.SUBSTITUTION, ""); } if (eBook != null) { @@ -745,41 +748,41 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("groupEncrypt")) { if (!sender.hasPermission("bookswithoutborders.groupencrypt")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { - sender.sendMessage(ChatColor.RED + "You must be holding a written book to encrypt it!"); + sender.sendMessage(errorColor + "You must be holding a written book to encrypt it!"); return false; } if (args.length < 3) { - sender.sendMessage(ChatColor.RED + "You must specify a key to encrypt a book!"); + sender.sendMessage(errorColor + "You must specify a key to encrypt a book!"); return false; } if (args.length > 4) { - sender.sendMessage(ChatColor.RED + "Too many command options specified!"); + sender.sendMessage(errorColor + "Too many command options specified!"); return false; } if (!((BookMeta) ((Player) sender).getItemInHand().getItemMeta()).hasPages()) { - sender.sendMessage(ChatColor.RED + "Book must have contents to encrypt!"); + sender.sendMessage(errorColor + "Book must have contents to encrypt!"); return false; } if (((Player) sender).getItemInHand().getItemMeta().hasLore() && ((Player) sender).getItemInHand().getItemMeta().getLore().get(0).contains(" encrypted]")) { - sender.sendMessage(ChatColor.RED + "Book is already group encrypted!"); + sender.sendMessage(errorColor + "Book is already group encrypted!"); return false; } ItemStack eBook; if (args.length == 4) { - eBook = encryptBook((Player) sender, true, args[2], args[3], args[1]); + eBook = encryptBook((Player) sender, true, args[2], EncryptionStyle.getFromString(args[3]), args[1]); } else { - eBook = encryptBook((Player) sender, true, args[2], "", args[1]); + eBook = encryptBook((Player) sender, true, args[2], EncryptionStyle.SUBSTITUTION, args[1]); } if (eBook != null) { @@ -791,12 +794,12 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("decrypt")) { if (!sender.hasPermission("bookswithoutborders.decrypt")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { - sender.sendMessage(ChatColor.RED + "You must be holding a written book to decrypt it!"); + sender.sendMessage(errorColor + "You must be holding a written book to decrypt it!"); return false; } @@ -818,12 +821,12 @@ public class BooksWithoutBorders extends JavaPlugin { ItemStack book = eLoad(((Player) sender), key, false); if (book != null) { ((Player) sender).setItemInHand(book); - sender.sendMessage(ChatColor.GREEN + "Book auto-decrypted!"); + sender.sendMessage(successColor + "Book auto-decrypted!"); return true; } else return false; } else { - sender.sendMessage(ChatColor.RED + "No matching encypted book found!"); + sender.sendMessage(errorColor + "No matching encypted book found!"); return false; } } @@ -833,7 +836,7 @@ public class BooksWithoutBorders extends JavaPlugin { ItemStack book = eLoad(((Player) sender), key, true); if (book != null) { ((Player) sender).setItemInHand(book); - sender.sendMessage(ChatColor.GREEN + "Book decrypted!"); + sender.sendMessage(successColor + "Book decrypted!"); return true; } else return false; @@ -841,17 +844,17 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("setTitle")) { if (!sender.hasPermission("bookswithoutborders.settitle")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "Too few command arguments!"); + sender.sendMessage(errorColor + "Too few command arguments!"); return false; } if (((Player) sender).getItemInHand().getType() == Material.AIR) { - sender.sendMessage(ChatColor.RED + "You must be holding an item to set title!"); + sender.sendMessage(errorColor + "You must be holding an item to set title!"); return false; } @@ -876,23 +879,23 @@ public class BooksWithoutBorders extends JavaPlugin { } ((Player) sender).getItemInHand().setItemMeta(meta); - sender.sendMessage(ChatColor.GREEN + "Title set to " + title + "!"); + sender.sendMessage(successColor + "Title set to " + title + "!"); return true; } if (args[0].equalsIgnoreCase("setAuthor")) { if (!sender.hasPermission("bookswithoutborders.setauthor")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "Too few command arguments!"); + sender.sendMessage(errorColor + "Too few command arguments!"); return false; } if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { - sender.sendMessage(ChatColor.RED + "You must be holding a written book to set author!"); + sender.sendMessage(errorColor + "You must be holding a written book to set author!"); return false; } @@ -906,23 +909,23 @@ public class BooksWithoutBorders extends JavaPlugin { } meta.setAuthor(author.toString()); ((Player) sender).getItemInHand().setItemMeta(meta); - sender.sendMessage(ChatColor.GREEN + "Book author set to " + author + "!"); + sender.sendMessage(successColor + "Book author set to " + author + "!"); return true; } if (args[0].equalsIgnoreCase("setLore")) { if (!sender.hasPermission("bookswithoutborders.setlore")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } if (args.length < 2) { - sender.sendMessage(ChatColor.RED + "Missing a command argument!"); + sender.sendMessage(errorColor + "Missing a command argument!"); return false; } if (((Player) sender).getItemInHand().getType() == Material.AIR) { - sender.sendMessage(ChatColor.RED + "Must be holding an item to set lore!"); + sender.sendMessage(errorColor + "Must be holding an item to set lore!"); return false; } @@ -941,7 +944,7 @@ public class BooksWithoutBorders extends JavaPlugin { ItemMeta meta = ((Player) sender).getItemInHand().getItemMeta(); meta.setLore(nulore); ((Player) sender).getItemInHand().setItemMeta(meta); - sender.sendMessage(ChatColor.GREEN + "Added lore to item!"); + sender.sendMessage(successColor + "Added lore to item!"); return true; } } @@ -949,13 +952,13 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("givePublic")) { if (sender instanceof Player) { if (!sender.hasPermission("bookswithoutborders.givepublic")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } } if (!(args.length == 1 || args.length == 3 || args.length == 4 || args.length == 5)) { - sender.sendMessage(ChatColor.RED + "Incorrect number of arguments for this command!"); + sender.sendMessage(errorColor + "Incorrect number of arguments for this command!"); return false; } @@ -974,12 +977,12 @@ public class BooksWithoutBorders extends JavaPlugin { ItemStack newBook; Player receivingPlayer = this.getServer().getPlayer(args[2]); if (receivingPlayer == null) { - sender.sendMessage(ChatColor.RED + "Player not found!"); + sender.sendMessage(errorColor + "Player not found!"); return false; } if (receivingPlayer.getInventory().firstEmpty() == -1) { - sender.sendMessage(ChatColor.RED + "Receiving player must have space in their inventory to receive books!"); + sender.sendMessage(errorColor + "Receiving player must have space in their inventory to receive books!"); return false; } //bwb give [bookname] [player] [numCopies] [issigned] @@ -996,15 +999,15 @@ public class BooksWithoutBorders extends JavaPlugin { if (newBook != null) { receivingPlayer.getInventory().addItem(newBook); - sender.sendMessage(ChatColor.GREEN + "Book sent!"); - receivingPlayer.sendMessage(ChatColor.GREEN + "Book received!"); + sender.sendMessage(successColor + "Book sent!"); + receivingPlayer.sendMessage(successColor + "Book received!"); return true; } else { - sender.sendMessage(ChatColor.RED + "Book failed to load!"); + sender.sendMessage(errorColor + "Book failed to load!"); return false; } } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "Invalid number of book copies specified!"); + sender.sendMessage(errorColor + "Invalid number of book copies specified!"); return false; } } @@ -1013,7 +1016,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (sender instanceof Player) { if (!sender.hasPermission("bookswithoutborders.admin")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } } @@ -1026,14 +1029,14 @@ public class BooksWithoutBorders extends JavaPlugin { //actual deletion if (args.length == 2) { if (!loadList.containsKey(sender.getName())) { - sender.sendMessage(ChatColor.RED + "You must first use /bwb deletePublic to create a list of delete-able files!"); + sender.sendMessage(errorColor + "You must first use /bwb deletePublic to create a list of delete-able files!"); return false; } else { if (!loadList.get(sender.getName()).isEmpty()) { deleteBook((sender), args[1], true); return true; } else { - sender.sendMessage(ChatColor.RED + "No files available to delete!"); + sender.sendMessage(errorColor + "No files available to delete!"); return false; } } @@ -1042,7 +1045,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (args[0].equalsIgnoreCase("setBookPrice")) { if (!sender.hasPermission("bookswithoutborders.setbookprice")) { - sender.sendMessage(ChatColor.RED + " You don't have permission to use this command!"); + sender.sendMessage(errorColor + " You don't have permission to use this command!"); return false; } @@ -1053,29 +1056,29 @@ public class BooksWithoutBorders extends JavaPlugin { this.getConfig().set("Options.Price_to_create_book.Required_quantity", bookPriceQuantity); this.saveConfig(); - sender.sendMessage(ChatColor.GREEN + "Price to create books removed!"); + sender.sendMessage(successColor + "Price to create books removed!"); return true; } if (args.length < 3) { - sender.sendMessage(ChatColor.RED + "[Item/Eco] and [quantity] must be specified!"); + sender.sendMessage(errorColor + "[Item/Eco] and [quantity] must be specified!"); return false; } if (!args[1].equalsIgnoreCase("Item") && !args[1].equalsIgnoreCase("Eco")) { - sender.sendMessage(ChatColor.RED + "Price type must be \"Item\" or \"Eco\"!"); + sender.sendMessage(errorColor + "Price type must be \"Item\" or \"Eco\"!"); return false; } try { if (Double.parseDouble(args[2]) <= 0) { - sender.sendMessage(ChatColor.RED + "[quantity] must be greater than 0!"); + sender.sendMessage(errorColor + "[quantity] must be greater than 0!"); return false; } if (args[1].equalsIgnoreCase("Item")) { if (((Player) sender).getItemInHand().getType() == Material.AIR) { - sender.sendMessage(ChatColor.RED + "Must be holding an item to set an [Item] price!"); + sender.sendMessage(errorColor + "Must be holding an item to set an [Item] price!"); return false; } @@ -1085,7 +1088,7 @@ public class BooksWithoutBorders extends JavaPlugin { this.getConfig().set("Options.Price_to_create_book.Required_quantity", bookPriceQuantity); this.saveConfig(); - sender.sendMessage(ChatColor.GREEN + "Book creation price set to " + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s)!"); + sender.sendMessage(successColor + "Book creation price set to " + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s)!"); return true; } else if (args[1].equalsIgnoreCase("Eco")) { if (setupEconomy()) { @@ -1095,20 +1098,20 @@ public class BooksWithoutBorders extends JavaPlugin { this.getConfig().set("Options.Price_to_create_book.Required_quantity", bookPriceQuantity); this.saveConfig(); - sender.sendMessage(ChatColor.GREEN + "Book creation price set to " + eco.format(bookPriceQuantity) + "!"); + sender.sendMessage(successColor + "Book creation price set to " + eco.format(bookPriceQuantity) + "!"); return true; } else { - sender.sendMessage(ChatColor.RED + "BooksWithoutBorders failed to hook into Vault! Book price not set!"); + sender.sendMessage(errorColor + "BooksWithoutBorders failed to hook into Vault! Book price not set!"); return false; } } } catch (NumberFormatException e) { - sender.sendMessage(ChatColor.RED + "[quantity] must be a number!"); + sender.sendMessage(errorColor + "[quantity] must be a number!"); } } - sender.sendMessage(ChatColor.RED + "Command not recognized! Use " + ChatColor.YELLOW + "/BwB" + ChatColor.RED + " for more info!"); + sender.sendMessage(errorColor + "Command not recognized! Use " + commandColor + "/BwB" + errorColor + " for more info!"); } return false; } @@ -1282,7 +1285,7 @@ public class BooksWithoutBorders extends JavaPlugin { //if this is a private save, make sure the dir exists if (!file.exists()) { if (!file.mkdir()) { - player.sendMessage(ChatColor.RED + "Saving Failed! If this continues to happen, consult server admin!"); + player.sendMessage(errorColor + "Saving Failed! If this continues to happen, consult server admin!"); return; } } @@ -1305,14 +1308,14 @@ public class BooksWithoutBorders extends JavaPlugin { } if (dupes > 0) { if (!fname.contains("Untitled") && dupe.equalsIgnoreCase("false")) { - player.sendMessage(ChatColor.RED + "Book is already saved!"); - player.sendMessage(ChatColor.RED + "Use " + ChatColor.YELLOW + "/bwb Save true " + ChatColor.RED + "to overwrite!"); + player.sendMessage(errorColor + "Book is already saved!"); + player.sendMessage(errorColor + "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); return; } if (dupes > bookDuplicateLimit) { - player.sendMessage(ChatColor.RED + "Maximum amount of " + fname + " duplicates reached!"); - player.sendMessage(ChatColor.RED + "Use " + ChatColor.YELLOW + "/bwb Save true " + ChatColor.RED + "to overwrite!"); + player.sendMessage(errorColor + "Maximum amount of " + fname + " duplicates reached!"); + player.sendMessage(errorColor + "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); return; } @@ -1327,7 +1330,7 @@ public class BooksWithoutBorders extends JavaPlugin { else bookToTXT(path, fname, book); - player.sendMessage(ChatColor.GREEN + "Book Saved as \"" + fname + "\""); + player.sendMessage(successColor + "Book Saved as \"" + fname + "\""); } catch (IOException e) { e.printStackTrace(); } @@ -1370,7 +1373,7 @@ public class BooksWithoutBorders extends JavaPlugin { file = null; if (!file.isFile()) { - sender.sendMessage(ChatColor.RED + "Incorrect file name!"); + sender.sendMessage(errorColor + "Incorrect file name!"); return null; } break NameCheck; @@ -1403,7 +1406,7 @@ public class BooksWithoutBorders extends JavaPlugin { file = null; if (!file.isFile()) { - sender.sendMessage(ChatColor.RED + "Incorrect file name!"); + sender.sendMessage(errorColor + "Incorrect file name!"); return null; } } @@ -1419,7 +1422,7 @@ public class BooksWithoutBorders extends JavaPlugin { bookFromYml(file, bDat); if (bDat == null) { - sender.sendMessage(ChatColor.RED + "File was blank!!"); + sender.sendMessage(errorColor + "File was blank!!"); return null; } @@ -1461,7 +1464,7 @@ public class BooksWithoutBorders extends JavaPlugin { bookToYml(path, fname, book); } catch (IOException e) { e.printStackTrace(); - player.sendMessage(ChatColor.RED + "Encrypted failed!"); + player.sendMessage(errorColor + "Encrypted failed!"); return false; } return true; @@ -1474,7 +1477,7 @@ public class BooksWithoutBorders extends JavaPlugin { if (!dirTest.exists()) { try { if (!dirTest.mkdir()) { - consoleSender.sendMessage(ChatColor.RED + "Unable to create encryption group folder!"); + consoleSender.sendMessage(errorColor + "Unable to create encryption group folder!"); return null; } } catch (Exception e) { @@ -1502,7 +1505,7 @@ public class BooksWithoutBorders extends JavaPlugin { bookToYml(path, fname, book); } catch (IOException e) { e.printStackTrace(); - player.sendMessage(ChatColor.RED + "Group encrypted failed!"); + player.sendMessage(errorColor + "Group encrypted failed!"); return null; } } @@ -1524,14 +1527,14 @@ public class BooksWithoutBorders extends JavaPlugin { file = new File(path + fname + ".txt"); if (!file.isFile()) { - player.sendMessage(ChatColor.RED + "Incorrect decryption key!"); + player.sendMessage(errorColor + "Incorrect decryption key!"); return null; } } else { try { book = bookFromYml(file, book); } catch (Exception e) { - player.sendMessage(ChatColor.RED + "Decryption failed!"); + player.sendMessage(errorColor + "Decryption failed!"); return null; } } @@ -1540,8 +1543,8 @@ public class BooksWithoutBorders extends JavaPlugin { try { file.delete(); } catch (Exception e) { - consoleSender.sendMessage(ChatColor.RED + "Book encryption data failed to delete upon decryption!"); - consoleSender.sendMessage(ChatColor.RED + "File location:" + file.getPath()); + consoleSender.sendMessage(errorColor + "Book encryption data failed to delete upon decryption!"); + consoleSender.sendMessage(errorColor + "File location:" + file.getPath()); } } @@ -1558,17 +1561,17 @@ public class BooksWithoutBorders extends JavaPlugin { File[] fl = file.listFiles(); if (!file.exists()) { - sender.sendMessage(ChatColor.RED + "No books have been saved!"); + sender.sendMessage(errorColor + "No books have been saved!"); return null; } if (fl.length == 0) { - sender.sendMessage(ChatColor.RED + "No books have been saved!"); + sender.sendMessage(errorColor + "No books have been saved!"); return null; } if (!silent) - sender.sendMessage(ChatColor.GREEN + "Available Books:"); + sender.sendMessage(successColor + "Available Books:"); for (File value : fl) { if (value.isFile()) { fileList.add(value.getName()); @@ -1646,18 +1649,18 @@ public class BooksWithoutBorders extends JavaPlugin { return rawPages; } - protected ItemStack encryptBook(Player player, boolean mainHand, String key, String style) { + protected ItemStack encryptBook(Player player, boolean mainHand, String key, EncryptionStyle style) { return encryptBook(player, mainHand, key, style, ""); } - protected ItemStack encryptBook(Player player, boolean mainHand, String key, String style, String groupName) { + protected ItemStack encryptBook(Player player, boolean mainHand, String key, EncryptionStyle style, String groupName) { //converts user supplied key into integer form String integerKey = EncryptionHelper.getNumberKeyFromStringKey(key); BookMeta book = getHeldBookMetadata(player, mainHand); if (!book.hasPages()) { - player.sendMessage(ChatColor.RED + "Book is empty!"); + player.sendMessage(errorColor + "Book is empty!"); return null; } @@ -1668,29 +1671,31 @@ public class BooksWithoutBorders extends JavaPlugin { List encryptedPages = new ArrayList<>(); List nuPages; - if (style.equalsIgnoreCase("dna")) { - GenenCrypt gc = new GenenCrypt(integerKey.substring(0, (integerKey.length())));//Length used to be divided by /4 + if (style == EncryptionStyle.DNA) { + GenenCrypt gc = new GenenCrypt(integerKey); for (int x = 0; x < book.getPages().size(); x++) { encryptedPages.add(gc.encrypt(book.getPage(x + 1))); } - } else if (style.equalsIgnoreCase("magic")) { + } else if (style == EncryptionStyle.MAGIC) { for (int i = 0; i < book.getPages().size(); i++) { String page = book.getPage(i + 1); page = "ァk" + page.replace("ァ", ""); encryptedPages.add(page); } - } else { + } else if (style == EncryptionStyle.SUBSTITUTION) { SubstitutionCipher sc = new SubstitutionCipher(); for (int x = 0; x < book.getPages().size(); x++) { encryptedPages.add(sc.encrypt(book.getPage(x + 1), integerKey)); } + } else { + player.sendMessage(errorColor + "Invalid encryption style encountered!"); } encryptedPages = pageFormat(encryptedPages); nuPages = cleanList(encryptedPages); - player.sendMessage(ChatColor.GREEN + "Book encrypted!"); + player.sendMessage(successColor + "Book encrypted!"); encryptedBook = new ItemStack(Material.WRITTEN_BOOK); book.setPages(nuPages); encryptedBook.setItemMeta(book); @@ -1731,19 +1736,19 @@ public class BooksWithoutBorders extends JavaPlugin { //Send message if no such file could be found if (file == null) { - sender.sendMessage(ChatColor.RED + "Incorrect file name!"); + sender.sendMessage(errorColor + "Incorrect file name!"); return; } //Try to delete the file try { if (file.delete()) { - sender.sendMessage(ChatColor.GREEN + "\"" + fileName + "\" deleted successfully"); + sender.sendMessage(successColor + "\"" + fileName + "\" deleted successfully"); } else { - sender.sendMessage(ChatColor.RED + "Deletion failed without an exception!"); + sender.sendMessage(errorColor + "Deletion failed without an exception!"); } } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Deletion failed!"); + sender.sendMessage(errorColor + "Deletion failed!"); } } @@ -1821,7 +1826,7 @@ public class BooksWithoutBorders extends JavaPlugin { payForBookPrintingItem(player, itemCost); return false; } else { - player.sendMessage(ChatColor.RED + String.valueOf(itemCost) + " " + bookPriceType.toString() + + player.sendMessage(errorColor + String.valueOf(itemCost) + " " + bookPriceType.toString() + "(s) are required for this command!"); return true; } @@ -1864,11 +1869,11 @@ public class BooksWithoutBorders extends JavaPlugin { Economy economy = BooksWithoutBorders.eco; if ((economy.getBalance(player) - cost) >= 0) { economy.withdrawPlayer(player, cost); - player.sendMessage(ChatColor.GREEN + economy.format(cost) + " withdrawn to create " + numCopies + " book(s)"); - player.sendMessage(ChatColor.GREEN + "New balance: " + economy.format(economy.getBalance(player))); + player.sendMessage(successColor + economy.format(cost) + " withdrawn to create " + numCopies + " book(s)"); + player.sendMessage(successColor + "New balance: " + economy.format(economy.getBalance(player))); return true; } else { - player.sendMessage(ChatColor.RED + economy.format(cost) + " is required for this command!"); + player.sendMessage(errorColor + economy.format(cost) + " is required for this command!"); return false; } } @@ -1886,7 +1891,7 @@ public class BooksWithoutBorders extends JavaPlugin { return true; } - player.sendMessage(ChatColor.RED + "You must be the author of this book to use this command!"); + player.sendMessage(errorColor + "You must be the author of this book to use this command!"); return false; } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBordersListener.java b/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBordersListener.java index 1dc2dc2..0d64df2 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBordersListener.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/BooksWithoutBordersListener.java @@ -384,7 +384,8 @@ public class BooksWithoutBordersListener implements Listener { boolean mainHand = hand == EquipmentSlot.HAND; if (heldItemType == Material.WRITTEN_BOOK) { player.closeInventory(); - eBook = BooksWithoutBorders.bwb.encryptBook(player, mainHand, lines[2].substring(2), lines[3].substring(2)); + eBook = BooksWithoutBorders.bwb.encryptBook(player, mainHand, ChatColor.stripColor(lines[2]), + EncryptionStyle.getFromString(ChatColor.stripColor(lines[3]))); if (eBook != null) { player.getInventory().setItem(hand, eBook); } @@ -398,7 +399,7 @@ public class BooksWithoutBordersListener implements Listener { * @param player

The player which clicked the sign

*/ private void giveBook(Sign sign, Player player) { - String fileName = sign.getLine(2).substring(2); + String fileName = ChatColor.stripColor(sign.getLine(2)); boolean isLoadListNumber = false; for (int x = 0; x < fileName.length(); x++) { @@ -411,7 +412,7 @@ public class BooksWithoutBordersListener implements Listener { } if (!isLoadListNumber && sign.getLine(3).length() >= 2) - fileName = sign.getLine(2).substring(2) + sign.getLine(3).substring(2); + fileName = ChatColor.stripColor(sign.getLine(2)) + ChatColor.stripColor(sign.getLine(3)); ItemStack newBook = BooksWithoutBorders.bwb.loadBook(player, fileName, "true", "public"); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/EncryptionStyle.java b/src/main/java/net/knarcraft/bookswithoutborders/EncryptionStyle.java new file mode 100644 index 0000000..224c70d --- /dev/null +++ b/src/main/java/net/knarcraft/bookswithoutborders/EncryptionStyle.java @@ -0,0 +1,30 @@ +package net.knarcraft.bookswithoutborders; + +/** + * This enum represents the different available encryption styles + */ +public enum EncryptionStyle { + DNA("dna"), + MAGIC("magic"), + SUBSTITUTION(""); + + private final String name; + + EncryptionStyle(String name) { + this.name = name; + } + + /** + * Gets an encryption style given its name + * @param name

The name of the encryption style

+ * @return

An encryption style or null if no match is found

+ */ + public static EncryptionStyle getFromString(String name) { + for (EncryptionStyle style : EncryptionStyle.values()) { + if (style.name.equalsIgnoreCase(name)) { + return style; + } + } + return null; + } +}