Solved smart solution for saving MetaData of LivingEntities

Discussion in 'Spigot Plugin Development' started by He-light, Mar 11, 2020.

  1. Hi, i have a plugin, where i apply metadata to every mob that spawns. The problem was that the metadata is not persistent and gets lost after the restart of the server. So i decided to store all data in a database when the server shuts down. Everything works.
    I have done som tests and apparently the server can not handle the saving of data from over 1600 Entities :)
    The console displays a warning/error that the server does no longer respond.

    My question now: Does anyone know a propper solution, for saving the Metadata all spawned mobs in a db, without overwelming the server?

    PS: what i am exactly doing currently:
    - if a entity spawns, i apply the metadata and save it with his uuid in a hashmap
    - if the entity dies (onEntityDeathEvent), i remove his entry from the hashmap
    - onDisable --> i save all entries in a sqllite database
    - onEnable (1.) --> i load all data and apply it to the entities (i recognised, that if no player is loading chunks, no entities are there, so i have to find a better solution)
    - onEnable (2.) --> i clear all entries from the database
    #1 He-light, Mar 11, 2020
    Last edited: Mar 11, 2020
  2. PersistentDataHolder-API
    • Agree Agree x 1
  3. drives_a_ford


    What are you actually trying to achieve?
    The "what I am exactly doing currently" part explains a procedure that is generally completely unnecessary.

    If you do in fact want to store persistent data on entities, then the PersistentDataHolder is the right thing to use like Schottky said. You can find a tutorial here.
    • Agree Agree x 1