Removes static strings from the deletePage command
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
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;
|
||||
@@ -20,20 +22,22 @@ import java.util.List;
|
||||
public class CommandDeletePage implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] arguments) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
StringFormatter stringFormatter = BooksWithoutBorders.getStringFormatter();
|
||||
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;
|
||||
}
|
||||
|
||||
if (arguments.length == 0) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "You must supply a page index");
|
||||
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_NO_BOOK_PAGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
if (heldBook == null) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "You must be holding a book to perform this command");
|
||||
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_NOT_HOLDING_ANY_BOOK);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -41,19 +45,19 @@ public class CommandDeletePage implements TabExecutor {
|
||||
try {
|
||||
index = Integer.parseInt(arguments[0]) - 1;
|
||||
} catch (NumberFormatException exception) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "Invalid page index given!");
|
||||
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_INVALID_BOOK_PAGE);
|
||||
return 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;
|
||||
}
|
||||
List<String> pages = new ArrayList<>(bookMeta.getPages());
|
||||
|
||||
if (index < 0 || index >= pages.size()) {
|
||||
BooksWithoutBorders.sendErrorMessage(sender, "The given page index is out of bounds!");
|
||||
stringFormatter.displayErrorMessage(sender, Translatable.ERROR_OUT_OF_RANGE_BOOK_PAGE);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ public class CommandDeletePage implements TabExecutor {
|
||||
|
||||
bookMeta.setPages(pages);
|
||||
heldBook.setItemMeta(bookMeta);
|
||||
BooksWithoutBorders.sendSuccessMessage(sender, "Page deleted!");
|
||||
stringFormatter.displaySuccessMessage(sender, Translatable.SUCCESS_PAGE_DELETED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -53,6 +53,11 @@ public enum Translatable implements TranslatableMessage {
|
||||
*/
|
||||
SUCCESS_TITLE_PAGE_ADDED,
|
||||
|
||||
/**
|
||||
* The success message displayed when a book page is successfully deleted
|
||||
*/
|
||||
SUCCESS_PAGE_DELETED,
|
||||
|
||||
/**
|
||||
* The error to display when the console attempts to run a player-only command
|
||||
*/
|
||||
@@ -198,6 +203,16 @@ public enum Translatable implements TranslatableMessage {
|
||||
*/
|
||||
ERROR_INVALID_BOOK_PAGE,
|
||||
|
||||
/**
|
||||
* The error displayed when a book page number is required, but none is specified
|
||||
*/
|
||||
ERROR_NO_BOOK_PAGE,
|
||||
|
||||
/**
|
||||
* The error displayed when a supplied book page number is out of bounds
|
||||
*/
|
||||
ERROR_OUT_OF_RANGE_BOOK_PAGE,
|
||||
|
||||
/**
|
||||
* The header displayed before printing all commands
|
||||
*/
|
||||
|
@@ -9,6 +9,7 @@ en:
|
||||
SUCCESS_GIVE_SENT: "Book sent!"
|
||||
SUCCESS_GIVE_RECEIVED: "Book received!"
|
||||
SUCCESS_TITLE_PAGE_ADDED: "Title page added!"
|
||||
SUCCESS_PAGE_DELETED: "Page deleted!"
|
||||
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_WRITABLE_BOOK: "You must be holding a writable book to {action} it!"
|
||||
@@ -46,6 +47,8 @@ en:
|
||||
ERROR_GIVE_INVALID_COPIES_AMOUNT: "Invalid number of book copies specified!"
|
||||
ERROR_GIVE_LOAD_FAILED: "Book failed to load!"
|
||||
ERROR_INVALID_BOOK_PAGE: "Invalid page index given!"
|
||||
ERROR_OUT_OF_RANGE_BOOK_PAGE: "The given page index is out of bounds!"
|
||||
ERROR_NO_BOOK_PAGE: "You must supply a page index"
|
||||
NEUTRAL_COMMANDS_HEADER: |
|
||||
&e[] denote optional parameters
|
||||
<> denote required parameters
|
||||
|
Reference in New Issue
Block a user