Replaces more static strings, and removes hard-coded lore separators in suggestions
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good

This commit is contained in:
2025-08-20 00:33:50 +02:00
parent ca738e55b3
commit 887cc72f0d
15 changed files with 128 additions and 70 deletions

View File

@@ -214,7 +214,7 @@ public class BooksWithoutBorders extends JavaPlugin {
translator.registerMessageCategory(Translatable.SUCCESS_COPY);
translator.registerMessageCategory(GiveMessage.SUCCESS_GIVE_SENT);
translator.registerMessageCategory(BookshelfMessage.SUCCESS_BOOKSHELF_TITLE_SET);
translator.registerMessageCategory(Formatting.ACTION_COPY);
translator.registerMessageCategory(Formatting.NEUTRAL_COMMANDS_HEADER);
translator.registerMessageCategory(CostMessage.SUCCESS_COST_ITEM_SET);
translator.registerMessageCategory(SaveMessage.SUCCESS_SAVED);

View File

@@ -45,9 +45,9 @@ public class CommandAddTitlePage implements TabExecutor {
if (arguments.length < 1) {
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_ADD_TITLE_AUTHOR_PAGE)),
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_ADD_TITLE_AUTHOR_PAGE)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_ADD_TITLE_AUTHOR_PAGE)))) {
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_ADD_TITLE_AUTHOR_PAGE)))) {
return false;
}
@@ -163,7 +163,8 @@ public class CommandAddTitlePage implements TabExecutor {
}
}
} else if (arguments.length == 2) {
return List.of("Title", "Chapter~Description");
String separator = BooksWithoutBorders.getConfiguration().getTitleAuthorSeparator();
return List.of("Title", "Chapter" + separator + "Description");
}
return List.of();
}

View File

@@ -1,7 +1,6 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
@@ -35,9 +34,9 @@ public class CommandClear implements TabExecutor {
if (InventoryHelper.notHoldingOneWritableBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITABLE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_CLEAR)),
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_CLEAR)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_CLEAR)))) {
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_CLEAR)))) {
return false;
}

View File

@@ -3,7 +3,6 @@ package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.BwBConfig;
import net.knarcraft.bookswithoutborders.config.Permission;
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.utility.BookHelper;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
@@ -40,9 +39,9 @@ public class CommandCopy implements TabExecutor {
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_COPY)),
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_COPY)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_COPY)))) {
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_COPY)))) {
return false;
}

View File

@@ -2,7 +2,6 @@ package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.Permission;
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.utility.BookHelper;
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
@@ -37,9 +36,9 @@ public class CommandDecrypt implements TabExecutor {
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_DECRYPT)),
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_DECRYPT)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_DECRYPT)))) {
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_DECRYPT)))) {
return false;
}

View File

@@ -1,7 +1,6 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.encryption.EncryptionStyle;
import net.knarcraft.bookswithoutborders.state.ItemSlot;
@@ -65,9 +64,9 @@ public class CommandEncrypt implements TabExecutor {
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_ENCRYPT)),
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_ENCRYPT)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_ENCRYPT)))) {
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_ENCRYPT)))) {
return null;
}

View File

@@ -1,7 +1,6 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.state.ItemSlot;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
@@ -41,9 +40,9 @@ public class CommandSetAuthor implements TabExecutor {
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_SET_AUTHOR)),
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_SET_AUTHOR)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Formatting.ACTION_SET_AUTHOR)))) {
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_SET_AUTHOR)))) {
return false;
}

View File

