diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/messages/MessageManager.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/messages/MessageManager.kt index 5a5232b..d1d82bd 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/messages/MessageManager.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/messages/MessageManager.kt @@ -8,7 +8,6 @@ import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin import java.util.Locale import kotlin.collections.HashMap -import kotlin.io.path.Path /** * The message manager class provides utility for dealing with messages in your @@ -22,7 +21,7 @@ class MessageManager(private val plugin: JavaPlugin) { private val miniMessage = MiniMessage.miniMessage() - private val messagesFolder = plugin.saveResources(Path("messages")) + private val messagesFolder = plugin.saveResources("messages") private val messageMap = HashMap>() diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/pack/resource/ResourcePackManager.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/pack/resource/ResourcePackManager.kt index 7b9653a..47706dc 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/pack/resource/ResourcePackManager.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/pack/resource/ResourcePackManager.kt @@ -6,7 +6,6 @@ import foundation.esoteric.minecraft.plugins.library.item.TexturedItem import org.apache.commons.io.FileUtils import org.bukkit.plugin.java.JavaPlugin import java.io.File -import kotlin.io.path.Path /** * A class that helps your plugin to implement custom resources via a resource pack. @@ -20,7 +19,7 @@ import kotlin.io.path.Path */ class ResourcePackManager(internal val plugin: JavaPlugin) { - internal val resourcePath = Path(plugin.name + "ResourcePack") + internal val resourcePath = plugin.name + "ResourcePack" internal val zipFile = File(plugin.dataFolder, "$resourcePath.zip") init { diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtility.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtility.kt index 4ca77d6..308380c 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtility.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtility.kt @@ -62,3 +62,21 @@ fun Plugin.saveResources(resourceFolderPath: Path): File { val subFolder = File(dataFolder, resourceFolderPath.toString()) return resourceFolderPath.saveResources(subFolder) } + +/** + * Saves the raw contents of any resource folder embedded with a plugin's .jar. + * + * The resources are saved into the plugin's data folder using the same + * hierarchy as the .jar file (subdirectories are preserved). + * @param resourceFolderPath the embedded resource path to look for within the plugin's .jar file. (No preceding slash). + * @return The saved folder `File`. + * @throws IllegalArgumentException if the resource path is null, empty, or points to a nonexistent resource folder. + * @see Plugin.saveResource + * @see Plugin.getResource + * @see Plugin.getDataFolder + * @see Plugin.getDataPath + * @author Esoteric Enderman + */ +fun Plugin.saveResources(resourceFolderPath: String): File { + return saveResources(Path.of(resourceFolderPath)) +} diff --git a/lib/src/test/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtilityTest.kt b/lib/src/test/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtilityTest.kt index 0fe5818..efbb6ad 100644 --- a/lib/src/test/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtilityTest.kt +++ b/lib/src/test/kotlin/foundation/esoteric/minecraft/plugins/library/utility/plugin/PluginUtilityTest.kt @@ -3,7 +3,6 @@ package foundation.esoteric.minecraft.plugins.library.utility.plugin import be.seeseemelk.mockbukkit.MockBukkit import foundation.esoteric.minecraft.plugins.library.TestPlugin import java.io.File -import kotlin.io.path.Path import kotlin.test.* class PluginUtilityTest { @@ -16,7 +15,7 @@ class PluginUtilityTest { } @Test fun savingFolderWorks() { - val file = plugin.saveResources(Path("TestPluginResourcePack")) + val file = plugin.saveResources("TestPluginResourcePack") assertTrue(file.exists()) assertTrue(file.isDirectory)