MySQL or "Loading"?

Discussion in 'Spigot Plugin Development' started by Alex_qp, Jul 12, 2018.

  1. Hey there,

    while I was thinking about a new plugin idea I was confronted with saving "live-data".

    So to give you an idea: I want a solution so if there is a specific block placed in the world it should get saved into my data files with some attributes. According to them the server should apply different stats to players and plants etc. whenever there is something around that block going on (lets say 50 blocks or so). Those blocks will also have a kind of fuel in them which is getting consumed while the block is active.

    So my question now is: Whats the idea to get this sort of mechanic as efficient as possible? It should also allow me to add new attributes in the future without rewriting the whole thing.

    Do you think live-saving / reading from a mysql database is good for server performance or is it better to like save all current placed blocks (of that kind) in a sort of list and just cycle threw it all the time.

    My current idea is:
    1. onEnable: read all existing blocks positions with radius and create like "activate zones" for each of them.
    2. If "something is going on" in an activate zone read the additional data for that specific block and do stuff
    3. If the block gets deactivated save all stats like fuel in the database and unload the block for the server
    (4. save everything if the server shuts down etc/plugin disables)

    But is this a good idea? So my second thoughts about this are just live-saving/reading from a mysql database all the time (fuel will probably update every 20 ticks or so) or is this not a good practice even if I use different threads? (and will fuel get saved properly even in an asynch thread)

    I hope you got my point.
    best regards
    Alex
     

Share This Page