Skip to content

Commit

Permalink
Add and use method override
Browse files Browse the repository at this point in the history
  • Loading branch information
esotericenderman committed Nov 3, 2024
1 parent ab0c99a commit 75ff143
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Locale, Map<String, String>>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 75ff143

Please sign in to comment.