Class ListDataManager<T extends Storable>

java.lang.Object
me.efekos.simpler.config.ListDataManager<T>
Type Parameters:
T - 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 T of database.

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

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

    Modifier and Type
    Method
    Description
    void
    add(T data)
    Adds the given data to list.
    void
    Searches for a data with the given id and deletes the data found.
    get(@NotNull UUID id)
    Grabs a data from the list using its UUID.
    Grabs the entire list 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.
    update(UUID id, T newData)
    Finds a data with the given id, and replaces it with the new one.

    Methods inherited from class java.lang.Object

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

    • ListDataManager

      public ListDataManager(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 T get(@NotNull @NotNull UUID id)
      Grabs a data from the list using its UUID.
      Parameters:
      id - ID of the data you want to get.
      Returns:
      Data if found, null otherwise.
    • delete

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

      public void add(T data)
      Adds the given data to list.
      Parameters:
      data - Data you want to add to the list.
    • update

      public T update(UUID id, T newData)
      Finds a data with the given id, and replaces it with the new one.
      Parameters:
      id - ID of the data you want to update. You can just do Storable.getUniqueId() for this.
      newData - New data to replace with the old one
      Returns:
      New data.
    • 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 List<T> getAll()
      Grabs the entire list and returns it.
      Returns:
      All the list of datas.