Skip to content

Conversation

@twisti-dev
Copy link
Contributor

This pull request introduces a new modular hook system for the Surf API, enabling plugins to declare and manage dependencies on classes and other plugins, and providing a lifecycle for hooks. The changes include the addition of hook metadata annotations, hook requirement annotations, a core hook API, a base AbstractHook class, and the backend services for hook discovery and management. The plugin test and server modules are updated to use this new system.

Core Hook System Implementation:

  • Introduced AbstractHook base class, which manages hook lifecycle (bootstrap, load, enable, disable) and enforces the presence of HookMeta annotation. Hooks are now comparable by priority.
  • Added HookMeta annotation for hooks, allowing specification of hook priority.
  • Implemented requirement annotations: DependsOnClass, DependsOnClassName, DependsOnPlugin, and DependsOnOnePlugin, enabling hooks to declare dependencies on classes or plugins. [1] [2] [3] [4]
  • Added SurfHookApi interface and singleton accessor for managing hook lifecycle and querying hooks by type or owner.
  • Implemented HookService abstract class, providing hook discovery, dependency checks, and lifecycle management, with support for caching and logging missing dependencies.

Bukkit/Server Integration:

  • Added PaperHookService implementation to integrate the hook system with Bukkit/Paper servers, handling plugin resource loading, classloader access, plugin presence checks, and logging.
  • Introduced JavaPluginProxy interface and integrated it into the server reflection utilities for classloader access. [1] [2]
  • Updated the test plugin (BukkitPluginMain) to use the new async lifecycle methods and call the hook API at appropriate stages.

Example Hook and Usage:

  • Added a sample TestHook class demonstrating the use of the new hook system, including requirement annotations and lifecycle logging.

Other Improvements and Fixes:

  • Improved reflection proxy handling in Java by using MethodHandles.privateLookupIn for better encapsulation and compatibility, and updated method finding logic. [1] [2] [3] [4] [5] [6]
  • Minor fix in EntityGlowingData to access TeamData companion object correctly.

These changes collectively introduce a robust, extensible hook system, improving modularity and dependency management for plugins in the Surf API ecosystem.

@twisti-dev twisti-dev self-assigned this Jan 24, 2026
Copilot AI review requested due to automatic review settings January 24, 2026 22:09
@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1112ea2a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a modular hook system for Surf API plugins, including compile-time hook metadata generation and runtime hook discovery/lifecycle management across supported server platforms.

Changes:

  • Added hook API + lifecycle (AbstractHook, SurfHookApi) and dependency annotations (DependsOn*).
  • Implemented runtime hook loading/validation via HookService with platform implementations (Paper/Bukkit, Velocity) and a fallback.
  • Added a KSP processor to generate surf-hooks.json during compilation and wired it into the gradle processor module.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
