<aside> ⚠️ The library is still very new and I not fully tested it. There might still be issues!
</aside>
PlayerStatsLib is a library specially designed to save player stats like for example wins, kills, blocks broken. The library is fully Open Source available here. Please note that it is always a good idea to code your own libraries for the usecase of saving playerstats. This one is for the ones who need a quick solution or are not that familiar with SQL.
PlayerStatsLib allows you to integrate a player stat tracker with ease. It uses asynchronus methods to access (write & read) stats of players. It has all basic features you would need to get started.
Currently there are two types of StatsDatabases:
ManagedStatsDatabase managedStatsDatabase = new ManagedStatsDatabase(this);
AsyncStatsDatabase asyncStatsDatabase = new AsyncStatsDatabase();
statsDatabase.createTableAsync("wins").thenRun(() -> {
getLogger().info("Table got created or loaded.");
});
This method creates the table if it does not exist already.
int score = 5;
statsDatabase.setPlayerValueAsync("wins", player.getUniqueId(), score).thenRun(() -> {
getLogger().info("Updated Player Value");
});
statsDatabase.getPlayerValueAsync("wins", player.getUniqueId()).thenAccept(wins -> {
getLogger().info("Player has " + wins + " wins in total.");
});
<aside>
⚠️ If a player has no value set already, this method will return -1
!
</aside>