Search
K

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..
package net.analyse.example;
import net.analyse.sdk.platform.Platform;
import net.analyse.sdk.platform.PlatformModule;
public class ExampleModule implements PlatformModule {
@Override
public String getName() {
return "ExampleModule";
}
@Override
public void onEnable() {
// Do something when the module is enabled.
}
@Override
public void onDisable() {
// Do something when the module is disabled.
}
}

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:
Platform platform = Analyse.get();
platform.getModuleManager().register(new ExampleModule());
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:
@Override
public String getRequiredPlugin() {
return "ExamplePlugin";
}
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:
[15:21:40 INFO]: [Analyse] Loading modules..
[15:21:40 WARN]: [Analyse] Skipped Example module due to a missing plugin: ExamplePlugin
[15:21:40 INFO]: [Analyse] Unloaded module: Example
[15:21:40 INFO]: [Analyse] 0 modules loaded.

Platform Methods

The Platform interface also provides a few other methods that you may find useful.

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()

Returns an instance of the SDK class that the platform is using.

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
Map<UUID, AnalysePlayer> players = platform.getPlayers();
for (Map.Entry<UUID, AnalysePlayer> entry : players.entrySet()) {
UUID uuid = entry.getKey();
AnalysePlayer player = entry.getValue();
// Do something with the player and UUID.
}

isSetup()

Returns true if the platform has been set-up correctly with a valid token, and false otherwise.

getVersion()

Returns the version of the platform.

log(Level, String)

Logs a message to the console with a specific log level.

log(String)

Logs a message of type INFO to the console.

warning(String)

Logs a message of type WARNING to the console.