Improves encapsulation and removes the custom tracking of existing players

This commit is contained in:
2021-09-04 01:06:01 +02:00
parent 1d3c50aab1
commit 0ca4b9817e
13 changed files with 133 additions and 140 deletions

View File

@@ -9,8 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
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.sendErrorMessage;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getCommandColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getSuccessColor;
@@ -54,11 +52,15 @@ public class CommandBooksWithoutBorders implements CommandExecutor {
*/
private void showPlayerCommands(CommandSender sender) {
//Lists all commands
Material bookPriceType = BooksWithoutBorders.getBookPriceType();
double bookPriceQuantity = BooksWithoutBorders.getBookPriceQuantity();
if (booksWithoutBorders.booksHavePrice()) {
if (bookPriceType != Material.AIR) {
sendErrorMessage(sender, "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() + "(s) are required to create a book]");
sendErrorMessage(sender, "[" + (int) bookPriceQuantity + " " + bookPriceType.toString() +
"(s) are required to create a book]");
} else {
sendErrorMessage(sender, "[" + EconomyHelper.getEconomy().format(bookPriceQuantity) + " is required to create a book]");
sendErrorMessage(sender, "[" + EconomyHelper.getEconomy().format(bookPriceQuantity) +
" is required to create a book]");
}
}
sender.sendMessage(getCommandColor() + "Commands:");

View File

@@ -41,7 +41,7 @@ public class CommandCopy implements CommandExecutor {
try {
int copies = Integer.parseInt(args[0]);
if (copies > 0) {
if (BooksWithoutBorders.authorOnlyCopy && !player.hasPermission("bookswithoutborders.bypassAuthorOnlyCopy")) {
if (BooksWithoutBorders.getAuthorOnlyCopy() && !player.hasPermission("bookswithoutborders.bypassAuthorOnlyCopy")) {
if (!isAuthor(player, (BookMeta) Objects.requireNonNull(heldBook.getItemMeta())))
return false;
}

View File

@@ -41,11 +41,11 @@ 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")) {
if (args.length == 0 && BooksWithoutBorders.getAdminDecrypt() && player.hasPermission("bookswithoutborders.admin")) {
String path = getBookFolder() + "Encrypted" + getSlash();
String fileName;
if (bookMetadata.hasTitle()) {
fileName = bookMetadata.getTitle() + BooksWithoutBorders.titleAuthorSeparator + bookMetadata.getAuthor();
fileName = bookMetadata.getTitle() + BooksWithoutBorders.getTitleAuthorSeparator() + bookMetadata.getAuthor();
} else {
fileName = "Untitled," + player.getName();
}

View File

@@ -14,7 +14,7 @@ public class CommandReload implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (booksWithoutBorders.loadConfig() && booksWithoutBorders.loadExistingPlayers()) {
if (booksWithoutBorders.loadConfig()) {
BooksWithoutBorders.sendSuccessMessage(sender, "BooksWithoutBorders configuration reloaded!");
} else {
BooksWithoutBorders.sendErrorMessage(sender, "Reload Failed!");

View File

@@ -15,7 +15,7 @@ import org.bukkit.inventory.meta.BookMeta;
import java.io.File;
import java.io.IOException;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.titleAuthorSeparator;
import static net.knarcraft.bookswithoutborders.BooksWithoutBorders.getTitleAuthorSeparator;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getBookFolder;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getCommandColor;
import static net.knarcraft.bookswithoutborders.BooksWithoutBordersSettings.getErrorColor;
@@ -86,7 +86,7 @@ public class CommandSave implements CommandExecutor {
if (!book.hasTitle()) {
fileName = "Untitled," + player.getName();
} else {
fileName = book.getTitle() + titleAuthorSeparator + book.getAuthor();
fileName = book.getTitle() + getTitleAuthorSeparator() + book.getAuthor();
}
fileName = cleanString(fileName);
fileName = fixName(fileName, false);
@@ -117,7 +117,7 @@ public class CommandSave implements CommandExecutor {
}
//Skip if duplicate limit is reached
if (foundDuplicates > BooksWithoutBorders.bookDuplicateLimit) {
if (foundDuplicates > BooksWithoutBorders.getBookDuplicateLimit()) {
BooksWithoutBorders.sendErrorMessage(player, "Maximum amount of " + fileName + " duplicates reached!");
BooksWithoutBorders.sendErrorMessage(player, "Use " + getCommandColor() + "/bwb Save true " + getErrorColor() + "to overwrite!");
return;
@@ -130,7 +130,7 @@ public class CommandSave implements CommandExecutor {
}
try {
if (BooksWithoutBorders.useYml) {
if (BooksWithoutBorders.getUseYml()) {
BookToFromTextHelper.bookToYml(savePath, fileName, book);
} else {
BookToFromTextHelper.bookToTXT(savePath, fileName, book);

View File

@@ -61,10 +61,10 @@ public class CommandSetBookPrice implements CommandExecutor {
* @param sender <p>The sender of the command</p>
*/
private void clearItemPrice(CommandSender sender) {
BooksWithoutBorders.bookPriceType = null;
BooksWithoutBorders.bookPriceQuantity = 0;
BooksWithoutBorders.setBookPriceType(null);
BooksWithoutBorders.setBookPriceQuantity(0);
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", "Item type name");
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", BooksWithoutBorders.bookPriceQuantity);
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", BooksWithoutBorders.getBookPriceQuantity());
booksWithoutBorders.saveConfig();
BooksWithoutBorders.sendSuccessMessage(sender, "Price to create books removed!");
@@ -89,16 +89,16 @@ public class CommandSetBookPrice implements CommandExecutor {
return false;
}
BooksWithoutBorders.bookPriceType = heldItem.getType();
BooksWithoutBorders.bookPriceQuantity = price;
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type",
BooksWithoutBorders.bookPriceType.toString());
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity",
BooksWithoutBorders.bookPriceQuantity);
BooksWithoutBorders.setBookPriceType(heldItem.getType());
BooksWithoutBorders.setBookPriceQuantity(price);
String newPriceType = BooksWithoutBorders.getBookPriceType().toString();
double newPriceQuantity = BooksWithoutBorders.getBookPriceQuantity();
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", newPriceType);
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", newPriceQuantity);
booksWithoutBorders.saveConfig();
BooksWithoutBorders.sendSuccessMessage(sender, "Book creation price set to " +
(int) BooksWithoutBorders.bookPriceQuantity + " " + BooksWithoutBorders.bookPriceType.toString() + "(s)!");
BooksWithoutBorders.sendSuccessMessage(sender, "Book creation price set to " + (int) newPriceQuantity +
" " + newPriceType + "(s)!");
return true;
}
@@ -111,15 +111,15 @@ public class CommandSetBookPrice implements CommandExecutor {
*/
private boolean setEconomyPrice(CommandSender sender, double price) {
if (EconomyHelper.setupEconomy()) {
BooksWithoutBorders.bookPriceQuantity = price;
BooksWithoutBorders.bookPriceType = Material.AIR;
BooksWithoutBorders.setBookPriceQuantity(price);
BooksWithoutBorders.setBookPriceType(Material.AIR);
double newPriceQuantity = BooksWithoutBorders.getBookPriceQuantity();
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", "Economy");
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity",
BooksWithoutBorders.bookPriceQuantity);
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", newPriceQuantity);
booksWithoutBorders.saveConfig();
BooksWithoutBorders.sendSuccessMessage(sender, "Book creation price set to " +
EconomyHelper.getEconomy().format(BooksWithoutBorders.bookPriceQuantity) + "!");
EconomyHelper.getEconomy().format(newPriceQuantity) + "!");
return true;
} else {
BooksWithoutBorders.sendErrorMessage(sender, "BooksWithoutBorders failed to hook into Vault! Book price not set!");

View File

@@ -43,7 +43,7 @@ public class CommandSetLore implements CommandExecutor {
//Format lore
rawLore = ChatColor.translateAlternateColorCodes('&', rawLore);
String[] loreParts = rawLore.split(BooksWithoutBorders.loreSeparator);
String[] loreParts = rawLore.split(BooksWithoutBorders.getLoreSeparator());
List<String> newLore = new ArrayList<>(Arrays.asList(loreParts));
//Update lore