-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
59 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 28 additions & 4 deletions
32
pcbridge-spigot/src/main/kotlin/com/projectcitybuild/support/spigot/SpigotIntegration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
package com.projectcitybuild.support.spigot | ||
|
||
interface SpigotIntegration { | ||
suspend fun onEnable() = run { } | ||
suspend fun onDisable() = run { } | ||
} | ||
import com.projectcitybuild.core.errors.SentryReporter | ||
import com.projectcitybuild.pcbridge.core.contracts.PlatformLogger | ||
import org.bukkit.plugin.Plugin | ||
import org.bukkit.plugin.PluginManager | ||
|
||
abstract class SpigotIntegration( | ||
private val pluginName: String, | ||
private val pluginManager: PluginManager, | ||
private val sentry: SentryReporter, | ||
private val logger: PlatformLogger, | ||
) { | ||
protected abstract suspend fun onEnable(loadedPlugin: Plugin) | ||
protected abstract suspend fun onDisable() | ||
|
||
suspend fun enable() = runCatching { | ||
val integratedPlugin = pluginManager.getPlugin(pluginName) | ||
if (integratedPlugin == null) { | ||
logger.warning("Cannot find dynmap plugin. Disabling marker integration") | ||
return@runCatching | ||
} | ||
onEnable(integratedPlugin) | ||
}.onFailure { | ||
logger.severe("Failed to enable Dynmap integration: ${it.localizedMessage}") | ||
sentry.report(it) | ||
} | ||
|
||
suspend fun disable() = onDisable() | ||
} |