Storing player data inside player's inventory

Discussion in 'Spigot Plugin Development' started by iSoda, Jun 2, 2017.

  1. This is just a really (really) wild idea,
    would it be possible to store player's data such as:
    Integers (for currencies, stats, etc) and string as for friendlist, ranks, etc.
    as items with custom name or lore inside a shulker box inside the player's inventory? (Needless to say, any attempt to remove the box will be canceled and the box will be kept inside the players inventory at all time (and be given to him again on respawn incase he dies)

    would it be possible? given that it has 27 slots, each slot can be used to store an item with custom name and lore, for example a dirt block that will have its lore set as
    "Money: 10000"
    "Time online: 10000 minutes"
    "Rank: RANK"
    and another item could store the players enderchest inventory,

    another approach would be loading the shelker box when the player joins the server into a config class and putting it inside a hashmap with the player uuid, the box could then be removed while the config will be edited throughout the players online time and once the player disconnect or server restarts, the config could be converted into a shulker box again and be put into the players inventory.

    *This will cost the player 1 inventory slot, but will eliminate the use of external configs,

    once again - this is a very WILD and untested idea, what do you guys think?
     
  2. I would question the persistantcy of such data using (I assume) NBT data. Personally, I would store the data somewhere else, like a MySQL database and then simply display it whenever the user accesses his (personal) shulker box. You shouldn't be using NBT as a database.
     
  3. It is possible. You can create items and set their name and lore to data. I would do it with NBT if i would do this. You can just create custom tags. At my server and api [URL=''https://www.spigotmc.org/resources/opensl.38265/]Open Squidcraft Library[/URL] we make use of custom nbt tags to make items 'speical' so that they can't be used to craft stuff.
    Would is use it as more then that? I don't think so. You have to update the items every time, sending more data to the clients. It has limits. it takes up a slot. If your plugin is not working and people can remove the shulkerbox, you lose ALL data! You can't change data of offline players. There is no easy way to remove ALL player data at once.
    It is a weird and great idea... but the implementation is just not something that would work great. I would suggest you just save data in a file or database, that are optimized for storing lots of data and loading that data.
     
  4. Thanks both of you, it was just a concept.