Developers
SDK
Learn how to utilise our Java SDK with Analyse.
Installation
- Git clone the repo using
git clone git@github.com:track/plugin.git
. - Install it using
./gradlew pushToMavenLocal
. - Inside of your project, install it like so:
dependencies { implementation("net.analyse:plugin:1.0.0")}
Setting Up
In order to set-up the SDK you'll need your server token, this can be found within the Analyse dashboard for each server. You'll also need to generate an encryption key, this is a randomised string that will encrypt all IP addresses before sending it to Analyse.
package net.analyse.example;import net.analyse.sdk.AnalyseSDK;import org.bukkit.plugin.java.JavaPlugin;class ExampleAnalyseIntegrationPlugin extends JavaPlugin { private final String API_HEADER = "ExampleAnalyseIntegrationPlugin v" + getDescription().getVersion(); private AnalyseSDK core; @Override public void onEnable() { String serverToken = "YOUR-TOKEN"; String encryptionKey = "YOUR-ENCRYPTION-KEY"; // Initialise the SDK. core = new AnalyseSDK(serverToken, encryptionKey); // Set our application specific header. core.setApiHeader(API_HEADER); }}
Get Server
Get basic information about a server from its token.
Example Usage:
package net.analyse.example;import net.analyse.sdk.AnalyseSDK;import org.bukkit.plugin.java.JavaPlugin;class ExampleAnalyseIntegrationPlugin extends JavaPlugin { private AnalyseSDK core; @Override public void onEnable() { // Initialise the SDK. core = new AnalyseSDK(...); try { GetServerResponse server = core.getServer(); server.getName(); // Get the servers name (String) server.getUuid(); // Get the servers UUID (String) server.getCreatedAt(); // Get when the server was made (Instant) server.getCurrentTeamQuota(); // Get the current teams quota sessions (Integer) server.getTeamQuotaLimit(); // Get the current teams quota session limit (Integer) } catch (ServerNotFoundException exception) { // The server token you specified doesn't exist. } }}
This will throw a ServerNotFoundException exception if the token is invalid.
Heartbeat
Send a server heartbeat with the current player count.
Example Usage:
package net.analyse.example;import net.analyse.sdk.AnalyseSDK;import org.bukkit.plugin.java.JavaPlugin;class ExampleAnalyseIntegrationPlugin extends JavaPlugin { private AnalyseSDK core; @Override public void onEnable() { // Initialise the SDK. core = new AnalyseSDK(...); try { core.sendHeartbeat(Bukkit.getOnlinePlayers().size()); } catch (ServerNotFoundException exception) { // The server token you specified doesn't exist. } }}
Add Session
Submits a player session for that particular server.
Example Usage:
package net.analyse.example;import net.analyse.sdk.AnalyseSDK;import org.bukkit.plugin.java.JavaPlugin;class ExampleAnalyseIntegrationPlugin extends JavaPlugin { private AnalyseSDK core; @Override public void onEnable() { // Initialise the SDK. core = new AnalyseSDK(...); // Somehow get the player... final UUID playerUuid = player.getUniqueId(); final String playerName = player.getName(); final Date joinedAt = new Date(); final String domainConnected = "test.analyse.net"; final String playerIp = "12.34.56.79"; final boolean useServerFirstJoinDate = true; final List<PlayerStatistic> playerStatistics = new ArrayList(); try { plugin.getCore().sendPlayerSession(playerUuid, playerName, joinedAt, domainConnected, playerIp, useServerFirstJoinDate ? new Date(player.getFirstPlayed()) : null, playerStatistics); } catch (ServerNotFoundException exception) { // The server token you specified doesn't exist. } }}
This will throw a ServerNotFoundException exception if the token is invalid.
You can find an example implementation within the bukkit
directory in our GitHub repository.