-
Notifications
You must be signed in to change notification settings - Fork 24
API
You're probably a developer and you want to know how Statz works and how to obtain data from Statz through its API. It's actually very easy. There are two methods that you can use to obtain info from players via Stats.
First, you'll have to get the API class of Statz:
` Plugin statz = Bukkit.getServer().getPluginManager().getPlugin("Statz");
if (statz != null && statz.isEnabled()) {
StatzAPI api = statz.getStatzAPI();
}
`
Now, you can either choose to use the getTotalOf() method to obtain a total value of a stat. You can also get the total amount of a stat per world. Examples of using getTotalOf() are when you want to get the total number of votes of player, regardless of the world he voted on, or the total number of mob kills of a player on one specific world.
To use this method, you'll need to provide a PlayerStat, a UUID of the player and a specific worldName. If you don't care about the world, you can just leave this as null. If Statz does not have to requested data, it will return null.
For example, to get the total amount of votes regardless of the world:
Double totalVotes = api.getTotalOf(PlayerStat.VOTES, UUID.fromString("c5f39a1d-3786-46a7-8953-d4efabf8880d"), null);
Another example, to get the total amount of mobs killed on the world 'Slaughterhouse':
Double totalMobsKilled = api.getTotalOf(PlayerStat.MOBS_KILLS, UUID.fromString("c5f39a1d-3786-46a7-8953-d4efabf8880d"), "Slaughterhouse");
This is fun and all, but let's say you want to know the number of cows a player killed on world 'Lala'. Since this is a more specific request, you will need to use getSpecificData(). This method is almost the same as getTotalOf except that it allows you to specify certain conditions, called RowRequirements. You can have an unlimited amount of requirements, but the more requirements you have, the more specific a request is. Let's get back to our example.
To obtain the amount of cows a player killed on world 'Lala', we'll have to run this code:
Double totalCowsKilled = api.getSpecificData(PlayerStat.MOBS_KILLS, UUID.fromString("c5f39a1d-3786-46a7-8953- d4efabf8880d"), new RowRequirement("mob", "COW"), new RowRequirement("world", "Lala"));
Each RowRequirement has two inputs; the first is the name of the column in the database (you can find the columns in the .db file in the /plugins/Statz/ folder), the second is the value it needs to have. The first RowRequirement says that we only want to count the data that has value COW for column mob. The second RowRequirement tells Statz to only look for data that also has value Lala for column world. Both these conditions need to be met.