Solved Best way to store statistics in memory

Discussion in 'Plugin Development' started by Tim_M, Nov 5, 2021.

  1. Offline


    I'm making a simple plugin that will keep track of player kills, deaths and more. I really wanted to minimize IO calls to make it faster however I came to an issue I'm not sure how to approach. Until now I was using Maps to store all the data with UUID and Integer. But now I need to sort this data for leaderboards and stuff. My first idea was to use List<Map.Entry<>> instead of Map and sort that every few minutes or so on the async thread. However it was kindof non-efficient with Map.Entry<>, like just adding a single kill would have me iterate every object in the list to find the correct Entry. My second idea was to have a list of custom Objects that store all of the data, and then a got a third idea which is to have a LinkedHashMap, and my last idea which was to have a Map with the data, and then have Lists of UUIDs for the top leaderboards. I feel like the last option is the best, but I'm not sure, maybe all of these are terrible. What should I do?
  2. Offline

    timtower Administrator Administrator Moderator

    @Tim_M Minecraft is a system that runs at 20 ticks per second, always, why are you so worried about the speed?
    Kars likes this.
  3. Offline


    Map<uuid, Integer> is fine.

    An efficient way to display score would be this:
    1. Clone your map;
    2. Find max value and append to leaderbord;
    3. Remove max value;
    4. Repeat step 2, 3 and 4 until map is empty.
  4. Offline

    timtower Administrator Administrator Moderator

    Would go with Uuid, customclass that holds more information though
  5. Offline


    Oh wow, thats a lot of responses I a very short time. I will go with Kars advice since it seems very easy to implement. Marking solved. Thanks.

Share This Page