Skip to content

2. Development API

Terry edited this page May 2, 2023 · 2 revisions

Welcome to the StatsAPI wiki!

Implementation

Step 1: Import using maven or gradle (or manually using the StatsAPI.jar)
You can see the latest version here.

Using Maven

<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>
<dependency>
    <groupId>com.github.teraprath</groupId>
    <artifactId>StatsAPI</artifactId>
    <version>INSERT_VERSION_HERE</version>
</dependency>

Using Gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.teraprath:StatsAPI:INSERT_VERSION_HERE'
}

Step 2: Add StatsAPI as dependency in your plugin.yml:

...
depend: [ StatsAPI ]

Step 4: Now initialize StatsAPI in your onEnable() method:

public final class TestPlugin extends JavaPlugin {

    @Override
    public void onEnable() {
        new StatsAPI(this).init();
    }

}

Step 5: You're done.

Basic Usage

An overview of the methods provided by the StatsAPI.

PlayerStats stats = StatsAPI.getPlayer(player);

stats.setKills(amount);
int kills = stats.getKills();

stats.setDeaths(amount);
int deaths = stats.getDeaths();

stats.setWins(amount);
int wins = stats.getWins();

stats.setLoses(amount);
int loses = stats.getLoses();

stats.setGamesPlayed(amount);
int gamesPlayed = stats.getGamesPlayed();

stats.setStreak(amount);
int streak = stats.getStreak();

stats.setGamePoints(amount);
int points = stats.getGamePoints();

StatsAPI.save(stats);

Asynchronous Processing

To process tasks asynchronously, use the following method provided by the Bukkit library.

Bukkit.getScheduler().runTaskAsynchronously(plugin, task -> {
    PlayerStats stats = StatsAPI.getPlayer(player);
    stats.setKills(stats.getKills() + 1);
    StatsAPI.save(stats);
});
Clone this wiki locally