Removes static strings from the clear command
This commit is contained in:
@@ -3,6 +3,7 @@ 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.config.Translatable;
|
||||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||||
|
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
import org.bukkit.command.TabExecutor;
|
||||||
@@ -23,13 +24,18 @@ public class CommandClear 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[] args) {
|
@NotNull String[] args) {
|
||||||
|
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
|
||||||
|
|
||||||
if (!(sender instanceof Player player)) {
|
if (!(sender instanceof Player player)) {
|
||||||
BooksWithoutBorders.getStringFormatter().displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
|
BooksWithoutBorders.getStringFormatter().displayErrorMessage(sender, Translatable.ERROR_PLAYER_ONLY);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (InventoryHelper.notHoldingOneWritableBookCheck(player, "You must be holding a writable book to " +
|
if (InventoryHelper.notHoldingOneWritableBookCheck(player,
|
||||||
"clear it!", "You cannot clear two books at once!")) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +43,7 @@ public class CommandClear implements TabExecutor {
|
|||||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, false);
|
ItemStack heldBook = InventoryHelper.getHeldBook(player, false);
|
||||||
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
||||||
if (bookMeta == null) {
|
if (bookMeta == null) {
|
||||||
BooksWithoutBorders.sendErrorMessage(sender, "Unable to get metadata for the held book!");
|
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_METADATA_MISSING);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bookMeta.setPages("");
|
bookMeta.setPages("");
|
||||||
@@ -45,7 +51,7 @@ public class CommandClear implements TabExecutor {
|
|||||||
bookMeta.setGeneration(null);
|
bookMeta.setGeneration(null);
|
||||||
bookMeta.setTitle(null);
|
bookMeta.setTitle(null);
|
||||||
heldBook.setItemMeta(bookMeta);
|
heldBook.setItemMeta(bookMeta);
|
||||||
BooksWithoutBorders.sendSuccessMessage(sender, "Book cleared!");
|
stringFormatter.displaySuccessMessage(sender, Translatable.SUCCESS_CLEARED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -39,8 +39,10 @@ public class CommandCopy implements TabExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||||
stringFormatter.getUnFormattedColoredMessage(Translatable.ERROR_NOT_HOLDING_BOOK_COPY),
|
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
|
||||||
stringFormatter.getUnFormattedColoredMessage(Translatable.ERROR_ONLY_ONE_BOOK_COPY))) {
|
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_COPY)),
|
||||||
|
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
|
||||||
|
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_COPY)))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,20 +18,30 @@ public enum Translatable implements TranslatableMessage {
|
|||||||
*/
|
*/
|
||||||
SUCCESS_COPY,
|
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
|
* The error to display when the console attempts to run a player-only command
|
||||||
*/
|
*/
|
||||||
ERROR_PLAYER_ONLY,
|
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
|
* 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,
|
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
|
* 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
|
* The format used when displaying a command's required permission
|
||||||
*/
|
*/
|
||||||
NEUTRAL_COMMANDS_COMMAND_PERMISSION,
|
NEUTRAL_COMMANDS_COMMAND_PERMISSION,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The translation of the copy action
|
||||||
|
*/
|
||||||
|
ACTION_COPY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The translation of the clear action
|
||||||
|
*/
|
||||||
|
ACTION_CLEAR,
|
||||||
;
|
;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
en:
|
en:
|
||||||
PREFIX: "[BwB]"
|
PREFIX: "[BwB]"
|
||||||
SUCCESS_COPY: "Book copied!"
|
SUCCESS_COPY: "Book copied!"
|
||||||
|
SUCCESS_CLEARED: "Book cleared!"
|
||||||
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_BOOK_COPY: "You must be holding a written book to copy it!"
|
ERROR_NOT_HOLDING_WRITTEN_BOOK: "You must be holding a written book to {action} it!"
|
||||||
ERROR_ONLY_ONE_BOOK_COPY: "You cannot copy two books at once!"
|
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_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_NEGATIVE_AMOUNT: "Number of copies must be larger than 0!"
|
||||||
ERROR_COPY_INVALID_AMOUNT: |
|
ERROR_COPY_INVALID_AMOUNT: |
|
||||||
@@ -11,6 +13,7 @@ en:
|
|||||||
Number specified was invalid!
|
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_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_INVENTORY_FULL: "You need an available slot in your inventory."
|
||||||
|
ERROR_METADATA_MISSING: "Unable to get metadata for the held book!"
|
||||||
NEUTRAL_COMMANDS_HEADER: |
|
NEUTRAL_COMMANDS_HEADER: |
|
||||||
&e[] denote optional parameters
|
&e[] denote optional parameters
|
||||||
<> denote required 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_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: "\n \n&e{usage}: &a{description}"
|
||||||
NEUTRAL_COMMANDS_COMMAND_NO_PERMISSION_REQUIRED: "None"
|
NEUTRAL_COMMANDS_COMMAND_NO_PERMISSION_REQUIRED: "None"
|
||||||
NEUTRAL_COMMANDS_COMMAND_PERMISSION: " &7{{permission}}"
|
NEUTRAL_COMMANDS_COMMAND_PERMISSION: " &7{{permission}}"
|
||||||
|
ACTION_COPY: "copy"
|
||||||
|
ACTION_CLEAR: "clear"
|
Reference in New Issue
Block a user