Skip to content

Commit

Permalink
Fix binary incompatibility with old plugins
Browse files Browse the repository at this point in the history
- Fix version building error
  • Loading branch information
DRSchlaubi committed Apr 2, 2023
1 parent 3ed6ad9 commit 7377276
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 88 deletions.
5 changes: 4 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 0 additions & 76 deletions api/src/main/java/dev/schlaubi/mikbot/plugin/api/Plugin.java

This file was deleted.

66 changes: 57 additions & 9 deletions api/src/main/kotlin/dev/schlaubi/mikbot/plugin/api/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import com.kotlindiscord.kord.extensions.builders.ExtensibleBotBuilder
import com.kotlindiscord.kord.extensions.extensions.Extension
import dev.schlaubi.mikbot.plugin.api.io.Database
import kotlinx.coroutines.CoroutineScope
import org.pf4j.Plugin
import org.pf4j.PluginWrapper
import java.util.*
import org.pf4j.PluginWrapper as PF4JPluginWrapper

/**
Expand All @@ -19,26 +22,71 @@ public interface PluginContext {
public val pluginWrapper: PF4JPluginWrapper
}

/**
* Basic plugin methods.
*
* **This is only used because of Java compatibility, please only extend [Plugin]**
*/
public interface PluginInterface {

public abstract class Plugin : Plugin {
/**
* Getter for [PluginContext].
*
* @return the context or `null` if it is a legacy plugin
* @see isLegacyPlugin
*/
public val context: PluginContext?

/**
* Fall back constructor
*
* @param wrapper the [PluginWrapper] provided by the plugin engine
*/
@Deprecated("Deprecated by PF4J (Use Plugin#Plugin(PluginContext) instead")
public constructor(wrapper: PF4JPluginWrapper) : super(wrapper) {
context = null
}

/**
* Constructor of a plugin.
*
* @param context the [PluginContext] provided by the engine
*/
public constructor(context: PluginContext) : super() {
Objects.requireNonNull(context, "Context needs not to be null")
this.context = context
}

/**
* Checks whether the plugin is running in legacy mode.
*
* @return whether the plugin is running in legacy mode or not
*/
public val isLegacyPlugin: Boolean
get() = context == null

/**
* Getter for [PluginContext].
*
* @return the context or `null`
* @see isLegacyPlugin
* @throws IllegalStateException if this is a legacy plugin
*/
public val contextSafe: PluginContext
get() {
checkNotNull(context) { "This plugin is a legacy plugin" }
return context
}

/**
* Add additional [ExtensibleBot] settings.
*
* **Do not add [Extensions][Extension] in here, use [addExtensions] instead.**
*/
public suspend fun ExtensibleBotBuilder.apply(): Unit = Unit
public open suspend fun ExtensibleBotBuilder.apply(): Unit = Unit

/**
* Add new extensions.
*/
public fun ExtensibleBotBuilder.ExtensionsBuilder.addExtensions(): Unit = Unit
public open fun ExtensibleBotBuilder.ExtensionsBuilder.addExtensions(): Unit = Unit

/**
* This is being executed directly after the bot got started.
*/
public fun CoroutineScope.atLaunch(bot: ExtensibleBot): Unit = Unit
public open fun CoroutineScope.atLaunch(bot: ExtensibleBot): Unit = Unit
}
2 changes: 1 addition & 1 deletion gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
}

group = "dev.schlaubi"
version = libs.versions.api
version = libs.versions.api.get()

repositories {
mavenCentral()
Expand Down

0 comments on commit 7377276

Please sign in to comment.