Best way to store custom inventories

Discussion in 'Spigot Plugin Development' started by tier4fusion, Apr 30, 2017.

  1. Hi everyone,

    I'm planning to do a plugin that has support for things like hats etc. that people can purchase. I'm wondering what is the best way to store these items, or essentially a player's store inventory. I've thought of a couple of ways.

    MySQL: Store each player's inventory in MySQL. Problem is, each item would need it's own column, and then if I was to store it all in one column, I would need to do text manipulation / JSON to search through it effectively. This possibly wouldn't be that bad if I was to cache it and then save it onDisable / onQuit however.

    JSON: Store each player's inventory in a json file, that I could cache and save. This has the benefit of creating easily handleable objects but with lots of players, this could be taxing on the server.

    YAML: Store each player's inventory in a yaml folder. Similar to JSON, creates easily handleable objects, but could also be taxing on the server even with caching.

    Just wondering what's the best way to do this kind of storing, thanks :)
  2. For the mySQL one, you could have a row for whatever key you are using, and a serialised form of the inventory, so you don't need to have a column for each item.
  3. Depends on how exactly you want to do this.
    If you want to store an inventory for every player, you might should prefer MySQL. (e.g. 1 row for name / UUID and one more row for each inventory slot, so you could save each slot as JSON formatted item into a single cell). But i guess storing a inventory for each player is the worst thing you can do.
    If you just want to save GUIs (common for all players), then you'll be fine using YAML and Bukkits configuration serialization API.

    For everything inbetween i would prefer using JSON files or NBT files.
    Using NBT is a quite elegant way to store much data within less disk space, but you need to hook into NMS to do so.

    However, when i understood you correctly, you want to save what features players already have purchased or what features they already can use. So don't do this by saving complete inventories! Define unique keys for every feature (hats,...) and only save a list of keys for each player. So you only need to save a simple map (key = player UUID, value = List of keys). Easy to load and safe and you're done.