Class PlexModule

java.lang.Object
dev.plex.module.PlexModule

public abstract class PlexModule extends Object
Base class for Plex modules.

Use api() for Plex services. Register native Paper tasks with ownTask(ScheduledTask) so Plex can cancel them when the module unloads.

  • Constructor Details

    • PlexModule

      public PlexModule()
      Creates a Plex module.
  • Method Details

    • api

      public PlexApi api()
      Returns the Plex API.
      Returns:
      Plex API
    • load

      public void load()
      Called when the module is loaded.
    • enable

      public void enable()
      Called when the module is enabled.
    • disable

      public void disable()
      Called when the module is disabled.
    • registerListener

      public void registerListener(org.bukkit.event.Listener listener)
      Registers and tracks a listener owned by this module.
      Parameters:
      listener - listener to register
    • plugin

      public org.bukkit.plugin.Plugin plugin()
      Returns the Paper plugin that owns this module's native scheduled tasks.
    • ownTask

      @Nullable public <T extends io.papermc.paper.threadedregions.scheduler.ScheduledTask> T ownTask(@Nullable T task)
      Registers a native Paper task for cancellation when this module unloads.
    • kickPlayerOnShutdown

      public void kickPlayerOnShutdown(org.bukkit.entity.Player player, net.kyori.adventure.text.Component reason)
      Disconnects a player during module shutdown. The lifecycle owner schedules the kick because this module's task scope is canceled immediately afterward.
      Parameters:
      player - player to disconnect
      reason - disconnect reason
    • completeShutdownBeforeClose

      public void completeShutdownBeforeClose(CompletableFuture<Void> completion)
      Keeps this module's classloader open until its bounded asynchronous shutdown work finishes.
    • unregisterListener

      public void unregisterListener(org.bukkit.event.Listener listener)
      Unregisters and stops tracking a listener owned by this module.
      Parameters:
      listener - listener to unregister
    • registerCommand

      public void registerCommand(PlexCommand command)
      Registers and tracks a command owned by this module.

      Register commands in load() to use them during the current server run. Later changes usually require a server restart.

      Parameters:
      command - command to register
    • unregisterCommand

      public void unregisterCommand(PlexCommand command)
      Unregisters and stops tracking a command owned by this module.

      The command can remain active until Paper rebuilds its command list. This usually happens after a server restart.

      Parameters:
      command - command to unregister
    • getCommand

      @Nullable public @Nullable PlexCommand getCommand(String name)
      Looks up a tracked command by name or alias.
      Parameters:
      name - command name or alias
      Returns:
      matching command, or null when no command matches
    • getResource

      @Nullable public @Nullable InputStream getResource(@NotNull @NotNull String filename)
      Opens a resource owned by this module.

      Plex module class loaders delegate to Plex's class loader. This method searches the module class loader itself first so common paths such as config.yml cannot resolve to a resource bundled by Plex.

      Parameters:
      filename - resource path
      Returns:
      resource stream, or null when the resource cannot be opened
    • getPlexModuleFile

      public PlexModuleFile getPlexModuleFile()
      Returns information read from this module's module.yml.
      Returns:
      module information
    • getDataFolder

      public File getDataFolder()
      Returns the module data folder.
      Returns:
      module data folder
    • getLogger

      public org.apache.logging.log4j.Logger getLogger()
      Returns the module logger.
      Returns:
      module logger
    • loadMessages

      public void loadMessages(String fileName)
      Loads this module's message file.
      Parameters:
      fileName - resource path and module data file path
    • messages

      @Nullable public @Nullable ModuleConfiguration messages()
      Returns this module's loaded messages, if any.
      Returns:
      module messages, or null when this module has no messages
    • messageComponent

      public net.kyori.adventure.text.Component messageComponent(String entry, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... placeholders)
      Resolves a module message into a component, falling back to Plex messages.
      Parameters:
      entry - message key
      placeholders - named replacement values
      Returns:
      resolved component
    • messageString

      public String messageString(String entry)
      Gets a raw MiniMessage template, falling back to Plex messages.
      Parameters:
      entry - message key
      Returns:
      raw message template