Class ApiModule

java.lang.Object
com.haven.havenplugin.ApiModule
All Implemented Interfaces:
Module

public class ApiModule extends Object implements Module
HTTP server module. Owns the server socket and the route table.

Routes registered via registerRoute(String, int, ApiModule.RouteHandler) (and removed via deregisterRoute(String)) are held in memory independently of the server lifecycle. Stopping and restarting the module does not wipe registered routes, so other modules can register their routes at enable-time once without caring whether ApiModule is currently up.

Other modules should obtain this instance via plugin.getModule(ApiModule.class) inside their own onEnable / onDisable.

DO NOT run without a reverse proxy.

  • Constructor Details

    • ApiModule

      public ApiModule(int port)
  • Method Details

    • registerRoute

      public void registerRoute(String path, int argCount, ApiModule.RouteHandler handler)
      Register a route. Always available regardless of module enable state.
      Parameters:
      path - Base path, no leading slash (e.g. "shop/buy")
      argCount - Number of URL segments expected after the base path
      handler - Handler invoked on a worker thread for every matching request
    • deregisterRoute

      public void deregisterRoute(String path)
      Remove all routes whose base path matches path. Call this from a module's onDisable to clean up its routes.
    • onEnable

      public void onEnable(Main plugin)
      Specified by:
      onEnable in interface Module
    • onDisable

      public void onDisable()
      Specified by:
      onDisable in interface Module
    • getName

      public String getName()
      Specified by:
      getName in interface Module
    • getListeners

      public List<org.bukkit.event.Listener> getListeners()
      Specified by:
      getListeners in interface Module
    • getCommands

      public List<String> getCommands()
      Description copied from interface: Module
      Command names this module owns, matching entries in plugin.yml.
      Specified by:
      getCommands in interface Module