Moves some settings into the BooksWithoutBordersSettings class

This commit is contained in:
2021-09-02 00:17:04 +02:00
parent 72e080f1c9
commit 996cb5da5c
19 changed files with 241 additions and 127 deletions

View File

@@ -9,10 +9,10 @@ import org.bukkit.entity.Player;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceQuantity;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceType;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.commandColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.sendErrorMessage;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.sendSuccessMessage;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.successColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getCommandColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSuccessColor;
/**
* Command executor for the books without borders (bwb) command
@@ -37,29 +37,31 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
/**
* Shows all commands available to the console
*
* @param sender <p>The console which sent the command</p>
*/
private void showConsoleCommands(CommandSender sender) {
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] [player name] [true/false]: " + successColor);
sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
sender.sendMessage(getCommandColor() + "[] denote parameters");
sender.sendMessage(getCommandColor() + "Commands:");
sender.sendMessage(getCommandColor() + "\nReload:" + getSuccessColor() + " Reloads BwB's config file");
sender.sendMessage(getCommandColor() + "givePublic [file name or number] [player name] [true/false]: " + getSuccessColor());
sendSuccessMessage(sender, "Gives the selected player a book from the public directory");
sendSuccessMessage(sender, "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(getCommandColor() + "deletePublic [file name or number]: " + getSuccessColor() + "Deletes the specified");
sendSuccessMessage(sender, "file in the public directory");
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
}
/**
* Shows all commands available to the sending player
*
* @param sender <p>The player which sent the command</p>
*/
private void showPlayerCommands(CommandSender sender) {
//Lists all commands
sender.sendMessage(commandColor + "Use: /bwb [Command]");
sender.sendMessage(commandColor + "[] denote parameters");
sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
sender.sendMessage(getCommandColor() + "[] denote parameters");
if (booksWithoutBorders.booksHavePrice()) {
if (bookPriceType != Material.AIR) {
@@ -68,80 +70,80 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
sendErrorMessage(sender, "[" + BooksWithoutBorders.eco.format(bookPriceQuantity) + " is required to create a book]");
}
}
sender.sendMessage(commandColor + "Commands:");
sender.sendMessage(getCommandColor() + "Commands:");
if (sender.hasPermission("bookswithoutborders.load")) {
sender.sendMessage(commandColor + "\nLoad [file name or number] [# of copies] [true/false]:");
sender.sendMessage(getCommandColor() + "\nLoad [file name or number] [# of copies] [true/false]:");
sendSuccessMessage(sender, "Creates a book from the specified file and gives it to the player");
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
sendSuccessMessage(sender, "If true is specified the book will be signed, if false it will be");
sendSuccessMessage(sender, "unsigned");
}
if (sender.hasPermission("bookswithoutborders.loadPublic")) {
sender.sendMessage(commandColor + "loadPublic [file name or number] [# of copies] [true/false]:");
sender.sendMessage(getCommandColor() + "loadPublic [file name or number] [# of copies] [true/false]:");
sendSuccessMessage(sender, "Same as Load, but views files in the public directory");
}
if (sender.hasPermission("bookswithoutborders.save")) {
sender.sendMessage("\n" + commandColor + "Save [true/false]: " + successColor + "Saves the book the player is");
sender.sendMessage("\n" + getCommandColor() + "Save [true/false]: " + getSuccessColor() + "Saves the book the player is");
sendSuccessMessage(sender, "holding to a text file in a private directory");
sendSuccessMessage(sender, "If true is specified, a book of the same name by the same");
sendSuccessMessage(sender, "author will be overwritten by the new book");
}
if (sender.hasPermission("bookswithoutborders.savePublic")) {
sender.sendMessage(commandColor + "savePublic [true/false]: " + successColor + "Same as Save,");
sender.sendMessage(getCommandColor() + "savePublic [true/false]: " + getSuccessColor() + "Same as Save,");
sendSuccessMessage(sender, "but saves files in the public directory");
}
if (sender.hasPermission("bookswithoutborders.give")) {
sender.sendMessage("\n" + commandColor + "Give [file name or number] [player name] [# of copies] [true/false]:");
sender.sendMessage("\n" + getCommandColor() + "Give [file name or number] [player name] [# of copies] [true/false]:");
sendSuccessMessage(sender, "Gives the selected player a book from your personal directory");
}
if (sender.hasPermission("bookswithoutborders.givePublic")) {
sender.sendMessage(commandColor + "givePublic [file name or number] [player name] [# of copies] [true/false]:");
sender.sendMessage(getCommandColor() + "givePublic [file name or number] [player name] [# of copies] [true/false]:");
sendSuccessMessage(sender, "Same as give, but uses books from the public directory");
}
if (sender.hasPermission("bookswithoutborders.delete")) {
sender.sendMessage(commandColor + "\nDelete [file name or number]: " + successColor + "Deletes the specified");
sender.sendMessage(getCommandColor() + "\nDelete [file name or number]: " + getSuccessColor() + "Deletes the specified");
sendSuccessMessage(sender, "file in the player's directory");
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
}
if (sender.hasPermission("bookswithoutborders.admin")) {
sender.sendMessage(commandColor + "deletePublic [file name or number]: " + successColor + "Same as Delete,");
sender.sendMessage(getCommandColor() + "deletePublic [file name or number]: " + getSuccessColor() + "Same as Delete,");
sendSuccessMessage(sender, "but deletes files in the public directory");
sender.sendMessage(commandColor + "\nReload:" + successColor + " Reloads BwB's configuration file");
sender.sendMessage(getCommandColor() + "\nReload:" + getSuccessColor() + " Reloads BwB's configuration file");
}
if (sender.hasPermission("bookswithoutborders.unsign")) {
sender.sendMessage("\n" + commandColor + "Unsign: " + successColor + "Un-signs the book the player is holding");
sender.sendMessage("\n" + getCommandColor() + "Unsign: " + getSuccessColor() + "Un-signs the book the player is holding");
}
if (sender.hasPermission("bookswithoutborders.copy")) {
sender.sendMessage("\n" + commandColor + "Copy [number of copies]: " + successColor + "Copies the book the player is holding");
sender.sendMessage("\n" + getCommandColor() + "Copy [number of copies]: " + getSuccessColor() + "Copies the book the player is holding");
}
if (sender.hasPermission("bookswithoutborders.encrypt")) {
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\"");
sender.sendMessage("\n" + getCommandColor() + "Encrypt [key] [style]: " + getSuccessColor() + "Encrypts the book the player is holding");
sender.sendMessage(getCommandColor() + "[key]" + getSuccessColor() + " is required and can be any phrase or number excluding spaces");
sender.sendMessage(getCommandColor() + "[style]" + getSuccessColor() + " is not required. Possible values are \"DNA\" or \"Magic\"");
}
if (sender.hasPermission("bookswithoutborders.groupEncrypt")) {
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");
sender.sendMessage("\n" + getCommandColor() + "groupEncrypt [group name] [key] [style]: " + getSuccessColor() + "Encrypts book so that only players with the" +
"\n bookswithoutborders.decrypt." + getCommandColor() + "[group name]" + getSuccessColor() + " permission may decrypt the book by holding and left clicking the book");
}
if (sender.hasPermission("bookswithoutborders.decrypt")) {
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");
sender.sendMessage("\n" + getCommandColor() + "Decrypt [key]: " + getSuccessColor() + "Decrypts the book the player is holding");
sender.sendMessage(getCommandColor() + "[key]" + getSuccessColor() + " is required and MUST be IDENTICAL to the key used to encrypt held book");
}
if (sender.hasPermission("bookswithoutborders.setTitle")) {
sender.sendMessage("\n" + commandColor + "setTitle [title]: " + successColor + "Sets the title of the book/item the player is holding");
sender.sendMessage("\n" + getCommandColor() + "setTitle [title]: " + getSuccessColor() + "Sets the title of the book/item the player is holding");
}
if (sender.hasPermission("bookswithoutborders.setAuthor")) {
sender.sendMessage("\n" + commandColor + "setAuthor [author]: " + successColor + "Sets the author of the book the player is holding");
sender.sendMessage("\n" + getCommandColor() + "setAuthor [author]: " + getSuccessColor() + "Sets the author of the book the player is holding");
}
if (sender.hasPermission("bookswithoutborders.setLore")) {
sender.sendMessage("\n" + commandColor + "setLore [lore]: " + successColor + "Sets the lore of the item the player is holding");
sender.sendMessage("\n" + getCommandColor() + "setLore [lore]: " + getSuccessColor() + "Sets the lore of the item the player is holding");
sendSuccessMessage(sender, "Insert the lore_line_separator character to force a new line\n[\"~\" by default]");
}
if (sender.hasPermission("bookswithoutborders.setBookPrice")) {
sender.sendMessage("\n" + commandColor + "setBookPrice [Item/Eco] [quantity]: " + successColor + "Sets the per-book-price to create a book via commands." +
sender.sendMessage("\n" + getCommandColor() + "setBookPrice [Item/Eco] [quantity]: " + getSuccessColor() + "Sets the per-book-price to create a book via commands." +
"\nIf [Item], the item in the player's hand in the amount of [quantity] 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.");
}

View File

@@ -12,6 +12,9 @@ import org.bukkit.inventory.meta.BookMeta;
import java.io.File;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSlash;
/**
* Command executor for the decrypt command
*/
@@ -39,7 +42,7 @@ public class CommandDecrypt implements CommandExecutor {
//Warning: admin decrypt only allows decrypting files created by the same player. Not sure if intended
if (args.length == 0 && BooksWithoutBorders.adminDecrypt && player.hasPermission("bookswithoutborders.admin")) {
String path = BooksWithoutBorders.bookFolder + "Encrypted" + BooksWithoutBorders.SLASH;
String path = getBookFolder() + "Encrypted" + getSlash();
String fileName;
if (bookMetadata.hasTitle()) {
fileName = bookMetadata.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetadata.getAuthor();

View File

@@ -10,6 +10,9 @@ import org.bukkit.entity.Player;
import java.io.File;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSlash;
/**
* Command executor for the delete command
*/
@@ -33,8 +36,9 @@ public class CommandDelete implements CommandExecutor {
/**
* Deletes a book
* @param sender <p>The sender trying to delete the book</p>
* @param args <p>The arguments given</p>
*
* @param sender <p>The sender trying to delete the book</p>
* @param args <p>The arguments given</p>
* @param deletePublic <p>Whether to delete a public book</p>
* @return <p>True if the book was deleted successfully</p>
*/
@@ -84,10 +88,10 @@ public class CommandDelete implements CommandExecutor {
//Get the file to be deleted
File file;
if (isPublic) {
file = FileHelper.getBookFile(BooksWithoutBorders.bookFolder + fileName);
file = FileHelper.getBookFile(getBookFolder() + fileName);
} else {
file = FileHelper.getBookFile(BooksWithoutBorders.bookFolder +
InputCleaningHelper.cleanString(sender.getName()) + BooksWithoutBorders.SLASH + fileName);
file = FileHelper.getBookFile(getBookFolder() +
InputCleaningHelper.cleanString(sender.getName()) + getSlash() + fileName);
}
//Send message if no such file could be found

View File

@@ -28,9 +28,10 @@ public class CommandEncrypt implements CommandExecutor {
/**
* Performs necessary pre-checks before going through with the encryption
* @param sender <p>The sender trying to encrypt a book</p>
* @param args <p>The arguments given</p>
* @param necessaryArguments <p>How many arguments is the minimum requirement</p>
*
* @param sender <p>The sender trying to encrypt a book</p>
* @param args <p>The arguments given</p>
* @param necessaryArguments <p>How many arguments is the minimum requirement</p>
* @param missingArgumentsError <p>The error to show if a required argument is missing</p>
* @return <p>The metadata of the book to encrypt, or null if any checks fail</p>
*/
@@ -71,10 +72,11 @@ public class CommandEncrypt implements CommandExecutor {
/**
* Encrypts the given book
*
* @param encryptionStyle <p>The encryption style to use</p>
* @param player <p>The player encrypting the book</p>
* @param key <p>The encryption key to use</p>
* @param group <p>The group to encrypt for</p>
* @param player <p>The player encrypting the book</p>
* @param key <p>The encryption key to use</p>
* @param group <p>The group to encrypt for</p>
* @return <p>True if the book was encrypted successfully</p>
*/
boolean encryptBook(EncryptionStyle encryptionStyle, Player player, String key, String group) {

View File

@@ -60,7 +60,8 @@ public class CommandGive implements CommandExecutor {
try {
Integer.parseInt(bookIdentifier);
BooksWithoutBorders.loadList.put(sender.getName(), booksWithoutBorders.listFiles(sender, givePublic, true));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
Player receivingPlayer = booksWithoutBorders.getServer().getPlayer(receivingPlayerName);
if (receivingPlayer == null) {

View File

@@ -26,9 +26,10 @@ public class CommandLoad implements CommandExecutor {
/**
* Loads a stored book
* @param sender <p>The sender asking to load the book</p>
* @param args <p>The arguments given</p>
* @param directory <p>The directory to load from (public/player)</p>
*
* @param sender <p>The sender asking to load the book</p>
* @param args <p>The arguments given</p>
* @param directory <p>The directory to load from (public/player)</p>
* @param loadPublic <p>Whether to list public files as loadable</p>
* @return <p>True if the book was loaded successfully</p>
*/
@@ -70,7 +71,8 @@ public class CommandLoad implements CommandExecutor {
try {
Integer.parseInt(bookIdentifier);
BooksWithoutBorders.loadList.put(player.getName(), booksWithoutBorders.listFiles(player, loadPublic, true));
} catch (NumberFormatException ignored) {}
} catch (NumberFormatException ignored) {
}
String bookToLoad = InputCleaningHelper.cleanString(bookIdentifier);
try {

View File

@@ -27,8 +27,9 @@ public class CommandSave implements CommandExecutor {
/**
* Saves the player's held book if it exists
* @param sender <p>The sender of the command</p>
* @param args <p>The arguments given</p>
*
* @param sender <p>The sender of the command</p>
* @param args <p>The arguments given</p>
* @param savePublic <p>Whether to save the book in the public directory or the player directory</p>
* @return <p>True if a book was saved successfully</p>
*/

View File

@@ -36,7 +36,7 @@ public class CommandSetBookPrice implements CommandExecutor {
//Warn about invalid argument
if (!args[0].equalsIgnoreCase("Item") && !args[0].equalsIgnoreCase("Eco")) {
BooksWithoutBorders. sendErrorMessage(sender, "Price type must be \"Item\" or \"Eco\"!");
BooksWithoutBorders.sendErrorMessage(sender, "Price type must be \"Item\" or \"Eco\"!");
return false;
}
@@ -60,6 +60,7 @@ public class CommandSetBookPrice implements CommandExecutor {
/**
* Removes the book price
*
* @param sender <p>The sender of the command</p>
*/
private void clearItemPrice(CommandSender sender) {
@@ -74,8 +75,9 @@ public class CommandSetBookPrice implements CommandExecutor {
/**
* Sets the book price to use items, and updates book price
*
* @param sender <p>The sender of the command</p>
* @param price <p>The new price</p>
* @param price <p>The new price</p>
* @return <p>True if the price was changed successfully</p>
*/
private boolean setItemPrice(CommandSender sender, double price) {
@@ -105,8 +107,9 @@ public class CommandSetBookPrice implements CommandExecutor {
/**
* Sets the book price to use economy, and updates book price
*
* @param sender <p>The sender of the command</p>
* @param price <p>The new price</p>
* @param price <p>The new price</p>
* @return <p>True if the price was changed successfully</p>
*/
private boolean setEconomyPrice(CommandSender sender, double price) {