Removes lots of static strings

This commit is contained in:
2025-08-19 20:09:36 +02:00
parent 8f60752e45
commit 20353ade99
13 changed files with 184 additions and 90 deletions

View File

@@ -1,7 +1,6 @@
package net.knarcraft.bookswithoutborders.command; package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.BwBCommand;
import net.knarcraft.bookswithoutborders.config.Translatable; import net.knarcraft.bookswithoutborders.config.Translatable;
import net.knarcraft.bookswithoutborders.gui.PagedBookIndex; import net.knarcraft.bookswithoutborders.gui.PagedBookIndex;
import net.knarcraft.bookswithoutborders.state.BookDirectory; import net.knarcraft.bookswithoutborders.state.BookDirectory;
@@ -33,7 +32,7 @@ public class CommandDelete implements TabExecutor {
return false; return false;
} }
return deleteBook(sender, arguments, false); return deleteBook(sender, arguments, false, label);
} }
/** /**
@@ -42,12 +41,12 @@ public class CommandDelete implements TabExecutor {
* @param sender <p>The sender trying to delete the book</p> * @param sender <p>The sender trying to delete the book</p>
* @param arguments <p>The arguments given</p> * @param arguments <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>
* @param commandName <p>The name of the command calling this method</p>
* @return <p>True if the book was deleted successfully</p> * @return <p>True if the book was deleted successfully</p>
*/ */
protected boolean deleteBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean deletePublic) { protected boolean deleteBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean deletePublic,
String command = deletePublic ? BwBCommand.DELETE_PUBLIC_BOOK.toString().toLowerCase() : @NotNull String commandName) {
BwBCommand.DELETE_BOOK.toString().toLowerCase(); if (PagedBookIndex.displayPage(arguments, sender, deletePublic, commandName)) {
if (PagedBookIndex.displayPage(arguments, sender, deletePublic, command)) {
return true; return true;
} }

View File

@@ -15,7 +15,7 @@ public class CommandDeletePublic extends CommandDelete implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
return deleteBook(sender, arguments, true); return deleteBook(sender, arguments, true, label);
} }
@Override @Override

View File

@@ -36,7 +36,7 @@ public class CommandGive implements TabExecutor {
return false; return false;
} }
return giveBook(sender, arguments, false, "player"); return giveBook(sender, arguments, false, "player", label);
} }
/** /**
@@ -46,12 +46,12 @@ public class CommandGive implements TabExecutor {
* @param arguments <p>The arguments given</p> * @param arguments <p>The arguments given</p>
* @param givePublic <p>Whether to give a public book</p> * @param givePublic <p>Whether to give a public book</p>
* @param folder <p>The folder containing the book to load</p> * @param folder <p>The folder containing the book to load</p>
* @param commandName <p>The name of the command calling this method</p>
* @return <p>True if the book was given successfully</p> * @return <p>True if the book was given successfully</p>
*/ */
boolean giveBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean givePublic, boolean giveBook(@NotNull CommandSender sender, @NotNull String[] arguments, boolean givePublic,
@NotNull String folder) { @NotNull String folder, @NotNull String commandName) {
String command = givePublic ? "givepublicbook" : "givebook"; if (PagedBookIndex.displayPage(arguments, sender, givePublic, commandName)) {
if (PagedBookIndex.displayPage(arguments, sender, givePublic, command)) {
return true; return true;
} }

View File

@@ -16,7 +16,7 @@ public class CommandGivePublic extends CommandGive implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
return giveBook(sender, arguments, true, "public"); return giveBook(sender, arguments, true, "public", label);
} }
@Override @Override

View File

