-
Notifications
You must be signed in to change notification settings - Fork 0
feat: hook api #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
twisti-dev
wants to merge
23
commits into
version/1.21.11
Choose a base branch
from
feat/hook-api
base: version/1.21.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: hook api #188
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a1112ea
feat: introduce hook framework with processor, annotations, and integ…
twisti-dev f4a0340
chore: update ABI and bump version [skip ci]
github-actions[bot] c5619cf
feat: refactor VelocityHookService to use classloader for resource re…
twisti-dev 25db719
Merge remote-tracking branch 'origin/feat/hook-api' into feat/hook-api
twisti-dev f693a76
Fix hook metadata emission on unresolved deps
twisti-dev c29cbc4
Fix hook metadata emission when class deps are unresolved (#189)
twisti-dev 153a7dc
Update ABI reference
twisti-dev cdfca6c
feat: improve error handling for hooks metadata loading
twisti-dev b342e50
feat: introduce shared hook metadata and configuration classes
twisti-dev 1c47e83
feat: refactor hook architecture to use shared Hook interface and add…
twisti-dev e12ea89
feat: add conditional hook evaluation with custom conditions support
twisti-dev 41f5bdd
feat: implement conditional hook support and enhance configuration ha…
twisti-dev e4f9736
feat: add shared Hook interface and enhance hook condition handling
twisti-dev ef61b30
feat: implement topological sort algorithm for directed graphs
twisti-dev 0471e83
Initial plan
Copilot 4d18670
feat: handle unresolved class dependencies in hook processing
twisti-dev 16cc998
feat: remove unused Kotlin compiler options for InternalSurfApi
twisti-dev ea677c5
fix: preserve topological order by using priority as tie-breaker duri…
Copilot 85b4f1b
chore: dump abi
twisti-dev 1a1a0d3
refactor: filter dependencies before sorting by priority
Copilot 0d30fd4
refactor: use Kahn's algorithm with priority queue for topological sort
Copilot 2b3abbb
Fix topological sort violating hook dependencies by using Kahn's algo…
twisti-dev db1645a
fix: ensure safe null handling for incoming edges in hook processing
twisti-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Binary file not shown.
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
...kit-plugin-test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/hook/PrimaryTestHook.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package dev.slne.surf.surfapi.bukkit.test.hook | ||
|
|
||
| import dev.slne.surf.surfapi.bukkit.test.hook.condition.EnabledCondition | ||
| import dev.slne.surf.surfapi.core.api.hook.AbstractHook | ||
| import dev.slne.surf.surfapi.core.api.util.logger | ||
| import dev.slne.surf.surfapi.shared.api.hook.HookMeta | ||
| import dev.slne.surf.surfapi.shared.api.hook.requirement.ConditionalOnCustom | ||
|
|
||
| @ConditionalOnCustom(EnabledCondition::class) | ||
| @HookMeta | ||
| class PrimaryTestHook : AbstractHook() { | ||
| private val log = logger() | ||
|
|
||
| override suspend fun onBootstrap() { | ||
| log.atInfo().log("PrimaryTestHook bootstrapped") | ||
| } | ||
|
|
||
| override suspend fun onLoad() { | ||
| log.atInfo().log("PrimaryTestHook loaded") | ||
| } | ||
|
|
||
| override suspend fun onEnable() { | ||
| log.atInfo().log("PrimaryTestHook enabled") | ||
| } | ||
|
|
||
| override suspend fun onDisable() { | ||
| log.atInfo().log("PrimaryTestHook disabled") | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
...api-bukkit-plugin-test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/hook/TestHook.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package dev.slne.surf.surfapi.bukkit.test.hook | ||
|
|
||
| import dev.slne.surf.surfapi.bukkit.test.BukkitPluginMain | ||
| import dev.slne.surf.surfapi.core.api.hook.AbstractHook | ||
| import dev.slne.surf.surfapi.core.api.util.logger | ||
| import dev.slne.surf.surfapi.shared.api.hook.HookMeta | ||
| import dev.slne.surf.surfapi.shared.api.hook.requirement.* | ||
|
|
||
| @HookMeta | ||
| @DependsOnClass(BukkitPluginMain::class) | ||
| @DependsOnClassName("dev.slne.surf.surfapi.bukkit.test.config.ModernTestConfig") | ||
| @DependsOnPlugin("SurfBukkitPluginTest") | ||
| @DependsOnOnePlugin(["SurfBukkitPlugin", "surf-bukkit-plugin", "SurfBukkitPluginTest"]) | ||
| @DependsOnHook(PrimaryTestHook::class) | ||
| class TestHook : AbstractHook() { | ||
| private val log = logger() | ||
|
|
||
| override suspend fun onBootstrap() { | ||
| log.atInfo().log("TestHook bootstrapped") | ||
| } | ||
|
|
||
| override suspend fun onLoad() { | ||
| log.atInfo().log("TestHook loaded") | ||
| } | ||
|
|
||
| override suspend fun onEnable() { | ||
| log.atInfo().log("TestHook enabled") | ||
| } | ||
|
|
||
| override suspend fun onDisable() { | ||
| log.atInfo().log("TestHook disabled") | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/hook/condition/EnabledCondition.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package dev.slne.surf.surfapi.bukkit.test.hook.condition | ||
|
|
||
| import dev.slne.surf.surfapi.bukkit.test.config.ModernTestConfig | ||
| import dev.slne.surf.surfapi.shared.api.hook.condition.HookCondition | ||
| import dev.slne.surf.surfapi.shared.api.hook.condition.HookConditionContext | ||
|
|
||
| class EnabledCondition : HookCondition { | ||
| override suspend fun evaluate(context: HookConditionContext): Boolean { | ||
| return ModernTestConfig.getConfig().enabled | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
...ukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/hook/PaperHookService.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package dev.slne.surf.surfapi.bukkit.server.hook | ||
|
|
||
| import com.google.auto.service.AutoService | ||
| import dev.slne.surf.surfapi.bukkit.api.extensions.pluginManager | ||
| import dev.slne.surf.surfapi.bukkit.server.reflection.Reflection | ||
| import dev.slne.surf.surfapi.core.server.hook.HookService | ||
| import net.kyori.adventure.text.logger.slf4j.ComponentLogger | ||
| import org.bukkit.plugin.java.JavaPlugin | ||
| import java.io.InputStream | ||
| import kotlin.contracts.ExperimentalContracts | ||
| import kotlin.contracts.contract | ||
|
|
||
| @AutoService(HookService::class) | ||
| class PaperHookService : HookService() { | ||
| override fun readHooksFileFromResources(owner: Any, fileName: String): InputStream? { | ||
| ensureOwnerIsPlugin(owner) | ||
| return owner.getResource(fileName) | ||
| } | ||
|
|
||
| override fun getClassloader(owner: Any): ClassLoader { | ||
| ensureOwnerIsPlugin(owner) | ||
| return Reflection.JAVA_PLUGIN_PROXY.getClassLoader(owner) | ||
| } | ||
|
|
||
| override fun isPluginLoaded(pluginId: String): Boolean { | ||
| return pluginManager.getPlugin(pluginId) != null | ||
| } | ||
|
|
||
| override fun getLogger(owner: Any): ComponentLogger { | ||
| ensureOwnerIsPlugin(owner) | ||
| return owner.componentLogger | ||
| } | ||
|
|
||
| @OptIn(ExperimentalContracts::class) | ||
| private fun ensureOwnerIsPlugin(owner: Any): JavaPlugin { | ||
| contract { | ||
| returns() implies (owner is JavaPlugin) | ||
| } | ||
|
|
||
| return owner as? JavaPlugin ?: error("Owner must be a JavaPlugin") | ||
| } | ||
| } |
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
...-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/reflection/JavaPluginProxy.kt
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package dev.slne.surf.surfapi.bukkit.server.reflection | ||
|
|
||
| import dev.slne.surf.surfapi.core.api.reflection.Name | ||
| import dev.slne.surf.surfapi.core.api.reflection.SurfProxy | ||
| import org.bukkit.plugin.java.JavaPlugin | ||
|
|
||
| @SurfProxy(JavaPlugin::class) | ||
| interface JavaPluginProxy { | ||
|
|
||
| @Name("getClassLoader") | ||
| fun getClassLoader(instance: JavaPlugin): ClassLoader | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.