Moves some settings into the BooksWithoutBordersSettings class
This commit is contained in:
parent
72e080f1c9
commit
996cb5da5c
14
README.md
14
README.md
@ -1,15 +1,15 @@
|
||||
# Books Without Borders
|
||||
|
||||
This is an attempt at a rewrite of the Books Without Borders plugin. This rewrite uses the
|
||||
source code given at [the original bukkit page](https://dev.bukkit.org/projects/books-without-borders).
|
||||
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
|
||||
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 the future.
|
||||
This is an attempt at a rewrite of the Books Without Borders plugin. This rewrite uses the source code given
|
||||
at [the original bukkit page](https://dev.bukkit.org/projects/books-without-borders). 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 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
|
||||
the future.
|
||||
|
||||
## 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
|
||||
|
||||
|
@ -24,7 +24,6 @@ import net.knarcraft.bookswithoutborders.listener.BooksWithoutBordersListener;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookToFromTextHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.FileHelper;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -54,6 +53,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
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.fixName;
|
||||
|
||||
@ -62,7 +66,6 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
//The separating string between the book title and the book author
|
||||
public static String titleAuthorSeparator;
|
||||
public static String loreSeparator;
|
||||
public static final String SLASH = System.getProperty("file.separator");
|
||||
public static List<String> firstBooks;
|
||||
public static String welcomeMessage;
|
||||
protected static List<String> existingPlayers;
|
||||
@ -77,21 +80,17 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
public static BooksWithoutBorders bwb;
|
||||
protected static BooksWithoutBordersListener bL;
|
||||
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
|
||||
public void onEnable() {
|
||||
bwb = this;
|
||||
consoleSender = this.getServer().getConsoleSender();
|
||||
bookFolder = this.getDataFolder().getAbsolutePath() + SLASH + "Books" + SLASH;
|
||||
bL = new BooksWithoutBordersListener();
|
||||
loadList = new HashMap<>();
|
||||
firstBooks = new ArrayList<>();
|
||||
BooksWithoutBordersSettings.initialize(this);
|
||||
|
||||
if (SLASH != null && init()) {
|
||||
if (getSlash() != null && init()) {
|
||||
this.getServer().getPluginManager().registerEvents(bL, this);
|
||||
} else {
|
||||
this.getPluginLoader().disablePlugin(this);
|
||||
@ -188,8 +187,8 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
|
||||
this.saveConfig();
|
||||
|
||||
File fTest = new File(bookFolder);
|
||||
File efTest = new File(bookFolder + "Encrypted" + SLASH);
|
||||
File fTest = new File(getBookFolder());
|
||||
File efTest = new File(getBookFolder() + "Encrypted" + getSlash());
|
||||
|
||||
if (!fTest.exists()) {
|
||||
try {
|
||||
@ -283,7 +282,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
if (!fTest.exists()) {
|
||||
@ -329,7 +328,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
existingPlayers.add(playerName);
|
||||
|
||||
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.close();
|
||||
} catch (IOException e) {
|
||||
@ -363,9 +362,9 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
|
||||
String savePath;
|
||||
if (saveToPublicFolder) {
|
||||
savePath = bookFolder;
|
||||
savePath = getBookFolder();
|
||||
} else {
|
||||
savePath = bookFolder + cleanString(player.getName()) + SLASH;
|
||||
savePath = getBookFolder() + cleanString(player.getName()) + getSlash();
|
||||
}
|
||||
|
||||
//Generate book filename
|
||||
@ -403,14 +402,14 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
//Skip duplicate book
|
||||
if (!fileName.contains("Untitled") && !overwrite) {
|
||||
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;
|
||||
}
|
||||
|
||||
//Skip if duplicate limit is reached
|
||||
if (foundDuplicates > bookDuplicateLimit) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -453,11 +452,11 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
|
||||
File file;
|
||||
if (dir.equalsIgnoreCase("public")) {
|
||||
file = FileHelper.getBookFile(bookFolder + fileName);
|
||||
file = FileHelper.getBookFile(getBookFolder() + fileName);
|
||||
} 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()) {
|
||||
file = FileHelper.getBookFile(bookFolder + "Encrypted" + SLASH + dir + SLASH + fileName);
|
||||
file = FileHelper.getBookFile(getBookFolder() + "Encrypted" + getSlash() + dir + getSlash() + fileName);
|
||||
} else {
|
||||
file = null;
|
||||
}
|
||||
@ -586,9 +585,9 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
public List<String> listFiles(CommandSender sender, Boolean listPublic, boolean silent) {
|
||||
File file;
|
||||
if (listPublic) {
|
||||
file = new File(bookFolder);
|
||||
file = new File(getBookFolder());
|
||||
} else {
|
||||
file = new File(bookFolder + cleanString(sender.getName()) + SLASH);
|
||||
file = new File(getBookFolder() + cleanString(sender.getName()) + getSlash());
|
||||
}
|
||||
return FileHelper.listFiles(sender, file, silent);
|
||||
}
|
||||
@ -600,7 +599,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
* @param message <p>The message to send</p>
|
||||
*/
|
||||
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>
|
||||
*/
|
||||
public static void sendErrorMessage(CommandSender sender, String message) {
|
||||
sender.sendMessage(errorColor + message);
|
||||
sender.sendMessage(getErrorColor() + message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
package net.knarcraft.bookswithoutborders;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Case-insensitive gene-based encryption
|
||||
@ -23,6 +23,7 @@ public class GenenCrypt {
|
||||
|
||||
/**
|
||||
* Instantiates a new GenenCrypt
|
||||
*
|
||||
* @param key <p>The key used to generate the codon table</p>
|
||||
*/
|
||||
public GenenCrypt(String key) {
|
||||
@ -126,6 +127,7 @@ public class GenenCrypt {
|
||||
|
||||
/**
|
||||
* Encrypts some input
|
||||
*
|
||||
* @param input <p>The input to encrypt</p>
|
||||
* @return <p>The encrypted input</p>
|
||||
*/
|
||||
@ -158,6 +160,7 @@ public class GenenCrypt {
|
||||
|
||||
/**
|
||||
* Decrypts some input
|
||||
*
|
||||
* @param input <p>The input to decrypt</p>
|
||||
* @return <p>The decrypted input</p>
|
||||
*/
|
||||
|
@ -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.");
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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>
|
||||
*/
|
||||
|
@ -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) {
|
||||
|
@ -1,9 +1,5 @@
|
||||
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.state.EncryptionStyle;
|
||||
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.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
|
||||
*/
|
||||
public class BooksWithoutBordersListener implements Listener {
|
||||
|
||||
private final String slash = BooksWithoutBorders.SLASH;
|
||||
private final String bookFolderPath = BooksWithoutBorders.bwb.getDataFolder().getAbsolutePath() + slash + "Books";
|
||||
private final String bookFolder = bookFolderPath + slash;
|
||||
private final String slash = getSlash();
|
||||
|
||||
/**
|
||||
* Updates old books to a newer format
|
||||
@ -63,10 +64,10 @@ public class BooksWithoutBordersListener implements Listener {
|
||||
String cleanPlayerName = InputCleaningHelper.cleanString(player.getName());
|
||||
|
||||
String[] possiblePaths = new String[]{
|
||||
bookFolder + fileName + ".yml",
|
||||
bookFolder + fileName + ".txt",
|
||||
bookFolder + cleanPlayerName + slash + fileName + ".yml",
|
||||
bookFolder + cleanPlayerName + slash + fileName + ".txt"
|
||||
getBookFolder() + fileName + ".yml",
|
||||
getBookFolder() + fileName + ".txt",
|
||||
getBookFolder() + cleanPlayerName + slash + fileName + ".yml",
|
||||
getBookFolder() + cleanPlayerName + slash + fileName + ".txt"
|
||||
};
|
||||
|
||||
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
|
||||
String signFile = bookFolder + lines[2] + lines[3];
|
||||
String signFile = getBookFolder() + lines[2] + lines[3];
|
||||
if (FileHelper.bookFileExists(signFile)) {
|
||||
markGiveSignValidity(event, true);
|
||||
} else {
|
||||
@ -252,7 +253,7 @@ public class BooksWithoutBordersListener implements Listener {
|
||||
* @return <p>True if the number is a book index</p>
|
||||
*/
|
||||
private boolean isBookListIndex(String possibleIndex) {
|
||||
File bookDirectory = new File(bookFolderPath);
|
||||
File bookDirectory = new File(getBookFolder().replaceAll("[\\\\/]$", ""));
|
||||
|
||||
try {
|
||||
//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";
|
||||
|
||||
File file = new File(bookFolder + "Encrypted" + slash + encryptionFile);
|
||||
File file = new File(getBookFolder() + "Encrypted" + slash + encryptionFile);
|
||||
if (!file.isFile()) {
|
||||
file = new File(bookFolder + fileName + ".txt");
|
||||
file = new File(getBookFolder() + fileName + ".txt");
|
||||
if (!file.isFile()) {
|
||||
return;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ public enum EncryptionStyle {
|
||||
|
||||
/**
|
||||
* Gets an encryption style given its name
|
||||
*
|
||||
* @param name <p>The name of the encryption style</p>
|
||||
* @return <p>An encryption style or null if no match is found</p>
|
||||
*/
|
||||
|
@ -37,7 +37,8 @@ public class BookFormatter {
|
||||
|
||||
/**
|
||||
* 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 fitsNewline <p>The max number of characters on a page which still fits a newline character</p>
|
||||
*/
|
||||
@ -65,7 +66,8 @@ public class BookFormatter {
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public static void formatLastPageCombinePages(List<String> rawPages, int maxPageText) {
|
||||
@ -79,7 +81,8 @@ public class BookFormatter {
|
||||
|
||||
/**
|
||||
* 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>
|
||||
*/
|
||||
public static void formatLastPageAddNewline(List<String> rawPages, int fitsNewline) {
|
||||
|
@ -21,12 +21,14 @@ import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.fixN
|
||||
*/
|
||||
public final class BookToFromTextHelper {
|
||||
|
||||
private BookToFromTextHelper() {}
|
||||
private BookToFromTextHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 fileName <p>The name of the file to load to</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 bookMetadata <p>Metadata about the book to save</p>
|
||||
* @throws IOException <p>If unable to save the book</p>
|
||||
*/
|
||||
@ -51,7 +53,8 @@ public final class BookToFromTextHelper {
|
||||
|
||||
/**
|
||||
* 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>
|
||||
* @return <p>Metadata for the loaded book</p>
|
||||
*/
|
||||
@ -77,8 +80,9 @@ public final class BookToFromTextHelper {
|
||||
|
||||
/**
|
||||
* 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 fileName <p>The name of the file to save to</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 bookMetadata <p>Metadata about the book to save</p>
|
||||
* @throws IOException <p>If unable to save the book</p>
|
||||
*/
|
||||
@ -96,8 +100,9 @@ public final class BookToFromTextHelper {
|
||||
|
||||
/**
|
||||
* 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 file <p>The file to load</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 bookMetadata <p>Metadata which will be altered with the book's contents</p>
|
||||
* @return <p>Metadata for the loaded book</p>
|
||||
*/
|
||||
|
@ -1,9 +1,9 @@
|
||||
package net.knarcraft.bookswithoutborders.utility;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.GenenCrypt;
|
||||
import net.knarcraft.bookswithoutborders.SubstitutionCipher;
|
||||
import net.knarcraft.bookswithoutborders.state.EncryptionStyle;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -15,6 +15,8 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
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.fixName;
|
||||
|
||||
@ -22,6 +24,7 @@ public class EncryptionHelper {
|
||||
|
||||
/**
|
||||
* Transforms a string key/password into its numerical values
|
||||
*
|
||||
* @param key <p>The key to transform</p>
|
||||
* @return <p>The numbers representing the key's characters</p>
|
||||
*/
|
||||
@ -35,10 +38,11 @@ public class EncryptionHelper {
|
||||
|
||||
/**
|
||||
* Encrypts the pages of a book
|
||||
* @param book <p>The book to encrypt</p>
|
||||
* @param style <p>The encryption style to use</p>
|
||||
*
|
||||
* @param book <p>The book to encrypt</p>
|
||||
* @param style <p>The encryption style to use</p>
|
||||
* @param integerKey <p>The encryption key to use</p>
|
||||
* @param player <p>The player trying to encrypt a book</p>
|
||||
* @param player <p>The player trying to encrypt a book</p>
|
||||
* @return <p>The pages of the book in encrypted form</p>
|
||||
*/
|
||||
public static List<String> encryptBookPages(BookMeta book, EncryptionStyle style, String integerKey, Player player) {
|
||||
@ -180,7 +184,7 @@ public class EncryptionHelper {
|
||||
public static ItemStack loadEncryptedBook(Player player, String key, boolean deleteEncryptedFile) {
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
|
||||
String path = BooksWithoutBorders.bookFolder + "Encrypted" + BooksWithoutBorders.SLASH;
|
||||
String path = getBookFolder() + "Encrypted" + getSlash();
|
||||
|
||||
if (bookMetadata == 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>
|
||||
*/
|
||||
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);
|
||||
//Creates group dir
|
||||
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>
|
||||
*/
|
||||
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() :
|
||||
bookMetaData.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetaData.getAuthor();
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.utility;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.state.BookHoldingState;
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.state.BookHoldingState;
|
||||
import net.knarcraft.bookswithoutborders.state.ItemSlot;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -50,6 +50,7 @@ public class InventoryHelper {
|
||||
|
||||
/**
|
||||
* Performs checks to validate that a player contains exactly one written book
|
||||
*
|
||||
* @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 twoBooksMessage <p>The message to display if the player is holding one book in each hand</p>
|
||||
@ -74,15 +75,16 @@ public class InventoryHelper {
|
||||
|
||||
/**
|
||||
* 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 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>
|
||||
* @param typeMatters <p>Whether the differentiation between signed and unsigned books is relevant</p>
|
||||
* @param writtenBook <p>Whether to search for written or unwritten books, if it's relevant</p>
|
||||
* @return <p>The slot of the player's held book</p>
|
||||
*/
|
||||
public static ItemSlot getHeldSlotBook(Player player, boolean handMatters, boolean mainHand,
|
||||
boolean typeMatters, boolean writtenBook) {
|
||||
boolean typeMatters, boolean writtenBook) {
|
||||
BookHoldingState state = getBookHoldingState(player);
|
||||
ItemStack mainHandItem = getHeldItem(player, true);
|
||||
ItemStack offHandItem = getHeldItem(player, false);
|
||||
@ -118,7 +120,7 @@ public class InventoryHelper {
|
||||
return ItemSlot.MAIN_HAND;
|
||||
} else if ((writtenBook && (state == BookHoldingState.SIGNED_OFF_HAND ||
|
||||
state == BookHoldingState.UNSIGNED_MAIN_HAND_SIGNED_OFF_HAND)) || (!writtenBook && (
|
||||
state == BookHoldingState.UNSIGNED_OFF_HAND) ||
|
||||
state == BookHoldingState.UNSIGNED_OFF_HAND) ||
|
||||
state == BookHoldingState.SIGNED_MAIN_HAND_UNSIGNED_OFF_HAND)) {
|
||||
return ItemSlot.OFF_HAND;
|
||||
}
|
||||
@ -134,6 +136,7 @@ public class InventoryHelper {
|
||||
|
||||
/**
|
||||
* Gets the state of the player's book holding from all possible states
|
||||
*
|
||||
* @param player <p>The player to check</p>
|
||||
* @return <p>The state of the player's book holding</p>
|
||||
*/
|
||||
|
@ -3,15 +3,15 @@ version: '${project.version}'
|
||||
main: net.knarcraft.bookswithoutborders.BooksWithoutBorders
|
||||
api-version: 1.17
|
||||
prefix: Books Without Borders
|
||||
authors: [EpicKnarvik97, AkiraAkiba]
|
||||
authors: [ EpicKnarvik97, AkiraAkiba ]
|
||||
description: A continuation of the original Books Without Borders
|
||||
softdepend: [Vault]
|
||||
softdepend: [ Vault ]
|
||||
website: ????
|
||||
dev-url: https://git.knarcraft.net/EpicKnarvik97/Books-Without-Borders
|
||||
commands:
|
||||
bookswithoutborders:
|
||||
description: Lists Books Without Borders's commands and uses.
|
||||
aliases: [bwb]
|
||||
aliases: [ bwb ]
|
||||
usage: /<command>
|
||||
give:
|
||||
description: Gives the held book to another player
|
||||
|
Loading…
Reference in New Issue
Block a user