@@ -26,7 +26,7 @@ public class CommandLoad implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
return loadBook(sender, arguments, "player", false); return loadBook(sender, arguments, "player", false, label);
} }
/** /**
@@ -36,10 +36,11 @@ public class CommandLoad implements TabExecutor {
* @param arguments <p>The arguments given</p> * @param arguments <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>
* @param loadPublic <p>Whether to list public files as loadable</p> * @param loadPublic <p>Whether to list public files as loadable</p>
* @param commandName <p>The name of the command calling this method</p>
* @return <p>True if the book was loaded successfully</p> * @return <p>True if the book was loaded successfully</p>
*/ */
public boolean loadBook(@NotNull CommandSender sender, @NotNull String[] arguments, @NotNull String directory, public boolean loadBook(@NotNull CommandSender sender, @NotNull String[] arguments, @NotNull String directory,
boolean loadPublic) { boolean loadPublic, @NotNull String commandName) {
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter(); StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
if (!(sender instanceof Player player)) { if (!(sender instanceof Player player)) {
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
@@ -53,8 +54,7 @@ public class CommandLoad implements TabExecutor {
int argumentCount = arguments.length; int argumentCount = arguments.length;
String command = loadPublic ? "loadpublicbook" : "loadbook"; if (PagedBookIndex.displayPage(arguments, sender, loadPublic, commandName)) {
if (PagedBookIndex.displayPage(arguments, sender, loadPublic, command)) {
return true; return true;
} }

View File

@@ -15,7 +15,7 @@ public class CommandLoadPublic extends CommandLoad implements CommandExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
return loadBook(sender, arguments, "public", true); return loadBook(sender, arguments, "public", true, label);
} }
@Override @Override

View File

@@ -176,7 +176,8 @@ public class CommandSave implements TabExecutor {
String fullCommand = "/" + command + " true"; String fullCommand = "/" + command + " true";
boolean isUnnamed = fileName.contains("Untitled" + separator); boolean isUnnamed = fileName.contains(stringFormatter.getUnFormattedColoredMessage(
Translatable.NEUTRAL_UNKNOWN_TITLE) + separator);
// Skip duplicate unnamed book saving // Skip duplicate unnamed book saving
if (!isUnnamed && !overwrite) { if (!isUnnamed && !overwrite) {

View File

@@ -1,8 +1,10 @@
package net.knarcraft.bookswithoutborders.command; package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.Translatable;
import net.knarcraft.bookswithoutborders.state.ItemSlot; import net.knarcraft.bookswithoutborders.state.ItemSlot;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.property.ColorConversion; import net.knarcraft.knarlib.property.ColorConversion;
import net.knarcraft.knarlib.util.ColorHelper; import net.knarcraft.knarlib.util.ColorHelper;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -25,19 +27,22 @@ public class CommandSetAuthor implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
if (!(sender instanceof Player player)) { if (!(sender instanceof Player player)) {
BooksWithoutBorders.sendErrorMessage(sender, "This command can only be used by a player!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
return false; return false;
} }
if (arguments.length < 1) { if (arguments.length < 1) {
BooksWithoutBorders.sendErrorMessage(player, "Too few command arguments!"); stringFormatter.displayErrorMessage(player, Translatable.ERROR_AUTHOR_BLANK);
return false; return false;
} }
if (InventoryHelper.notHoldingOneWrittenBookCheck(player, if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
"You must be holding a written book to set author!", "You cannot set the " + stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
"author of two books at once!")) { stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_SET_AUTHOR)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_SET_AUTHOR)))) {
return false; return false;
} }
@@ -46,14 +51,15 @@ public class CommandSetAuthor implements TabExecutor {
ItemStack heldBook = InventoryHelper.getHeldItem(player, mainHand); ItemStack heldBook = InventoryHelper.getHeldItem(player, mainHand);
BookMeta bookMetaData = InventoryHelper.getHeldBookMetadata(player, mainHand); BookMeta bookMetaData = InventoryHelper.getHeldBookMetadata(player, mainHand);
if (bookMetaData == null) { if (bookMetaData == null) {
BooksWithoutBorders.sendErrorMessage(player, "Unable to get metadata for the held book!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_METADATA_MISSING);
return false; return false;
} }
String author = ColorHelper.translateColorCodes(String.join(" ", arguments), ColorConversion.RGB); String author = ColorHelper.translateColorCodes(String.join(" ", arguments), ColorConversion.RGB);
bookMetaData.setAuthor(author); bookMetaData.setAuthor(author);
heldBook.setItemMeta(bookMetaData); heldBook.setItemMeta(bookMetaData);
BooksWithoutBorders.sendSuccessMessage(player, "Book author set to " + author + "!"); stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(Translatable.SUCCESS_SET_AUTHOR,
"{author}", author));
return true; return true;
} }

View File

@@ -2,10 +2,13 @@ package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.BwBConfig; import net.knarcraft.bookswithoutborders.config.BwBConfig;
import net.knarcraft.bookswithoutborders.config.ConfigOption;
import net.knarcraft.bookswithoutborders.config.StaticMessage; import net.knarcraft.bookswithoutborders.config.StaticMessage;
import net.knarcraft.bookswithoutborders.config.Translatable;
import net.knarcraft.bookswithoutborders.manager.EconomyManager; import net.knarcraft.bookswithoutborders.manager.EconomyManager;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper; import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper; import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.util.TabCompletionHelper; import net.knarcraft.knarlib.util.TabCompletionHelper;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -29,6 +32,7 @@ public class CommandSetBookPrice implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@NotNull String[] arguments) { @NotNull String[] arguments) {
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
//Clear the current price //Clear the current price
if (arguments.length == 0) { if (arguments.length == 0) {
clearItemPrice(sender); clearItemPrice(sender);
@@ -37,34 +41,32 @@ public class CommandSetBookPrice implements TabExecutor {
//Warn about missing arguments //Warn about missing arguments
if (arguments.length < 2) { if (arguments.length < 2) {
BooksWithoutBorders.sendErrorMessage(sender, "[Item/Eco] and [quantity] must be specified!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_COST_NOT_SPECIFIED);
return false;
}
//Warn about invalid argument
if (!arguments[0].equalsIgnoreCase("Item") && !arguments[0].equalsIgnoreCase("Eco")) {
BooksWithoutBorders.sendErrorMessage(sender, "Price type must be \"Item\" or \"Eco\"!");
return false; return false;
} }
double price;
try { try {
double price = Double.parseDouble(arguments[1]); price = Double.parseDouble(arguments[1]);
if (price <= 0) { if (price <= 0) {
BooksWithoutBorders.sendErrorMessage(sender, "[quantity] must be greater than 0!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_COST_INVALID_QUANTITY);
return false; return false;
} }
if (arguments[0].equalsIgnoreCase("Item")) {
return setItemPrice(sender, price);
} else if (arguments[0].equalsIgnoreCase("Eco")) {
return setEconomyPrice(sender, price);
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
BooksWithoutBorders.sendErrorMessage(sender, "[quantity] must be a number!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_COST_INVALID_QUANTITY);
}
return false; return false;
} }
return switch (arguments[0].toLowerCase()) {
case "item" -> setItemPrice(sender, price);
case "economy" -> setEconomyPrice(sender, price);
default -> {
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_COST_INVALID_TYPE);
yield false;
}
};
}
/** /**
* Removes the book price * Removes the book price
* *
@@ -74,11 +76,11 @@ public class CommandSetBookPrice implements TabExecutor {
BwBConfig config = BooksWithoutBorders.getConfiguration(); BwBConfig config = BooksWithoutBorders.getConfiguration();
config.setBookPriceType(null); config.setBookPriceType(null);
config.setBookPriceQuantity(0); config.setBookPriceQuantity(0);
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", "Item type name"); booksWithoutBorders.getConfig().set(ConfigOption.PRICE_ITEM_TYPE.getConfigNode(), "Item type name");
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", config.getBookPriceQuantity()); booksWithoutBorders.getConfig().set(ConfigOption.PRICE_QUANTITY.getConfigNode(), config.getBookPriceQuantity());
booksWithoutBorders.saveConfig(); booksWithoutBorders.saveConfig();
BooksWithoutBorders.sendSuccessMessage(sender, "Price to create books removed!"); BooksWithoutBorders.getStringFormatter().displaySuccessMessage(sender, Translatable.SUCCESS_COST_REMOVED);
} }
/** /**
@@ -89,14 +91,15 @@ public class CommandSetBookPrice implements TabExecutor {
* @return <p>True if the price was changed successfully</p> * @return <p>True if the price was changed successfully</p>
*/ */
private boolean setItemPrice(@NotNull CommandSender sender, double price) { private boolean setItemPrice(@NotNull CommandSender sender, double price) {
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
if (!(sender instanceof Player player)) { if (!(sender instanceof Player player)) {
BooksWithoutBorders.sendErrorMessage(sender, "[Item] price can only be used by a player!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
return false; return false;
} }
ItemStack heldItem = InventoryHelper.getHeldItem(player, true); ItemStack heldItem = InventoryHelper.getHeldItem(player, true);
if (heldItem.getType() == Material.AIR) { if (heldItem.getType() == Material.AIR) {
BooksWithoutBorders.sendErrorMessage(sender, "Must be holding an item to set an [Item] price!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_COST_ITEM_MISSING);
return false; return false;
} }
@@ -105,12 +108,13 @@ public class CommandSetBookPrice implements TabExecutor {
config.setBookPriceQuantity(price); config.setBookPriceQuantity(price);
String newPriceType = config.getBookPriceType().toString(); String newPriceType = config.getBookPriceType().toString();
double newPriceQuantity = config.getBookPriceQuantity(); double newPriceQuantity = config.getBookPriceQuantity();
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", newPriceType); booksWithoutBorders.getConfig().set(ConfigOption.PRICE_ITEM_TYPE.getConfigNode(), newPriceType);
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", newPriceQuantity); booksWithoutBorders.getConfig().set(ConfigOption.PRICE_QUANTITY.getConfigNode(), newPriceQuantity);
booksWithoutBorders.saveConfig(); booksWithoutBorders.saveConfig();
BooksWithoutBorders.sendSuccessMessage(sender, "Book creation price set to " + (int) newPriceQuantity + stringFormatter.displaySuccessMessage(sender, stringFormatter.replacePlaceholders(
" " + newPriceType + "(s)!"); Translatable.SUCCESS_COST_ITEM_SET, List.of("{quantity}", "{price}"),
List.of(String.valueOf((int) newPriceQuantity), newPriceType)));
return true; return true;
} }
@@ -122,18 +126,19 @@ public class CommandSetBookPrice implements TabExecutor {
* @return <p>True if the price was changed successfully</p> * @return <p>True if the price was changed successfully</p>
*/ */
private boolean setEconomyPrice(@NotNull CommandSender sender, double price) { private boolean setEconomyPrice(@NotNull CommandSender sender, double price) {
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
EconomyManager economyManager = BooksWithoutBorders.getConfiguration().getEconomyManager(); EconomyManager economyManager = BooksWithoutBorders.getConfiguration().getEconomyManager();
if (economyManager.getEconomy() != null) { if (economyManager.getEconomy() != null) {
BwBConfig config = BooksWithoutBorders.getConfiguration(); BwBConfig config = BooksWithoutBorders.getConfiguration();
config.setBookPriceQuantity(price); config.setBookPriceQuantity(price);
config.setBookPriceType(Material.AIR); config.setBookPriceType(Material.AIR);
double newPriceQuantity = config.getBookPriceQuantity(); double newPriceQuantity = config.getBookPriceQuantity();
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Item_type", "Economy"); booksWithoutBorders.getConfig().set(ConfigOption.PRICE_ITEM_TYPE.getConfigNode(), "Economy");
booksWithoutBorders.getConfig().set("Options.Price_to_create_book.Required_quantity", newPriceQuantity); booksWithoutBorders.getConfig().set(ConfigOption.PRICE_QUANTITY.getConfigNode(), newPriceQuantity);
booksWithoutBorders.saveConfig(); booksWithoutBorders.saveConfig();
BooksWithoutBorders.sendSuccessMessage(sender, "Book creation price set to " + stringFormatter.displaySuccessMessage(sender, stringFormatter.replacePlaceholder(
economyManager.getEconomy().format(newPriceQuantity) + "!"); Translatable.SUCCESS_COST_ECONOMY_SET, "{cost}", economyManager.getEconomy().format(newPriceQuantity)));
return true; return true;
} else { } else {
BooksWithoutBorders.sendErrorMessage(sender, StaticMessage.EXCEPTION_VAULT_PRICE_NOT_CHANGED.toString()); BooksWithoutBorders.sendErrorMessage(sender, StaticMessage.EXCEPTION_VAULT_PRICE_NOT_CHANGED.toString());
@@ -163,7 +168,7 @@ public class CommandSetBookPrice implements TabExecutor {
private void initializeTabCompleteLists() { private void initializeTabCompleteLists() {
paymentTypes = new ArrayList<>(); paymentTypes = new ArrayList<>();
paymentTypes.add("item"); paymentTypes.add("item");
paymentTypes.add("eco"); paymentTypes.add("economy");
} }
} }

View File

@@ -1,8 +1,10 @@
package net.knarcraft.bookswithoutborders.command; package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.Translatable;
import net.knarcraft.bookswithoutborders.container.Bookshelf; import net.knarcraft.bookswithoutborders.container.Bookshelf;
import net.knarcraft.bookswithoutborders.handler.BookshelfHandler; import net.knarcraft.bookswithoutborders.handler.BookshelfHandler;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.util.TabCompletionHelper; import net.knarcraft.knarlib.util.TabCompletionHelper;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@@ -23,16 +25,17 @@ import java.util.List;
public class CommandSetBookshelfData implements TabExecutor { public class CommandSetBookshelfData implements TabExecutor {
@Override @Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) { @NotNull String[] arguments) {
if (!(commandSender instanceof Player player)) { StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
BooksWithoutBorders.sendErrorMessage(commandSender, "This command must be used by a player!"); if (!(sender instanceof Player player)) {
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
return false; return false;
} }
Block targetBlock = player.getTargetBlockExact(7); Block targetBlock = player.getTargetBlockExact(7);
if (targetBlock == null || targetBlock.getType() != Material.CHISELED_BOOKSHELF) { if (targetBlock == null || targetBlock.getType() != Material.CHISELED_BOOKSHELF) {
BooksWithoutBorders.sendErrorMessage(commandSender, "You are not looking at a bookshelf!"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_BOOKSHELF_NOT_FOUND);
return false; return false;
} }
@@ -44,9 +47,9 @@ public class CommandSetBookshelfData implements TabExecutor {
if (bookshelf != null) { if (bookshelf != null) {
shelfHandler.unregisterBookshelf(bookshelf); shelfHandler.unregisterBookshelf(bookshelf);
shelfHandler.save(); shelfHandler.save();
BooksWithoutBorders.sendSuccessMessage(commandSender, "Bookshelf successfully deleted"); stringFormatter.displaySuccessMessage(sender, Translatable.SUCCESS_BOOKSHELF_DATA_DELETED);
} else { } else {
BooksWithoutBorders.sendErrorMessage(commandSender, "The block you are looking at is not a registered bookshelf"); stringFormatter.displayErrorMessage(sender, Translatable.ERROR_BOOKSHELF_NOT_REGISTERED);
} }
return true; return true;
} else { } else {
@@ -69,17 +72,16 @@ public class CommandSetBookshelfData implements TabExecutor {
bookshelf.setTitle(builder.toString()); bookshelf.setTitle(builder.toString());
} }
shelfHandler.save(); shelfHandler.save();
BooksWithoutBorders.sendSuccessMessage(commandSender, "Title successfully saved"); stringFormatter.displaySuccessMessage(sender, Translatable.SUCCESS_BOOKSHELF_TITLE_SET);
return true; return true;
case "lore": case "lore":
if (bookshelf == null) { if (bookshelf == null) {
BooksWithoutBorders.sendErrorMessage(commandSender, "You must name the bookshelf before " + stringFormatter.displayErrorMessage(sender, Translatable.ERROR_BOOKSHELF_NAME_REQUIRED);
"assigning lore!");
} else { } else {
List<String> loreParts = Arrays.asList(builder.toString().split(BooksWithoutBorders.getConfiguration().getLoreSeparator())); List<String> loreParts = Arrays.asList(builder.toString().split(BooksWithoutBorders.getConfiguration().getLoreSeparator()));
bookshelf.setLore(loreParts); bookshelf.setLore(loreParts);
shelfHandler.save(); shelfHandler.save();
BooksWithoutBorders.sendSuccessMessage(commandSender, "Lore successfully saved"); stringFormatter.displaySuccessMessage(sender, Translatable.SUCCESS_BOOKSHELF_LORE_SET);
} }
return true; return true;
} }

View File

@@ -289,7 +289,6 @@ public class BwBConfig {
* Saves the config * Saves the config
*/ */
public void saveConfigValues() { public void saveConfigValues() {
Logger logger = BooksWithoutBorders.getInstance().getLogger();
Configuration config = BooksWithoutBorders.getInstance().getConfig(); Configuration config = BooksWithoutBorders.getInstance().getConfig();
config.set(ConfigOption.MAX_DUPLICATES.getConfigNode(), this.bookDuplicateLimit); config.set(ConfigOption.MAX_DUPLICATES.getConfigNode(), this.bookDuplicateLimit);
config.set(ConfigOption.TITLE_AUTHOR_SEPARATOR.getConfigNode(), this.titleAuthorSeparator); config.set(ConfigOption.TITLE_AUTHOR_SEPARATOR.getConfigNode(), this.titleAuthorSeparator);
@@ -317,20 +316,6 @@ public class BwBConfig {
config.set(ConfigOption.AUTHOR_ONLY_UNSIGN.getConfigNode(), this.authorOnlyUnsign); config.set(ConfigOption.AUTHOR_ONLY_UNSIGN.getConfigNode(), this.authorOnlyUnsign);
config.set(ConfigOption.AUTHOR_ONLY_SAVE.getConfigNode(), this.authorOnlySave); config.set(ConfigOption.AUTHOR_ONLY_SAVE.getConfigNode(), this.authorOnlySave);
config.set(ConfigOption.CHANGE_GENERATION_ON_COPY.getConfigNode(), this.changeGenerationOnCopy); config.set(ConfigOption.CHANGE_GENERATION_ON_COPY.getConfigNode(), this.changeGenerationOnCopy);
//Handles old book and quill settings
if (config.contains("Options.Require_book_and_quill_to_create_book")) {
logger.log(Level.INFO, "[BooksWithoutBorders] Found old config setting " +
"\"Require_book_and_quill_to_create_book\"\nUpdating to \"Price_to_create_book\" settings");
if (config.getBoolean("Options.Require_book_and_quill_to_create_book")) {
this.bookPriceType = Material.WRITABLE_BOOK;
this.bookPriceQuantity = 1;
config.set("Options.Price_to_create_book.Item_type", this.bookPriceType.toString());
config.set("Options.Price_to_create_book.Required_quantity", this.bookPriceQuantity);
}
config.set("Options.Require_book_and_quill_to_create_book", null);
}
BooksWithoutBorders.getInstance().saveConfig(); BooksWithoutBorders.getInstance().saveConfig();
} }
@@ -383,10 +368,10 @@ public class BwBConfig {
//Make sure titleAuthorSeparator is a valid value //Make sure titleAuthorSeparator is a valid value
this.titleAuthorSeparator = cleanString(this.titleAuthorSeparator); this.titleAuthorSeparator = cleanString(this.titleAuthorSeparator);
if (this.titleAuthorSeparator.length() != 1) { if (this.titleAuthorSeparator.length() != 1) {
logger.log(Level.SEVERE, "Title-Author_Separator is set to an invalid value!\n" + logger.log(Level.SEVERE, "Title author separator is set to an invalid value!\n" +
"Reverting to default value of \",\""); "Reverting to default value of \",\"");
this.titleAuthorSeparator = ","; this.titleAuthorSeparator = ",";
config.set("Options.Title-Author_Separator", this.titleAuthorSeparator); config.set(ConfigOption.TITLE_AUTHOR_SEPARATOR.getConfigNode(), this.titleAuthorSeparator);
} }
} catch (Exception exception) { } catch (Exception exception) {
logger.log(Level.SEVERE, exception.getMessage()); logger.log(Level.SEVERE, exception.getMessage());

View File

@@ -78,6 +78,41 @@ public enum Translatable implements TranslatableMessage {
*/ */
SUCCESS_SAVED, SUCCESS_SAVED,
/**
* The success message displayed when a book author is successfully set
*/
SUCCESS_SET_AUTHOR,
/**
* The success message displayed when the book creation cost is successfully removed
*/
SUCCESS_COST_REMOVED,
/**
* The success message displayed when the book creation cost is successfully set to an item
*/
SUCCESS_COST_ITEM_SET,
/**
* The success message displayed when the book creation cost is successfully set to an economy cost
*/
SUCCESS_COST_ECONOMY_SET,
/**
* The success message displayed when a bookshelf's data has been successfully removed
*/
SUCCESS_BOOKSHELF_DATA_DELETED,
/**
* The success message displayed when a bookshelf's title is successfully set
*/
SUCCESS_BOOKSHELF_TITLE_SET,
/**
* The success message displayed when a bookshelf's lore is successfully set
*/
SUCCESS_BOOKSHELF_LORE_SET,
/** /**
* The error to display when the console attempts to run a player-only command * The error to display when the console attempts to run a player-only command
*/ */
@@ -283,6 +318,46 @@ public enum Translatable implements TranslatableMessage {
*/ */
ERROR_UNKNOWN_COMMAND, ERROR_UNKNOWN_COMMAND,
/**
* The error displayed when changing a book's author without providing the new author
*/
ERROR_AUTHOR_BLANK,
/**
* The error displayed when attempting to specify a cost without necessary arguments
*/
ERROR_COST_NOT_SPECIFIED,
/**
* The error displayed when specifying an invalid cost quantity when setting a cost
*/
ERROR_COST_INVALID_QUANTITY,
/**
* The error displayed when specifying an invalid cost type when setting a cost
*/
ERROR_COST_INVALID_TYPE,
/**
* The error displayed when attempting to set an item cost without providing an item
*/
ERROR_COST_ITEM_MISSING,
/**
* The error displayed when attempting to alter bookshelf data while not looking at a bookshelf
*/
ERROR_BOOKSHELF_NOT_FOUND,
/**
* The error displayed when attempting to deleting a bookshelf while looking at a non-registered bookshelf
*/
ERROR_BOOKSHELF_NOT_REGISTERED,
/**
* The error displayed when attempting to set other bookshelf data before setting the name
*/
ERROR_BOOKSHELF_NAME_REQUIRED,
/** /**
* The header displayed before printing all commands * The header displayed before printing all commands
*/ */
@@ -372,6 +447,11 @@ public enum Translatable implements TranslatableMessage {
* The translation of the add title page action * The translation of the add title page action
*/ */
ACTION_ADD_TITLE_AUTHOR_PAGE, ACTION_ADD_TITLE_AUTHOR_PAGE,
/**
* The translation of the set author action
*/
ACTION_SET_AUTHOR,
; ;
@Override @Override

View File

@@ -14,12 +14,20 @@ en:
SUCCESS_MIGRATION_STARTED: "Starting book migration..." SUCCESS_MIGRATION_STARTED: "Starting book migration..."
SUCCESS_RELOADED: "Configuration, books and language strings reloaded!" SUCCESS_RELOADED: "Configuration, books and language strings reloaded!"
SUCCESS_SAVED: "Book Saved as &e\"{fileName}\"&r" SUCCESS_SAVED: "Book Saved as &e\"{fileName}\"&r"
SUCCESS_SET_AUTHOR: "Book author set to {author}!"
SUCCESS_COST_REMOVED: "Price to create books removed!"
SUCCESS_COST_ITEM_SET: "Book creation price set to {quantity} {price}(s)!"
SUCCESS_COST_ECONOMY_SET: "Book creation price set to {cost}!"
SUCCESS_BOOKSHELF_DATA_DELETED: "Bookshelf successfully deleted"
SUCCESS_BOOKSHELF_TITLE_SET: "Title successfully saved"
SUCCESS_BOOKSHELF_LORE_SET: "Lore successfully saved"
ACTION_COPY: "copy" ACTION_COPY: "copy"
ACTION_CLEAR: "clear" ACTION_CLEAR: "clear"
ACTION_DECRYPT: "decrypt" ACTION_DECRYPT: "decrypt"
ACTION_ENCRYPT: "encrypt" ACTION_ENCRYPT: "encrypt"
ACTION_FORMAT: "format" ACTION_FORMAT: "format"
ACTION_ADD_TITLE_AUTHOR_PAGE: "add an author title page to" ACTION_ADD_TITLE_AUTHOR_PAGE: "add an author title page to"
ACTION_SET_AUTHOR: "set author"
ERROR_PLAYER_ONLY: "This command can only be used by a player!" ERROR_PLAYER_ONLY: "This command can only be used by a player!"
ERROR_NOT_HOLDING_WRITTEN_BOOK: "You must be holding a written book to {action} it!" ERROR_NOT_HOLDING_WRITTEN_BOOK: "You must be holding a written book to {action} it!"
ERROR_NOT_HOLDING_WRITABLE_BOOK: "You must be holding a writable book to {action} it!" ERROR_NOT_HOLDING_WRITABLE_BOOK: "You must be holding a writable book to {action} it!"
@@ -65,6 +73,14 @@ en:
ERROR_SAVE_DUPLICATE_NAMED: "Book is already saved!" ERROR_SAVE_DUPLICATE_NAMED: "Book is already saved!"
ERROR_SAVE_DUPLICATE_UNNAMED: "Maximum amount of {fileName} duplicates reached!" ERROR_SAVE_DUPLICATE_UNNAMED: "Maximum amount of {fileName} duplicates reached!"
ERROR_UNKNOWN_COMMAND: "Invalid command specified" ERROR_UNKNOWN_COMMAND: "Invalid command specified"
ERROR_AUTHOR_BLANK: "You must specify an author"
ERROR_COST_NOT_SPECIFIED: "[Item/Eco] and [quantity] must be specified!"
ERROR_COST_INVALID_QUANTITY: "[quantity] must be a number greater than 0!"
ERROR_COST_INVALID_TYPE: "Price type must be \"item\" or \"economy\"!"
ERROR_COST_ITEM_MISSING: "Must be holding an item to set an [Item] price!"
ERROR_BOOKSHELF_NOT_FOUND: "You are not looking at a bookshelf!"
ERROR_BOOKSHELF_NOT_REGISTERED: "The block you are looking at is not a registered bookshelf"
ERROR_BOOKSHELF_NAME_REQUIRED: "You must name the bookshelf before assigning lore!"
NEUTRAL_COMMANDS_HEADER: | NEUTRAL_COMMANDS_HEADER: |
&nBooks without Borders help page&r &nBooks without Borders help page&r
&e[] = optional, <> = required (see each description for exceptions) &e[] = optional, <> = required (see each description for exceptions)