Class MapDataManager<K,V extends Storable>

java.lang.Object
me.efekos.simpler.config.MapDataManager<K,V>
Type Parameters:
K - Type of the keys you will use. Probably String but you can change it to something else if you want.
V - Type of the data you want to store as a list. Be aware that using incompatible types in this type might cause errors. Just to let you know, there is a list of the classes compatible to be used inside V.

public class MapDataManager<K,V extends Storable> extends Object
A basic database class made using Gson. You can store a Map<K,V extends Storable> in this data. Use save() and load() to load your data.
  • Constructor Summary

    Constructors
    Constructor
    Description
    MapDataManager(String path, org.bukkit.plugin.java.JavaPlugin plugin)
    Constructs a new manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    delete(K id)
    Searches for a data with the given id and deletes the data found.
    get(K id)
    Grabs a data from the map using its UUID.
    Grabs the entire map and returns it.
    void
    Loads all the data from the save before.
    void
    Saves all the data to the plugins data folder using the given path.
    void
    set(K key, V data)
    Puts the given data to map.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MapDataManager

      public MapDataManager(String path, org.bukkit.plugin.java.JavaPlugin plugin)
      Constructs a new manager.
      Parameters:
      path - Path to the file where all the data will be saved with save(). Must end with .json. You can't choose a path outside your plugins data folder.
      plugin - Instance of the plugin that will use this database. Recommended to be this, assuming that you are constructing a database inside your JavaPlugin.onEnable() method.
  • Method Details

    • get

      @Nullable public V get(@NotNull K id)
      Grabs a data from the map using its UUID.
      Parameters:
      id - ID of the data you want to get.
      Returns:
      Data if found, null otherwise.
    • delete

      public void delete(K id)
      Searches for a data with the given id and deletes the data found.
      Parameters:
      id - ID of the data you want to delete
    • set

      public void set(K key, V data)
      Puts the given data to map.
      Parameters:
      key - Key of the data in map.
      data - Data you want to put to the map.
    • save

      public void save()
      Saves all the data to the plugins data folder using the given path. It will save the data as a '.json' file, to path under plugins data folder.
    • load

      public void load()
      Loads all the data from the save before. You don't have to check if file exists, because method does it.
    • getAll

      public Map<K,V> getAll()
      Grabs the entire map and returns it.
      Returns:
      All the map of data.