DevelopersยปPlatform SDK

Developers

Platform SDK

This guide will show you how to use the Analyse Platform SDK.


If you haven't already, you should read the SDK Documentation first to get an understanding of how the SDK works.

Get a Player

You can fetch an instance of AnalysePlayer for an online by using the getPlayer method of the Platform interface, which takes a UUID and returns an AnalysePlayer.

Available Methods

  • getName() - Returns the player's name.
  • getUniqueId() - Returns the player's unique ID.
  • getJoinedAt() - Returns the date the player joined the server.
  • getFirstJoinedAt() - Returns the date the player first joined the server.
  • getIpAddress() - Returns the player's IP address.
  • getStatistics() - Returns the player's statistics.
  • getEvents() - Returns the player's events.
  • getDomain() - Returns the domain the player joined from.
  • getCountry() - Returns the player's country code.
  • getType() - Returns the type of player (JAVA or BEDROCK).
  • track(PlayerEvent) - Tracks a player event.
  • setType(PlayerType) - Sets the player's type.

Example Usage

AnalysePlayer analysePlayer = platform.getPlayer(UUID.fromString("00000000-0000-0000-0000-000000000000"));
if (analysePlayer != null) {
    // Do something with the player.
}

Custom Events

You can send custom events to Analyse by using the track method of the AnalysePlayer interface, which takes an instance of PlayerEvent (or multiple).

Example Usage

PlayerEvent playerEvent = new PlayerEvent("kill_mob", "ExamplePlugin")
    .withMetadata("mob_type", "ZOMBIE")
    .withMetadata("mob_name", "Zombieee")
    .withMetadata("mob_health", 10);
player.track(playerEvent);

The PlayerEvent class takes an id and an origin as parameters. The ID is a unique identifier for the event, and the origin is the name of the plugin that is sending the event. The origin is used to identify the plugin that is sending the event, and is displayed in the Analyse dashboard.

You can also add metadata to the event by using the withMetadata method. This method takes a key and a value as parameters, returning the PlayerEvent instance - allowing you to chain multiple calls to the method.

Module System

The Analyse 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.

Example Module

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.

Other 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.