Developers
SDK Documentation
This guide will help you get started with using our SDK with Analyse.
Build Tools
Depending on which build tool you use, you can easily add the Analyse SDK to your project using Gradle or Maven.
Gradle
To add the Analyse SDK into your Gradle project, head to your build.gradle
file and add the following to the repositories
section like so:
repositories {
mavenCentral()
}
Then add the following to the dependencies
section:
dependencies {
compileOnly "net.analyse:sdk:2.0.8"
}
That's it! You're now ready to use the Analyse SDK in your project.
Maven
To add the Analyse SDK into your Maven project, head to your pom.xml
file and add the following to the dependencies
section like so:
<dependency>
<groupId>net.analyse</groupId>
<artifactId>sdk</artifactId>
<version>2.0.8</version>
<scope>provided</scope>
</dependency>
That's it! You're now ready to use the Analyse SDK in your project.
Accessing the Java API
To access the API you will need to fetch the live instance of Platform
, this provides access to the Platform & Server SDK methods and can be accessed like so:
package net.analyse.example;
import net.analyse.sdk.Analyse;
import net.analyse.sdk.SDK;
import net.analyse.sdk.platform.Platform;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public final class ExampleAnalysePlugin extends JavaPlugin {
private Platform platform;
private SDK sdk;
@Override
public void onEnable() {
// If Analyse is not enabled, disable the plugin.
if(!Bukkit.getPluginManager().isPluginEnabled("Analyse")) {
getLogger().severe("Analyse is not enabled!");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
// Get the platform instance.
platform = Analyse.get();
sdk = platform.getSDK();
}
}
Building your own platform
If you run a complicated set-up, such as one that involves multiple shards or any form of load balancing, you can build your own platform using the Platform SDK. This allows you to run Analyse freely on your own infrastructure, whilst still able to send data to the Analyse Web API and dashboard.
To do this, you'll need to create a class which implements the Platform
interface, and then implement any required methods. You can check out our Bukkit Codebase for an example of how to do this.
Implementing the SDK
Once you've got your platform class set-up, you can initialise the SDK
package net.analyse.example;
import net.analyse.sdk.Analyse;
import net.analyse.sdk.SDK;
import net.analyse.sdk.platform.Platform;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public final class CustomAnalysePlatform extends JavaPlugin implements Platform {
private SDK sdk;
@Override
public void onEnable() {
Analyse.init(this);
sdk = new SDK(this, "TOKEN");
}
// Other platform methods
}
Sending data to Analyse
You can start tracking player sessions with Analyse now that you've initialised the SDK. You'll need to call the trackPlayerSession
SDK method once the player leaves the server, this takes an AnalysePlayer object as an argument. It's recommended to create this object once the player joins the server, and then remove it once they leave.
You can also call the trackHeartbeat
SDK method to send a heartbeat to Analyse which takes the current player count as its argument. This is useful for tracking the amount of players online at any given time.
Check out the Javadocs for up-to-date information on the latest available methods. You may also view the Platform SDK Documentation to learn about the other Platform SDK methods.