Renames some classes, splits some classes and fixes some encrypted book loading problems
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:
@@ -43,8 +43,8 @@ import net.knarcraft.bookswithoutborders.listener.BookshelfListener;
|
||||
import net.knarcraft.bookswithoutborders.listener.GroupDecryptListener;
|
||||
import net.knarcraft.bookswithoutborders.listener.PlayerEventListener;
|
||||
import net.knarcraft.bookswithoutborders.listener.SignEventListener;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.knarlib.formatting.Translator;
|
||||
@@ -132,7 +132,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
} else if (sender instanceof Player player) {
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (!getInstance().playerBooksList.containsKey(playerUUID)) {
|
||||
List<String> newFiles = BookFileHelper.listFiles(sender, false);
|
||||
List<String> newFiles = BookFileUtil.listFiles(sender, false);
|
||||
if (newFiles != null) {
|
||||
getInstance().playerBooksList.put(playerUUID, newFiles);
|
||||
getInstance().playerLetterIndex.put(playerUUID, populateLetterIndices(newFiles));
|
||||
@@ -172,7 +172,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
* @param updatePublic <p>Whether to update public books</p>
|
||||
*/
|
||||
public static void updateBooks(@NotNull CommandSender sender, boolean updatePublic) {
|
||||
List<String> newFiles = BookFileHelper.listFiles(sender, updatePublic);
|
||||
List<String> newFiles = BookFileUtil.listFiles(sender, updatePublic);
|
||||
if (newFiles == null) {
|
||||
return;
|
||||
}
|
||||
@@ -223,7 +223,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
playerBooksList = new HashMap<>();
|
||||
playerLetterIndex = new HashMap<>();
|
||||
booksWithoutBordersConfig = new BwBConfig(this, translator);
|
||||
@Nullable List<String> files = BookFileHelper.listFiles(this.getServer().getConsoleSender(), true);
|
||||
@Nullable List<String> files = BookFileUtil.listFiles(this.getServer().getConsoleSender(), true);
|
||||
if (files != null) {
|
||||
publicBooksList = files;
|
||||
publicLetterIndex = populateLetterIndices(files);
|
||||
@@ -390,7 +390,7 @@ public class BooksWithoutBorders extends JavaPlugin {
|
||||
Map<Character, Integer> firstEncounter = new HashMap<>();
|
||||
Character current = null;
|
||||
for (int i = 0; i < books.size(); i++) {
|
||||
char first = InputCleaningHelper.stripColor(books.get(i)).toLowerCase().charAt(0);
|
||||
char first = InputCleaningUtil.stripColor(books.get(i)).toLowerCase().charAt(0);
|
||||
if (current == null || current != first) {
|
||||
current = first;
|
||||
firstEncounter.put(first, i);
|
||||
|
@@ -3,9 +3,9 @@ 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.BookHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookMetaUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -34,7 +34,7 @@ public class CommandAddTitlePage implements TabExecutor {
|
||||
}
|
||||
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player);
|
||||
if (heldBook == null) {
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_ANY_BOOK).error(sender);
|
||||
return false;
|
||||
@@ -46,7 +46,7 @@ public class CommandAddTitlePage implements TabExecutor {
|
||||
Translatable.ACTION_ADD_TITLE_AUTHOR_PAGE).build();
|
||||
String twoBooksError = new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}",
|
||||
Translatable.ACTION_ADD_TITLE_AUTHOR_PAGE).build();
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player, noBookError, twoBooksError)) {
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player, noBookError, twoBooksError)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ public class CommandAddTitlePage implements TabExecutor {
|
||||
// Add a page with the book title and book author
|
||||
String loreSeparator = BooksWithoutBorders.getConfiguration().getLoreSeparator();
|
||||
String pageText = formatTitle(new FormatBuilder(Formatting.NEUTRAL_TITLE_PAGE_TITLE_AUTHOR_FORMAT).
|
||||
replace("{title}", InputCleaningHelper.stripColor(BookHelper.getBookTitle(bookMeta))).
|
||||
replace("{title}", InputCleaningUtil.stripColor(BookMetaUtil.getBookTitle(bookMeta))).
|
||||
replace("{separator}", loreSeparator).
|
||||
replace("{author}", InputCleaningHelper.stripColor(BookHelper.getBookAuthor(bookMeta, null))).build());
|
||||
replace("{author}", InputCleaningUtil.stripColor(BookMetaUtil.getBookAuthor(bookMeta, null))).build());
|
||||
|
||||
if (index > pages.size()) {
|
||||
pages.add(pageText);
|
||||
@@ -146,7 +146,7 @@ public class CommandAddTitlePage implements TabExecutor {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
return List.of("1", "2", "3", "4");
|
||||
}
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player);
|
||||
if (heldBook != null) {
|
||||
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
||||
if (bookMeta != null) {
|
||||
|
@@ -2,7 +2,7 @@ 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.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -30,14 +30,14 @@ public class CommandClear implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWritableBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWritableBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITABLE_BOOK).replace("{action}", Translatable.ACTION_CLEAR).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_CLEAR).build())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Clear the player's held book
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, false);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, false);
|
||||
|
||||
WritableBookMeta newMetadata = (BookMeta) BooksWithoutBorders.getItemFactory().getItemMeta(heldBook.getType());
|
||||
if (newMetadata != null) {
|
||||
|
@@ -4,9 +4,9 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.BwBConfig;
|
||||
import net.knarcraft.bookswithoutborders.config.Permission;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookMetaUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.Material;
|
||||
@@ -35,7 +35,7 @@ public class CommandCopy implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK).replace("{action}", Translatable.ACTION_COPY).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_COPY).build())) {
|
||||
return false;
|
||||
@@ -47,7 +47,7 @@ public class CommandCopy implements TabExecutor {
|
||||
}
|
||||
|
||||
try {
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, true);
|
||||
int copies = Integer.parseInt(arguments[0]);
|
||||
if (copies <= 0) {
|
||||
new FormatBuilder(Translatable.ERROR_COPY_NEGATIVE_AMOUNT).error(player);
|
||||
@@ -74,7 +74,7 @@ public class CommandCopy implements TabExecutor {
|
||||
//Make sure the player owns the book if authorOnlyCopy is enabled
|
||||
if (config.getAuthorOnlyCopy() &&
|
||||
!player.hasPermission(Permission.BYPASS_AUTHOR_ONLY_COPY.toString())) {
|
||||
if (BookHelper.isNotAuthor(player, (BookMeta) Objects.requireNonNull(heldBook.getItemMeta()))) {
|
||||
if (BookMetaUtil.isNotAuthor(player, (BookMeta) Objects.requireNonNull(heldBook.getItemMeta()))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ public class CommandCopy implements TabExecutor {
|
||||
ItemStack itemStack = new ItemStack(Material.WRITTEN_BOOK);
|
||||
itemStack.setItemMeta(bookMeta);
|
||||
//Increase the generation of the book
|
||||
BookHelper.increaseGeneration(itemStack);
|
||||
BookMetaUtil.increaseGeneration(itemStack);
|
||||
itemStack.setAmount(copies);
|
||||
|
||||
player.getInventory().addItem(itemStack);
|
||||
@@ -149,7 +149,7 @@ public class CommandCopy implements TabExecutor {
|
||||
@NotNull String[] arguments) {
|
||||
int argumentCount = arguments.length;
|
||||
if (argumentCount == 1) {
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getNumbers(1, 20), arguments[0]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeUtil.getNumbers(1, 20), arguments[0]);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@@ -3,9 +3,10 @@ package net.knarcraft.bookswithoutborders.command;
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.Permission;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptedBookUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -32,13 +33,13 @@ public class CommandDecrypt implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK).replace("{action}", Translatable.ACTION_DECRYPT).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_DECRYPT).build())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = InventoryHelper.getHeldBook(player, true);
|
||||
ItemStack heldItem = InventoryUtil.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldItem.getItemMeta();
|
||||
if (bookMetadata == null) {
|
||||
new FormatBuilder(Translatable.ERROR_METADATA_MISSING).error(sender);
|
||||
@@ -55,13 +56,13 @@ public class CommandDecrypt implements TabExecutor {
|
||||
}
|
||||
|
||||
//Decrypt the book normally
|
||||
ItemStack book = EncryptionHelper.loadEncryptedBook(player, arguments[0], true, false);
|
||||
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, arguments[0], true, false);
|
||||
if (book == null) {
|
||||
book = EncryptionHelper.loadEncryptedBookLegacy(player, arguments[0], true);
|
||||
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, arguments[0], true);
|
||||
}
|
||||
|
||||
if (book != null) {
|
||||
InventoryHelper.setHeldWrittenBook(player, book);
|
||||
InventoryUtil.setHeldWrittenBook(player, book);
|
||||
new FormatBuilder(Translatable.SUCCESS_DECRYPTED).success(player);
|
||||
return true;
|
||||
} else {
|
||||
@@ -78,9 +79,9 @@ public class CommandDecrypt implements TabExecutor {
|
||||
* @return <p>True if successful</p>
|
||||
*/
|
||||
private boolean adminDecrypt(@NotNull Player player, @NotNull BookMeta bookMetadata) {
|
||||
ItemStack decrypted = EncryptionHelper.loadEncryptedBook(player, "", false, true);
|
||||
ItemStack decrypted = EncryptedBookUtil.loadEncryptedBook(player, "", false, true);
|
||||
if (decrypted != null) {
|
||||
InventoryHelper.setHeldWrittenBook(player, decrypted);
|
||||
InventoryUtil.setHeldWrittenBook(player, decrypted);
|
||||
new FormatBuilder(Translatable.SUCCESS_AUTO_DECRYPTED).success(player);
|
||||
return true;
|
||||
} else {
|
||||
@@ -106,8 +107,8 @@ public class CommandDecrypt implements TabExecutor {
|
||||
//Get the "encryption key" from the filename
|
||||
String key = "";
|
||||
for (String encryptedFile : encryptedFiles) {
|
||||
if (encryptedFile.contains(BookFileHelper.getBookFile(bookMetadata, player, true).replace(" ", "_"))) {
|
||||
key = EncryptionHelper.extractLegacyKey(encryptedFile);
|
||||
if (encryptedFile.contains(BookFileUtil.getBookFile(bookMetadata, player, true).replace(" ", "_"))) {
|
||||
key = EncryptionUtil.extractLegacyKey(encryptedFile);
|
||||
if (!key.isBlank()) {
|
||||
break;
|
||||
}
|
||||
@@ -116,9 +117,9 @@ public class CommandDecrypt implements TabExecutor {
|
||||
|
||||
if (!key.isBlank()) {
|
||||
//Decrypt the book
|
||||
ItemStack book = EncryptionHelper.loadEncryptedBookLegacy(player, key, false);
|
||||
ItemStack book = EncryptedBookUtil.loadEncryptedBookLegacy(player, key, false);
|
||||
if (book != null) {
|
||||
InventoryHelper.setHeldWrittenBook(player, book);
|
||||
InventoryUtil.setHeldWrittenBook(player, book);
|
||||
new FormatBuilder(Translatable.SUCCESS_AUTO_DECRYPTED).success(player);
|
||||
return true;
|
||||
} else {
|
||||
|
@@ -4,9 +4,9 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.gui.PagedBookIndex;
|
||||
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputParsingUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -56,7 +56,7 @@ public class CommandDelete implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
performBookDeletion(sender, InputCleaningHelper.mergeArguments(arguments, 0), deletePublic);
|
||||
performBookDeletion(sender, InputParsingUtil.mergeArguments(arguments, 0), deletePublic);
|
||||
//Update the book list
|
||||
BooksWithoutBorders.updateBooks(sender, deletePublic);
|
||||
return true;
|
||||
@@ -81,7 +81,7 @@ public class CommandDelete implements TabExecutor {
|
||||
}
|
||||
|
||||
//Get the file to be deleted
|
||||
File file = BookFileHelper.getFile(BookDirectory.getCommon(isPublic), fileName, sender);
|
||||
File file = BookFileUtil.getFile(BookDirectory.getCommon(isPublic), fileName, sender);
|
||||
|
||||
//Send message if no such file could be found
|
||||
if (file == null) {
|
||||
@@ -119,9 +119,9 @@ public class CommandDelete implements TabExecutor {
|
||||
protected List<String> doTabCompletion(@NotNull CommandSender sender, @NotNull String[] arguments, boolean deletePublic) {
|
||||
List<String> filtered = TabCompletionHelper.filterMatchingContains(
|
||||
BooksWithoutBorders.getAvailableBooks(sender, deletePublic),
|
||||
InputCleaningHelper.mergeArguments(arguments, 0));
|
||||
InputParsingUtil.mergeArguments(arguments, 0));
|
||||
if (arguments.length > 1) {
|
||||
return TabCompletionTypeHelper.getCleanedTabCompletions(arguments, filtered);
|
||||
return TabCompletionTypeUtil.getCleanedTabCompletions(arguments, filtered);
|
||||
} else {
|
||||
return filtered;
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -33,7 +33,7 @@ public class CommandDeletePage implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player);
|
||||
if (heldBook == null) {
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_ANY_BOOK).error(sender);
|
||||
return false;
|
||||
@@ -75,7 +75,7 @@ public class CommandDeletePage implements TabExecutor {
|
||||
if (!(commandSender instanceof Player player)) {
|
||||
return List.of("1", "2", "3", "4");
|
||||
}
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player);
|
||||
if (heldBook != null) {
|
||||
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
||||
if (bookMeta != null) {
|
||||
|
@@ -6,8 +6,8 @@ import net.knarcraft.bookswithoutborders.config.Permission;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.encryption.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.state.ItemSlot;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptedBookUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -67,7 +67,7 @@ public class CommandEncrypt implements TabExecutor {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK).replace("{action}", Translatable.ACTION_ENCRYPT).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_ENCRYPT).build())) {
|
||||
return null;
|
||||
@@ -83,7 +83,7 @@ public class CommandEncrypt implements TabExecutor {
|
||||
return null;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
|
||||
if (bookMetadata == null) {
|
||||
new FormatBuilder(Translatable.ERROR_METADATA_MISSING).error(player);
|
||||
@@ -108,12 +108,12 @@ public class CommandEncrypt implements TabExecutor {
|
||||
*/
|
||||
protected boolean encryptBook(@NotNull EncryptionStyle encryptionStyle, @NotNull Player player, @NotNull String key,
|
||||
@NotNull String group, boolean preventAdminDecryption) {
|
||||
ItemSlot heldSlot = InventoryHelper.getHeldSlotBook(player, false, false, true, true);
|
||||
ItemStack encryptedBook = EncryptionHelper.encryptBook(player, heldSlot == ItemSlot.MAIN_HAND, key,
|
||||
ItemSlot heldSlot = InventoryUtil.getHeldSlotBook(player, false, false, true, true);
|
||||
ItemStack encryptedBook = EncryptedBookUtil.encryptBook(player, heldSlot == ItemSlot.MAIN_HAND, key,
|
||||
encryptionStyle, group, preventAdminDecryption);
|
||||
|
||||
if (encryptedBook != null) {
|
||||
InventoryHelper.setHeldWrittenBook(player, encryptedBook);
|
||||
InventoryUtil.setHeldWrittenBook(player, encryptedBook);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@@ -2,7 +2,7 @@ package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFormatterUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -28,7 +28,7 @@ public class CommandFormat implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player);
|
||||
if (heldBook == null) {
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_ANY_BOOK).error(sender);
|
||||
return false;
|
||||
|
@@ -4,9 +4,9 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.GiveMessage;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.gui.PagedBookIndex;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoader;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -22,6 +22,11 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Boolean.parseBoolean;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputParsingUtil.isBoolean;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputParsingUtil.isInt;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputParsingUtil.mergeArguments;
|
||||
|
||||
/**
|
||||
* Command executor for the give command
|
||||
*/
|
||||
@@ -89,26 +94,26 @@ public class CommandGive implements TabExecutor {
|
||||
List<String> output = new ArrayList<>();
|
||||
List<String> books = BooksWithoutBorders.getAvailableBooks(sender, listPublic);
|
||||
List<String> filtered = TabCompletionHelper.filterMatchingContains(books,
|
||||
InputCleaningHelper.mergeArguments(arguments, 0));
|
||||
mergeArguments(arguments, 0));
|
||||
|
||||
if (!filtered.isEmpty()) {
|
||||
List<String> cleaned = TabCompletionTypeHelper.getCleanedTabCompletions(arguments, filtered);
|
||||
if (!books.contains(InputCleaningHelper.mergeArguments(arguments, 1))) {
|
||||
List<String> cleaned = TabCompletionTypeUtil.getCleanedTabCompletions(arguments, filtered);
|
||||
if (!books.contains(mergeArguments(arguments, 1))) {
|
||||
return cleaned;
|
||||
} else {
|
||||
output.addAll(cleaned);
|
||||
}
|
||||
}
|
||||
|
||||
if (argumentCount > 2 && InputCleaningHelper.isBoolean(arguments[argumentCount - 2])) {
|
||||
if (argumentCount > 2 && isBoolean(arguments[argumentCount - 2])) {
|
||||
return output;
|
||||
} else if (argumentCount > 2 && server.getPlayerExact(arguments[argumentCount - 3]) != null &&
|
||||
InputCleaningHelper.isInt(arguments[argumentCount - 2])) {
|
||||
isInt(arguments[argumentCount - 2])) {
|
||||
output.addAll(TabCompletionHelper.filterMatchingStartsWith(
|
||||
TabCompletionTypeHelper.getBooleans(), arguments[argumentCount - 1]));
|
||||
TabCompletionTypeUtil.getBooleans(), arguments[argumentCount - 1]));
|
||||
} else if (argumentCount > 2 && server.getPlayerExact(arguments[argumentCount - 2]) != null) {
|
||||
output.addAll(TabCompletionHelper.filterMatchingStartsWith(
|
||||
TabCompletionTypeHelper.getBooleansAndNumbers(1, 3), arguments[argumentCount - 1]));
|
||||
TabCompletionTypeUtil.getBooleansAndNumbers(1, 3), arguments[argumentCount - 1]));
|
||||
} else {
|
||||
List<String> players = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
@@ -139,23 +144,22 @@ public class CommandGive implements TabExecutor {
|
||||
boolean isSigned = true;
|
||||
|
||||
// Parse arguments at the end of the command, and treat the rest as the book name
|
||||
if (argumentCount > 3 && InputCleaningHelper.isInt(arguments[argumentCount - 2]) &&
|
||||
InputCleaningHelper.isBoolean(arguments[argumentCount - 1])) {
|
||||
if (argumentCount > 3 && isInt(arguments[argumentCount - 2]) && isBoolean(arguments[argumentCount - 1])) {
|
||||
receivingPlayerName = arguments[argumentCount - 3];
|
||||
isSigned = Boolean.parseBoolean(arguments[argumentCount - 1]);
|
||||
isSigned = parseBoolean(arguments[argumentCount - 1]);
|
||||
copies = arguments[argumentCount - 2];
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 3);
|
||||
} else if (argumentCount > 2 && InputCleaningHelper.isBoolean(arguments[argumentCount - 1])) {
|
||||
isSigned = Boolean.parseBoolean(arguments[argumentCount - 1]);
|
||||
bookIdentifier = mergeArguments(arguments, 3);
|
||||
} else if (argumentCount > 2 && isBoolean(arguments[argumentCount - 1])) {
|
||||
isSigned = parseBoolean(arguments[argumentCount - 1]);
|
||||
receivingPlayerName = arguments[argumentCount - 2];
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 2);
|
||||
} else if (argumentCount > 2 && InputCleaningHelper.isInt(arguments[argumentCount - 1])) {
|
||||
bookIdentifier = mergeArguments(arguments, 2);
|
||||
} else if (argumentCount > 2 && isInt(arguments[argumentCount - 1])) {
|
||||
copies = arguments[argumentCount - 1];
|
||||
receivingPlayerName = arguments[argumentCount - 2];
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 2);
|
||||
bookIdentifier = mergeArguments(arguments, 2);
|
||||
} else {
|
||||
receivingPlayerName = arguments[argumentCount - 1];
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 1);
|
||||
bookIdentifier = mergeArguments(arguments, 1);
|
||||
}
|
||||
|
||||
//Try and find the target player
|
||||
@@ -190,8 +194,8 @@ public class CommandGive implements TabExecutor {
|
||||
private boolean loadAndGiveBook(@NotNull String bookIdentifier, @NotNull CommandSender sender,
|
||||
@NotNull Player receivingPlayer, boolean isSigned, @NotNull String folder,
|
||||
@NotNull String copies) throws NumberFormatException {
|
||||
String bookToLoad = InputCleaningHelper.cleanString(bookIdentifier);
|
||||
ItemStack newBook = BookLoader.loadBook(sender, bookToLoad, isSigned, folder, Integer.parseInt(copies));
|
||||
String bookToLoad = InputCleaningUtil.cleanString(bookIdentifier);
|
||||
ItemStack newBook = BookLoaderUtil.loadBook(sender, bookToLoad, isSigned, folder, Integer.parseInt(copies));
|
||||
if (newBook != null) {
|
||||
//NOTE: As this method bypasses cost, it should also bypass the generation change
|
||||
receivingPlayer.getInventory().addItem(newBook);
|
||||
|
@@ -3,9 +3,9 @@ package net.knarcraft.bookswithoutborders.command;
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.gui.PagedBookIndex;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoader;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -18,6 +18,11 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Integer.parseInt;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputParsingUtil.isBoolean;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputParsingUtil.isInt;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputParsingUtil.mergeArguments;
|
||||
|
||||
/**
|
||||
* Command executor for the load command
|
||||
*/
|
||||
@@ -83,23 +88,23 @@ public class CommandLoad implements TabExecutor {
|
||||
List<String> output = new ArrayList<>();
|
||||
List<String> books = BooksWithoutBorders.getAvailableBooks(sender, loadPublic);
|
||||
List<String> filtered = TabCompletionHelper.filterMatchingContains(books,
|
||||
InputCleaningHelper.mergeArguments(arguments, 0));
|
||||
mergeArguments(arguments, 0));
|
||||
|
||||
if (!filtered.isEmpty()) {
|
||||
List<String> cleaned = TabCompletionTypeHelper.getCleanedTabCompletions(arguments, filtered);
|
||||
if (!books.contains(InputCleaningHelper.mergeArguments(arguments, 1))) {
|
||||
List<String> cleaned = TabCompletionTypeUtil.getCleanedTabCompletions(arguments, filtered);
|
||||
if (!books.contains(mergeArguments(arguments, 1))) {
|
||||
return cleaned;
|
||||
} else {
|
||||
output.addAll(cleaned);
|
||||
}
|
||||
}
|
||||
|
||||
if (InputCleaningHelper.isBoolean(arguments[argumentCount - 2])) {
|
||||
if (isBoolean(arguments[argumentCount - 2])) {
|
||||
return output;
|
||||
} else if (InputCleaningHelper.isInt(arguments[argumentCount - 2])) {
|
||||
output.addAll(TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getBooleans(), arguments[argumentCount - 1]));
|
||||
} else if (isInt(arguments[argumentCount - 2])) {
|
||||
output.addAll(TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeUtil.getBooleans(), arguments[argumentCount - 1]));
|
||||
} else {
|
||||
output.addAll(TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getBooleansAndNumbers(1, 3), arguments[argumentCount - 1]));
|
||||
output.addAll(TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeUtil.getBooleansAndNumbers(1, 3), arguments[argumentCount - 1]));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
@@ -123,19 +128,18 @@ public class CommandLoad implements TabExecutor {
|
||||
|
||||
// Parse arguments at the end of the command, and treat the rest as the book name
|
||||
if (argumentCount > 1) {
|
||||
if (argumentCount > 2 && InputCleaningHelper.isInt(arguments[argumentCount - 2]) &&
|
||||
InputCleaningHelper.isBoolean(arguments[argumentCount - 1])) {
|
||||
if (argumentCount > 2 && isInt(arguments[argumentCount - 2]) && isBoolean(arguments[argumentCount - 1])) {
|
||||
isSigned = Boolean.parseBoolean(arguments[argumentCount - 1]);
|
||||
copies = Integer.parseInt(arguments[argumentCount - 2]);
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 2);
|
||||
} else if (InputCleaningHelper.isBoolean(arguments[argumentCount - 1])) {
|
||||
copies = parseInt(arguments[argumentCount - 2]);
|
||||
bookIdentifier = mergeArguments(arguments, 2);
|
||||
} else if (isBoolean(arguments[argumentCount - 1])) {
|
||||
isSigned = Boolean.parseBoolean(arguments[argumentCount - 1]);
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 1);
|
||||
} else if (InputCleaningHelper.isInt(arguments[argumentCount - 1])) {
|
||||
copies = Integer.parseInt(arguments[argumentCount - 1]);
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 1);
|
||||
bookIdentifier = mergeArguments(arguments, 1);
|
||||
} else if (isInt(arguments[argumentCount - 1])) {
|
||||
copies = parseInt(arguments[argumentCount - 1]);
|
||||
bookIdentifier = mergeArguments(arguments, 1);
|
||||
} else {
|
||||
bookIdentifier = InputCleaningHelper.mergeArguments(arguments, 0);
|
||||
bookIdentifier = mergeArguments(arguments, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,10 +161,10 @@ public class CommandLoad implements TabExecutor {
|
||||
boolean isSigned, @NotNull String directory, int copies) {
|
||||
BooksWithoutBorders.updateBooks(player, loadPublic);
|
||||
|
||||
String bookToLoad = InputCleaningHelper.cleanString(bookIdentifier);
|
||||
String bookToLoad = InputCleaningUtil.cleanString(bookIdentifier);
|
||||
|
||||
//Give the new book if it can be loaded
|
||||
ItemStack newBook = BookLoader.loadBook(player, bookToLoad, isSigned, directory, copies);
|
||||
ItemStack newBook = BookLoaderUtil.loadBook(player, bookToLoad, isSigned, directory, copies);
|
||||
if (newBook != null) {
|
||||
player.getInventory().addItem(newBook);
|
||||
new FormatBuilder(Translatable.SUCCESS_BOOK_LOADED).success(player);
|
||||
|
@@ -8,10 +8,10 @@ import net.knarcraft.bookswithoutborders.config.translation.Formatting;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.SaveMessage;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileReaderWriterUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookMetaUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -54,7 +54,7 @@ public class CommandSave implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player);
|
||||
if (heldBook != null) {
|
||||
boolean duplicate = arguments.length == 1 && Boolean.parseBoolean(arguments[0]);
|
||||
saveBook(player, heldBook, duplicate, savePublic, command);
|
||||
@@ -87,11 +87,11 @@ public class CommandSave implements TabExecutor {
|
||||
//Only allow saving of own books if enabled
|
||||
if (config.getAuthorOnlySave() && !saveToPublicFolder &&
|
||||
(!player.hasPermission(Permission.BYPASS_AUTHOR_ONLY_SAVE.toString()) &&
|
||||
BookHelper.isNotAuthor(player, book))) {
|
||||
BookMetaUtil.isNotAuthor(player, book))) {
|
||||
return;
|
||||
}
|
||||
|
||||
String savePath = BookFileHelper.getBookDirectoryPathString(BookDirectory.getCommon(saveToPublicFolder), player);
|
||||
String savePath = BookFileUtil.getBookDirectoryPathString(BookDirectory.getCommon(saveToPublicFolder), player);
|
||||
if (savePath == null) {
|
||||
new FormatBuilder(SaveMessage.ERROR_SAVE_INVALID_PATH).error(player);
|
||||
return;
|
||||
@@ -100,7 +100,7 @@ public class CommandSave implements TabExecutor {
|
||||
//Generate book filename
|
||||
String fileName;
|
||||
try {
|
||||
fileName = BookFileHelper.getBookFile(book, player, saveToPublicFolder);
|
||||
fileName = BookFileUtil.getBookFile(book, player, saveToPublicFolder);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
new FormatBuilder(exception.getMessage()).error(player);
|
||||
return;
|
||||
@@ -164,7 +164,7 @@ public class CommandSave implements TabExecutor {
|
||||
}
|
||||
|
||||
// Find any duplicates of the book
|
||||
int foundDuplicates = BookFileHelper.findDuplicates(foundFiles, fileName);
|
||||
int foundDuplicates = BookFileUtil.findDuplicates(foundFiles, fileName);
|
||||
|
||||
// No duplicates to process
|
||||
if (foundDuplicates <= 0) {
|
||||
|
@@ -2,7 +2,7 @@ package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.state.ItemSlot;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
@@ -36,16 +36,16 @@ public class CommandSetAuthor implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK).replace("{action}", Translatable.ACTION_SET_AUTHOR).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_SET_AUTHOR).build())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemSlot heldBookSlot = InventoryHelper.getHeldSlotBook(player, false, false, true, true);
|
||||
ItemSlot heldBookSlot = InventoryUtil.getHeldSlotBook(player, false, false, true, true);
|
||||
boolean mainHand = heldBookSlot == ItemSlot.MAIN_HAND;
|
||||
ItemStack heldBook = InventoryHelper.getHeldItem(player, mainHand);
|
||||
BookMeta bookMetaData = InventoryHelper.getHeldBookMetadata(player, mainHand);
|
||||
ItemStack heldBook = InventoryUtil.getHeldItem(player, mainHand);
|
||||
BookMeta bookMetaData = InventoryUtil.getHeldBookMetadata(player, mainHand);
|
||||
if (bookMetaData == null) {
|
||||
new FormatBuilder(Translatable.ERROR_METADATA_MISSING).error(player);
|
||||
return false;
|
||||
|
@@ -7,8 +7,8 @@ import net.knarcraft.bookswithoutborders.config.StaticMessage;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.CostMessage;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.manager.EconomyManager;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.TabCompletionTypeUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.util.TabCompletionHelper;
|
||||
import org.bukkit.Material;
|
||||
@@ -96,7 +96,7 @@ public class CommandSetBookPrice implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = InventoryHelper.getHeldItem(player, true);
|
||||
ItemStack heldItem = InventoryUtil.getHeldItem(player, true);
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
new FormatBuilder(CostMessage.ERROR_COST_ITEM_MISSING).error(sender);
|
||||
return false;
|
||||
@@ -154,7 +154,7 @@ public class CommandSetBookPrice implements TabExecutor {
|
||||
if (argumentCount == 1) {
|
||||
return TabCompletionHelper.filterMatchingStartsWith(paymentTypes, arguments[0]);
|
||||
} else if (argumentCount == 2) {
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeHelper.getNumbers(1, 3), arguments[1]);
|
||||
return TabCompletionHelper.filterMatchingStartsWith(TabCompletionTypeUtil.getNumbers(1, 3), arguments[1]);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -28,7 +28,7 @@ public class CommandSetGeneration implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK).replace("{action}", Translatable.ACTION_CHANGE_GENERATION).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_CHANGE_GENERATION).build())) {
|
||||
return false;
|
||||
@@ -47,7 +47,7 @@ public class CommandSetGeneration implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, true);
|
||||
BookMeta bookMeta = (BookMeta) heldBook.getItemMeta();
|
||||
if (bookMeta != null) {
|
||||
bookMeta.setGeneration(generation);
|
||||
|
@@ -2,7 +2,7 @@ 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.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
@@ -37,7 +37,7 @@ public class CommandSetLore implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = InventoryHelper.getHeldItem(player, true);
|
||||
ItemStack heldItem = InventoryUtil.getHeldItem(player, true);
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
new FormatBuilder(Translatable.ERROR_NO_ITEM).error(player);
|
||||
return false;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package net.knarcraft.bookswithoutborders.command;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputParsingUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -35,7 +35,7 @@ public class CommandSetTitle implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack heldItem = InventoryHelper.getHeldItem(player, true);
|
||||
ItemStack heldItem = InventoryUtil.getHeldItem(player, true);
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
new FormatBuilder(Translatable.ERROR_NO_ITEM).error(player);
|
||||
return false;
|
||||
@@ -43,9 +43,9 @@ public class CommandSetTitle implements TabExecutor {
|
||||
|
||||
boolean setDisplayName = false;
|
||||
String title;
|
||||
if (InputCleaningHelper.isBoolean(arguments[arguments.length - 1])) {
|
||||
if (InputParsingUtil.isBoolean(arguments[arguments.length - 1])) {
|
||||
setDisplayName = Boolean.parseBoolean(arguments[arguments.length - 1]);
|
||||
title = InputCleaningHelper.mergeArguments(arguments, 1);
|
||||
title = InputParsingUtil.mergeArguments(arguments, 1);
|
||||
} else {
|
||||
title = String.join(" ", arguments);
|
||||
}
|
||||
|
@@ -4,8 +4,8 @@ import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.Permission;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.state.ItemSlot;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookMetaUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InventoryUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -32,14 +32,14 @@ public class CommandUnSign implements TabExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (InventoryHelper.notHoldingOneWrittenBookCheck(player,
|
||||
if (InventoryUtil.notHoldingOneWrittenBookCheck(player,
|
||||
new FormatBuilder(Translatable.ERROR_NOT_HOLDING_WRITTEN_BOOK).replace("{action}", Translatable.ACTION_UNSIGN).build(),
|
||||
new FormatBuilder(Translatable.ERROR_ONLY_ONE_BOOK).replace("{action}", Translatable.ACTION_UNSIGN).build())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Find which hand the player is using to hold the book. If holding one in each, throw an error
|
||||
ItemSlot holdingSlot = InventoryHelper.getHeldSlotBook(player, false, false, true, true);
|
||||
ItemSlot holdingSlot = InventoryUtil.getHeldSlotBook(player, false, false, true, true);
|
||||
unSignHeldBook(player, holdingSlot == ItemSlot.MAIN_HAND);
|
||||
return true;
|
||||
}
|
||||
@@ -52,29 +52,29 @@ public class CommandUnSign implements TabExecutor {
|
||||
*/
|
||||
protected void unSignHeldBook(@NotNull Player player, boolean mainHand) {
|
||||
//Get the old book
|
||||
BookMeta oldMetadata = InventoryHelper.getHeldBookMetadata(player, mainHand);
|
||||
BookMeta oldMetadata = InventoryUtil.getHeldBookMetadata(player, mainHand);
|
||||
if (oldMetadata == null) {
|
||||
new FormatBuilder(Translatable.ERROR_METADATA_MISSING).error(player);
|
||||
return;
|
||||
}
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, mainHand);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, mainHand);
|
||||
|
||||
//Only allow the owner to un-sign the book
|
||||
if (BooksWithoutBorders.getConfiguration().getAuthorOnlyUnsign() &&
|
||||
!player.hasPermission(Permission.AUTHOR_ONLY_UNSIGN.toString())) {
|
||||
if (BookHelper.isNotAuthor(player, Objects.requireNonNull(oldMetadata))) {
|
||||
if (BookMetaUtil.isNotAuthor(player, Objects.requireNonNull(oldMetadata))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Give the player the new book
|
||||
ItemStack book = BookHelper.unsignBook(oldMetadata, heldBook.getAmount());
|
||||
ItemStack book = BookMetaUtil.unsignBook(oldMetadata, heldBook.getAmount());
|
||||
if (book == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
reverseColorCodes(book);
|
||||
InventoryHelper.replaceHeldItem(player, book, mainHand);
|
||||
InventoryUtil.replaceHeldItem(player, book, mainHand);
|
||||
new FormatBuilder(Translatable.SUCCESS_UNSIGNED).success(player);
|
||||
}
|
||||
|
||||
|
@@ -12,7 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputCleaningUtil.cleanString;
|
||||
|
||||
/**
|
||||
* A config class that keeps track of all config values
|
||||
|
@@ -2,8 +2,8 @@ package net.knarcraft.bookswithoutborders.gui;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.formatting.TranslatableMessage;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@@ -32,7 +32,7 @@ public class AuthorBookIndex extends BookIndex {
|
||||
@NotNull String authorName) {
|
||||
List<String> availableBooks = BooksWithoutBorders.getAvailableBooks(sender, listPublic);
|
||||
availableBooks.removeIf((bookPath) ->
|
||||
!InputCleaningHelper.stripColor(BookFileHelper.getBookAuthorFromPath(bookPath)).equalsIgnoreCase(authorName));
|
||||
!InputCleaningUtil.stripColor(BookFileUtil.getBookAuthorFromPath(bookPath)).equalsIgnoreCase(authorName));
|
||||
|
||||
int totalPages = (int) Math.ceil((double) availableBooks.size() / booksPerPage);
|
||||
if (page > totalPages) {
|
||||
@@ -84,8 +84,8 @@ public class AuthorBookIndex extends BookIndex {
|
||||
@NotNull List<String> availableBooks) {
|
||||
int startIndex = (page - 1) * booksPerPage;
|
||||
for (int bookIndex = startIndex; bookIndex < Math.min(startIndex + booksPerPage, availableBooks.size()); bookIndex++) {
|
||||
String title = BookFileHelper.getBookTitleFromPath(availableBooks.get(bookIndex));
|
||||
String author = BookFileHelper.getBookAuthorFromPath(availableBooks.get(bookIndex));
|
||||
String title = BookFileUtil.getBookTitleFromPath(availableBooks.get(bookIndex));
|
||||
String author = BookFileUtil.getBookAuthorFromPath(availableBooks.get(bookIndex));
|
||||
String niceName = new FormatBuilder(title).append(Formatting.NEUTRAL_BOOK_LIST_AUTHOR_SEPARATOR).append(author).color().build();
|
||||
|
||||
componentBuilder.append(niceName).color(ChatColor.WHITE).event(
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.gui;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputParsingUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
@@ -34,15 +34,15 @@ public abstract class BookIndex {
|
||||
PagedBookIndex.printBooks(sender, selectPublic, command, 1);
|
||||
return true;
|
||||
} else if (arguments.length == 1) {
|
||||
int page = InputCleaningHelper.parsePageNumber(arguments[0]);
|
||||
int page = InputParsingUtil.parsePageNumber(arguments[0]);
|
||||
if (page > 0) {
|
||||
PagedBookIndex.printBooks(sender, selectPublic, command, page);
|
||||
return true;
|
||||
}
|
||||
} else if (arguments.length == 2) {
|
||||
String author = InputCleaningHelper.parseAuthorSpecifier(arguments[0]);
|
||||
String author = InputParsingUtil.parseAuthorSpecifier(arguments[0]);
|
||||
if (author != null) {
|
||||
int page = InputCleaningHelper.parsePageNumber(arguments[1]);
|
||||
int page = InputParsingUtil.parsePageNumber(arguments[1]);
|
||||
if (page > 0) {
|
||||
AuthorBookIndex.printBooks(sender, selectPublic, command, page, author);
|
||||
}
|
||||
@@ -52,12 +52,12 @@ public abstract class BookIndex {
|
||||
|
||||
// Parse book author from input
|
||||
for (int authorIndex = 0; authorIndex < arguments.length; authorIndex++) {
|
||||
String author = InputCleaningHelper.parseAuthorSpecifier(arguments[authorIndex]);
|
||||
String author = InputParsingUtil.parseAuthorSpecifier(arguments[authorIndex]);
|
||||
if (author == null) {
|
||||
continue;
|
||||
}
|
||||
for (int pageIndex = authorIndex + 1; pageIndex < arguments.length; pageIndex++) {
|
||||
int pageNumber = InputCleaningHelper.parsePageNumber(arguments[pageIndex]);
|
||||
int pageNumber = InputParsingUtil.parsePageNumber(arguments[pageIndex]);
|
||||
if (pageNumber <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -2,8 +2,8 @@ package net.knarcraft.bookswithoutborders.gui;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.knarcraft.knarlib.formatting.TranslatableMessage;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
@@ -94,16 +94,16 @@ public class PagedBookIndex extends BookIndex {
|
||||
@NotNull List<String> availableBooks) {
|
||||
int startIndex = (page - 1) * booksPerPage;
|
||||
for (int bookIndex = startIndex; bookIndex < Math.min(startIndex + booksPerPage, availableBooks.size()); bookIndex++) {
|
||||
String title = new FormatBuilder(BookFileHelper.getBookTitleFromPath(availableBooks.get(bookIndex))).color().build();
|
||||
String author = new FormatBuilder(BookFileHelper.getBookAuthorFromPath(availableBooks.get(bookIndex))).color().build();
|
||||
String title = new FormatBuilder(BookFileUtil.getBookTitleFromPath(availableBooks.get(bookIndex))).color().build();
|
||||
String author = new FormatBuilder(BookFileUtil.getBookAuthorFromPath(availableBooks.get(bookIndex))).color().build();
|
||||
|
||||
ClickEvent indexClick = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + command + " " + (bookIndex + 1));
|
||||
HoverEvent indexHover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new FormatBuilder(Formatting.NEUTRAL_BOOK_LIST_BOOK_INDEX_HOVER).color().build()));
|
||||
ClickEvent pathClick = new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + command + " " + availableBooks.get(bookIndex));
|
||||
HoverEvent pathHover = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(new FormatBuilder(Formatting.NEUTRAL_BOOK_LIST_PATH_HOVER).color().build()));
|
||||
ClickEvent authorClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + command + " author" + InputCleaningHelper.stripColor(author) + " page1");
|
||||
ClickEvent authorClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/" + command + " author" + InputCleaningUtil.stripColor(author) + " page1");
|
||||
HoverEvent authorHover = new HoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
new Text(new FormatBuilder(Formatting.NEUTRAL_BOOK_LIST_AUTHOR_HOVER).replace("{author}", InputCleaningHelper.stripColor(author)).color().build()));
|
||||
new Text(new FormatBuilder(Formatting.NEUTRAL_BOOK_LIST_AUTHOR_HOVER).replace("{author}", InputCleaningUtil.stripColor(author)).color().build()));
|
||||
|
||||
componentBuilder.append(new FormatBuilder(Formatting.NEUTRAL_BOOK_LIST_BOOK_INDEX_NUMBER).replace("{index}",
|
||||
String.valueOf(bookIndex + 1)).color().build()).color(interactColor).event(indexClick).event(indexHover);
|
||||
|
@@ -5,8 +5,8 @@ import net.knarcraft.bookswithoutborders.config.Permission;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Formatting;
|
||||
import net.knarcraft.bookswithoutborders.container.Bookshelf;
|
||||
import net.knarcraft.bookswithoutborders.handler.BookshelfHandler;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.IntegerToRomanConverter;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookMetaUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.IntegerToRomanUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@@ -166,8 +166,8 @@ public class BookshelfListener implements Listener {
|
||||
*/
|
||||
@NotNull
|
||||
private String getBookDescription(@NotNull BookMeta bookMeta) {
|
||||
String title = BookHelper.getBookTitle(bookMeta);
|
||||
String author = BookHelper.getBookAuthor(bookMeta, null);
|
||||
String title = BookMetaUtil.getBookTitle(bookMeta);
|
||||
String author = BookMetaUtil.getBookAuthor(bookMeta, null);
|
||||
return new FormatBuilder(Formatting.NEUTRAL_BOOKSHELF_WRITTEN_FORMAT).replace("{title}", title).
|
||||
replace("{author}", author).build();
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public class BookshelfListener implements Listener {
|
||||
List<String> enchantments = new ArrayList<>(enchantmentMap.size());
|
||||
for (Map.Entry<Enchantment, Integer> enchantmentEntry : enchantmentMap.entrySet()) {
|
||||
enchantments.add(getEnchantmentName(enchantmentEntry.getKey()) + " " +
|
||||
IntegerToRomanConverter.getRomanNumber(enchantmentEntry.getValue()));
|
||||
IntegerToRomanUtil.getRomanNumber(enchantmentEntry.getValue()));
|
||||
}
|
||||
builder.append(String.join(", ", enchantments));
|
||||
return builder.toString();
|
||||
|
@@ -5,8 +5,8 @@ import net.knarcraft.bookswithoutborders.config.BwBConfig;
|
||||
import net.knarcraft.bookswithoutborders.config.Permission;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoader;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -79,13 +79,13 @@ public class GroupDecryptListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
File file = BookFileHelper.getFile(BookDirectory.ENCRYPTED, groupName, oldBook);
|
||||
File file = BookFileUtil.getFile(BookDirectory.ENCRYPTED, groupName, oldBook);
|
||||
if (file == null) {
|
||||
new FormatBuilder(Translatable.ERROR_GROUP_DECRYPT_NOT_FOUND).error(player);
|
||||
return;
|
||||
}
|
||||
|
||||
newBook = BookLoader.loadBook(player, file, true, BookDirectory.ENCRYPTED, heldItem.getAmount());
|
||||
newBook = BookLoaderUtil.loadBook(player, file, true, BookDirectory.ENCRYPTED, heldItem.getAmount());
|
||||
|
||||
if (newBook == null) {
|
||||
new FormatBuilder(Translatable.ERROR_GROUP_DECRYPT_LOAD_FAILED).error(player);
|
||||
|
@@ -3,8 +3,8 @@ package net.knarcraft.bookswithoutborders.listener;
|
||||
import net.knarcraft.bookswithoutborders.BooksWithoutBorders;
|
||||
import net.knarcraft.bookswithoutborders.config.BwBConfig;
|
||||
import net.knarcraft.bookswithoutborders.config.StaticMessage;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoader;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -30,7 +30,7 @@ public class PlayerEventListener implements Listener {
|
||||
|
||||
//If a book directory exists with this player's name, move it to this player's UUID
|
||||
String bookFolder = config.getBookFolder();
|
||||
File file = new File(bookFolder, InputCleaningHelper.cleanString(player.getName()));
|
||||
File file = new File(bookFolder, InputCleaningUtil.cleanString(player.getName()));
|
||||
if (file.exists() && !file.renameTo(new File(bookFolder, player.getUniqueId().toString()))) {
|
||||
BooksWithoutBorders.log(Level.WARNING, new FormatBuilder(
|
||||
StaticMessage.WARNING_USER_BOOK_MIGRATION_IMPOSSIBLE.toString()).
|
||||
@@ -60,7 +60,7 @@ public class PlayerEventListener implements Listener {
|
||||
if (!bookName.trim().isEmpty()) {
|
||||
|
||||
//Give the book to the player if it exists
|
||||
ItemStack newBook = BookLoader.loadBook(player, bookName, true, "public");
|
||||
ItemStack newBook = BookLoaderUtil.loadBook(player, bookName, true, "public");
|
||||
if (newBook != null) {
|
||||
player.getInventory().addItem(newBook);
|
||||
}
|
||||
|
@@ -7,10 +7,11 @@ import net.knarcraft.bookswithoutborders.config.translation.SignText;
|
||||
import net.knarcraft.bookswithoutborders.encryption.EncryptionStyle;
|
||||
import net.knarcraft.bookswithoutborders.state.BookDirectory;
|
||||
import net.knarcraft.bookswithoutborders.state.SignType;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoader;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookLoaderUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptedBookUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
@@ -31,7 +32,7 @@ import org.bukkit.inventory.PlayerInventory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static net.knarcraft.bookswithoutborders.utility.BookFileHelper.isBookListIndex;
|
||||
import static net.knarcraft.bookswithoutborders.utility.BookFileUtil.isBookListIndex;
|
||||
|
||||
/**
|
||||
* A listener for relevant sign events such as clicking a decryption sign
|
||||
@@ -136,12 +137,12 @@ public class SignEventListener implements Listener {
|
||||
player.closeInventory();
|
||||
|
||||
//Converts user supplied key into integer form
|
||||
String lineText = InputCleaningHelper.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||
String key = EncryptionHelper.getNumberKeyFromStringKey(lineText);
|
||||
String lineText = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||
String key = EncryptionUtil.getNumberKeyFromStringKey(lineText);
|
||||
|
||||
ItemStack book = EncryptionHelper.loadEncryptedBook(player, key, false, false);
|
||||
ItemStack book = EncryptedBookUtil.loadEncryptedBook(player, key, false, false);
|
||||
if (book == null) {
|
||||
book = EncryptionHelper.loadEncryptedBookLegacy(player, key, false);
|
||||
book = EncryptedBookUtil.loadEncryptedBookLegacy(player, key, false);
|
||||
}
|
||||
|
||||
if (book != null) {
|
||||
@@ -160,7 +161,7 @@ public class SignEventListener implements Listener {
|
||||
@Nullable
|
||||
private ChatColor getSignLine2Color(@NotNull Sign sign) {
|
||||
String line = sign.getSide(Side.FRONT).getLine(2);
|
||||
if (!InputCleaningHelper.stripColor(line).equals(line)) {
|
||||
if (!InputCleaningUtil.stripColor(line).equals(line)) {
|
||||
return ChatColor.getByChar(sign.getSide(Side.FRONT).getLine(2).substring(1, 2).charAt(0));
|
||||
} else {
|
||||
return null;
|
||||
@@ -178,7 +179,7 @@ public class SignEventListener implements Listener {
|
||||
@NotNull Player player) {
|
||||
//Tests if a full file name has been supplied and points to an actual file
|
||||
String signFile = lines[2] + lines[3];
|
||||
if (BookFileHelper.getFile(BookDirectory.PUBLIC, null, signFile) != null) {
|
||||
if (BookFileUtil.getFile(BookDirectory.PUBLIC, null, signFile) != null) {
|
||||
markGiveSignValidity(event, true);
|
||||
return;
|
||||
} else {
|
||||
@@ -223,8 +224,8 @@ public class SignEventListener implements Listener {
|
||||
boolean mainHand = hand == EquipmentSlot.HAND;
|
||||
if (heldItemType == Material.WRITTEN_BOOK) {
|
||||
player.closeInventory();
|
||||
eBook = EncryptionHelper.encryptBook(player, mainHand, InputCleaningHelper.stripColor(lines[2]),
|
||||
EncryptionStyle.getFromString(InputCleaningHelper.stripColor(lines[3])), false);
|
||||
eBook = EncryptedBookUtil.encryptBook(player, mainHand, InputCleaningUtil.stripColor(lines[2]),
|
||||
EncryptionStyle.getFromString(InputCleaningUtil.stripColor(lines[3])), false);
|
||||
if (eBook != null) {
|
||||
player.getInventory().setItem(hand, eBook);
|
||||
}
|
||||
@@ -238,7 +239,7 @@ public class SignEventListener implements Listener {
|
||||
* @param player <p>The player which clicked the sign</p>
|
||||
*/
|
||||
private void giveBook(@NotNull Sign sign, @NotNull Player player) {
|
||||
String fileName = InputCleaningHelper.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||
String fileName = InputCleaningUtil.stripColor(sign.getSide(Side.FRONT).getLine(2));
|
||||
boolean isLoadListNumber = false;
|
||||
|
||||
try {
|
||||
@@ -250,10 +251,10 @@ public class SignEventListener implements Listener {
|
||||
//Add the third line to the second line for the full filename
|
||||
String thirdLine = sign.getSide(Side.FRONT).getLine(3);
|
||||
if (!isLoadListNumber && thirdLine.length() >= 2) {
|
||||
fileName += InputCleaningHelper.stripColor(thirdLine);
|
||||
fileName += InputCleaningUtil.stripColor(thirdLine);
|
||||
}
|
||||
|
||||
ItemStack newBook = BookLoader.loadBook(player, fileName, true, "public");
|
||||
ItemStack newBook = BookLoaderUtil.loadBook(player, fileName, true, "public");
|
||||
|
||||
if (newBook != null) {
|
||||
player.getInventory().addItem(newBook);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package net.knarcraft.bookswithoutborders.state;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.config.translation.SignText;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.InputCleaningUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -51,7 +51,7 @@ public enum SignType {
|
||||
*/
|
||||
@Nullable
|
||||
public static SignType fromString(@NotNull String input) {
|
||||
input = InputCleaningHelper.stripColor(input);
|
||||
input = InputCleaningUtil.stripColor(input);
|
||||
for (SignType signType : SignType.values()) {
|
||||
if (input.equalsIgnoreCase(getText(signType.text))) {
|
||||
return signType;
|
||||
@@ -68,7 +68,7 @@ public enum SignType {
|
||||
*/
|
||||
@NotNull
|
||||
private static String getText(@NotNull SignText signText) {
|
||||
return InputCleaningHelper.stripColor(new FormatBuilder(signText).build());
|
||||
return InputCleaningUtil.stripColor(new FormatBuilder(signText).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -5,9 +5,9 @@ import net.knarcraft.bookswithoutborders.config.StaticMessage;
|
||||
import net.knarcraft.bookswithoutborders.config.translation.Translatable;
|
||||
import net.knarcraft.bookswithoutborders.container.EncryptedBook;
|
||||
import net.knarcraft.bookswithoutborders.container.MigrationRequest;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileReaderWriterUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
||||
import net.knarcraft.knarlib.formatting.FormatBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@@ -96,7 +96,7 @@ public class MigrationQueueThread implements Runnable {
|
||||
|
||||
EncryptedBook encryptedBook = null;
|
||||
BookMeta loadedBook = null;
|
||||
String extension = BookFileHelper.getExtensionFromPath(file.getName());
|
||||
String extension = BookFileUtil.getExtensionFromPath(file.getName());
|
||||
|
||||
if (!extension.equalsIgnoreCase("txt") && !extension.equalsIgnoreCase("yml")) {
|
||||
BooksWithoutBorders.log(Level.WARNING, new FormatBuilder(StaticMessage.EXCEPTION_UNEXPECTED_EXTENSION.toString()).
|
||||
@@ -134,10 +134,10 @@ public class MigrationQueueThread implements Runnable {
|
||||
}
|
||||
|
||||
try {
|
||||
String newName = BookFileHelper.getBookFile(loadedBook, author, isPublic);
|
||||
String newName = BookFileUtil.getBookFile(loadedBook, author, isPublic);
|
||||
|
||||
// Retain legacy key
|
||||
String key = EncryptionHelper.extractLegacyKey(file.getName());
|
||||
String key = EncryptionUtil.extractLegacyKey(file.getName());
|
||||
if (!key.isBlank()) {
|
||||
newName = "[" + key + "]" + newName;
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Helper class for converting books to and from text/yml files
|
||||
* Utility class for converting books to and from text/yml files
|
||||
*/
|
||||
public final class BookFileReaderWriterUtil {
|
||||
|
||||
@@ -81,15 +81,15 @@ public final class BookFileReaderWriterUtil {
|
||||
if (encryptedBook.aesConfiguration() == null) {
|
||||
throw new IOException(StaticMessage.EXCEPTION_AES_NO_CONFIGURATION.toString());
|
||||
}
|
||||
bookYml.set("Encryption.AES.IV", EncryptionHelper.bytesToHex(encryptedBook.aesConfiguration().iv()));
|
||||
bookYml.set("Encryption.AES.Salt", EncryptionHelper.bytesToHex(encryptedBook.aesConfiguration().salt()));
|
||||
bookYml.set("Encryption.AES.IV", EncryptionUtil.bytesToHex(encryptedBook.aesConfiguration().iv()));
|
||||
bookYml.set("Encryption.AES.Salt", EncryptionUtil.bytesToHex(encryptedBook.aesConfiguration().salt()));
|
||||
}
|
||||
|
||||
// If data is non-empty, that means the book is already encrypted
|
||||
if (!encryptedBook.data().isEmpty()) {
|
||||
bookYml.set("Encryption.Data", encryptedBook.data());
|
||||
} else {
|
||||
List<String> encryptedPages = EncryptionHelper.encryptDecryptBookPages(encryptedBook.bookMeta(),
|
||||
List<String> encryptedPages = EncryptedBookUtil.encryptDecryptBookPages(encryptedBook.bookMeta(),
|
||||
encryptedBook.encryptionStyle(), encryptedBook.aesConfiguration(), encryptedBook.encryptionKey(), true);
|
||||
if (encryptedPages == null || encryptedPages.isEmpty()) {
|
||||
throw new IOException(StaticMessage.EXCEPTION_ENCRYPTED_LOAD_FAILED.toString());
|
||||
@@ -134,7 +134,7 @@ public final class BookFileReaderWriterUtil {
|
||||
FileConfiguration bookYml = YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
// If key is blank, it's either not real encrypted, or admin decryption is disabled for the book
|
||||
userKey = EncryptionHelper.sha256(userKey);
|
||||
userKey = EncryptionUtil.sha256(userKey);
|
||||
String realKey = bookYml.getString("Encryption.Key", "");
|
||||
if (!realKey.isBlank()) {
|
||||
if (forceDecrypt) {
|
||||
@@ -156,8 +156,8 @@ public final class BookFileReaderWriterUtil {
|
||||
|
||||
AESConfiguration aesConfiguration = null;
|
||||
if (encryptionStyle == EncryptionStyle.AES) {
|
||||
byte[] iv = EncryptionHelper.hexStringToByteArray(bookYml.getString("Encryption.AES.IV", ""));
|
||||
byte[] salt = EncryptionHelper.hexStringToByteArray(bookYml.getString("Encryption.AES.Salt", ""));
|
||||
byte[] iv = EncryptionUtil.hexStringToByteArray(bookYml.getString("Encryption.AES.IV", ""));
|
||||
byte[] salt = EncryptionUtil.hexStringToByteArray(bookYml.getString("Encryption.AES.Salt", ""));
|
||||
aesConfiguration = new AESConfiguration(iv, salt, userKey);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public final class BookFileReaderWriterUtil {
|
||||
|
||||
// Perform the actual AES decryption
|
||||
meta.setPages(data);
|
||||
List<String> decryptedPages = EncryptionHelper.encryptDecryptBookPages(meta, encryptionStyle, aesConfiguration,
|
||||
List<String> decryptedPages = EncryptedBookUtil.encryptDecryptBookPages(meta, encryptionStyle, aesConfiguration,
|
||||
userKey, false);
|
||||
if (decryptedPages != null && !decryptedPages.isEmpty()) {
|
||||
meta.setPages(decryptedPages);
|
||||
@@ -246,7 +246,7 @@ public final class BookFileReaderWriterUtil {
|
||||
}
|
||||
|
||||
bookMetadata.setTitle(bookYml.getString("Title", new FormatBuilder(Formatting.NEUTRAL_UNKNOWN_TITLE).build()));
|
||||
bookMetadata.setAuthor(BookFileHelper.authorFromUUID(bookYml.getString("Author",
|
||||
bookMetadata.setAuthor(BookFileUtil.authorFromUUID(bookYml.getString("Author",
|
||||
new FormatBuilder(Formatting.NEUTRAL_UNKNOWN_AUTHOR).build())));
|
||||
bookMetadata.setPages(bookYml.getStringList("Pages"));
|
||||
bookMetadata.setLore(bookYml.getStringList("Lore"));
|
||||
@@ -264,8 +264,8 @@ public final class BookFileReaderWriterUtil {
|
||||
@Nullable
|
||||
private static BookMeta bookFromTXT(@NotNull File file, @NotNull BookMeta bookMetadata) {
|
||||
//Get title and author from the file name
|
||||
String title = BookFileHelper.getBookTitleFromPath(file.getName());
|
||||
String author = BookFileHelper.getBookAuthorFromPath(file.getName());
|
||||
String title = BookFileUtil.getBookTitleFromPath(file.getName());
|
||||
String author = BookFileUtil.getBookAuthorFromPath(file.getName());
|
||||
|
||||
//Read the .txt file
|
||||
List<String> rawPages;
|
||||
@@ -287,10 +287,10 @@ public final class BookFileReaderWriterUtil {
|
||||
}
|
||||
|
||||
//Remove any empty pages
|
||||
List<String> pages = new ArrayList<>(InputCleaningHelper.cleanList(rawPages));
|
||||
List<String> pages = new ArrayList<>(InputCleaningUtil.cleanList(rawPages));
|
||||
|
||||
//Update the metadata of the book with its new values
|
||||
bookMetadata.setAuthor(BookFileHelper.authorFromUUID(author));
|
||||
bookMetadata.setAuthor(BookFileUtil.authorFromUUID(author));
|
||||
bookMetadata.setTitle(title.substring(0, Math.min(title.length(), 32)));
|
||||
bookMetadata.setPages(pages);
|
||||
|
||||
|
@@ -23,11 +23,11 @@ import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Helper class for dealing with files
|
||||
* Helper class for listing and finding files
|
||||
*/
|
||||
public final class BookFileHelper {
|
||||
public final class BookFileUtil {
|
||||
|
||||
private BookFileHelper() {
|
||||
private BookFileUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,11 +60,11 @@ public final class BookFileHelper {
|
||||
*/
|
||||
@Nullable
|
||||
public static List<String> listFiles(@NotNull CommandSender sender, @NotNull Boolean listPublic) {
|
||||
File file = BookFileHelper.getBookDirectoryPath(BookDirectory.getCommon(listPublic), sender);
|
||||
File file = BookFileUtil.getBookDirectoryPath(BookDirectory.getCommon(listPublic), sender);
|
||||
if (file == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return BookFileHelper.listFiles(file);
|
||||
return BookFileUtil.listFiles(file);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +165,7 @@ public final class BookFileHelper {
|
||||
* @return <p>The filename, or the filename with the author replaced with UUID</p>
|
||||
*/
|
||||
public static String replaceAuthorWithUUID(@NotNull String fileName) {
|
||||
String userName = InputCleaningHelper.stripColor(getBookAuthorFromPath(fileName));
|
||||
String userName = InputCleaningUtil.stripColor(getBookAuthorFromPath(fileName));
|
||||
|
||||
Player player = Bukkit.getPlayerExact(userName);
|
||||
if (player != null) {
|
||||
@@ -184,7 +184,7 @@ public final class BookFileHelper {
|
||||
@NotNull
|
||||
public static String authorFromUUID(@NotNull String author) {
|
||||
try {
|
||||
UUID authorID = UUID.fromString(InputCleaningHelper.stripColor(author));
|
||||
UUID authorID = UUID.fromString(InputCleaningUtil.stripColor(author));
|
||||
Player player = Bukkit.getPlayer(authorID);
|
||||
if (player != null) {
|
||||
author = player.getName();
|
||||
@@ -205,17 +205,17 @@ public final class BookFileHelper {
|
||||
@NotNull
|
||||
public static String getBookFile(@NotNull BookMeta book, @NotNull OfflinePlayer player, boolean isPublic) throws IllegalArgumentException {
|
||||
String separator = BooksWithoutBorders.getConfiguration().getTitleAuthorSeparator();
|
||||
String bookName = BookHelper.getBookTitle(book);
|
||||
String authorName = BookHelper.getBookAuthor(book, isPublic ? null : player);
|
||||
String bookName = BookMetaUtil.getBookTitle(book);
|
||||
String authorName = BookMetaUtil.getBookAuthor(book, isPublic ? null : player);
|
||||
|
||||
if (InputCleaningHelper.cleanString(bookName).contains(separator) ||
|
||||
InputCleaningHelper.cleanString(authorName).contains(separator)) {
|
||||
if (InputCleaningUtil.cleanString(bookName).contains(separator) ||
|
||||
InputCleaningUtil.cleanString(authorName).contains(separator)) {
|
||||
throw new IllegalArgumentException(new FormatBuilder(StaticMessage.EXCEPTION_META_HAS_SEPARATOR.toString()).
|
||||
replace("{author}", authorName).replace("{title}", bookName).
|
||||
replace("{separator}", separator).build());
|
||||
}
|
||||
|
||||
return InputCleaningHelper.cleanString(bookName + separator + authorName);
|
||||
return InputCleaningUtil.cleanString(bookName + separator + authorName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,6 +261,7 @@ public final class BookFileHelper {
|
||||
* @param bookMeta <p>The book meta of the book to locate</p>
|
||||
* @return <p>The file, or null if not found</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static File getFile(@NotNull BookDirectory bookDirectory, @Nullable String group, @NotNull BookMeta bookMeta) {
|
||||
String separator = BooksWithoutBorders.getConfiguration().getTitleAuthorSeparator();
|
||||
return getFile(bookDirectory, group, bookMeta.getTitle() + separator + bookMeta.getAuthor());
|
||||
@@ -274,6 +275,7 @@ public final class BookFileHelper {
|
||||
* @param sender <p>The command sender looking for a file</p>
|
||||
* @return <p>The file, or null if not found</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static File getFile(@NotNull BookDirectory bookDirectory, @NotNull String fileName, @NotNull CommandSender sender) {
|
||||
String folder = getBookDirectoryPathString(bookDirectory, sender);
|
||||
if (folder != null) {
|
||||
@@ -295,7 +297,7 @@ public final class BookFileHelper {
|
||||
public static File getFile(@NotNull BookDirectory bookDirectory, @Nullable String subFolder, @NotNull String fileName) {
|
||||
File baseFolder = new File(BooksWithoutBorders.getConfiguration().getBookFolder());
|
||||
if (subFolder != null) {
|
||||
subFolder = InputCleaningHelper.cleanString(subFolder);
|
||||
subFolder = InputCleaningUtil.cleanString(subFolder);
|
||||
}
|
||||
File parentFolder = switch (bookDirectory) {
|
||||
case PUBLIC -> baseFolder;
|
||||
@@ -320,7 +322,7 @@ public final class BookFileHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
fileName = InputCleaningHelper.cleanString(fileName);
|
||||
fileName = InputCleaningUtil.cleanString(fileName);
|
||||
List<String> possiblePaths = List.of(
|
||||
fileName,
|
||||
fileName.replace(" ", "_"),
|
||||
@@ -411,7 +413,7 @@ public final class BookFileHelper {
|
||||
//Convert the UUID into a username if necessary
|
||||
String userName = getBookAuthorFromPath(fileName);
|
||||
String title = getBookTitleFromPath(fileName);
|
||||
fileList.add(title + separator + BookFileHelper.authorFromUUID(userName));
|
||||
fileList.add(title + separator + BookFileUtil.authorFromUUID(userName));
|
||||
} else {
|
||||
fileList.add(fileName);
|
||||
}
|
||||
@@ -419,8 +421,8 @@ public final class BookFileHelper {
|
||||
|
||||
// Sort the book list
|
||||
Comparator<String> bookComparator = Comparator.naturalOrder();
|
||||
fileList.sort((a, b) -> bookComparator.compare(InputCleaningHelper.stripColor(a).toLowerCase(),
|
||||
InputCleaningHelper.stripColor(b).toLowerCase()));
|
||||
fileList.sort((a, b) -> bookComparator.compare(InputCleaningUtil.stripColor(a).toLowerCase(),
|
||||
InputCleaningUtil.stripColor(b).toLowerCase()));
|
||||
return fileList;
|
||||
}
|
||||
|
@@ -19,11 +19,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A helper class for loading books from files
|
||||
* A utility class for loading books, and taking required cost
|
||||
*/
|
||||
public final class BookLoader {
|
||||
public final class BookLoaderUtil {
|
||||
|
||||
private BookLoader() {
|
||||
private BookLoaderUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,9 +89,9 @@ public final class BookLoader {
|
||||
//Get the full path of the book to load
|
||||
File file;
|
||||
if (bookDirectory == BookDirectory.PUBLIC) {
|
||||
file = BookFileHelper.getFile(bookDirectory, null, fileName);
|
||||
file = BookFileUtil.getFile(bookDirectory, null, fileName);
|
||||
} else {
|
||||
file = BookFileHelper.getFile(bookDirectory, fileName, sender);
|
||||
file = BookFileUtil.getFile(bookDirectory, fileName, sender);
|
||||
}
|
||||
if (file == null) {
|
||||
new FormatBuilder(Translatable.ERROR_INCORRECT_FILE_NAME).error(sender);
|
||||
@@ -153,11 +153,11 @@ public final class BookLoader {
|
||||
//Set the metadata and amount to the new book
|
||||
book.setItemMeta(bookMetadata);
|
||||
//Increase book generation if enabled
|
||||
BookHelper.increaseGeneration(book);
|
||||
BookMetaUtil.increaseGeneration(book);
|
||||
book.setAmount(numCopies);
|
||||
|
||||
if (!isSigned && book.getItemMeta() != null) {
|
||||
return BookHelper.unsignBook((BookMeta) book.getItemMeta(), book.getAmount());
|
||||
return BookMetaUtil.unsignBook((BookMeta) book.getItemMeta(), book.getAmount());
|
||||
}
|
||||
return book;
|
||||
}
|
@@ -19,11 +19,11 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Helper class for getting abstract book information
|
||||
* Utility class for getting book meta data
|
||||
*/
|
||||
public final class BookHelper {
|
||||
public final class BookMetaUtil {
|
||||
|
||||
private BookHelper() {
|
||||
private BookMetaUtil() {
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public final class BookHelper {
|
||||
public static void increaseGeneration(@NotNull ItemStack bookItem) {
|
||||
BookMeta bookMeta = (BookMeta) bookItem.getItemMeta();
|
||||
if (BooksWithoutBorders.getConfiguration().changeGenerationOnCopy() && bookMeta != null) {
|
||||
bookMeta.setGeneration(BookHelper.getNextGeneration(bookMeta.getGeneration()));
|
||||
bookMeta.setGeneration(BookMetaUtil.getNextGeneration(bookMeta.getGeneration()));
|
||||
bookItem.setItemMeta(bookMeta);
|
||||
}
|
||||
}
|
||||
@@ -158,8 +158,8 @@ public final class BookHelper {
|
||||
* @return <p>True if the player is the author</p>
|
||||
*/
|
||||
private static boolean isAuthor(@NotNull String playerName, @Nullable String author) {
|
||||
playerName = InputCleaningHelper.cleanString(playerName);
|
||||
return author != null && playerName.equalsIgnoreCase(InputCleaningHelper.cleanString(author));
|
||||
playerName = InputCleaningUtil.cleanString(playerName);
|
||||
return author != null && playerName.equalsIgnoreCase(InputCleaningUtil.cleanString(author));
|
||||
}
|
||||
|
||||
}
|
@@ -25,58 +25,18 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputCleaningHelper.cleanString;
|
||||
import static net.knarcraft.bookswithoutborders.utility.InputCleaningUtil.cleanString;
|
||||
|
||||
/**
|
||||
* Helper class for book encryption
|
||||
* Utility class for book encryption and decryption
|
||||
*/
|
||||
public final class EncryptionHelper {
|
||||
public final class EncryptedBookUtil {
|
||||
|
||||
private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
|
||||
|
||||
private EncryptionHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string key/password into its numerical values
|
||||
*
|
||||
* @param key <p>The key to transform</p>
|
||||
* @return <p>A comma-separated string of the numbers representing the key's characters</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String getNumberKeyFromStringKey(@NotNull String key) {
|
||||
StringBuilder integerKey = new StringBuilder(String.valueOf(Character.codePointAt(key, 0)));
|
||||
for (int x = 1; x < key.length(); x++) {
|
||||
integerKey.append(", ").append(Character.codePointAt(key, x));
|
||||
}
|
||||
return integerKey.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs sha256 hashing on the input string
|
||||
*
|
||||
* @param input <p>The input to hash</p>
|
||||
* @return <p>The hashed input</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String sha256(@NotNull String input) {
|
||||
String hashed;
|
||||
try {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA3-256");
|
||||
final byte[] hashBytes = digest.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
hashed = Base64.getEncoder().encodeToString(hashBytes);
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
hashed = input;
|
||||
}
|
||||
return hashed;
|
||||
private EncryptedBookUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,8 +54,8 @@ public final class EncryptionHelper {
|
||||
@Nullable AESConfiguration aesConfiguration, @NotNull String key,
|
||||
boolean encrypt) {
|
||||
Encryptor encryptor = switch (style) {
|
||||
case DNA -> new GenenCrypt(EncryptionHelper.getNumberKeyFromStringKey(key));
|
||||
case SUBSTITUTION -> new SubstitutionCipher(EncryptionHelper.getNumberKeyFromStringKey(key));
|
||||
case DNA -> new GenenCrypt(EncryptionUtil.getNumberKeyFromStringKey(key));
|
||||
case SUBSTITUTION -> new SubstitutionCipher(EncryptionUtil.getNumberKeyFromStringKey(key));
|
||||
case AES -> {
|
||||
if (aesConfiguration == null) {
|
||||
throw new IllegalArgumentException(StaticMessage.EXCEPTION_AES_NO_CONFIGURATION.toString());
|
||||
@@ -155,7 +115,7 @@ public final class EncryptionHelper {
|
||||
public static ItemStack encryptBook(Player player, boolean mainHand, @NotNull String key,
|
||||
@NotNull EncryptionStyle style, @NotNull String groupName,
|
||||
boolean preventAdminDecrypt) {
|
||||
BookMeta book = InventoryHelper.getHeldBookMetadata(player, mainHand);
|
||||
BookMeta book = InventoryUtil.getHeldBookMetadata(player, mainHand);
|
||||
if (book == null) {
|
||||
new FormatBuilder(Translatable.ERROR_METADATA_MISSING).error(player);
|
||||
return null;
|
||||
@@ -166,7 +126,7 @@ public final class EncryptionHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
String hashedKey = sha256(key);
|
||||
String hashedKey = EncryptionUtil.sha256(key);
|
||||
AESConfiguration configuration = AESConfiguration.getNewConfiguration(hashedKey);
|
||||
|
||||
//Save the book's un-encrypted contents to a file
|
||||
@@ -177,7 +137,7 @@ public final class EncryptionHelper {
|
||||
}
|
||||
|
||||
//Get the encrypted pages
|
||||
List<String> encryptedPages = EncryptionHelper.encryptDecryptBookPages(book, style, configuration, hashedKey,
|
||||
List<String> encryptedPages = EncryptedBookUtil.encryptDecryptBookPages(book, style, configuration, hashedKey,
|
||||
true);
|
||||
if (encryptedPages == null) {
|
||||
return null;
|
||||
@@ -186,7 +146,7 @@ public final class EncryptionHelper {
|
||||
//Format the last page just in case
|
||||
BookFormatterUtil.formatLastPage(encryptedPages);
|
||||
//Remove empty pages
|
||||
List<String> newPages = InputCleaningHelper.cleanList(encryptedPages);
|
||||
List<String> newPages = InputCleaningUtil.cleanList(encryptedPages);
|
||||
|
||||
ItemStack encryptedBook = createEncryptedBook(book, newPages, player, newMetadata);
|
||||
|
||||
@@ -212,7 +172,7 @@ public final class EncryptionHelper {
|
||||
encryptedBook.setItemMeta(book);
|
||||
|
||||
//Update item amount
|
||||
encryptedBook.setAmount(InventoryHelper.getHeldBook(player, true).getAmount());
|
||||
encryptedBook.setAmount(InventoryUtil.getHeldBook(player, true).getAmount());
|
||||
//Set new item metadata
|
||||
encryptedBook.setItemMeta(newMetadata);
|
||||
|
||||
@@ -257,15 +217,15 @@ public final class EncryptionHelper {
|
||||
@Nullable
|
||||
public static ItemStack loadEncryptedBook(@NotNull Player player, @NotNull String key, boolean deleteEncryptedFile,
|
||||
boolean forceDecrypt) {
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
|
||||
|
||||
if (bookMetadata == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File file = BookFileHelper.getFile(BookDirectory.ENCRYPTED, null, bookMetadata);
|
||||
if (!file.isFile()) {
|
||||
File file = BookFileUtil.getFile(BookDirectory.ENCRYPTED, null, bookMetadata);
|
||||
if (file == null || !file.isFile()) {
|
||||
new FormatBuilder(Translatable.ERROR_DECRYPT_NOT_FOUND).error(player);
|
||||
return null;
|
||||
} else {
|
||||
@@ -288,7 +248,7 @@ public final class EncryptionHelper {
|
||||
|
||||
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
|
||||
newBook.setItemMeta(bookMetadata);
|
||||
newBook.setAmount(InventoryHelper.getHeldBook(player, true).getAmount());
|
||||
newBook.setAmount(InventoryUtil.getHeldBook(player, true).getAmount());
|
||||
return newBook;
|
||||
}
|
||||
|
||||
@@ -303,9 +263,8 @@ public final class EncryptionHelper {
|
||||
@Nullable
|
||||
public static ItemStack loadEncryptedBookLegacy(@NotNull Player player, @NotNull String key, boolean deleteEncryptedFile) {
|
||||
new FormatBuilder(Translatable.NEUTRAL_ATTEMPTING_LEGACY_DECRYPTION).neutral(player);
|
||||
ItemStack heldBook = InventoryHelper.getHeldBook(player, true);
|
||||
ItemStack heldBook = InventoryUtil.getHeldBook(player, true);
|
||||
BookMeta bookMetadata = (BookMeta) heldBook.getItemMeta();
|
||||
String path = BooksWithoutBorders.getConfiguration().getEncryptedBookPath();
|
||||
|
||||
if (bookMetadata == null) {
|
||||
return null;
|
||||
@@ -316,16 +275,13 @@ public final class EncryptionHelper {
|
||||
integerKey.append(Character.getNumericValue(Character.codePointAt(key, x)));
|
||||
}
|
||||
|
||||
String fileName = "[" + integerKey + "]" + BookFileHelper.getBookFile(bookMetadata, player, true);
|
||||
String fileName = "[" + integerKey + "]" + BookFileUtil.getBookFile(bookMetadata, player, true);
|
||||
fileName = cleanString(fileName).replace(" ", "_");
|
||||
|
||||
File file = new File(path + fileName + ".yml");
|
||||
if (!file.isFile()) {
|
||||
file = new File(path + fileName + ".txt");
|
||||
if (!file.isFile()) {
|
||||
new FormatBuilder(Translatable.ERROR_DECRYPT_LEGACY_INVALID_KEY).error(player);
|
||||
return null;
|
||||
}
|
||||
File file = BookFileUtil.getFile(BookDirectory.ENCRYPTED, null, fileName);
|
||||
if (file == null) {
|
||||
new FormatBuilder(Translatable.ERROR_DECRYPT_LEGACY_INVALID_KEY).error(player);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -345,58 +301,10 @@ public final class EncryptionHelper {
|
||||
|
||||
ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
|
||||
newBook.setItemMeta(bookMetadata);
|
||||
newBook.setAmount(InventoryHelper.getHeldBook(player, true).getAmount());
|
||||
newBook.setAmount(InventoryUtil.getHeldBook(player, true).getAmount());
|
||||
return newBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to extract a legacy password key from a filename
|
||||
*
|
||||
* @param fileName <p>The filename to get the legacy key from</p>
|
||||
* @return <p>The legacy key, or an empty string if not found</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String extractLegacyKey(@NotNull String fileName) {
|
||||
if (fileName.matches("^\\[[0-9]+].*")) {
|
||||
return fileName.substring(fileName.indexOf("[") + 1, fileName.indexOf("]"));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte array to a hexadecimal string
|
||||
*
|
||||
* @param bytes <p>The bytes to convert</p>
|
||||
* @return <p>The resulting hexadecimal string</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
byte[] hexChars = new byte[bytes.length * 2];
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
||||
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string of hexadecimals to a byte array
|
||||
*
|
||||
* @param input <p>The hexadecimal input to parse</p>
|
||||
* @return <p>The resulting byte array</p>
|
||||
*/
|
||||
public static byte[] hexStringToByteArray(@NotNull String input) {
|
||||
int len = input.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(input.charAt(i), 16) << 4) +
|
||||
Character.digit(input.charAt(i + 1), 16));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to delete the encryption file after a book has been decrypted
|
||||
*
|
||||
@@ -441,7 +349,7 @@ public final class EncryptionHelper {
|
||||
}
|
||||
}
|
||||
//Generate file name
|
||||
String fileName = BookFileHelper.getBookFile(bookMetadata, player, true);
|
||||
String fileName = BookFileUtil.getBookFile(bookMetadata, player, true);
|
||||
|
||||
List<String> newLore = new ArrayList<>();
|
||||
newLore.add(ChatColor.GRAY + "[" + groupName + " encrypted]");
|
||||
@@ -478,7 +386,7 @@ public final class EncryptionHelper {
|
||||
private static Boolean saveEncryptedBook(@NotNull Player player, @NotNull EncryptedBook encryptedBook) {
|
||||
String path = BooksWithoutBorders.getConfiguration().getEncryptedBookPath();
|
||||
|
||||
String fileName = BookFileHelper.getBookFile(encryptedBook.bookMeta(), player, true);
|
||||
String fileName = BookFileUtil.getBookFile(encryptedBook.bookMeta(), player, true);
|
||||
fileName = cleanString(fileName);
|
||||
|
||||
//cancels saving if file is already encrypted
|
@@ -0,0 +1,103 @@
|
||||
package net.knarcraft.bookswithoutborders.utility;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* A utility class for encryption-related tasks
|
||||
*/
|
||||
public final class EncryptionUtil {
|
||||
|
||||
private static final byte[] HEX_ARRAY = "0123456789ABCDEF".getBytes(StandardCharsets.US_ASCII);
|
||||
|
||||
private EncryptionUtil() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a string key/password into its numerical values
|
||||
*
|
||||
* @param key <p>The key to transform</p>
|
||||
* @return <p>A comma-separated string of the numbers representing the key's characters</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String getNumberKeyFromStringKey(@NotNull String key) {
|
||||
StringBuilder integerKey = new StringBuilder(String.valueOf(Character.codePointAt(key, 0)));
|
||||
for (int x = 1; x < key.length(); x++) {
|
||||
integerKey.append(", ").append(Character.codePointAt(key, x));
|
||||
}
|
||||
return integerKey.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs sha256 hashing on the input string
|
||||
*
|
||||
* @param input <p>The input to hash</p>
|
||||
* @return <p>The hashed input</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String sha256(@NotNull String input) {
|
||||
String hashed;
|
||||
try {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA3-256");
|
||||
final byte[] hashBytes = digest.digest(input.getBytes(StandardCharsets.UTF_8));
|
||||
hashed = Base64.getEncoder().encodeToString(hashBytes);
|
||||
} catch (NoSuchAlgorithmException exception) {
|
||||
hashed = input;
|
||||
}
|
||||
return hashed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to extract a legacy password key from a filename
|
||||
*
|
||||
* @param fileName <p>The filename to get the legacy key from</p>
|
||||
* @return <p>The legacy key, or an empty string if not found</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String extractLegacyKey(@NotNull String fileName) {
|
||||
if (fileName.matches("^\\[[0-9]+].*")) {
|
||||
return fileName.substring(fileName.indexOf("[") + 1, fileName.indexOf("]"));
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte array to a hexadecimal string
|
||||
*
|
||||
* @param bytes <p>The bytes to convert</p>
|
||||
* @return <p>The resulting hexadecimal string</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
byte[] hexChars = new byte[bytes.length * 2];
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
||||
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string of hexadecimals to a byte array
|
||||
*
|
||||
* @param input <p>The hexadecimal input to parse</p>
|
||||
* @return <p>The resulting byte array</p>
|
||||
*/
|
||||
public static byte[] hexStringToByteArray(@NotNull String input) {
|
||||
int len = input.length();
|
||||
byte[] data = new byte[len / 2];
|
||||
for (int i = 0; i < len; i += 2) {
|
||||
data[i / 2] = (byte) ((Character.digit(input.charAt(i), 16) << 4) +
|
||||
Character.digit(input.charAt(i + 1), 16));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
package net.knarcraft.bookswithoutborders.utility;
|
||||
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Helper class for cleaning input and names
|
||||
*/
|
||||
public final class InputCleaningUtil {
|
||||
|
||||
private InputCleaningUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes null and empty items from a list
|
||||
*
|
||||
* @param list <p>The list to clean</p>
|
||||
* @return <p>A clean list containing all relevant values</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static List<String> cleanList(@NotNull List<String> list) {
|
||||
List<String> resultList = new ArrayList<>(list);
|
||||
resultList.removeIf((item) -> item == null || item.trim().isEmpty());
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any special character from a filename
|
||||
*
|
||||
* @param fileName <p>The file name to clean</p>
|
||||
* @return <p>The cleaned file name</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String cleanString(@NotNull String fileName) {
|
||||
fileName = fileName.replace("/", "");
|
||||
fileName = fileName.replace("\\", "");
|
||||
fileName = fileName.replace("*", "");
|
||||
fileName = fileName.replace(":", "");
|
||||
fileName = fileName.replace("|", "");
|
||||
fileName = fileName.replace("<", "");
|
||||
fileName = fileName.replace(">", "");
|
||||
fileName = fileName.replace("?", "");
|
||||
fileName = fileName.replace("\"", "");
|
||||
fileName = fileName.replace("§", "&");
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the color from the given input
|
||||
*
|
||||
* @param input <p>The input to strip</p>
|
||||
* @return <p>The color stripped input</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String stripColor(@NotNull String input) {
|
||||
return ColorHelper.stripColorCodes(input, ColorConversion.RGB);
|
||||
}
|
||||
|
||||
}
|
@@ -1,66 +1,51 @@
|
||||
package net.knarcraft.bookswithoutborders.utility;
|
||||
|
||||
import net.knarcraft.knarlib.property.ColorConversion;
|
||||
import net.knarcraft.knarlib.util.ColorHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Helper class for cleaning input and names
|
||||
*/
|
||||
public final class InputCleaningHelper {
|
||||
public final class InputParsingUtil {
|
||||
|
||||
private InputParsingUtil() {
|
||||
|
||||
private InputCleaningHelper() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes null and empty items from a list
|
||||
* Checks whether the given input is a boolean
|
||||
*
|
||||
* @param list <p>The list to clean</p>
|
||||
* @return <p>A clean list containing all relevant values</p>
|
||||
* @param input <p>The input to validate</p>
|
||||
* @return <p>True if the given input is a boolean</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static List<String> cleanList(@NotNull List<String> list) {
|
||||
List<String> resultList = new ArrayList<>(list);
|
||||
resultList.removeIf((item) -> item == null || item.trim().isEmpty());
|
||||
return resultList;
|
||||
public static boolean isBoolean(@NotNull String input) {
|
||||
return input.matches("(true|false)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any special character from a filename
|
||||
* Checks whether the given input is an integer
|
||||
*
|
||||
* @param fileName <p>The file name to clean</p>
|
||||
* @return <p>The cleaned file name</p>
|
||||
* @param input <p>The input to validate</p>
|
||||
* @return <p>True if the given input is an integer</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String cleanString(@NotNull String fileName) {
|
||||
fileName = fileName.replace("/", "");
|
||||
fileName = fileName.replace("\\", "");
|
||||
fileName = fileName.replace("*", "");
|
||||
fileName = fileName.replace(":", "");
|
||||
fileName = fileName.replace("|", "");
|
||||
fileName = fileName.replace("<", "");
|
||||
fileName = fileName.replace(">", "");
|
||||
fileName = fileName.replace("?", "");
|
||||
fileName = fileName.replace("\"", "");
|
||||
fileName = fileName.replace("§", "&");
|
||||
return fileName;
|
||||
public static boolean isInt(@NotNull String input) {
|
||||
return input.matches("[0-9]+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the color from the given input
|
||||
* Merges all arguments to a string with spaces
|
||||
*
|
||||
* @param input <p>The input to strip</p>
|
||||
* @return <p>The color stripped input</p>
|
||||
* @param arguments <p>The arguments to merge</p>
|
||||
* @param stripLastN <p>How many of the last arguments to ignore</p>
|
||||
* @return <p>The merged arguments</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String stripColor(@NotNull String input) {
|
||||
return ColorHelper.stripColorCodes(input, ColorConversion.RGB);
|
||||
public static String mergeArguments(String[] arguments, int stripLastN) {
|
||||
StringBuilder builder = new StringBuilder(arguments[0]);
|
||||
for (int i = 1; i < arguments.length - stripLastN; i++) {
|
||||
builder.append(" ").append(arguments[i]);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,40 +85,4 @@ public final class InputCleaningHelper {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given input is a boolean
|
||||
*
|
||||
* @param input <p>The input to validate</p>
|
||||
* @return <p>True if the given input is a boolean</p>
|
||||
*/
|
||||
public static boolean isBoolean(@NotNull String input) {
|
||||
return input.matches("(true|false)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given input is an integer
|
||||
*
|
||||
* @param input <p>The input to validate</p>
|
||||
* @return <p>True if the given input is an integer</p>
|
||||
*/
|
||||
public static boolean isInt(@NotNull String input) {
|
||||
return input.matches("[0-9]+");
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges all arguments to a string with spaces
|
||||
*
|
||||
* @param arguments <p>The arguments to merge</p>
|
||||
* @param stripLastN <p>How many of the last arguments to ignore</p>
|
||||
* @return <p>The merged arguments</p>
|
||||
*/
|
||||
@NotNull
|
||||
public static String mergeArguments(String[] arguments, int stripLastN) {
|
||||
StringBuilder builder = new StringBuilder(arguments[0]);
|
||||
for (int i = 1; i < arguments.length - stripLastN; i++) {
|
||||
builder.append(" ").append(arguments[i]);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@@ -6,9 +6,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A converter from an integer to a roman numeral
|
||||
* A utility for converting from an integer to a roman numeral
|
||||
*/
|
||||
public final class IntegerToRomanConverter {
|
||||
public final class IntegerToRomanUtil {
|
||||
|
||||
private final static List<Integer> romanValues = new ArrayList<>();
|
||||
private final static List<Character> romanCharacters = new ArrayList<>();
|
||||
@@ -32,7 +32,7 @@ public final class IntegerToRomanConverter {
|
||||
romanCharacters.add('I');
|
||||
}
|
||||
|
||||
private IntegerToRomanConverter() {
|
||||
private IntegerToRomanUtil() {
|
||||
|
||||
}
|
||||
|
@@ -15,9 +15,9 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* The inventory helper mainly helps with getting and setting books
|
||||
*/
|
||||
public final class InventoryHelper {
|
||||
public final class InventoryUtil {
|
||||
|
||||
private InventoryHelper() {
|
||||
private InventoryUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,10 +26,11 @@ public final class InventoryHelper {
|
||||
* @param player <p>The player holding the book</p>
|
||||
* @return <p>The held book, or null if not holding one book in the main hand</p>
|
||||
*/
|
||||
@Nullable
|
||||
public static ItemStack getHeldBook(@NotNull Player player) {
|
||||
ItemSlot holdingSlot = InventoryHelper.getHeldSlotBook(player, false, false, false, false);
|
||||
ItemSlot holdingSlot = InventoryUtil.getHeldSlotBook(player, false, false, false, false);
|
||||
if (holdingSlot != ItemSlot.NONE) {
|
||||
return InventoryHelper.getHeldItem(player, holdingSlot == ItemSlot.MAIN_HAND);
|
||||
return InventoryUtil.getHeldItem(player, holdingSlot == ItemSlot.MAIN_HAND);
|
||||
} else {
|
||||
return null;
|
||||
}
|
@@ -6,11 +6,11 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Helper class for getting string lists required for auto-completion
|
||||
* Utility class for getting string lists required for auto-completion
|
||||
*/
|
||||
public final class TabCompletionTypeHelper {
|
||||
public final class TabCompletionTypeUtil {
|
||||
|
||||
private TabCompletionTypeHelper() {
|
||||
private TabCompletionTypeUtil() {
|
||||
}
|
||||
|
||||
/**
|
@@ -1,6 +1,6 @@
|
||||
package net.knarcraft.bookswithoutborders.encryption;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -11,7 +11,7 @@ public class GenenCryptTest {
|
||||
|
||||
@Test
|
||||
public void encryptDecryptTest() {
|
||||
String encryptionKey = EncryptionHelper.getNumberKeyFromStringKey("My secret password!");
|
||||
String encryptionKey = EncryptionUtil.getNumberKeyFromStringKey("My secret password!");
|
||||
String plaintext = "Very secret &4colored&r message. That might be quite long. Of course, the length might " +
|
||||
"cause problems, especially as the gene encryption requires several characters for every encrypted " +
|
||||
"character. Also, the hexadecimal representation of the original text is encrypted. It is unknown if " +
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package net.knarcraft.bookswithoutborders.encryption;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -13,7 +13,7 @@ public class SubstitutionCipherTest {
|
||||
public void encryptDecryptTest() {
|
||||
String plaintext = "Very secret text that should be kept secret. It should be noted that several characters, " +
|
||||
"like !\"#¤%&/()=?`§|@£${[]}'*,.-;:_<>µ need to be tested. Also foreign characters, like: øæåØÆÅ";
|
||||
String integerKey = EncryptionHelper.getNumberKeyFromStringKey("Very secret key that you will never guess!¤%&/");
|
||||
String integerKey = EncryptionUtil.getNumberKeyFromStringKey("Very secret key that you will never guess!¤%&/");
|
||||
SubstitutionCipher substitutionCipher = new SubstitutionCipher(integerKey);
|
||||
String cypherText = substitutionCipher.encryptText(plaintext);
|
||||
|
||||
|
@@ -1,13 +1,13 @@
|
||||
package net.knarcraft.bookswithoutborders.util;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.BookFileUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BookFileHelperTest {
|
||||
public class BookFileUtilTest {
|
||||
|
||||
@Test
|
||||
public void findDuplicatesTest() {
|
||||
@@ -17,9 +17,9 @@ public class BookFileHelperTest {
|
||||
files[2] = new File("test/asd/(3)book+)Crab.yml");
|
||||
files[3] = new File("test/asd/(2)book+)Crab.yml");
|
||||
files[4] = new File("test/asd/(1)book+)Crab.yml");
|
||||
assertEquals(4, BookFileHelper.findDuplicates(files, "book+)Crab.yml"));
|
||||
assertEquals(1, BookFileHelper.findDuplicates(files, "book+)Fish.yml"));
|
||||
assertEquals(0, BookFileHelper.findDuplicates(files, "book+)Horse.yml"));
|
||||
assertEquals(4, BookFileUtil.findDuplicates(files, "book+)Crab.yml"));
|
||||
assertEquals(1, BookFileUtil.findDuplicates(files, "book+)Fish.yml"));
|
||||
assertEquals(0, BookFileUtil.findDuplicates(files, "book+)Horse.yml"));
|
||||
}
|
||||
|
||||
}
|
@@ -1,15 +1,15 @@
|
||||
package net.knarcraft.bookswithoutborders.util;
|
||||
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionHelper;
|
||||
import net.knarcraft.bookswithoutborders.utility.EncryptionUtil;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EncryptionHelperTest {
|
||||
public class EncryptedBookUtilTest {
|
||||
|
||||
@Test
|
||||
public void getNumberKeyFromStringKey() {
|
||||
String numberKey = EncryptionHelper.getNumberKeyFromStringKey("hello");
|
||||
String numberKey = EncryptionUtil.getNumberKeyFromStringKey("hello");
|
||||
assertEquals("104, 101, 108, 108, 111", numberKey);
|
||||
}
|
||||
|
@@ -2,13 +2,13 @@ package net.knarcraft.bookswithoutborders.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static net.knarcraft.bookswithoutborders.utility.IntegerToRomanConverter.getRomanNumber;
|
||||
import static net.knarcraft.bookswithoutborders.utility.IntegerToRomanUtil.getRomanNumber;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* A test class for IntegerToRomanConverter
|
||||
*/
|
||||
public class IntegerToRomanConverterTest {
|
||||
public class IntegerToRomanUtilTest {
|
||||
|
||||
@Test
|
||||
public void basicNumbersTest() {
|
Reference in New Issue
Block a user