Game dev #9: Stats tracking, part 2

Last time, I explained the path I took when it comes to player stats, and what the next challenges were. Due to our previous plugin no longer being able to work under 1.14, I had to replace it with another option. Rather than try and find something suitable, I chose to expand my own stats plugin to cover everything that'd be needed.

This was completed last weekend, as the Minecraft servers got updated to 1.14 and the new plugin took over. The way I see it, there were three critical parts to this project: track everything that we need, keep the data of the previous plugin, and make it efficient. There were some challenges along the way, so here's how that played out.

Track everything that we need I replicated everything already tracked, which is used for the display of the player profiles and the achievements, among other things, In the future, when new achievements get added, it'll only be a matter of tracking more gameplay events and save them to the database. The framework to do this is already in place now, as the saving methods are shared for all stats, making new additions relatively simple.

Keep the data of the previous plugin The great aspect of doing everything on your own is that you have full control over it, and it's designed the way that works best for you. The worst aspect of doing everything on your own is that you need to do everything on your own. And that takes time. In this case, I needed to bring in pre-1.13 item names to the post-1.13 format. For example, a “bed” of type 15 is now known as a “black_bed”. Thankfully, Mojang provided a file with the list of naming changes between the two game versions, so I could use that directly as a reference to write a converter. I had accounted for most of the challenges related to this, except for one that I didn't foresee...

The plugin in place hadn't been updated in quite a while, and its data was stored using old item names, from several game versions ago. There was no crafting table to be found, it was a “workbench”. Slabs were absents, I had “step”s. The spelling of various names was different. And so on. This meant that I had to create a whole additional conversion layer to bring items to their 1.12 format before I could bring those over to post-1.13. Not an impossible task by any means, but it took more time than I wanted it to!

Make it efficient Stats tracking involves running constant checks on all players to know what they're doing. Things like emptying buckets or changing worlds happen once in a while and are easy to do. Tracking movement is a continuous job; counting the amount of blocks broken goes quick if you've got Efficiency V and beacons to help you! You don't want to save every single individual action, as it would drag the performance of the entire server down very quickly.

What I did instead was batch all actions in groups (for example, player Doctacosa has broken 25 stone blocks and 20 dirt blocks in the Laurasia overworld so far), then push these to the database every minute. This minimises the number of calls done to the database, as we save the total values created in a minute instead of every individual action. Additionally, the saving process is done in a separate thread, so the server's activity isn't on hold while it happens. The end result is super efficient, as a sample analysis revealed that the plugin is accounting for only 0.0019% of Laurasia's workload!

The work on that is completed, the player profiles have been adjusted to pull from the new source, and so have the achievements. Time to move onward!

#gamedev #projects

– Doctacosa