Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 29, 2026

Refactors the hook system to a Spring-inspired component system with meta-annotation support, auto-discovery of post-processors, and proper cycle detection using Tarjan's SCC algorithm.

Renames

  • HookComponent, AbstractHookAbstractComponent
  • @HookMeta@ComponentMeta, @DependsOnHook@DependsOnComponent
  • @ConditionalOnCustom@ConditionalOn
  • HookServiceComponentService, surfHookApisurfComponentApi
  • Metadata path: META-INF/surf-api/hooks/META-INF/surf-api/components/

New Features

Separate @Priority annotation:

@ComponentMeta
@Priority(10)
class MyComponent : AbstractComponent() { ... }

Meta-annotation support@ComponentMeta on annotation classes enables custom component annotations:

@ComponentMeta
@Priority(100)
annotation class Service

@Service  // Auto-detected as component with priority 100
class MyService : AbstractComponent() { ... }

Auto-discovered post-processors — no annotation required:

class LoggingProcessor : ComponentPostProcessor {
    override val priority = 5
    override suspend fun postProcessAfterInitialization(component, name, ctx) = component.also { log.info("Init: $name") }
}

New conditional annotations:

  • @ConditionalOnProperty(key, havingValue, matchIfMissing)
  • @ConditionalOnMissingComponent(component)
  • @ConditionalOnEnvironment(environments)

Cycle Detection Rewrite

Replaced broken DFS-based cycle detection with Tarjan's SCC algorithm. Detects all cycle types (simple, complex, self-loops) with detailed error messages showing full dependency paths.

Unchanged

PAPI hook files (SurfBukkitPAPIHook, SurfBukkitHookManager) remain in .hook. package — unrelated to component system.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • downloads.gradle.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -Xmx64m -Xms64m -Dorg.gradle.appname=gradlew -jar /home/REDACTED/work/surf-api/surf-api/gradle/wrapper/gradle-wrapper.jar classes --no-daemon (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Refactor Hook System to Component System with Meta-Annotation Support

Overview

Refactor the current hook system to a more general component system inspired by Spring Framework. The system should support meta-annotations (annotations on annotations) and be more flexible.

Core Changes

1. Rename Hook → Component

  • Rename Hook interface → Component
  • Rename AbstractHookAbstractComponent
  • Rename @HookMeta@Component
  • Rename HookServiceComponentService
  • Rename surfHookApisurfComponentApi
  • Rename SurfHookApiSurfComponentApi
  • Update all related classes, files, and directories (e.g., hook/component/)

2. Update Lifecycle Methods

Keep the existing lifecycle methods in Component interface:

  • bootstrap() - Initial bootstrap phase
  • load() - Loading phase
  • enable() - Enable phase
  • disable() - Disable phase

3. Make @component a Meta-Annotation

Update @Component annotation to be usable on other annotations:

@Target(AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class Component(
    val priority: Short = 0
)

4. Support Meta-Annotations in Processor

Update HookSymbolProcessorComponentSymbolProcessor to:

  • Recursively scan for @Component annotation on target classes AND their annotations
  • If a class has annotation @Service which is annotated with @Component, treat the class as a component
  • Collect all annotations from the entire annotation hierarchy
  • Merge dependency annotations from meta-annotations

Example meta-annotation support:

@Component
annotation class Service(val priority: Short = 0)

@Component  
@ConditionalOn(FreebuildFeatureEnabledCondition::class)
annotation class FreebuildFeature(
    val name: String,
    val priority: Short = 0
)

// Usage - should be detected as component automatically
@Service
class MyService : AbstractComponent() { ... }

@FreebuildFeature("plots")
class PlotManager : AbstractComponent() { ... }

5. Auto-Discovery of ComponentPostProcessor

Update the processor to automatically discover ComponentPostProcessor implementations:

5.1 Extend PluginComponentMeta

Add post-processor list to metadata:

@Serializable
data class PluginComponentMeta(
    val components: List<Component>,
    val postProcessors: List<PostProcessor> = emptyList()
) {
    @Serializable
    data class Component(
        val priority: Short,
        val className: String,
        val classDependencies: List<String> = emptyList(),
        val pluginDependencies: List<String> = emptyList(),
        val pluginOneDependencies: List<List<String>> = emptyList(),
        val componentDependencies: List<String> = emptyList(),
        val customConditions: List<String> = emptyList(),
    )
    
    @Serializable
    data class PostProcessor(
        val className: String,
        val priority: Int
    )
}

5.2 Scan for ComponentPostProcessor in Symbol Processor

In ComponentSymbolProcessor:

  • Scan for all classes implementing ComponentPostProcessor interface
  • Extract their priority (from the property or default to 0)
  • Add them to PluginComponentMeta.postProcessors list
  • No annotation required - just implementing the interface is enough

Example:

class LoggingPostProcessor : ComponentPostProcessor {
    override val priority: Int = 10
    
    override suspend fun postProcessAfterInitialization(
        component: Component,
        componentName: String,
        context: ComponentContext
    ): Component {
        println("Initialized: $componentName")
        return component
    }
}
// ^ This should be automatically discovered and registered

6. Rename and Extend Conditionals

  • Rename @ConditionalOnCustom@ConditionalOn
  • Keep existing annotations: @DependsOnClass, @DependsOnClassName, @DependsOnPlugin, @DependsOnOnePlugin, @DependsOnHook@DependsOnComponent
  • Add new conditional annotations (you also add additional conditions which you think are useful):
@Target(AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Repeatable
annotation class ConditionalOnProperty(
    val key: String,
    val havingValue: String = "",
    val matchIfMissing: Boolean = false
)

@Target(AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Repeatable
annotation class ConditionalOnMissingComponent(val component: KClass<out Component>)

@Target(AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Repeatable
annotation class ConditionalOnEnvironment(val environments: Array<String>)

7. Add ComponentPostProcessor Interface

Create new interface for post-processing components after initialization:

package dev.slne.surf.surfapi.shared.api.component.processor

interface ComponentPostProcessor {
    /**
     * Pri...

</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.

Copilot AI and others added 5 commits January 29, 2026 13:48
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Co-authored-by: twisti-dev <76837088+twisti-dev@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor hook system to component system with meta-annotation support Refactor Hook System to Component System with Meta-Annotation Support Jan 29, 2026
Copilot AI requested a review from twisti-dev January 29, 2026 14:03
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