Class ProviderManager

java.lang.Object
dev.crafty.core.storage.ProviderManager

public class ProviderManager extends Object
Manages storage provider instances, handling creation, caching, and configuration. This class centralizes the provider management logic that was previously spread across multiple classes.
Since:
1.0.0
  • Method Details

    • getInstance

      public static ProviderManager getInstance()
      Gets the singleton instance of the ProviderManager.
      Returns:
      The ProviderManager instance
    • getYamlProvider

      public <T> StorageProvider<T,String> getYamlProvider(Class<T> valueType, String directory)
      Gets a YAML storage provider for the specified type. If the provider doesn't exist, it will be created.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      directory - The directory to store files in
      Returns:
      The storage provider
    • getPostgresProvider

      public <T> StorageProvider<T,String> getPostgresProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Gets a PostgreSQL storage provider for the specified type. If the provider doesn't exist, it will be created.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      tableName - The name of the table to store objects in
      connectionUrl - The JDBC connection URL
      username - The database username
      password - The database password
      Returns:
      The storage provider
    • getMongoDbProvider

      public <T> StorageProvider<T,String> getMongoDbProvider(Class<T> valueType, String tableName, String connectionUrl)
      Gets a MongoDb storage provider for the specified type. If the provider doesn't exist, it will be created.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      tableName - The name of the table to store objects in
      connectionUrl - The JDBC connection URL
      Returns:
      The storage provider
    • getMySqlProvider

      public <T> StorageProvider<T,String> getMySqlProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Gets a MySQL storage provider for the specified type. If the provider doesn't exist, it will be created.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      tableName - The name of the table to store objects in
      connectionUrl - The JDBC connection URL
      username - The database username
      password - The database password
      Returns:
      The storage provider
    • setDefaultYamlConfig

      public void setDefaultYamlConfig(String directory)
      Sets the default YAML configuration.
      Parameters:
      directory - The directory to store files in
    • setDefaultPostgresConfig

      public void setDefaultPostgresConfig(String tableName, String connectionUrl, String username, String password)
      Sets the default PostgreSQL configuration.
      Parameters:
      tableName - The base table name to use
      connectionUrl - The JDBC connection URL
      username - The database username
      password - The database password
    • setDefaultMongoDbConfig

      public void setDefaultMongoDbConfig(String tableName, String connectionUrl)
      Sets the default MongoDB configuration.
      Parameters:
      tableName - The base table name to use
      connectionUrl - The JDBC connection URL
    • setDefaultMySqlConfig

      public void setDefaultMySqlConfig(String tableName, String connectionUrl, String username, String password)
      Sets the default MySQL configuration.
      Parameters:
      tableName - The base table name to use
      connectionUrl - The JDBC connection URL
      username - The database username
      password - The database password
    • getProvider

      public <T> StorageProvider<T,String> getProvider(Class<T> valueType)
      Gets a storage provider using the default configuration. The provider type is determined by the default storage type.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      Returns:
      The storage provider
      Throws:
      IllegalStateException - If the default configuration for the selected storage type is not set
    • getProvider

      public <T> StorageProvider<T,String> getProvider(Class<T> valueType, String identifier)
      Gets a storage provider using the default configuration. The provider type is determined by the default storage type.
      Type Parameters:
      T - The type of object to store
      Parameters:
      valueType - The class of the value type
      identifier - A unique identifier for this provider (e.g., table name or directory suffix)
      Returns:
      The storage provider
      Throws:
      IllegalStateException - If the default configuration for the selected storage type is not set
    • forPlayer

      public <T> PlayerDataProvider<T> forPlayer(UUID playerId, Class<T> valueType)
      Gets a player data provider for the specified player ID and value type.
      Type Parameters:
      T - The type of object to store
      Parameters:
      playerId - The UUID of the player
      valueType - The class of the value type
      Returns:
      The player data provider
    • closeAllProviders

      public void closeAllProviders()
      Closes all storage providers. This should be called when the plugin is disabled.