A simple API for creating custom statistics in Minecraft.
- Create custom statistics
- Database and file storage
- Easily implementable into any plugin
Using JStatsAPI was designed to be as simple as possible. There are only a few steps to creating a statistic.
This is a required step as many functions in the API require a provider to be passed in. The first argument is the plugin instance, and the second is whether other plugins can change the value of the statistics provided by this provider. 9 times out of 10, you will want to set this to false.
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
JStatProvider provider = new JStatProvider(this, false);
}
}
The first argument is the name of the statistic, the second is the provider, the third is the ID of the statistic,
and the fourth is the default value of the statistic. JStat accepts any class that extends Number
(e.g. Integer
, Double
, Float
, etc.)
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
JStatProvider provider = new JStatProvider(this);
JStatsAPI.getInstance().registerStat(
new JStat<>(
"Test Stat",
provider,
"test-stat",
0
)
);
}
}
In order to get a statistic, you must first create a StatRequest
object. This object takes two arguments: the provider, and the ID of the statistic.
This then gets passed into the JStatsAPI.makeRequest() method, which returns a JStat
object. If the statistic does not exist, null
will be returned.
In order to change the value, you must pass the UUID of the player you want to change the value for.
import java.util.UUID;
public final class Main extends JavaPlugin {
@Override
public void onEnable() {
JStatProvider provider = new JStatProvider(this);
JStat<Integer> testStat = new JStat<>(
"Test Stat",
provider,
"test-stat",
0
);
JStatsAPI.getInstance().registerStat(testStat);
incrementTestStat(UUID.randomUUID());
}
public void incrementTestStat(UUID uuid) {
JStat<Integer> stat = JStatsAPI.getInstance().makeRequest(
StatRequest(
provider,
"test-stat"
)
);
if (stat != null) {
stat.addValueFor(uuid, 1);
}
}
}