Storing a players health, food level, and inventory.

Discussion in 'BungeeCord Plugin Development' started by black_, May 3, 2017.

  1. Hello! I need your help with storing a player's inventory/food/health. I am making "staff mode" plugin, and I would like to know what is the best way to do this. I'm wondering how to store it temporarily so that when the staff member logs out, his items are returned before he logs out, as opposed to storing all his/her data in a config file.
     
  2. Serialize the content of the inventory and all other important things.
    Pseudocode:
    Code (Text):
    config.set("inv_size", inventory.getSize());
    for (int i = 0; i < inventory.getSize(); ++i) {
          configuration.set("" + i, inventory.getContents()[i]);
    }
    //...
    Deserializing is easy too. It works the same way but reverse.
     
  3. @black_, you can store ints in the default "config.yml" file. Use this to store health and food level. Use the method provided by @Igel_Borstel to store inventories.

    Remember to save the config after writing to it.
     
  4. thank you both for the help
     
    • Friendly Friendly x 1