Modules
This guide will show you how to use the module system within the Java SDK.
The Analytics Platform SDK has a module system that allows you to add additional functionality to the SDK. Modules are loaded automatically when the platform is set-up, and can be used to add additional functionality to the platform.
Creating a Module
To create a module, you need to create a class that implements the PlatformModule
interface. The PlatformModule
interface has 3 methods, getName
, onEnable
and onDisable
. These methods are called when the module is enabled and disabled respectively.
Here's an example..
Registering a Module
There are multiple ways to register a module with the platform. The first way is to use the registerModule
method of the Platform
interface, which takes an instance of PlatformModule
as a parameter. This is useful for registering modules as part of an existing plugin.
For example, if you wanted to register the module above, you would do the following:
The second way to register a module is to build the jar file and place it within the plugins/Analyse/modules
directory. This is useful if you want to create a module without having to modify an existing plugin.
Adding Dependencies
If your module depends on a specific plugin being installed, you can do this by adding the following method to your module class:
Now when the module is loaded, the platform will check if the plugin is installed. If the plugin is not installed, the module will not be loaded. The platform will also log a warning message to the console similar to the following:
Platform Methods
The Platform
interface also provides a few other methods that you may find useful.
getType()
getType()
Returns the type of platform that the SDK is running on. For example, you can check if the platform is a specific type, such as PlatformType.BUKKIT
or PlatformType.BUNGEECORD
.
getSDK()
getSDK()
Returns an instance of the SDK class that the platform is using.
getPlayers()
getPlayers()
Returns a map of all players on the platform. The keys of the map are the players' UUIDs, and the values are instances of AnalysePlayer.
Example Usage
isSetup()
isSetup()
Returns true
if the platform has been set-up correctly with a valid token, and false
otherwise.
getVersion()
getVersion()
Returns the version of the platform.
log(Level, String)
log(Level, String)
Logs a message to the console with a specific log level.
log(String)
log(String)
Logs a message of type INFO
to the console.
warning(String)
warning(String)
Logs a message of type WARNING
to the console.
Last updated