@@ -94,6 +94,7 @@ public class CommandSetBookshelfData implements TabExecutor {
@Override
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@NotNull String[] arguments) {
String separator = BooksWithoutBorders.getConfiguration().getTitleAuthorSeparator();
if (arguments.length == 1) {
return TabCompletionHelper.filterMatchingStartsWith(List.of("delete", "name", "lore"), arguments[0]);
} else if (arguments.length == 2) {
@@ -101,8 +102,8 @@ public class CommandSetBookshelfData implements TabExecutor {
case "delete" -> new ArrayList<>();
case "name" ->
TabCompletionHelper.filterMatchingStartsWith(List.of("Epic Title", "Lame Title"), arguments[1]);
case "lore" ->
TabCompletionHelper.filterMatchingStartsWith(List.of("Interesting lore", "Line1~Line2~Line3"), arguments[1]);
case "lore" -> TabCompletionHelper.filterMatchingStartsWith(List.of("Interesting lore",
"Line1" + separator + "Line2" + separator + "Line3"), arguments[1]);
default -> null;
};
} else {

View File

@@ -1,7 +1,9 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.translation.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;
@@ -22,18 +24,22 @@ public class CommandSetGeneration implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@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 (InventoryHelper.notHoldingOneWrittenBookCheck(player, "You must be holding a written book to" +
" change its generation!", "You cannot change the generation of two books at once!")) {
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
stringFormatter.replacePlaceholder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_CHANGE_GENERATION)),
stringFormatter.replacePlaceholder(Translatable.ERROR_ONLY_ONE_BOOK, "{action}",
stringFormatter.getUnFormattedColoredMessage(Translatable.ACTION_CHANGE_GENERATION)))) {
return false;
}
if (arguments.length < 1) {
BooksWithoutBorders.sendErrorMessage(player, "You must specify the new generation for your book!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_GENERATION_NOT_SPECIFIED);
return false;
}
@@ -41,7 +47,7 @@ public class CommandSetGeneration implements TabExecutor {
try {
generation = BookMeta.Generation.valueOf(arguments[0]);
} catch (IllegalArgumentException exception) {
BooksWithoutBorders.sendErrorMessage(player, "Invalid book generation specified!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_GENERATION_INVALID);
return false;
}
@@ -50,9 +56,10 @@ public class CommandSetGeneration implements TabExecutor {
if (bookMeta != null) {
bookMeta.setGeneration(generation);
heldBook.setItemMeta(bookMeta);
stringFormatter.displayErrorMessage(player, Translatable.SUCCESS_GENERATION_CHANGED);
return true;
} else {
BooksWithoutBorders.sendErrorMessage(player, "Unable to get book metadata!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_METADATA_MISSING);
return false;
}
}

View File

@@ -1,7 +1,9 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.property.ColorConversion;
import net.knarcraft.knarlib.util.ColorHelper;
import org.bukkit.Material;
@@ -25,19 +27,20 @@ public class CommandSetLore implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@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 < 1) {
BooksWithoutBorders.sendErrorMessage(player, "Missing a command argument!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_LORE_EMPTY);
return false;
}
ItemStack heldItem = InventoryHelper.getHeldItem(player, true);
if (heldItem.getType() == Material.AIR) {
BooksWithoutBorders.sendErrorMessage(player, "Must be holding an item to set lore!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_LORE_NO_ITEM);
return false;
}
@@ -51,21 +54,21 @@ public class CommandSetLore implements TabExecutor {
//Update lore
ItemMeta meta = heldItem.getItemMeta();
if (meta == null) {
BooksWithoutBorders.sendErrorMessage(player, "Could not get metadata from the held item!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_METADATA_MISSING);
return false;
}
meta.setLore(newLore);
heldItem.setItemMeta(meta);
BooksWithoutBorders.sendSuccessMessage(player, "Added lore to item!");
stringFormatter.displaySuccessMessage(player, Translatable.SUCCESS_LORE_SET);
return true;
}
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias,
@NotNull String[] arguments) {
//TODO: Figure out if there is a better way to display that an argument is required
String separator = BooksWithoutBorders.getConfiguration().getTitleAuthorSeparator();
List<String> options = new ArrayList<>();
options.add("<new lore>");
options.add("Line1" + separator + "Line2" + separator + "Line3");
return options;
}

View File

@@ -1,7 +1,9 @@
package net.knarcraft.bookswithoutborders.command;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.knarlib.property.ColorConversion;
import net.knarcraft.knarlib.util.ColorHelper;
import org.bukkit.Material;
@@ -25,13 +27,14 @@ public class CommandSetTitle implements TabExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
@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 < 1) {
BooksWithoutBorders.sendErrorMessage(player, "Too few command arguments!");
stringFormatter.displayErrorMessage(player, Translatable.ERROR_TITLE_EMPTY);
return false;
}

View File

@@ -67,36 +67,6 @@ public enum Formatting implements TranslatableMessage {
* The format used when formatting text on a title page
*/
NEUTRAL_TITLE_PAGE_TEXT_FORMAT,
/**
* The translation of the copy action
*/
ACTION_COPY,
/**
* The translation of the clear action
*/
ACTION_CLEAR,
/**
* The translation of the decrypt action
*/
ACTION_DECRYPT,
/**
* The translation of the encrypt action
*/
ACTION_ENCRYPT,
/**
* The translation of the add title page action
*/
ACTION_ADD_TITLE_AUTHOR_PAGE,
/**
* The translation of the set author action
*/
ACTION_SET_AUTHOR,
;
@Override

View File

@@ -68,6 +68,16 @@ public enum Translatable implements TranslatableMessage {
*/
SUCCESS_SET_AUTHOR,
/**
* The success message displayed when a book's generation is successfully changed
*/
SUCCESS_GENERATION_CHANGED,
/**
* The success message displayed when an item's lore is successfully set
*/
SUCCESS_LORE_SET,
/**
* The error to display when the console attempts to run a player-only command
*/
@@ -83,6 +93,41 @@ public enum Translatable implements TranslatableMessage {
*/
ERROR_NOT_HOLDING_WRITABLE_BOOK,
/**
* The translation of the copy action
*/
ACTION_COPY,
/**
* The translation of the clear action
*/
ACTION_CLEAR,
/**
* The translation of the decrypt action
*/
ACTION_DECRYPT,
/**
* The translation of the encrypt action
*/
ACTION_ENCRYPT,
/**
* The translation of the add title page action
*/
ACTION_ADD_TITLE_AUTHOR_PAGE,
/**
* The translation of the set author action
*/
ACTION_SET_AUTHOR,
/**
* The translation of the change generation action
*/
ACTION_CHANGE_GENERATION,
/**
* The error displayed when running a relevant command while holding one book in each hand
*/
@@ -227,6 +272,31 @@ public enum Translatable implements TranslatableMessage {
* The error displayed when changing a book's author without providing the new author
*/
ERROR_AUTHOR_BLANK,
/**
* The error displayed when attempting to change a book's generation without specifying the new generation
*/
ERROR_GENERATION_NOT_SPECIFIED,
/**
* The error displayed when attempting to change a book's generation, but giving an invalid generation
*/
ERROR_GENERATION_INVALID,
/**
* The error displayed when attempting to change an item's lore without specifying the new lore
*/
ERROR_LORE_EMPTY,
/**
* The error displayed when attempting to change the lore of an item without holding an item
*/
ERROR_LORE_NO_ITEM,
/**
* The error displayed when attempting to change an item's title/display name without specifying the new title/display name
*/
ERROR_TITLE_EMPTY,
;
@Override

View File

@@ -18,15 +18,18 @@ en:
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"
SUCCESS_BOOKSHELF_DATA_DELETED: "Bookshelf successfully deleted!"
SUCCESS_BOOKSHELF_TITLE_SET: "Title successfully saved!"
SUCCESS_BOOKSHELF_LORE_SET: "Lore successfully saved!"
SUCCESS_GENERATION_CHANGED: "Book generation successfully changed!"
SUCCESS_LORE_SET: "Added lore to item!"
ACTION_COPY: "copy"
ACTION_CLEAR: "clear"
ACTION_DECRYPT: "decrypt"
ACTION_ENCRYPT: "encrypt"
ACTION_ADD_TITLE_AUTHOR_PAGE: "add an author title page to"
ACTION_SET_AUTHOR: "set author"
ACTION_CHANGE_GENERATION: "change generation"
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!"
@@ -80,6 +83,11 @@ en:
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!"
ERROR_GENERATION_NOT_SPECIFIED: "You must specify the new generation for your book!"
ERROR_GENERATION_INVALID: "Invalid book generation specified!"
ERROR_LORE_EMPTY: "You must specify the new lore to set!"
ERROR_LORE_NO_ITEM: "Must be holding an item to set lore!"
ERROR_TITLE_EMPTY: "You must specify the new title/display name to set!"
NEUTRAL_COMMANDS_HEADER: |
&nBooks without Borders help page&r
&e[] = optional, <> = required (see each description for exceptions)