From 6d539a14dfe4d47c5e8e22c4df3c8721a7de8754 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 8 Nov 2022 20:34:53 +0100 Subject: [PATCH] Fixes the files provided in the tab-completion not translating to actual files --- .../utility/BookLoader.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java index 93f76ff..37f3399 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/utility/BookLoader.java @@ -3,6 +3,7 @@ package net.knarcraft.bookswithoutborders.utility; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig; import net.knarcraft.bookswithoutborders.state.BookDirectory; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -60,7 +61,22 @@ public final class BookLoader { //Get the full path of the book to load File file = getFullPath(sender, fileName, bookDirectory, directory); if (file == null) { - return null; + //Try converting the username to UUID + String titleAuthorSeparator = BooksWithoutBordersConfig.getTitleAuthorSeparator(); + String[] data = fileName.split(titleAuthorSeparator); + String extension = data[1].substring(data[1].length() - 4); + String userName = data[1].substring(0, data[1].length() - 4); + Player player = Bukkit.getPlayer(userName); + if (player != null) { + data[1] = player.getUniqueId() + extension; + file = getFullPath(sender, String.join(titleAuthorSeparator, data), bookDirectory, directory); + if (file == null) { + BooksWithoutBorders.sendErrorMessage(sender, "Incorrect file name!"); + return null; + } + } else { + return null; + } } //Make sure the player can pay for the book @@ -124,9 +140,7 @@ public final class BookLoader { } else { file = FileHelper.getBookFile(BookHelper.getBookDirectoryPathString(bookDirectory, sender) + fileName); } - if (file == null || !file.isFile()) { - BooksWithoutBorders.sendErrorMessage(sender, "Incorrect file name!"); return null; } else { return file;