Class PlexModule
java.lang.Object
dev.plex.module.PlexModule
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapi()Returns the Plex API.voidcompleteShutdownBeforeClose(CompletableFuture<Void> completion) Keeps this module's classloader open until its bounded asynchronous shutdown work finishes.voiddisable()Called when the module is disabled.voidenable()Called when the module is enabled.@Nullable PlexCommandgetCommand(String name) Looks up a tracked command by name or alias.Returns the module data folder.org.apache.logging.log4j.LoggerReturns the module logger.Returns information read from this module's module.yml.@Nullable InputStreamgetResource(@NotNull String filename) Opens a resource owned by this module.voidkickPlayerOnShutdown(org.bukkit.entity.Player player, net.kyori.adventure.text.Component reason) Disconnects a player during module shutdown.voidload()Called when the module is loaded.voidloadMessages(String fileName) Loads this module's message file.net.kyori.adventure.text.ComponentmessageComponent(String entry, net.kyori.adventure.text.minimessage.tag.resolver.TagResolver... placeholders) Resolves a module message into a component, falling back to Plex messages.@Nullable ModuleConfigurationmessages()Returns this module's loaded messages, if any.messageString(String entry) Gets a raw MiniMessage template, falling back to Plex messages.<T extends io.papermc.paper.threadedregions.scheduler.ScheduledTask>
TownTask(T task) Registers a native Paper task for cancellation when this module unloads.org.bukkit.plugin.Pluginplugin()Returns the Paper plugin that owns this module's native scheduled tasks.voidregisterCommand(PlexCommand command) Registers and tracks a command owned by this module.voidregisterListener(org.bukkit.event.Listener listener) Registers and tracks a listener owned by this module.voidunregisterCommand(PlexCommand command) Unregisters and stops tracking a command owned by this module.voidunregisterListener(org.bukkit.event.Listener listener) Unregisters and stops tracking a listener owned by this module.
-
Constructor Details
-
PlexModule
public PlexModule()Creates a Plex module.
-
-
Method Details
-
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 disconnectreason- disconnect reason
-
completeShutdownBeforeClose
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
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
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
Looks up a tracked command by name or alias.- Parameters:
name- command name or alias- Returns:
- matching command, or
nullwhen no command matches
-
getResource
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.ymlcannot resolve to a resource bundled by Plex.- Parameters:
filename- resource path- Returns:
- resource stream, or
nullwhen the resource cannot be opened
-
getPlexModuleFile
Returns information read from this module's module.yml.- Returns:
- module information
-
getDataFolder
-
getLogger
public org.apache.logging.log4j.Logger getLogger()Returns the module logger.- Returns:
- module logger
-
loadMessages
Loads this module's message file.- Parameters:
fileName- resource path and module data file path
-
messages
Returns this module's loaded messages, if any.- Returns:
- module messages, or
nullwhen 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 keyplaceholders- named replacement values- Returns:
- resolved component
-
messageString
-