Best way to store large amounts of items

Discussion in 'Plugin Development' started by Zix, Apr 25, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Zix

    I want to have a plugin where players can sell an item, that item will then go onto the global marketplace and can be bought by other players. However I am not sure on how to store the items that are currently on the global marketplace. I was thinking a config file with the IDs of every item that goes up for sale but could there be a better way? Also how would I go about checking the players inventory for a specific item and amount.

    Thanks.
     
  2. Offline

    Deleted user

  3. Offline

    Slikey

    Zix So you need to store data.. The best way of storing a big amount of data is a database. I suggest a mysql connection.. You need to find a way to do all the queries async because of the lag to the database.
     
  4. Offline

    Zethariel

    Zix Flatfile for storage, load it up on enable and keep in memory during run-time in the form of a HashMap or Array, YamlConfiguration if you don't feel like creating a custom SoldItem class or the likes.
    To check an inventory, get the player's inventory, the ItemStack array inside it and check for a containts(). Mind you, it will have to literally match the search criterium, so it's better to iterate through the contents and compare name or material type, along with amount.
     
  5. Offline

    coasterman10

    This may depend on whether you just want all the items as a bunch of items, or whether they should be referenced by keys. Either way, you can use a Configuration if you don't plan to see too many hits on the list, but if lots of people are going to be using this at once it is a good idea to store it in active memory instead of in a String-based configuration. You could choose to store items under an Integer or Material key for their type in a Map, or you could use a Collection for just a bunch of items.
     
Thread Status:
Not open for further replies.

Share This Page