Prevents some unintended usage of UUID for filenames

This commit is contained in:
Kristian Knarvik 2022-08-11 00:53:29 +02:00
parent 396c0a9d41
commit 8b47aeb8f2
4 changed files with 9 additions and 7 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -116,7 +116,7 @@ public final class BookHelper {
* @param player <p>The player trying to do something with the book</p>
* @return <p>The book file</p>
*/
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();
}

View File

@ -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<String> 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