diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandClear.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandClear.java index 68645f4..1a66de7 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandClear.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandClear.java @@ -3,6 +3,7 @@ package net.knarcraft.bookswithoutborders.command; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.config.Translatable; import net.knarcraft.bookswithoutborders.utility.InventoryHelper; +import net.knarcraft.knarlib.formatting.StringFormatter; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -23,13 +24,18 @@ public class CommandClear implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter(); + if (!(sender instanceof Player player)) { BooksWithoutBorders.getStringFormatter().displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY); return false; } - if (InventoryHelper.notHoldingOneWritableBookCheck(player, "You must be holding a writable book to " + - "clear it!", "You cannot clear two books at once!")) { + if (InventoryHelper.notHoldingOneWritableBookCheck(player, + stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITABLE_BOOK, "{action}", + stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_CLEAR)), + stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}", + stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_CLEAR)))) { return false; } @@ -37,7 +43,7 @@ public class CommandClear implements TabExecutor { ItemStack heldBook = InventoryHelper.getHeldBook(player, false); BookMeta bookMeta = (BookMeta) heldBook.getItemMeta(); if (bookMeta == null) { - BooksWithoutBorders.sendErrorMessage(sender, "Unable to get metadata for the held book!"); + stringFormatter.displayErrorMessage(sender, Translatable.ERROR_METADATA_MISSING); return false; } bookMeta.setPages(""); @@ -45,7 +51,7 @@ public class CommandClear implements TabExecutor { bookMeta.setGeneration(null); bookMeta.setTitle(null); heldBook.setItemMeta(bookMeta); - BooksWithoutBorders.sendSuccessMessage(sender, "Book cleared!"); + stringFormatter.displaySuccessMessage(sender, Translatable.SUCCESS_CLEARED); return true; } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandCopy.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandCopy.java index 93fbbb3..b977ee5 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandCopy.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandCopy.java @@ -39,8 +39,10 @@ public class CommandCopy implements TabExecutor { } if (InventoryHelper.notHoldingOneWrittenBookCheck(player, - stringFormatter.getUnFormattedColoredMessage(Translatable.ERROR_NOT_HOLDING_BOOK_COPY), - stringFormatter.getUnFormattedColoredMessage(Translatable.ERROR_ONLY_ONE_BOOK_COPY))) { + stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}", + stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_COPY)), + stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}", + stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_COPY)))) { return false; } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/config/Translatable.java b/src/main/java/net/knarcraft/bookswithoutborders/config/Translatable.java index 949a122..7960b36 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/config/Translatable.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/config/Translatable.java @@ -18,20 +18,30 @@ public enum Translatable implements TranslatableMessage { */ SUCCESS_COPY, + /** + * The success message displayed when the clear command succeeds + */ + SUCCESS_CLEARED, + /** * The error to display when the console attempts to run a player-only command */ ERROR_PLAYER_ONLY, /** - * The error displayed when running the copy command without holding a written book + * The error displayed when running a relevant command without holding a written book */ - ERROR_NOT_HOLDING_BOOK_COPY, + ERROR_NOT_HOLDING_WRITTEN_BOOK, /** - * The error displayed when running the copy command while holding one book in each hand + * The error displayed when running a relevant command without holding a writable book */ - ERROR_ONLY_ONE_BOOK_COPY, + ERROR_NOT_HOLDING_WRITABLE_BOOK, + + /** + * The error displayed when running a relevant command while holding one book in each hand + */ + ERROR_ONLY_ONE_BOOK, /** * The error displayed when running the copy command without specifying the amount of copies @@ -53,6 +63,11 @@ public enum Translatable implements TranslatableMessage { */ ERROR_BOOK_COPIED_TOO_FAR, + /** + * The error displayed when unable to get book metadata from the held book + */ + ERROR_METADATA_MISSING, + /** * The error displayed when trying to receive a book with a full inventory */ @@ -87,6 +102,16 @@ public enum Translatable implements TranslatableMessage { * The format used when displaying a command's required permission */ NEUTRAL_COMMANDS_COMMAND_PERMISSION, + + /** + * The translation of the copy action + */ + ACTION_COPY, + + /** + * The translation of the clear action + */ + ACTION_CLEAR, ; @Override diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index 1930038..e048f05 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -1,9 +1,11 @@ en: PREFIX: "[BwB]" SUCCESS_COPY: "Book copied!" + SUCCESS_CLEARED: "Book cleared!" ERROR_PLAYER_ONLY: "This command can only be used by a player!" - ERROR_NOT_HOLDING_BOOK_COPY: "You must be holding a written book to copy it!" - ERROR_ONLY_ONE_BOOK_COPY: "You cannot copy two books at once!" + 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_ONLY_ONE_BOOK: "You cannot {action} two books at once!" ERROR_COPY_COUNT_NOT_SPECIFIED: "You must specify the number of copies to be made!" ERROR_COPY_NEGATIVE_AMOUNT: "Number of copies must be larger than 0!" ERROR_COPY_INVALID_AMOUNT: | @@ -11,6 +13,7 @@ en: Number specified was invalid! ERROR_BOOK_COPIED_TOO_FAR: "You cannot copy this book any further. You must have the original or a direct copy." ERROR_INVENTORY_FULL: "You need an available slot in your inventory." + ERROR_METADATA_MISSING: "Unable to get metadata for the held book!" NEUTRAL_COMMANDS_HEADER: | &e[] denote optional parameters <> denote required parameters @@ -22,4 +25,6 @@ en: NEUTRAL_COMMANDS_BOOK_PRICE_ITEM: "&c[{quantity} {type} (s) are required to create a book]\n" NEUTRAL_COMMANDS_COMMAND: "\n \n&e{usage}: &a{description}" NEUTRAL_COMMANDS_COMMAND_NO_PERMISSION_REQUIRED: "None" - NEUTRAL_COMMANDS_COMMAND_PERMISSION: " &7{{permission}}" \ No newline at end of file + NEUTRAL_COMMANDS_COMMAND_PERMISSION: " &7{{permission}}" + ACTION_COPY: "copy" + ACTION_CLEAR: "clear" \ No newline at end of file