Interface IHookDefinition


  • public interface IHookDefinition
    Defines metadata for a script hook, enabling rich hook registration with proper type information for stub generation, imports, and documentation.

    Design Decision

    Uses String eventClassName instead of Class<?> in the API to avoid classloading issues with addons (addon classes may not be loaded when hooks are registered).

    Usage Example

    
     // Addon registration with full metadata
     IScriptHookHandler hooks = NpcAPI.Instance().getScriptHooks();
     hooks.registerHookDefinition("player", HookDefinition.builder("onDBCTransform")
         .eventClass("com.dbc.api.event.IDBCEvent$TransformEvent")
         .paramNames("event")
         .requiredImports("com.dbc.api.event.IDBCEvent")
         .cancelable(true)
         .build());
     
    • Method Detail

      • hookName

        String hookName()
        The hook name (function name in scripts).
        Returns:
        Hook name, e.g., "questStart", "onDBCTransform"
      • eventClassName

        String eventClassName()
        Full qualified class name of the event type. Uses '$' for nested classes (e.g., "noppes.npcs.api.event.IQuestEvent$QuestStartEvent").
        Returns:
        Fully qualified event class name, or null if unknown
      • paramNames

        String[] paramNames()
        Parameter names for stub generation.
        Returns:
        Array of parameter names, defaults to ["event"]
      • requiredImports

        String[] requiredImports()
        Imports required for this hook's event type. These will be added to the script's default imports.
        Returns:
        Array of fully qualified class/package names to import
      • isCancelable

        boolean isCancelable()
        Whether the event is cancelable (has @Cancelable annotation).
        Returns:
        true if event can be canceled
      • getEventClass

        default Class<?> getEventClass()
        Lazily resolve the event class. Returns null if class is not available (e.g., addon not loaded).
        Returns:
        The event class, or null if unavailable
      • getUsableTypeName

        default String getUsableTypeName()
        Generate a usable type name for stub generation. Handles nested classes by converting '$' to '.'.

        Examples:

        • "noppes.npcs.api.event.IQuestEvent$QuestStartEvent" → "IQuestEvent.QuestStartEvent"
        • "com.example.MyEvent" → "MyEvent"
        Returns:
        The usable type name for code generation, or null if no event class