I use mysql database for my coins plugin.. and i query "SELECT..." every time a player run /coins... Is this a bad practice? What would be a better one?
Player wouldn't run /coins too often, while MySQL queries are usually fast (less than 0.1s most of the time). What makes you think it's bad? However, if you have to check it really frequently (e.g. in PlayerMoveEvent), you may want to cache the result in memory for a minute or so. No matter you're storing in MySQL or in config files, you're still querying external resources, which is slow by definition. You should not abuse MySQL or config files as a temporary storage. To be precise, you should always store data in ram when they are used frequently (e.g. if the relevant players are online), and persist them using a database when the data are not used frequently. How does JSON make any difference? Stop posting irrelevant replies everywhere.
Cache the query result for as long as you think is a significant time. You could write your code in an efficient way to deal with the problem of frequent database calls. But again, it all points back to cache manipulation.
You can query once and store it in a variable, update it when you change the value and save to db when player quits
You can do that by saving all online players' data in onDisable and optionally do a check if server is running before saving if thats what you wanted
Since names can be changed, I would choose the UUID or XUID because it is (usually) a unique identifier for a player.
OKay so right now I save players data from MySQL into memory on PlayerLoginEvent. Something worries me though... what if multiple players join simultaneously? Will MySQL be able to keep up with querying, and not let a player join the server without their data saved in the memory?
If you are querying asynchronously, yes, there is the chance. You might want to check if the data are ready before doing anything on the player (and block the player from interacting if you are paranoid).
So I save data from mysql to an array right now.. should I unset the player from the array when they leave? I think I shouldn't so that when they join I won't have to query again. And when the server restarts, does the array get abandoned or cleared itself?