Most efficient way of grabbing all users / servers block information?

Discussion in 'Spigot Plugin Development' started by Sean0402, Jan 9, 2020.

  1. Hello,

    I was wondering what's the most efficient way of grabbing all the users on my servers block count to show a server total block count? I currently store ALL my data in MySQL storage. This stores the user's ID, UUID, and blocks mined.

    Would it be best to just grab all users blocks mined information from the database and update at intervals of say, every 2 minutes and update the number in-game? This can also be done aSync since I don't see any need of the Bukkit API to be used in this method?

    Or would it be best to store an Integer in a file somewhere and use that? Is JSON a viable solution? What's your guy's opinion on this? Looking to make this as smooth as possible with little to no lag.
     
  2. You suggested the possibility of this being in a file, so why not just use player statistics?

    Blocks mined can be retrieved with Player#getStatistic(Statistic.MINE_BLOCK)
     
  3. Will that return the same amount as the BlockBreakEvent? I'm unsure of Statistics. Going to look more into that now.
     
  4. couldnt you do a sum query against that table? it'd be very lightweight, no point in storing it in a file - the point of sql is to be able to query the data stored in it.
    select sum(blocksMined) from yourTable;
     
    • Informative Informative x 1
  5. That was my thought. Just seeing if any other viable solutions come up from others who have done large integers. I know it's not huge since it's just a number so it'd be lightweight no matter what really.
     
  6. Yes it will, it is unnecessary to put it in to a database especially one such as SQL.

    If you are dead set on using a database instead of statistics (I don't see why you would though), go with something like MongoDB or Cassandra.
     
  7. If you do end up choosing to use a database for this, please don't do something like:
    Code (Text):
    public void onBlockBreak() {
       incrementBlockBreakCountInDatabase();
    }
    Its going to slow down your server significantly. What I'd recommend doing is storing the block break count per player in memory and occasionally updating it to the database (also on server stop).
     
    • Useful Useful x 1