Test plugin dependencies and casting the existing instance.

This commit is contained in:
Logan Gorence 2021-12-21 09:07:10 +00:00
parent aed37ae013
commit e303f6f937
No known key found for this signature in database
GPG Key ID: 9743CEF10935949A
3 changed files with 25 additions and 3 deletions

View File

@ -1,3 +1,5 @@
dependencies {
implementation("net.dv8tion:JDA:5.0.0-alpha.2")
compileOnly(project(":foundation-core"))
}

View File

@ -1,9 +1,13 @@
package cloud.kubelet.foundation.bifrost
import cloud.kubelet.foundation.core.FoundationCorePlugin
import org.bukkit.plugin.java.JavaPlugin
class FoundationBifrostPlugin : JavaPlugin() {
override fun onEnable() {
slF4JLogger.info("Enabling!")
val foundation = server.pluginManager.getPlugin("Foundation") as FoundationCorePlugin
slF4JLogger.info("Plugin data path: ${foundation.pluginDataPath}")
}
}

View File

@ -7,14 +7,30 @@ import org.bukkit.command.CommandExecutor
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.plugin.java.JavaPlugin
import java.nio.file.Path
class FoundationCorePlugin : JavaPlugin(), Listener {
private lateinit var _pluginDataPath: Path
var pluginDataPath: Path
/**
* Data path of the core plugin.
* Can be used as a sanity check of sorts for dependencies to be sure the plugin is loaded.
*/
get() {
if (!::_pluginDataPath.isInitialized) {
throw Exception("FoundationCore is not loaded!")
}
return _pluginDataPath
}
private set(value) { _pluginDataPath = value }
override fun onEnable() {
val dataPath = dataFolder.toPath()
val backupPath = dataPath.resolve(BACKUPS_DIRECTORY)
pluginDataPath = dataFolder.toPath()
val backupPath = pluginDataPath.resolve(BACKUPS_DIRECTORY)
// Create Foundation plugin directories.
dataPath.toFile().mkdir()
pluginDataPath.toFile().mkdir()
backupPath.toFile().mkdir()
// Register this as an event listener.