surf-api-velocity/surf-api-velocity-server/src/main/kotlin/dev/slne/surf/surfapi/velocity/server/hook/VelocityHookService.kt Velocity implementation of HookService for resource/classloader access and plugin checks.
surf-api-gradle-plugin/surf-api-processor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider Registers the new hook KSP processor provider alongside the existing AutoService provider.
surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/dev/slne/surf/surfapi/processor/util/util.kt Adds shared KSP utilities for deriving binary class names.
surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/dev/slne/surf/surfapi/processor/hook/PluginHookMeta.kt Defines the serialized hook metadata model used by the processor output.
surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/dev/slne/surf/surfapi/processor/hook/HookSymbolProcessorProvider.kt Adds KSP provider for hook metadata generation.
surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/dev/slne/surf/surfapi/processor/hook/HookSymbolProcessor.kt Implements hook annotation scanning and surf-hooks.json generation.
surf-api-gradle-plugin/surf-api-processor/src/main/kotlin/dev/slne/surf/surfapi/processor/autoservice/AutoServiceSymbolProcessor.kt Refactors to use the shared binary-name utility.
surf-api-gradle-plugin/surf-api-processor/build.gradle.kts Enables serialization support and adds JSON serialization dependency for the processor.
surf-api-core/surf-api-core-server/src/main/kotlin/dev/slne/surf/surfapi/core/server/impl/hook/SurfHookApiImpl.kt Runtime implementation of SurfHookApi delegating to HookService.
surf-api-core/surf-api-core-server/src/main/kotlin/dev/slne/surf/surfapi/core/server/hook/PluginHookMeta.kt Runtime model for decoding surf-hooks.json.
surf-api-core/surf-api-core-server/src/main/kotlin/dev/slne/surf/surfapi/core/server/hook/HookServiceFallback.kt Fallback service when hooks aren’t supported on the current platform.
surf-api-core/surf-api-core-server/src/main/kotlin/dev/slne/surf/surfapi/core/server/hook/HookService.kt Core runtime hook discovery, dependency checks, caching, and ordering.
surf-api-core/surf-api-core-server/src/main/java/dev/slne/surf/surfapi/core/server/impl/reflection/SurfInvocationHandlerJava.java Updates reflection proxy implementation to use privateLookupIn and adjusts method resolution.
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/requirement/DependsOnPlugin.kt Adds plugin dependency annotation.
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/requirement/DependsOnOnePlugin.kt Adds “one-of” plugin dependency annotation.
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/requirement/DependsOnClassName.kt Adds class-name dependency annotation.
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/requirement/DependsOnClass.kt Adds class dependency annotation.
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/SurfHookApi.kt Defines the public hook API entrypoint and singleton accessor.
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/HookMeta.kt Adds hook metadata annotation (priority).
surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/hook/AbstractHook.kt Adds base hook lifecycle + priority ordering.
surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/reflection/Reflection.kt Registers JavaPluginProxy and adjusts classloader access usage.
surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/reflection/JavaPluginProxy.kt Adds reflection proxy for accessing JavaPlugin classloader.
surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/impl/glow/entity/EntityGlowingData.kt Fixes TeamData companion access.
surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/hook/PaperHookService.kt Paper/Bukkit implementation of HookService.
surf-api-bukkit/surf-api-bukkit-plugin-test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/hook/TestHook.kt Adds an example hook demonstrating dependency annotations and lifecycle logs.
surf-api-bukkit/surf-api-bukkit-plugin-test/src/main/kotlin/dev/slne/surf/surfapi/bukkit/test/BukkitPluginMain.kt Updates test plugin to invoke hook lifecycle in async plugin lifecycle methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

Copy link
Contributor

Copilot AI commented Jan 24, 2026

@twisti-dev I've opened a new pull request, #190, to work on those changes. Once the pull request is ready, I'll request review from you.

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

@twisti-dev
Copy link
Contributor Author

@codex review

@twisti-dev twisti-dev requested a review from Copilot January 25, 2026 17:49
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 53 out of 55 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

validHooks.forEach { (meta, _) -> visit(meta.className) }
return sorted.sortedBy { it.priority }
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

topologicalSort builds a dependency-respecting order via DFS in sorted, but the final sorted.sortedBy { it.priority } reorders hooks and can violate declared DependsOnHook ordering (a dependent hook may run before its dependency). Return the computed topological order as-is, or incorporate priority as a tie-breaker during traversal / Kahn’s algorithm without re-sorting the final list.

Suggested change
return sorted.sortedBy { it.priority }
return sorted

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

Copy link
Contributor

Copilot AI commented Jan 25, 2026

@twisti-dev I've opened a new pull request, #191, to work on those changes. Once the pull request is ready, I'll request review from you.

@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

…ng DFS

Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
@github-actions
Copy link

⚠️ API/ABI changes detected!

This PR contains changes that modified the public API. To update the reference ABI dumps:

./gradlew updateLegacyAbi
git add **/api/**
git commit -m "Update ABI reference"
git push

After updating, the CI will pass. Make sure the changes are backward compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants