From 8b47aeb8f2555a96eee32e20bc4eee1626c84221 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Thu, 11 Aug 2022 00:53:29 +0200 Subject: [PATCH] Prevents some unintended usage of UUID for filenames --- .../bookswithoutborders/command/CommandDecrypt.java | 2 +- .../knarcraft/bookswithoutborders/command/CommandSave.java | 2 +- .../knarcraft/bookswithoutborders/utility/BookHelper.java | 6 ++++-- .../bookswithoutborders/utility/EncryptionHelper.java | 6 +++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandDecrypt.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandDecrypt.java index 0a4c0a8..8d2840f 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandDecrypt.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandDecrypt.java @@ -59,7 +59,7 @@ public class CommandDecrypt implements TabExecutor { //Get the "encryption key" from the filename String key = ""; for (String encryptedFile : encryptedFiles) { - if (encryptedFile.contains(BookHelper.getBookFile(bookMetadata, player))) { + if (encryptedFile.contains(BookHelper.getBookFile(bookMetadata, player, true))) { key = encryptedFile.substring(encryptedFile.indexOf("[") + 1, encryptedFile.indexOf("]")); break; } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java index 4874d26..06cfebb 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/command/CommandSave.java @@ -86,7 +86,7 @@ public class CommandSave implements TabExecutor { saveToPublicFolder ? BookDirectory.PUBLIC : BookDirectory.PLAYER, player); //Generate book filename - String fileName = BookHelper.getBookFile(book, player); + String fileName = BookHelper.getBookFile(book, player, saveToPublicFolder); //Make sure the used folders exist File file = new File(savePath); diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookHelper.java index 2d7cb2d..af7cf1f 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookHelper.java @@ -116,7 +116,7 @@ public final class BookHelper { * @param player

The player trying to do something with the book

* @return

The book file

*/ - public static String getBookFile(BookMeta book, Player player) { + public static String getBookFile(BookMeta book, Player player, boolean isPublic) { String titleAuthorSeparator = BooksWithoutBordersConfig.getTitleAuthorSeparator(); String bookName; if (book.hasTitle()) { @@ -126,9 +126,11 @@ public final class BookHelper { } String authorName; - if (!book.hasAuthor() || isAuthor(player.getName(), book.getAuthor())) { + if ((!book.hasAuthor() || isAuthor(player.getName(), book.getAuthor())) && !isPublic) { //Store as unique id to account for name changes authorName = player.getUniqueId().toString(); + } else if (!book.hasAuthor()) { + authorName = player.getName(); } else { authorName = book.getAuthor(); } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java index 9eb84d5..632a0c2 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/EncryptionHelper.java @@ -198,7 +198,7 @@ public final class EncryptionHelper { return null; } - String fileName = "[" + key + "]" + BookHelper.getBookFile(bookMetadata, player); + String fileName = "[" + key + "]" + BookHelper.getBookFile(bookMetadata, player, true); fileName = fixName(cleanString(fileName), false); File file = new File(path + fileName + ".yml"); @@ -261,7 +261,7 @@ public final class EncryptionHelper { } } //Generate file name - String fileName = BookHelper.getBookFile(bookMetadata, player); + String fileName = BookHelper.getBookFile(bookMetadata, player, true); List newLore = new ArrayList<>(); newLore.add(ChatColor.GRAY + "[" + groupName + " encrypted]"); @@ -300,7 +300,7 @@ public final class EncryptionHelper { private static Boolean saveEncryptedBook(Player player, BookMeta bookMetaData, String key) { String path = getBookFolder() + "Encrypted" + getSlash(); - String fileName = "[" + key + "]" + BookHelper.getBookFile(bookMetaData, player); + String fileName = "[" + key + "]" + BookHelper.getBookFile(bookMetaData, player, true); fileName = fixName(cleanString(fileName), false); //cancels saving if file is already encrypted