Makes error message formatting more customizable
This commit is contained in:
		| @@ -75,13 +75,13 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|     } | ||||
|  | ||||
|     protected boolean init() { | ||||
|         try //initializes Item Factory | ||||
|         { | ||||
|         //initializes Item Factory | ||||
|         try { | ||||
|             iF = this.getServer().getItemFactory(); | ||||
|         } catch (java.lang.NoSuchMethodError nsmE) { | ||||
|             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!"); | ||||
|             sendErrorMessage(consoleSender, "Warning! [BooksWithoutBorders] failed to initialize!"); | ||||
|             sendErrorMessage(consoleSender, "Please confirm the correct version of [BooksWithoutBorders] is"); | ||||
|             sendErrorMessage(consoleSender, "being run for this version of bukkit!"); | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
| @@ -130,7 +130,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         if (!fTest.exists()) { | ||||
|             try { | ||||
|                 if (!fTest.mkdir()) { | ||||
|                     consoleSender.sendMessage(errorColor + "Saving failed! Aborting..."); | ||||
|                     sendErrorMessage(consoleSender, "Saving failed! Aborting..."); | ||||
|                     return false; | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
| @@ -141,7 +141,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         if (!efTest.exists()) { | ||||
|             try { | ||||
|                 if (!efTest.mkdir()) { | ||||
|                     consoleSender.sendMessage(errorColor + "Saving failed! Aborting..."); | ||||
|                     sendErrorMessage(consoleSender, "Saving failed! Aborting..."); | ||||
|                     return false; | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
| @@ -177,7 +177,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 if (setupEconomy()) | ||||
|                     bookPriceType = Material.AIR; | ||||
|                 else { | ||||
|                     consoleSender.sendMessage(errorColor + "BooksWithoutBorders failed to hook into Vault! Book price not set!"); | ||||
|                     sendErrorMessage(consoleSender, "BooksWithoutBorders failed to hook into Vault! Book price not set!"); | ||||
|                     bookPriceType = null; | ||||
|                 } | ||||
|             } else if (!sMaterial.equalsIgnoreCase(" ")) { | ||||
| @@ -188,17 +188,17 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             } | ||||
|             bookPriceQuantity = this.getConfig().getDouble("Options.Price_to_create_book.Required_quantity", 0); | ||||
|  | ||||
|             //makes sure TsepA is a valid value | ||||
|             //makes sure titleAuthorSeparator is a valid value | ||||
|             titleAuthorSeparator = cleanString(titleAuthorSeparator); | ||||
|             if (titleAuthorSeparator.length() != 1) { | ||||
|                 consoleSender.sendMessage(errorColor + "Title-Author_Separator is set to an invalid value!"); | ||||
|                 consoleSender.sendMessage(errorColor + "Reverting to default value of \",\""); | ||||
|                 sendErrorMessage(consoleSender, "Title-Author_Separator is set to an invalid value!"); | ||||
|                 sendErrorMessage(consoleSender, "Reverting to default value of \",\""); | ||||
|                 titleAuthorSeparator = ","; | ||||
|                 this.getConfig().set("Options.Title-Author_Separator", titleAuthorSeparator); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             consoleSender.sendMessage(errorColor + "Warning! Config.yml failed to load!"); | ||||
|             consoleSender.sendMessage(errorColor + "Try Looking for settings that are missing values!"); | ||||
|             sendErrorMessage(consoleSender, "Warning! Config.yml failed to load!"); | ||||
|             sendErrorMessage(consoleSender, "Try Looking for settings that are missing values!"); | ||||
|             return false; | ||||
|         } | ||||
|  | ||||
| @@ -225,7 +225,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         if (!fTest.exists()) { | ||||
|             try { | ||||
|                 if (!fTest.createNewFile()) { | ||||
|                     consoleSender.sendMessage(errorColor + "Could not create Existing Players file! Aborting..."); | ||||
|                     sendErrorMessage(consoleSender, "Could not create Existing Players file! Aborting..."); | ||||
|                     return false; | ||||
|                 } | ||||
|                 PrintWriter pw = new PrintWriter(new FileWriter(fTest)); | ||||
| @@ -269,7 +269,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             pw.println(playerName); | ||||
|             pw.close(); | ||||
|         } catch (IOException e) { | ||||
|             consoleSender.sendMessage(errorColor + "Failed to add " + playerName + " to Existing Players list"); | ||||
|             sendErrorMessage(consoleSender, "Failed to add " + playerName + " to Existing Players list"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -292,10 +292,11 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 sender.sendMessage(commandColor + "[] denote parameters"); | ||||
|  | ||||
|                 if (booksHavePrice()) { | ||||
|                     if (bookPriceType != Material.AIR) | ||||
|                         sender.sendMessage(errorColor + "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]"); | ||||
|                     else | ||||
|                         sender.sendMessage(errorColor + "[" + BooksWithoutBorders.eco.format(bookPriceQuantity) + " is required to create a book]"); | ||||
|                     if (bookPriceType != Material.AIR) { | ||||
|                         sendErrorMessage(sender, "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]"); | ||||
|                     } else { | ||||
|                         sendErrorMessage(sender, "[" + BooksWithoutBorders.eco.format(bookPriceQuantity) + " is required to create a book]"); | ||||
|                     } | ||||
|                 } | ||||
|                 sender.sendMessage(commandColor + "Commands:"); | ||||
|  | ||||
| @@ -391,7 +392,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             if (args[0].equalsIgnoreCase("reload")) { | ||||
|                 if (sender instanceof Player) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.admin") && !sender.hasPermission("*")) { | ||||
|                         sender.sendMessage(errorColor + "You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, "You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
| @@ -399,8 +400,8 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 if (loadConfig() && loadExistingPlayers()) | ||||
|                     sender.sendMessage(successColor + "BooksWithoutBorders configuration reloaded!"); | ||||
|                 else { | ||||
|                     sender.sendMessage(errorColor + "Reload Failed!"); | ||||
|                     sender.sendMessage(errorColor + "See console for details"); | ||||
|                     sendErrorMessage(sender, "Reload Failed!"); | ||||
|                     sendErrorMessage(sender, "See console for details"); | ||||
|                 } | ||||
|                 return true; | ||||
|             } | ||||
| @@ -410,7 +411,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("savePublic")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.savepublic")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -422,14 +423,14 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                         } | ||||
|                         return true; | ||||
|                     } else { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book or book and quill to save it!"); | ||||
|                         sendErrorMessage(sender, "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(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -441,19 +442,19 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                         } | ||||
|                         return true; | ||||
|                     } else { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book or book and quill to save it!"); | ||||
|                         sendErrorMessage(sender, "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(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (((Player) sender).getInventory().firstEmpty() == -1) { | ||||
|                         sender.sendMessage(errorColor + "You must have space in your inventory to load books!"); | ||||
|                         sendErrorMessage(sender, "You must have space in your inventory to load books!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -486,23 +487,23 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                             sender.sendMessage(successColor + "Book created!"); | ||||
|                             return true; | ||||
|                         } else { | ||||
|                             sender.sendMessage(errorColor + "Book failed to load!"); | ||||
|                             sendErrorMessage(sender, "Book failed to load!"); | ||||
|                             return false; | ||||
|                         } | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         sender.sendMessage(errorColor + "Invalid number of book copies specified!"); | ||||
|                         sendErrorMessage(sender, "Invalid number of book copies specified!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("load")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.load")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (((Player) sender).getInventory().firstEmpty() == -1) { | ||||
|                         sender.sendMessage(errorColor + "You must have space in your inventory to load books!"); | ||||
|                         sendErrorMessage(sender, "You must have space in your inventory to load books!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -536,23 +537,23 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                             sender.sendMessage(successColor + "Book created!"); | ||||
|                             return true; | ||||
|                         } else { | ||||
|                             sender.sendMessage(errorColor + "Book failed to load!"); | ||||
|                             sendErrorMessage(sender, "Book failed to load!"); | ||||
|                             return false; | ||||
|                         } | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         sender.sendMessage(errorColor + "Invalid number of book copies specified!"); | ||||
|                         sendErrorMessage(sender, "Invalid number of book copies specified!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("give")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.give")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " 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(errorColor + "Incorrect number of arguments for this command!"); | ||||
|                     if (args.length == 2 || args.length > 5) { | ||||
|                         sendErrorMessage(sender, "Incorrect number of arguments for this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -571,12 +572,12 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                     ItemStack newBook; | ||||
|                     Player receivingPlayer = this.getServer().getPlayer(args[2]); | ||||
|                     if (receivingPlayer == null) { | ||||
|                         sender.sendMessage(errorColor + "Player not found!"); | ||||
|                         sendErrorMessage(sender, "Player not found!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (receivingPlayer.getInventory().firstEmpty() == -1) { | ||||
|                         sender.sendMessage(errorColor + "Receiving player must have space in their inventory to receive books!"); | ||||
|                         sendErrorMessage(sender, "Receiving player must have space in their inventory to receive books!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -599,18 +600,18 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                             receivingPlayer.sendMessage(successColor + "Book received!"); | ||||
|                             return true; | ||||
|                         } else { | ||||
|                             sender.sendMessage(errorColor + "Book failed to load!"); | ||||
|                             sendErrorMessage(sender, "Book failed to load!"); | ||||
|                             return false; | ||||
|                         } | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         sender.sendMessage(errorColor + "Invalid number of book copies specified!"); | ||||
|                         sendErrorMessage(sender, "Invalid number of book copies specified!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("delete")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.delete")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -622,14 +623,14 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                     //actual deletion | ||||
|                     if (args.length == 2) { | ||||
|                         if (!loadList.containsKey(sender.getName())) { | ||||
|                             sender.sendMessage(errorColor + "You must first use /bwb delete to create a list of delete-able files!"); | ||||
|                             sendErrorMessage(sender, "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(errorColor + "No files available to delete!"); | ||||
|                                 sendErrorMessage(sender, "No files available to delete!"); | ||||
|                                 return false; | ||||
|                             } | ||||
|                         } | ||||
| @@ -638,12 +639,12 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("unsign")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.unsign")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book to unsign it!"); | ||||
|                         sendErrorMessage(sender, "You must be holding a written book to unsign it!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -652,7 +653,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(errorColor + "You cannot un-sign two books at once. Please un-equip one " + | ||||
|                         sendErrorMessage(sender, "You cannot un-sign two books at once. Please un-equip one " + | ||||
|                                 "of the books you're holding!"); | ||||
|                     } else if (hasBookInMainHand) { | ||||
|                         unSignHeldBook(player, true); | ||||
| @@ -664,17 +665,17 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("copy")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.copy")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book to copy it!"); | ||||
|                         sendErrorMessage(sender, "You must be holding a written book to copy it!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args.length < 2) { | ||||
|                         sender.sendMessage(errorColor + "You must specifiy the number of copies to be made!"); | ||||
|                         sendErrorMessage(sender, "You must specifiy the number of copies to be made!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -694,13 +695,13 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                             ((Player) sender).getItemInHand().setAmount(((Player) sender).getItemInHand().getAmount() + Integer.parseInt(args[1])); | ||||
|                             sender.sendMessage(successColor + "Book copied!"); | ||||
|                         } else { | ||||
|                             sender.sendMessage(errorColor + "Book not copied!"); | ||||
|                             sender.sendMessage(errorColor + "Number specified was invalid!"); | ||||
|                             sendErrorMessage(sender, "Book not copied!"); | ||||
|                             sendErrorMessage(sender, "Number specified was invalid!"); | ||||
|                             return false; | ||||
|                         } | ||||
|                     } catch (NumberFormatException e) { | ||||
|                         sender.sendMessage(errorColor + "Book not copied!"); | ||||
|                         sender.sendMessage(errorColor + "Number specified was invalid!"); | ||||
|                         sendErrorMessage(sender, "Book not copied!"); | ||||
|                         sendErrorMessage(sender, "Number specified was invalid!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                     return true; | ||||
| @@ -708,26 +709,26 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("encrypt")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.encrypt")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book to encrypt it!"); | ||||
|                         sendErrorMessage(sender, "You must be holding a written book to encrypt it!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args.length < 2) { | ||||
|                         sender.sendMessage(errorColor + "You must specify a key to encrypt a book!"); | ||||
|                         sendErrorMessage(sender, "You must specify a key to encrypt a book!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                     if (args.length > 3) { | ||||
|                         sender.sendMessage(errorColor + "Too many command options specified!"); | ||||
|                         sendErrorMessage(sender, "Too many command options specified!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!((BookMeta) ((Player) sender).getItemInHand().getItemMeta()).hasPages()) { | ||||
|                         sender.sendMessage(errorColor + "Book must have contents to encrypt!"); | ||||
|                         sendErrorMessage(sender, "Book must have contents to encrypt!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -748,32 +749,32 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("groupEncrypt")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.groupencrypt")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book to encrypt it!"); | ||||
|                         sendErrorMessage(sender, "You must be holding a written book to encrypt it!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args.length < 3) { | ||||
|                         sender.sendMessage(errorColor + "You must specify a key to encrypt a book!"); | ||||
|                         sendErrorMessage(sender, "You must specify a key to encrypt a book!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                     if (args.length > 4) { | ||||
|                         sender.sendMessage(errorColor + "Too many command options specified!"); | ||||
|                         sendErrorMessage(sender, "Too many command options specified!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!((BookMeta) ((Player) sender).getItemInHand().getItemMeta()).hasPages()) { | ||||
|                         sender.sendMessage(errorColor + "Book must have contents to encrypt!"); | ||||
|                         sendErrorMessage(sender, "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(errorColor + "Book is already group encrypted!"); | ||||
|                         sendErrorMessage(sender, "Book is already group encrypted!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -794,12 +795,12 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("decrypt")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.decrypt")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book to decrypt it!"); | ||||
|                         sendErrorMessage(sender, "You must be holding a written book to decrypt it!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -826,7 +827,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                             } else | ||||
|                                 return false; | ||||
|                         } else { | ||||
|                             sender.sendMessage(errorColor + "No matching encypted book found!"); | ||||
|                             sendErrorMessage(sender, "No matching encrypted book found!"); | ||||
|                             return false; | ||||
|                         } | ||||
|                     } | ||||
| @@ -844,17 +845,17 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("setTitle")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.settitle")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args.length < 2) { | ||||
|                         sender.sendMessage(errorColor + "Too few command arguments!"); | ||||
|                         sendErrorMessage(sender, "Too few command arguments!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (((Player) sender).getItemInHand().getType() == Material.AIR) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding an item to set title!"); | ||||
|                         sendErrorMessage(sender, "You must be holding an item to set title!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -885,17 +886,17 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("setAuthor")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.setauthor")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args.length < 2) { | ||||
|                         sender.sendMessage(errorColor + "Too few command arguments!"); | ||||
|                         sendErrorMessage(sender, "Too few command arguments!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (!(((Player) sender).getItemInHand().getType() == Material.WRITTEN_BOOK)) { | ||||
|                         sender.sendMessage(errorColor + "You must be holding a written book to set author!"); | ||||
|                         sendErrorMessage(sender, "You must be holding a written book to set author!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -915,17 +916,17 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (args[0].equalsIgnoreCase("setLore")) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.setlore")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args.length < 2) { | ||||
|                         sender.sendMessage(errorColor + "Missing a command argument!"); | ||||
|                         sendErrorMessage(sender, "Missing a command argument!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (((Player) sender).getItemInHand().getType() == Material.AIR) { | ||||
|                         sender.sendMessage(errorColor + "Must be holding an item to set lore!"); | ||||
|                         sendErrorMessage(sender, "Must be holding an item to set lore!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
| @@ -952,13 +953,13 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             if (args[0].equalsIgnoreCase("givePublic")) { | ||||
|                 if (sender instanceof Player) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.givepublic")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " 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(errorColor + "Incorrect number of arguments for this command!"); | ||||
|                 if (args.length == 2 || args.length > 5) { | ||||
|                     sendErrorMessage(sender, "Incorrect number of arguments for this command!"); | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
| @@ -977,12 +978,12 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 ItemStack newBook; | ||||
|                 Player receivingPlayer = this.getServer().getPlayer(args[2]); | ||||
|                 if (receivingPlayer == null) { | ||||
|                     sender.sendMessage(errorColor + "Player not found!"); | ||||
|                     sendErrorMessage(sender, "Player not found!"); | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
|                 if (receivingPlayer.getInventory().firstEmpty() == -1) { | ||||
|                     sender.sendMessage(errorColor + "Receiving player must have space in their inventory to receive books!"); | ||||
|                     sendErrorMessage(sender, "Receiving player must have space in their inventory to receive books!"); | ||||
|                     return false; | ||||
|                 } | ||||
|                 //bwb give [bookname] [player] [numCopies] [issigned] | ||||
| @@ -1003,11 +1004,11 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                         receivingPlayer.sendMessage(successColor + "Book received!"); | ||||
|                         return true; | ||||
|                     } else { | ||||
|                         sender.sendMessage(errorColor + "Book failed to load!"); | ||||
|                         sendErrorMessage(sender, "Book failed to load!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } catch (NumberFormatException e) { | ||||
|                     sender.sendMessage(errorColor + "Invalid number of book copies specified!"); | ||||
|                     sendErrorMessage(sender, "Invalid number of book copies specified!"); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
| @@ -1016,7 +1017,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|                 if (sender instanceof Player) { | ||||
|                     if (!sender.hasPermission("bookswithoutborders.admin")) { | ||||
|                         sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                         sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                         return false; | ||||
|                     } | ||||
|                 } | ||||
| @@ -1029,14 +1030,14 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 //actual deletion | ||||
|                 if (args.length == 2) { | ||||
|                     if (!loadList.containsKey(sender.getName())) { | ||||
|                         sender.sendMessage(errorColor + "You must first use /bwb deletePublic to create a list of delete-able files!"); | ||||
|                         sendErrorMessage(sender, "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(errorColor + "No files available to delete!"); | ||||
|                             sendErrorMessage(sender, "No files available to delete!"); | ||||
|                             return false; | ||||
|                         } | ||||
|                     } | ||||
| @@ -1045,7 +1046,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|             if (args[0].equalsIgnoreCase("setBookPrice")) { | ||||
|                 if (!sender.hasPermission("bookswithoutborders.setbookprice")) { | ||||
|                     sender.sendMessage(errorColor + " You don't have permission to use this command!"); | ||||
|                     sendErrorMessage(sender, " You don't have permission to use this command!"); | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
| @@ -1061,24 +1062,24 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 } | ||||
|  | ||||
|                 if (args.length < 3) { | ||||
|                     sender.sendMessage(errorColor + "[Item/Eco] and [quantity] must be specified!"); | ||||
|                     sendErrorMessage(sender, "[Item/Eco] and [quantity] must be specified!"); | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
|                 if (!args[1].equalsIgnoreCase("Item") && !args[1].equalsIgnoreCase("Eco")) { | ||||
|                     sender.sendMessage(errorColor + "Price type must be \"Item\" or \"Eco\"!"); | ||||
|                     sendErrorMessage(sender, "Price type must be \"Item\" or \"Eco\"!"); | ||||
|                     return false; | ||||
|                 } | ||||
|  | ||||
|                 try { | ||||
|                     if (Double.parseDouble(args[2]) <= 0) { | ||||
|                         sender.sendMessage(errorColor + "[quantity] must be greater than 0!"); | ||||
|                         sendErrorMessage(sender, "[quantity] must be greater than 0!"); | ||||
|                         return false; | ||||
|                     } | ||||
|  | ||||
|                     if (args[1].equalsIgnoreCase("Item")) { | ||||
|                         if (((Player) sender).getItemInHand().getType() == Material.AIR) { | ||||
|                             sender.sendMessage(errorColor + "Must be holding an item to set an [Item] price!"); | ||||
|                             sendErrorMessage(sender, "Must be holding an item to set an [Item] price!"); | ||||
|                             return false; | ||||
|                         } | ||||
|  | ||||
| @@ -1101,17 +1102,17 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                             sender.sendMessage(successColor + "Book creation price set to " + eco.format(bookPriceQuantity) + "!"); | ||||
|                             return true; | ||||
|                         } else { | ||||
|                             sender.sendMessage(errorColor + "BooksWithoutBorders failed to hook into Vault! Book price not set!"); | ||||
|                             sendErrorMessage(sender, "BooksWithoutBorders failed to hook into Vault! Book price not set!"); | ||||
|                             return false; | ||||
|                         } | ||||
|  | ||||
|                     } | ||||
|                 } catch (NumberFormatException e) { | ||||
|                     sender.sendMessage(errorColor + "[quantity] must be a number!"); | ||||
|                     sendErrorMessage(sender, "[quantity] must be a number!"); | ||||
|                 } | ||||
|             } | ||||
|  | ||||
|             sender.sendMessage(errorColor + "Command not recognized! Use " + commandColor + "/BwB" + errorColor + " for more info!"); | ||||
|             sendErrorMessage(sender, "Command not recognized! Use " + commandColor + "/BwB" + errorColor + " for more info!"); | ||||
|         } | ||||
|         return false; | ||||
|     } | ||||
| @@ -1285,7 +1286,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(errorColor + "Saving Failed! If this continues to happen, consult server admin!"); | ||||
|                 sendErrorMessage(player, "Saving Failed! If this continues to happen, consult server admin!"); | ||||
|                 return; | ||||
|             } | ||||
|         } | ||||
| @@ -1308,14 +1309,14 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         } | ||||
|         if (dupes > 0) { | ||||
|             if (!fname.contains("Untitled") && dupe.equalsIgnoreCase("false")) { | ||||
|                 player.sendMessage(errorColor + "Book is already saved!"); | ||||
|                 player.sendMessage(errorColor + "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); | ||||
|                 sendErrorMessage(player, "Book is already saved!"); | ||||
|                 sendErrorMessage(player, "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
|             if (dupes > bookDuplicateLimit) { | ||||
|                 player.sendMessage(errorColor + "Maximum amount of " + fname + " duplicates reached!"); | ||||
|                 player.sendMessage(errorColor + "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); | ||||
|                 sendErrorMessage(player, "Maximum amount of " + fname + " duplicates reached!"); | ||||
|                 sendErrorMessage(player, "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); | ||||
|                 return; | ||||
|             } | ||||
|  | ||||
| @@ -1373,7 +1374,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                         file = null; | ||||
|  | ||||
|                     if (!file.isFile()) { | ||||
|                         sender.sendMessage(errorColor + "Incorrect file name!"); | ||||
|                         sendErrorMessage(sender, "Incorrect file name!"); | ||||
|                         return null; | ||||
|                     } | ||||
|                     break NameCheck; | ||||
| @@ -1406,7 +1407,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                     file = null; | ||||
|  | ||||
|                 if (!file.isFile()) { | ||||
|                     sender.sendMessage(errorColor + "Incorrect file name!"); | ||||
|                     sendErrorMessage(sender, "Incorrect file name!"); | ||||
|                     return null; | ||||
|                 } | ||||
|             } | ||||
| @@ -1422,7 +1423,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|         bookFromYml(file, bDat); | ||||
|         if (bDat == null) { | ||||
|             sender.sendMessage(errorColor + "File was blank!!"); | ||||
|             sendErrorMessage(sender, "File was blank!!"); | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
| @@ -1464,7 +1465,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             bookToYml(path, fname, book); | ||||
|         } catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|             player.sendMessage(errorColor + "Encrypted failed!"); | ||||
|             sendErrorMessage(player, "Encrypted failed!"); | ||||
|             return false; | ||||
|         } | ||||
|         return true; | ||||
| @@ -1477,7 +1478,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         if (!dirTest.exists()) { | ||||
|             try { | ||||
|                 if (!dirTest.mkdir()) { | ||||
|                     consoleSender.sendMessage(errorColor + "Unable to create encryption group folder!"); | ||||
|                     sendErrorMessage(consoleSender, "Unable to create encryption group folder!"); | ||||
|                     return null; | ||||
|                 } | ||||
|             } catch (Exception e) { | ||||
| @@ -1505,7 +1506,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 bookToYml(path, fname, book); | ||||
|             } catch (IOException e) { | ||||
|                 e.printStackTrace(); | ||||
|                 player.sendMessage(errorColor + "Group encrypted failed!"); | ||||
|                 sendErrorMessage(player, "Group encrypted failed!"); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| @@ -1527,14 +1528,14 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             file = new File(path + fname + ".txt"); | ||||
|  | ||||
|             if (!file.isFile()) { | ||||
|                 player.sendMessage(errorColor + "Incorrect decryption key!"); | ||||
|                 sendErrorMessage(player, "Incorrect decryption key!"); | ||||
|                 return null; | ||||
|             } | ||||
|         } else { | ||||
|             try { | ||||
|                 book = bookFromYml(file, book); | ||||
|             } catch (Exception e) { | ||||
|                 player.sendMessage(errorColor + "Decryption failed!"); | ||||
|                 sendErrorMessage(player, "Decryption failed!"); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
| @@ -1543,8 +1544,8 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             try { | ||||
|                 file.delete(); | ||||
|             } catch (Exception e) { | ||||
|                 consoleSender.sendMessage(errorColor + "Book encryption data failed to delete upon decryption!"); | ||||
|                 consoleSender.sendMessage(errorColor + "File location:" + file.getPath()); | ||||
|                 sendErrorMessage(consoleSender, "Book encryption data failed to delete upon decryption!"); | ||||
|                 sendErrorMessage(consoleSender, "File location:" + file.getPath()); | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @@ -1561,12 +1562,12 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         File[] fl = file.listFiles(); | ||||
|  | ||||
|         if (!file.exists()) { | ||||
|             sender.sendMessage(errorColor + "No books have been saved!"); | ||||
|             sendErrorMessage(sender, "No books have been saved!"); | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         if (fl.length == 0) { | ||||
|             sender.sendMessage(errorColor + "No books have been saved!"); | ||||
|             sendErrorMessage(sender, "No books have been saved!"); | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
| @@ -1660,7 +1661,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         BookMeta book = getHeldBookMetadata(player, mainHand); | ||||
|  | ||||
|         if (!book.hasPages()) { | ||||
|             player.sendMessage(errorColor + "Book is empty!"); | ||||
|             sendErrorMessage(player, "Book is empty!"); | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
| @@ -1689,7 +1690,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                     encryptedPages.add(sc.encrypt(book.getPage(x + 1), integerKey)); | ||||
|                 } | ||||
|             } else { | ||||
|                 player.sendMessage(errorColor + "Invalid encryption style encountered!"); | ||||
|                 sendErrorMessage(player, "Invalid encryption style encountered!"); | ||||
|             } | ||||
|  | ||||
|             encryptedPages = pageFormat(encryptedPages); | ||||
| @@ -1708,6 +1709,15 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Sends an error message to a player | ||||
|      * @param sender <p>The sender to send the message to</p> | ||||
|      * @param message <p>The message to send</p> | ||||
|      */ | ||||
|     private void sendErrorMessage(CommandSender sender, String message) { | ||||
|         sender.sendMessage(errorColor + message); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Deletes the given book | ||||
|      * | ||||
| @@ -1736,7 +1746,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|  | ||||
|         //Send message if no such file could be found | ||||
|         if (file == null) { | ||||
|             sender.sendMessage(errorColor + "Incorrect file name!"); | ||||
|             sendErrorMessage(sender, "Incorrect file name!"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
| @@ -1745,10 +1755,10 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             if (file.delete()) { | ||||
|                 sender.sendMessage(successColor + "\"" + fileName + "\" deleted successfully"); | ||||
|             } else { | ||||
|                 sender.sendMessage(errorColor + "Deletion failed without an exception!"); | ||||
|                 sendErrorMessage(sender, "Deletion failed without an exception!"); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             sender.sendMessage(errorColor + "Deletion failed!"); | ||||
|             sendErrorMessage(sender, "Deletion failed!"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @@ -1826,7 +1836,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|                 payForBookPrintingItem(player, itemCost); | ||||
|                 return false; | ||||
|             } else { | ||||
|                 player.sendMessage(errorColor + String.valueOf(itemCost) + " " + bookPriceType.toString() + | ||||
|                 sendErrorMessage(player, itemCost + " " + bookPriceType.toString() + | ||||
|                         "(s) are required for this command!"); | ||||
|                 return true; | ||||
|             } | ||||
| @@ -1873,7 +1883,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             player.sendMessage(successColor + "New balance: " + economy.format(economy.getBalance(player))); | ||||
|             return true; | ||||
|         } else { | ||||
|             player.sendMessage(errorColor + economy.format(cost) + " is required for this command!"); | ||||
|             sendErrorMessage(player, economy.format(cost) + " is required for this command!"); | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
| @@ -1891,7 +1901,7 @@ public class BooksWithoutBorders extends JavaPlugin { | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         player.sendMessage(errorColor + "You must be the author of this book to use this command!"); | ||||
|         sendErrorMessage(player, "You must be the author of this book to use this command!"); | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user