Moves some settings into the BooksWithoutBordersSettings class

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

View File

@ -1,15 +1,15 @@
# Books Without Borders # Books Without Borders
This is an attempt at a rewrite of the Books Without Borders plugin. This rewrite uses the This is an attempt at a rewrite of the Books Without Borders plugin. This rewrite uses the source code given
source code given at [the original bukkit page](https://dev.bukkit.org/projects/books-without-borders). at [the original bukkit page](https://dev.bukkit.org/projects/books-without-borders). I'm not planning any new features
I'm not planning any new features at this time. The only goal is to make it 1.17.1 compliant, but I'll make the code at this time. The only goal is to make it 1.17.1 compliant, but I'll make the code more maintainable along the way.
more maintainable along the way. While the original version still works, it's using a lot of depreciated function calls which will most likely break in
While the original version still works, it's using a lot of depreciated function calls which will the future.
most likely break in the future.
## Books without Borders! ## Books without Borders!
Ever wanted to export your book to a text file? Ever want to import it back in? Accidentally sign it too soon? If so, Books without Borders has got your back! Ever wanted to export your book to a text file? Ever want to import it back in? Accidentally sign it too soon? If so,
Books without Borders has got your back!
### Features ### Features

View File

@ -24,7 +24,6 @@ import net.knarcraft.bookswithoutborders.listener.BooksWithoutBordersListener;
import net.knarcraft.bookswithoutborders.utility.BookToFromTextHelper; import net.knarcraft.bookswithoutborders.utility.BookToFromTextHelper;
import net.knarcraft.bookswithoutborders.utility.FileHelper; import net.knarcraft.bookswithoutborders.utility.FileHelper;
import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.economy.Economy;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -54,6 +53,11 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getCommandColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getErrorColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSlash;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSuccessColor;
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString; import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString;
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixName; import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixName;
@ -62,7 +66,6 @@ public class BooksWithoutBorders extends JavaPlugin {
//The separating string between the book title and the book author //The separating string between the book title and the book author
public static String titleAuthorSeparator; public static String titleAuthorSeparator;
public static String loreSeparator; public static String loreSeparator;
public static final String SLASH = System.getProperty("file.separator");
public static List<String> firstBooks; public static List<String> firstBooks;
public static String welcomeMessage; public static String welcomeMessage;
protected static List<String> existingPlayers; protected static List<String> existingPlayers;
@ -77,21 +80,17 @@ public class BooksWithoutBorders extends JavaPlugin {
public static BooksWithoutBorders bwb; public static BooksWithoutBorders bwb;
protected static BooksWithoutBordersListener bL; protected static BooksWithoutBordersListener bL;
public static ConsoleCommandSender consoleSender; public static ConsoleCommandSender consoleSender;
public static String bookFolder;
public static final ChatColor errorColor = ChatColor.RED;
public static final ChatColor successColor = ChatColor.GREEN;
public static final ChatColor commandColor = ChatColor.YELLOW;
@Override @Override
public void onEnable() { public void onEnable() {
bwb = this; bwb = this;
consoleSender = this.getServer().getConsoleSender(); consoleSender = this.getServer().getConsoleSender();
bookFolder = this.getDataFolder().getAbsolutePath() + SLASH + "Books" + SLASH;
bL = new BooksWithoutBordersListener(); bL = new BooksWithoutBordersListener();
loadList = new HashMap<>(); loadList = new HashMap<>();
firstBooks = new ArrayList<>(); firstBooks = new ArrayList<>();
BooksWithoutBordersSettings.initialize(this);
if (SLASH != null && init()) { if (getSlash() != null && init()) {
this.getServer().getPluginManager().registerEvents(bL, this); this.getServer().getPluginManager().registerEvents(bL, this);
} else { } else {
this.getPluginLoader().disablePlugin(this); this.getPluginLoader().disablePlugin(this);
@ -188,8 +187,8 @@ public class BooksWithoutBorders extends JavaPlugin {
this.saveConfig(); this.saveConfig();
File fTest = new File(bookFolder); File fTest = new File(getBookFolder());
File efTest = new File(bookFolder + "Encrypted" + SLASH); File efTest = new File(getBookFolder() + "Encrypted" + getSlash());
if (!fTest.exists()) { if (!fTest.exists()) {
try { try {
@ -283,7 +282,7 @@ public class BooksWithoutBorders extends JavaPlugin {
} }
public boolean loadExistingPlayers() { public boolean loadExistingPlayers() {
File fTest = new File(this.getDataFolder().getAbsolutePath() + SLASH + "Existing Players.txt"); File fTest = new File(this.getDataFolder().getAbsolutePath() + getSlash() + "Existing Players.txt");
existingPlayers = new ArrayList<>(); existingPlayers = new ArrayList<>();
if (!fTest.exists()) { if (!fTest.exists()) {
@ -329,7 +328,7 @@ public class BooksWithoutBorders extends JavaPlugin {
existingPlayers.add(playerName); existingPlayers.add(playerName);
try { try {
PrintWriter pw = new PrintWriter(new FileWriter(this.getDataFolder().getAbsolutePath() + SLASH + "Existing Players.txt", true)); PrintWriter pw = new PrintWriter(new FileWriter(this.getDataFolder().getAbsolutePath() + getSlash() + "Existing Players.txt", true));
pw.println(playerName); pw.println(playerName);
pw.close(); pw.close();
} catch (IOException e) { } catch (IOException e) {
@ -363,9 +362,9 @@ public class BooksWithoutBorders extends JavaPlugin {
String savePath; String savePath;
if (saveToPublicFolder) { if (saveToPublicFolder) {
savePath = bookFolder; savePath = getBookFolder();
} else { } else {
savePath = bookFolder + cleanString(player.getName()) + SLASH; savePath = getBookFolder() + cleanString(player.getName()) + getSlash();
} }
//Generate book filename //Generate book filename
@ -403,14 +402,14 @@ public class BooksWithoutBorders extends JavaPlugin {
//Skip duplicate book //Skip duplicate book
if (!fileName.contains("Untitled") && !overwrite) { if (!fileName.contains("Untitled") && !overwrite) {
sendErrorMessage(player, "Book is already saved!"); sendErrorMessage(player, "Book is already saved!");
sendErrorMessage(player, "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); sendErrorMessage(player, "Use " + getCommandColor() + "/bwb Save true " + getErrorColor() + "to overwrite!");
return; return;
} }
//Skip if duplicate limit is reached //Skip if duplicate limit is reached
if (foundDuplicates > bookDuplicateLimit) { if (foundDuplicates > bookDuplicateLimit) {
sendErrorMessage(player, "Maximum amount of " + fileName + " duplicates reached!"); sendErrorMessage(player, "Maximum amount of " + fileName + " duplicates reached!");
sendErrorMessage(player, "Use " + commandColor + "/bwb Save true " + errorColor + "to overwrite!"); sendErrorMessage(player, "Use " + getCommandColor() + "/bwb Save true " + getErrorColor() + "to overwrite!");
return; return;
} }
@ -453,11 +452,11 @@ public class BooksWithoutBorders extends JavaPlugin {
File file; File file;
if (dir.equalsIgnoreCase("public")) { if (dir.equalsIgnoreCase("public")) {
file = FileHelper.getBookFile(bookFolder + fileName); file = FileHelper.getBookFile(getBookFolder() + fileName);
} else if (dir.equalsIgnoreCase("player")) { } else if (dir.equalsIgnoreCase("player")) {
file = FileHelper.getBookFile(bookFolder + cleanString(sender.getName()) + SLASH + fileName); file = FileHelper.getBookFile(getBookFolder() + cleanString(sender.getName()) + getSlash() + fileName);
} else if (dir.trim().isEmpty()) { } else if (dir.trim().isEmpty()) {
file = FileHelper.getBookFile(bookFolder + "Encrypted" + SLASH + dir + SLASH + fileName); file = FileHelper.getBookFile(getBookFolder() + "Encrypted" + getSlash() + dir + getSlash() + fileName);
} else { } else {
file = null; file = null;
} }
@ -586,9 +585,9 @@ public class BooksWithoutBorders extends JavaPlugin {
public List<String> listFiles(CommandSender sender, Boolean listPublic, boolean silent) { public List<String> listFiles(CommandSender sender, Boolean listPublic, boolean silent) {
File file; File file;
if (listPublic) { if (listPublic) {
file = new File(bookFolder); file = new File(getBookFolder());
} else { } else {
file = new File(bookFolder + cleanString(sender.getName()) + SLASH); file = new File(getBookFolder() + cleanString(sender.getName()) + getSlash());
} }
return FileHelper.listFiles(sender, file, silent); return FileHelper.listFiles(sender, file, silent);
} }
@ -600,7 +599,7 @@ public class BooksWithoutBorders extends JavaPlugin {
* @param message <p>The message to send</p> * @param message <p>The message to send</p>
*/ */
public static void sendSuccessMessage(CommandSender sender, String message) { public static void sendSuccessMessage(CommandSender sender, String message) {
sender.sendMessage(successColor + message); sender.sendMessage(getSuccessColor() + message);
} }
/** /**
@ -610,7 +609,7 @@ public class BooksWithoutBorders extends JavaPlugin {
* @param message <p>The message to send</p> * @param message <p>The message to send</p>
*/ */
public static void sendErrorMessage(CommandSender sender, String message) { public static void sendErrorMessage(CommandSender sender, String message) {
sender.sendMessage(errorColor + message); sender.sendMessage(getErrorColor() + message);
} }
/** /**

View File

@ -0,0 +1,77 @@
package net.knarcraft.bookswithoutborders;
import org.bukkit.ChatColor;
/**
* Class for getting various settings
*/
public class BooksWithoutBordersSettings {
//Static settings
private static final ChatColor errorColor = ChatColor.RED;
private static final ChatColor successColor = ChatColor.GREEN;
private static final ChatColor commandColor = ChatColor.YELLOW;
private static final String SLASH = System.getProperty("file.separator");
private static boolean isInitialized;
public static String bookFolder;
/**
* Initializes the books without borders settings class
*
* @param booksWithoutBorders <p>The books without borders object used for getting required data</p>
*/
public static void initialize(BooksWithoutBorders booksWithoutBorders) {
if (isInitialized) {
throw new IllegalArgumentException("Settings class initialized twice. This should not happen!");
}
isInitialized = true;
bookFolder = booksWithoutBorders.getDataFolder().getAbsolutePath() + getSlash() + "Books" + getSlash();
}
/**
* Gets the folder used for storing books
*
* @return <p>The folder used for storing books</p>
*/
public static String getBookFolder() {
return bookFolder;
}
/**
* Gets the color to use for error messages
*
* @return <p>The color to use for error messages</p>
*/
public static ChatColor getErrorColor() {
return errorColor;
}
/**
* Gets the color to use for success messages
*
* @return <p>The color to use for success messages</p>
*/
public static ChatColor getSuccessColor() {
return successColor;
}
/**
* Gets the color used to color commands
*
* @return <p>The color used to color commands</p>
*/
public static ChatColor getCommandColor() {
return commandColor;
}
/**
* Gets the correct slash to use for the used OS
*
* @return <p>The slash to use for file separators</p>
*/
public static String getSlash() {
return SLASH;
}
}

View File

@ -1,8 +1,8 @@
package net.knarcraft.bookswithoutborders; package net.knarcraft.bookswithoutborders;
import java.util.Random;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random;
/** /**
* Case-insensitive gene-based encryption * Case-insensitive gene-based encryption
@ -23,6 +23,7 @@ public class GenenCrypt {
/** /**
* Instantiates a new GenenCrypt * Instantiates a new GenenCrypt
*
* @param key <p>The key used to generate the codon table</p> * @param key <p>The key used to generate the codon table</p>
*/ */
public GenenCrypt(String key) { public GenenCrypt(String key) {
@ -126,6 +127,7 @@ public class GenenCrypt {
/** /**
* Encrypts some input * Encrypts some input
*
* @param input <p>The input to encrypt</p> * @param input <p>The input to encrypt</p>
* @return <p>The encrypted input</p> * @return <p>The encrypted input</p>
*/ */
@ -158,6 +160,7 @@ public class GenenCrypt {
/** /**
* Decrypts some input * Decrypts some input
*
* @param input <p>The input to decrypt</p> * @param input <p>The input to decrypt</p>
* @return <p>The decrypted input</p> * @return <p>The decrypted input</p>
*/ */

View File

@ -9,10 +9,10 @@ import org.bukkit.entity.Player;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceQuantity; import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceQuantity;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.bookPriceType; 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.sendErrorMessage;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.sendSuccessMessage; 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 * 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 * Shows all commands available to the console
*
* @param sender <p>The console which sent the command</p> * @param sender <p>The console which sent the command</p>
*/ */
private void showConsoleCommands(CommandSender sender) { private void showConsoleCommands(CommandSender sender) {
sender.sendMessage(commandColor + "Use: /bwb [Command]"); sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
sender.sendMessage(commandColor + "[] denote parameters"); sender.sendMessage(getCommandColor() + "[] denote parameters");
sender.sendMessage(commandColor + "Commands:"); sender.sendMessage(getCommandColor() + "Commands:");
sender.sendMessage(commandColor + "\nReload:" + successColor + " Reloads BwB's config file"); sender.sendMessage(getCommandColor() + "\nReload:" + getSuccessColor() + " Reloads BwB's config file");
sender.sendMessage(commandColor + "givePublic [file name or number] [player name] [true/false]: " + successColor); 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, "Gives the selected player a book from the public directory");
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned"); 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, "file in the public directory");
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned"); sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
} }
/** /**
* Shows all commands available to the sending player * Shows all commands available to the sending player
*
* @param sender <p>The player which sent the command</p> * @param sender <p>The player which sent the command</p>
*/ */
private void showPlayerCommands(CommandSender sender) { private void showPlayerCommands(CommandSender sender) {
//Lists all commands //Lists all commands
sender.sendMessage(commandColor + "Use: /bwb [Command]"); sender.sendMessage(getCommandColor() + "Use: /bwb [Command]");
sender.sendMessage(commandColor + "[] denote parameters"); sender.sendMessage(getCommandColor() + "[] denote parameters");
if (booksWithoutBorders.booksHavePrice()) { if (booksWithoutBorders.booksHavePrice()) {
if (bookPriceType != Material.AIR) { 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]"); 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")) { 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, "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 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, "If true is specified the book will be signed, if false it will be");
sendSuccessMessage(sender, "unsigned"); sendSuccessMessage(sender, "unsigned");
} }
if (sender.hasPermission("bookswithoutborders.loadPublic")) { 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"); sendSuccessMessage(sender, "Same as Load, but views files in the public directory");
} }
if (sender.hasPermission("bookswithoutborders.save")) { 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, "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, "If true is specified, a book of the same name by the same");
sendSuccessMessage(sender, "author will be overwritten by the new book"); sendSuccessMessage(sender, "author will be overwritten by the new book");
} }
if (sender.hasPermission("bookswithoutborders.savePublic")) { 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"); sendSuccessMessage(sender, "but saves files in the public directory");
} }
if (sender.hasPermission("bookswithoutborders.give")) { 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"); sendSuccessMessage(sender, "Gives the selected player a book from your personal directory");
} }
if (sender.hasPermission("bookswithoutborders.givePublic")) { 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"); sendSuccessMessage(sender, "Same as give, but uses books from the public directory");
} }
if (sender.hasPermission("bookswithoutborders.delete")) { 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, "file in the player's directory");
sendSuccessMessage(sender, "If no file is specified, a list of available files is returned"); sendSuccessMessage(sender, "If no file is specified, a list of available files is returned");
} }
if (sender.hasPermission("bookswithoutborders.admin")) { 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"); 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")) { 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")) { 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")) { if (sender.hasPermission("bookswithoutborders.encrypt")) {
sender.sendMessage("\n" + commandColor + "Encrypt [key] [style]: " + successColor + "Encrypts the book the player is holding"); sender.sendMessage("\n" + getCommandColor() + "Encrypt [key] [style]: " + getSuccessColor() + "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(getCommandColor() + "[key]" + getSuccessColor() + " 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(getCommandColor() + "[style]" + getSuccessColor() + " is not required. Possible values are \"DNA\" or \"Magic\"");
} }
if (sender.hasPermission("bookswithoutborders.groupEncrypt")) { if (sender.hasPermission("bookswithoutborders.groupEncrypt")) {
sender.sendMessage("\n" + commandColor + "groupEncrypt [group name] [key] [style]: " + successColor + "Encrypts book so that only players with the" + sender.sendMessage("\n" + getCommandColor() + "groupEncrypt [group name] [key] [style]: " + getSuccessColor() + "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"); "\n bookswithoutborders.decrypt." + getCommandColor() + "[group name]" + getSuccessColor() + " permission may decrypt the book by holding and left clicking the book");
} }
if (sender.hasPermission("bookswithoutborders.decrypt")) { if (sender.hasPermission("bookswithoutborders.decrypt")) {
sender.sendMessage("\n" + commandColor + "Decrypt [key]: " + successColor + "Decrypts the book the player is holding"); sender.sendMessage("\n" + getCommandColor() + "Decrypt [key]: " + getSuccessColor() + "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(getCommandColor() + "[key]" + getSuccessColor() + " is required and MUST be IDENTICAL to the key used to encrypt held book");
} }
if (sender.hasPermission("bookswithoutborders.setTitle")) { 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")) { 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")) { 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]"); sendSuccessMessage(sender, "Insert the lore_line_separator character to force a new line\n[\"~\" by default]");
} }
if (sender.hasPermission("bookswithoutborders.setBookPrice")) { 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 [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."); "\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 java.io.File;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSlash;
/** /**
* Command executor for the decrypt command * 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 //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")) { if (args.length == 0 && BooksWithoutBorders.adminDecrypt && player.hasPermission("bookswithoutborders.admin")) {
String path = BooksWithoutBorders.bookFolder + "Encrypted" + BooksWithoutBorders.SLASH; String path = getBookFolder() + "Encrypted" + getSlash();
String fileName; String fileName;
if (bookMetadata.hasTitle()) { if (bookMetadata.hasTitle()) {
fileName = bookMetadata.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetadata.getAuthor(); fileName = bookMetadata.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetadata.getAuthor();

View File

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

View File

@ -28,6 +28,7 @@ public class CommandEncrypt implements CommandExecutor {
/** /**
* Performs necessary pre-checks before going through with the encryption * Performs necessary pre-checks before going through with the encryption
*
* @param sender <p>The sender trying to encrypt a book</p> * @param sender <p>The sender trying to encrypt a book</p>
* @param args <p>The arguments given</p> * @param args <p>The arguments given</p>
* @param necessaryArguments <p>How many arguments is the minimum requirement</p> * @param necessaryArguments <p>How many arguments is the minimum requirement</p>
@ -71,6 +72,7 @@ public class CommandEncrypt implements CommandExecutor {
/** /**
* Encrypts the given book * Encrypts the given book
*
* @param encryptionStyle <p>The encryption style to use</p> * @param encryptionStyle <p>The encryption style to use</p>
* @param player <p>The player encrypting the book</p> * @param player <p>The player encrypting the book</p>
* @param key <p>The encryption key to use</p> * @param key <p>The encryption key to use</p>

View File

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

View File

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

View File

@ -27,6 +27,7 @@ public class CommandSave implements CommandExecutor {
/** /**
* Saves the player's held book if it exists * Saves the player's held book if it exists
*
* @param sender <p>The sender of the command</p> * @param sender <p>The sender of the command</p>
* @param args <p>The arguments given</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> * @param savePublic <p>Whether to save the book in the public directory or the player directory</p>

View File

@ -36,7 +36,7 @@ public class CommandSetBookPrice implements CommandExecutor {
//Warn about invalid argument //Warn about invalid argument
if (!args[0].equalsIgnoreCase("Item") && !args[0].equalsIgnoreCase("Eco")) { 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; return false;
} }
@ -60,6 +60,7 @@ public class CommandSetBookPrice implements CommandExecutor {
/** /**
* Removes the book price * Removes the book price
*
* @param sender <p>The sender of the command</p> * @param sender <p>The sender of the command</p>
*/ */
private void clearItemPrice(CommandSender sender) { private void clearItemPrice(CommandSender sender) {
@ -74,6 +75,7 @@ public class CommandSetBookPrice implements CommandExecutor {
/** /**
* Sets the book price to use items, and updates book price * Sets the book price to use items, and updates book price
*
* @param sender <p>The sender of the command</p> * @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> * @return <p>True if the price was changed successfully</p>
@ -105,6 +107,7 @@ public class CommandSetBookPrice implements CommandExecutor {
/** /**
* Sets the book price to use economy, and updates book price * Sets the book price to use economy, and updates book price
*
* @param sender <p>The sender of the command</p> * @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> * @return <p>True if the price was changed successfully</p>

View File

@ -1,9 +1,5 @@
package net.knarcraft.bookswithoutborders.listener; package net.knarcraft.bookswithoutborders.listener;
import java.io.File;
import java.util.List;
import java.util.Objects;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.state.EncryptionStyle; import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper; import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
@ -28,14 +24,19 @@ import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.io.File;
import java.util.List;
import java.util.Objects;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSlash;
/** /**
* A listener for relevant events * A listener for relevant events
*/ */
public class BooksWithoutBordersListener implements Listener { public class BooksWithoutBordersListener implements Listener {
private final String slash = BooksWithoutBorders.SLASH; private final String slash = getSlash();
private final String bookFolderPath = BooksWithoutBorders.bwb.getDataFolder().getAbsolutePath() + slash + "Books";
private final String bookFolder = bookFolderPath + slash;
/** /**
* Updates old books to a newer format * Updates old books to a newer format
@ -63,10 +64,10 @@ public class BooksWithoutBordersListener implements Listener {
String cleanPlayerName = InputCleaningHelper.cleanString(player.getName()); String cleanPlayerName = InputCleaningHelper.cleanString(player.getName());
String[] possiblePaths = new String[]{ String[] possiblePaths = new String[]{
bookFolder + fileName + ".yml", getBookFolder() + fileName + ".yml",
bookFolder + fileName + ".txt", getBookFolder() + fileName + ".txt",
bookFolder + cleanPlayerName + slash + fileName + ".yml", getBookFolder() + cleanPlayerName + slash + fileName + ".yml",
bookFolder + cleanPlayerName + slash + fileName + ".txt" getBookFolder() + cleanPlayerName + slash + fileName + ".txt"
}; };
for (String path : possiblePaths) { for (String path : possiblePaths) {
@ -231,7 +232,7 @@ public class BooksWithoutBordersListener implements Listener {
} }
//Tests if a full file name has been supplied and points to an actual file //Tests if a full file name has been supplied and points to an actual file
String signFile = bookFolder + lines[2] + lines[3]; String signFile = getBookFolder() + lines[2] + lines[3];
if (FileHelper.bookFileExists(signFile)) { if (FileHelper.bookFileExists(signFile)) {
markGiveSignValidity(event, true); markGiveSignValidity(event, true);
} else { } else {
@ -252,7 +253,7 @@ public class BooksWithoutBordersListener implements Listener {
* @return <p>True if the number is a book index</p> * @return <p>True if the number is a book index</p>
*/ */
private boolean isBookListIndex(String possibleIndex) { private boolean isBookListIndex(String possibleIndex) {
File bookDirectory = new File(bookFolderPath); File bookDirectory = new File(getBookFolder().replaceAll("[\\\\/]$", ""));
try { try {
//Tests if a load list number has been supplied //Tests if a load list number has been supplied
@ -363,9 +364,9 @@ public class BooksWithoutBordersListener implements Listener {
String encryptionFile = InputCleaningHelper.cleanString(groupName) + slash + fileName + ".yml"; String encryptionFile = InputCleaningHelper.cleanString(groupName) + slash + fileName + ".yml";
File file = new File(bookFolder + "Encrypted" + slash + encryptionFile); File file = new File(getBookFolder() + "Encrypted" + slash + encryptionFile);
if (!file.isFile()) { if (!file.isFile()) {
file = new File(bookFolder + fileName + ".txt"); file = new File(getBookFolder() + fileName + ".txt");
if (!file.isFile()) { if (!file.isFile()) {
return; return;
} }

View File

@ -15,6 +15,7 @@ public enum EncryptionStyle {
/** /**
* Gets an encryption style given its name * Gets an encryption style given its name
*
* @param name <p>The name of the encryption style</p> * @param name <p>The name of the encryption style</p>
* @return <p>An encryption style or null if no match is found</p> * @return <p>An encryption style or null if no match is found</p>
*/ */

View File

@ -37,6 +37,7 @@ public class BookFormatter {
/** /**
* Splits the last page if it overflows * Splits the last page if it overflows
*
* @param rawPages <p>The raw pages to format</p> * @param rawPages <p>The raw pages to format</p>
* @param maxPageText <p>The max number of characters which fit on a page</p> * @param maxPageText <p>The max number of characters which fit on a page</p>
* @param fitsNewline <p>The max number of characters on a page which still fits a newline character</p> * @param fitsNewline <p>The max number of characters on a page which still fits a newline character</p>
@ -65,6 +66,7 @@ public class BookFormatter {
/** /**
* Combines the two last pages if they can fit on the same page * Combines the two last pages if they can fit on the same page
*
* @param rawPages <p>The raw pages to format</p> * @param rawPages <p>The raw pages to format</p>
* @param maxPageText <p>The max number of characters which fit on a page</p> * @param maxPageText <p>The max number of characters which fit on a page</p>
*/ */
@ -79,6 +81,7 @@ public class BookFormatter {
/** /**
* Adds newline if the contents of the last page does not exceed page limit and is non-empty * Adds newline if the contents of the last page does not exceed page limit and is non-empty
*
* @param rawPages <p>The raw pages to format</p> * @param rawPages <p>The raw pages to format</p>
* @param fitsNewline <p>The max number of characters on a page which still fits a newline character</p> * @param fitsNewline <p>The max number of characters on a page which still fits a newline character</p>
*/ */

View File

@ -21,10 +21,12 @@ import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixN
*/ */
public final class BookToFromTextHelper { public final class BookToFromTextHelper {
private BookToFromTextHelper() {} private BookToFromTextHelper() {
}
/** /**
* Saves a book's contents to a .yml file * Saves a book's contents to a .yml file
*
* @param path <p>The path of the folder to save to. Must end with a slash</p> * @param path <p>The path of the folder to save to. Must end with a slash</p>
* @param fileName <p>The name of the file to load to</p> * @param fileName <p>The name of the file to load to</p>
* @param bookMetadata <p>Metadata about the book to save</p> * @param bookMetadata <p>Metadata about the book to save</p>
@ -51,6 +53,7 @@ public final class BookToFromTextHelper {
/** /**
* Loads a book from a .yml file * Loads a book from a .yml file
*
* @param file <p>The path of the file to load</p> * @param file <p>The path of the file to load</p>
* @param bookMetadata <p>Metadata which will be altered with the book's contents</p> * @param bookMetadata <p>Metadata which will be altered with the book's contents</p>
* @return <p>Metadata for the loaded book</p> * @return <p>Metadata for the loaded book</p>
@ -77,6 +80,7 @@ public final class BookToFromTextHelper {
/** /**
* Saves a book's contents to a text file * Saves a book's contents to a text file
*
* @param folderPath <p>The folder path to save to. Must end with a slash</p> * @param folderPath <p>The folder path to save to. Must end with a slash</p>
* @param fileName <p>The name of the file to save to</p> * @param fileName <p>The name of the file to save to</p>
* @param bookMetadata <p>Metadata about the book to save</p> * @param bookMetadata <p>Metadata about the book to save</p>
@ -96,6 +100,7 @@ public final class BookToFromTextHelper {
/** /**
* Loads a book from a text file * Loads a book from a text file
*
* @param fileName <p>The name of the file to load. Used to create author and title</p> * @param fileName <p>The name of the file to load. Used to create author and title</p>
* @param file <p>The file to load</p> * @param file <p>The file to load</p>
* @param bookMetadata <p>Metadata which will be altered with the book's contents</p> * @param bookMetadata <p>Metadata which will be altered with the book's contents</p>

View File

@ -1,9 +1,9 @@
package net.knarcraft.bookswithoutborders.utility; package net.knarcraft.bookswithoutborders.utility;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
import net.knarcraft.bookswithoutborders.GenenCrypt; import net.knarcraft.bookswithoutborders.GenenCrypt;
import net.knarcraft.bookswithoutborders.SubstitutionCipher; import net.knarcraft.bookswithoutborders.SubstitutionCipher;
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,6 +15,8 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSlash;
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString; import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString;
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixName; import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixName;
@ -22,6 +24,7 @@ public class EncryptionHelper {
/** /**
* Transforms a string key/password into its numerical values * Transforms a string key/password into its numerical values
*
* @param key <p>The key to transform</p> * @param key <p>The key to transform</p>
* @return <p>The numbers representing the key's characters</p> * @return <p>The numbers representing the key's characters</p>
*/ */
@ -35,6 +38,7 @@ public class EncryptionHelper {
/** /**
* Encrypts the pages of a book * Encrypts the pages of a book
*
* @param book <p>The book to encrypt</p> * @param book <p>The book to encrypt</p>
* @param style <p>The encryption style to use</p> * @param style <p>The encryption style to use</p>
* @param integerKey <p>The encryption key to use</p> * @param integerKey <p>The encryption key to use</p>
@ -180,7 +184,7 @@ public class EncryptionHelper {
public static ItemStack loadEncryptedBook(Player player, String key, boolean deleteEncryptedFile) { public static ItemStack loadEncryptedBook(Player player, String key, boolean deleteEncryptedFile) {
ItemStack heldBook = InventoryHelper.getHeldBook(player, true); ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta(); BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
String path = BooksWithoutBorders.bookFolder + "Encrypted" + BooksWithoutBorders.SLASH; String path = getBookFolder() + "Encrypted" + getSlash();
if (bookMetadata == null) { if (bookMetadata == null) {
return null; return null;
@ -236,7 +240,7 @@ public class EncryptionHelper {
* @return <p>The new encrypted metadata for the book, or null if encryption failed</p> * @return <p>The new encrypted metadata for the book, or null if encryption failed</p>
*/ */
protected static BookMeta saveEncryptedBookForGroup(Player player, BookMeta bookMetadata, String groupName) { protected static BookMeta saveEncryptedBookForGroup(Player player, BookMeta bookMetadata, String groupName) {
String path = BooksWithoutBorders.bookFolder + "Encrypted" + BooksWithoutBorders.SLASH + cleanString(groupName) + BooksWithoutBorders.SLASH; String path = getBookFolder() + "Encrypted" + getSlash() + cleanString(groupName) + getSlash();
File dirTest = new File(path); File dirTest = new File(path);
//Creates group dir //Creates group dir
if (!dirTest.exists()) { if (!dirTest.exists()) {
@ -291,7 +295,7 @@ public class EncryptionHelper {
* @return <p>The new encrypted metadata for the book, or null if encryption failed</p> * @return <p>The new encrypted metadata for the book, or null if encryption failed</p>
*/ */
protected static Boolean saveEncryptedBook(Player player, BookMeta bookMetaData, String key) { protected static Boolean saveEncryptedBook(Player player, BookMeta bookMetaData, String key) {
String path = BooksWithoutBorders.bookFolder + "Encrypted" + BooksWithoutBorders.SLASH; String path = getBookFolder() + "Encrypted" + getSlash();
String fileName = (!bookMetaData.hasTitle()) ? "Untitled," + player.getName() : String fileName = (!bookMetaData.hasTitle()) ? "Untitled," + player.getName() :
bookMetaData.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetaData.getAuthor(); bookMetaData.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetaData.getAuthor();

View File

@ -1,7 +1,7 @@
package net.knarcraft.bookswithoutborders.utility; package net.knarcraft.bookswithoutborders.utility;
import net.knarcraft.bookswithoutborders.state.BookHoldingState;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.state.BookHoldingState;
import net.knarcraft.bookswithoutborders.state.ItemSlot; import net.knarcraft.bookswithoutborders.state.ItemSlot;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -50,6 +50,7 @@ public class InventoryHelper {
/** /**
* Performs checks to validate that a player contains exactly one written book * Performs checks to validate that a player contains exactly one written book
*
* @param player <p>The player to validate</p> * @param player <p>The player to validate</p>
* @param noBookMessage <p>The message to display if the player is not holding a book</p> * @param noBookMessage <p>The message to display if the player is not holding a book</p>
* @param twoBooksMessage <p>The message to display if the player is holding one book in each hand</p> * @param twoBooksMessage <p>The message to display if the player is holding one book in each hand</p>
@ -74,6 +75,7 @@ public class InventoryHelper {
/** /**
* Gets the slot of the player's held book * Gets the slot of the player's held book
*
* @param player <p>The player holding the book</p> * @param player <p>The player holding the book</p>
* @param handMatters <p>Whether the differentiation between the main hand and the off hand is relevant</p> * @param handMatters <p>Whether the differentiation between the main hand and the off hand is relevant</p>
* @param mainHand <p>Whether to search the player's main hand or off hand, if it's relevant</p> * @param mainHand <p>Whether to search the player's main hand or off hand, if it's relevant</p>
@ -134,6 +136,7 @@ public class InventoryHelper {
/** /**
* Gets the state of the player's book holding from all possible states * Gets the state of the player's book holding from all possible states
*
* @param player <p>The player to check</p> * @param player <p>The player to check</p>
* @return <p>The state of the player's book holding</p> * @return <p>The state of the player's book holding</p>
*/ */

View File

@ -3,15 +3,15 @@ version: '${project.version}'
main: net.knarcraft.bookswithoutborders.BooksWithoutBorders main: net.knarcraft.bookswithoutborders.BooksWithoutBorders
api-version: 1.17 api-version: 1.17
prefix: Books Without Borders prefix: Books Without Borders
authors: [EpicKnarvik97, AkiraAkiba] authors: [ EpicKnarvik97, AkiraAkiba ]
description: A continuation of the original Books Without Borders description: A continuation of the original Books Without Borders
softdepend: [Vault] softdepend: [ Vault ]
website: ???? website: ????
dev-url: https://git.knarcraft.net/EpicKnarvik97/Books-Without-Borders dev-url: https://git.knarcraft.net/EpicKnarvik97/Books-Without-Borders
commands: commands:
bookswithoutborders: bookswithoutborders:
description: Lists Books Without Borders's commands and uses. description: Lists Books Without Borders's commands and uses.
aliases: [bwb] aliases: [ bwb ]
usage: /<command> usage: /<command>
give: give:
description: Gives the held book to another player description: Gives the held book to another player