-
Notifications
You must be signed in to change notification settings - Fork 0
2. Development API
Terry edited this page May 2, 2023
·
2 revisions
Welcome to the StatsAPI wiki!
Step 1: Import using maven or gradle (or manually using the StatsAPI.jar
)
You can see the latest version here.
<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>
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.
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);
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);
});