Removes some hard-coded exception strings
All checks were successful
EpicKnarvik97/Books-Without-Borders/pipeline/head This commit looks good

This commit is contained in:
2025-08-26 11:23:25 +02:00
parent b9edc52896
commit 36f031c6f9
5 changed files with 17 additions and 7 deletions

View File

@@ -43,6 +43,11 @@ public enum StaticMessage {
Warning! [BooksWithoutBorders] failed to initialize! Warning! [BooksWithoutBorders] failed to initialize!
Please confirm the correct version of [BooksWithoutBorders] is Please confirm the correct version of [BooksWithoutBorders] is
being run for this version of spigot!"""), being run for this version of spigot!"""),
EXCEPTION_UNKNOWN_DIRECTORY("Unknown directory {directory}"),
EXCEPTION_UNEXPECTED_EXTENSION("File with unexpected extension {extension} encountered!"),
EXCEPTION_MIGRATE_BOOK_LOAD_FAILED("Unable to load book: {path}"),
EXCEPTION_META_HAS_SEPARATOR("The author; {author} or title; {title} contains the title author separator" +
" ({separator}). Saving this book would lead to unexpected problems."),
/** /**
* The cost type used to specify economy * The cost type used to specify economy

View File

@@ -1,6 +1,7 @@
package net.knarcraft.bookswithoutborders.thread; package net.knarcraft.bookswithoutborders.thread;
import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
import net.knarcraft.bookswithoutborders.config.StaticMessage;
import net.knarcraft.bookswithoutborders.config.translation.Translatable; import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.container.EncryptedBook; import net.knarcraft.bookswithoutborders.container.EncryptedBook;
import net.knarcraft.bookswithoutborders.container.MigrationRequest; import net.knarcraft.bookswithoutborders.container.MigrationRequest;
@@ -99,7 +100,8 @@ public class MigrationQueueThread implements Runnable {
String extension = BookFileHelper.getExtensionFromPath(file.getName()); String extension = BookFileHelper.getExtensionFromPath(file.getName());
if (!extension.equalsIgnoreCase("txt") && !extension.equalsIgnoreCase("yml")) { if (!extension.equalsIgnoreCase("txt") && !extension.equalsIgnoreCase("yml")) {
BooksWithoutBorders.log(Level.WARNING, "File with unexpected extension " + extension + " encountered!"); BooksWithoutBorders.log(Level.WARNING, new FormatBuilder(StaticMessage.EXCEPTION_UNEXPECTED_EXTENSION.toString()).
replace("{extension}", extension).build());
return true; return true;
} }
@@ -117,7 +119,8 @@ public class MigrationQueueThread implements Runnable {
} }
if (loadedBook == null) { if (loadedBook == null) {
BooksWithoutBorders.log(Level.SEVERE, "Unable to load book: " + file.getAbsolutePath()); BooksWithoutBorders.log(Level.SEVERE, new FormatBuilder(StaticMessage.EXCEPTION_MIGRATE_BOOK_LOAD_FAILED.toString()).
replace("{path}", file.getAbsolutePath()).build());
return false; return false;
} }

View File

@@ -170,9 +170,9 @@ public final class BookHelper {
if (InputCleaningHelper.cleanString(bookName).contains(separator) || if (InputCleaningHelper.cleanString(bookName).contains(separator) ||
InputCleaningHelper.cleanString(authorName).contains(separator)) { InputCleaningHelper.cleanString(authorName).contains(separator)) {
throw new IllegalArgumentException("The author; " + authorName + " or title; " + bookName + throw new IllegalArgumentException(new FormatBuilder(StaticMessage.EXCEPTION_META_HAS_SEPARATOR.toString()).
" contains the title author separator (" + separator + "). Saving this " + replace("{author}", authorName).replace("{title}", bookName).
"book would lead to unexpected problems."); replace("{separator}", separator).build());
} }
return InputCleaningHelper.cleanString(bookName + separator + authorName); return InputCleaningHelper.cleanString(bookName + separator + authorName);

View File

@@ -3,6 +3,7 @@ package net.knarcraft.bookswithoutborders.utility;
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.Permission; import net.knarcraft.bookswithoutborders.config.Permission;
import net.knarcraft.bookswithoutborders.config.StaticMessage;
import net.knarcraft.bookswithoutborders.config.translation.Translatable; import net.knarcraft.bookswithoutborders.config.translation.Translatable;
import net.knarcraft.bookswithoutborders.state.BookDirectory; import net.knarcraft.bookswithoutborders.state.BookDirectory;
import net.knarcraft.knarlib.formatting.FormatBuilder; import net.knarcraft.knarlib.formatting.FormatBuilder;
@@ -170,7 +171,8 @@ public final class BookLoader {
if (folder != null) { if (folder != null) {
file = BookFileHelper.findBookFile(folder, fileName); file = BookFileHelper.findBookFile(folder, fileName);
} else { } else {
BooksWithoutBorders.log(Level.WARNING, "Unknown directory " + bookDirectory); BooksWithoutBorders.log(Level.WARNING, new FormatBuilder(StaticMessage.EXCEPTION_UNKNOWN_DIRECTORY.toString()).
replace("{directory}", bookDirectory.toString()).build());
} }
} }
if (file == null || !file.isFile()) { if (file == null || !file.isFile()) {

View File

@@ -97,7 +97,7 @@ public final class EncryptionHelper {
case SUBSTITUTION -> new SubstitutionCipher(EncryptionHelper.getNumberKeyFromStringKey(key)); case SUBSTITUTION -> new SubstitutionCipher(EncryptionHelper.getNumberKeyFromStringKey(key));
case AES -> { case AES -> {
if (aesConfiguration == null) { if (aesConfiguration == null) {
throw new IllegalArgumentException("Attempted to perform AES encryption without a valid AES configuration"); throw new IllegalArgumentException(StaticMessage.EXCEPTION_AES_NO_CONFIGURATION.toString());
} else { } else {
yield new AES(aesConfiguration); yield new AES(aesConfiguration);
} }