Class ProviderManager

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

public class ProviderManager extends Object
  • Constructor Details

    • ProviderManager

      public ProviderManager()
  • Method Details

    • getYamlProvider

      public <T> StorageProvider<String,T> getYamlProvider(Class<T> valueType, String directory)
      Gets a YAML storage provider for the specified type with String keys. 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
    • getYamlProvider

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

      public <T> StorageProvider<String,T> getPostgresProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Gets a PostgreSQL storage provider for the specified type with String keys. 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
    • getPostgresProvider

      public <K, T> StorageProvider<K,T> getPostgresProvider(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Gets a PostgreSQL storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.
      Type Parameters:
      K - The type of key used to identify objects
      T - The type of object to store
      Parameters:
      keyType - The class of the key type
      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<String,T> getMongoDbProvider(Class<T> valueType, String tableName, String connectionUrl)
      Gets a MongoDb storage provider for the specified type with String keys. 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
    • getMongoDbProvider

      public <K, T> StorageProvider<K,T> getMongoDbProvider(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl)
      Gets a MongoDb storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.
      Type Parameters:
      K - The type of key used to identify objects
      T - The type of object to store
      Parameters:
      keyType - The class of the key type
      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<String,T> getMySqlProvider(Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Gets a MySQL storage provider for the specified type with String keys. 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
    • getMySqlProvider

      public <K, T> StorageProvider<K,T> getMySqlProvider(Class<K> keyType, Class<T> valueType, String tableName, String connectionUrl, String username, String password)
      Gets a MySQL storage provider for the specified type with generic key type. If the provider doesn't exist, it will be created.
      Type Parameters:
      K - The type of key used to identify objects
      T - The type of object to store
      Parameters:
      keyType - The class of the key type
      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<String,T> getProvider(Class<T> valueType)
      Gets a storage provider using the default configuration with String keys. 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<String,T> getProvider(Class<T> valueType, String identifier)
      Gets a storage provider using the default configuration with String keys. 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
    • getProvider

      public <K, T> StorageProvider<K,T> getProvider(Class<K> keyType, Class<T> valueType, String identifier)
      Gets a storage provider using the default configuration with generic key type. The provider type is determined by the default storage type.
      Type Parameters:
      K - The type of key used to identify objects
      T - The type of object to store
      Parameters:
      keyType - The class of the key type
      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
    • generatePlayerDataKey

      public String generatePlayerDataKey(UUID playerId, String identifier)
    • closeAllProviders

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