Module ultimategdbot.api
Class GuildConfigurator<D extends GuildConfigData<D>>
- java.lang.Object
-
- com.github.alex1304.ultimategdbot.api.database.guildconfig.GuildConfigurator<D>
-
- Type Parameters:
D
- the type of database entity backing this configurator
public final class GuildConfigurator<D extends GuildConfigData<D>> extends Object
Allows to view and edit configuration for a guild. This high-level class is backed by a lower-level database entity, and the configuration entries represent an abstracted way to view or edit a specific field of that entity.This class is thread-safe: getting the data after having modified it via the different entries will always give the most up-to-date result, even if data is being modified by concurrent threads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GuildConfigurator.Builder<D extends GuildConfigData<D>>
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <D extends GuildConfigData<D>>
GuildConfigurator.Builder<D>builder(String name, D initialData, Class<? extends GuildConfigDao<D>> daoType)
Creates a new configurator builder with the given name and initial data.Collection<ConfigEntry<?>>
getConfigEntries()
Gets a collection of configuration entries containied in this configurator.ConfigEntry<?>
getConfigEntry(String key)
Gets the configuration entry corresponding to the given keyString
getDescription()
Gets the description of this configurator.discord4j.common.util.Snowflake
getGuildId()
Gets the ID of the guild this configurator is atttached to.String
getName()
Gets the name of this configurator.reactor.core.publisher.Mono<D>
resetConfig(DatabaseService database)
Resets the configuration to its default value and saves the data with the default values in the given database.reactor.core.publisher.Mono<Void>
saveConfig(DatabaseService database)
Saves in the given database the data object reflecting all modifications performed through the entries of this configurator.
-
-
-
Method Detail
-
getName
public String getName()
Gets the name of this configurator.- Returns:
- a String
-
getDescription
public String getDescription()
Gets the description of this configurator.- Returns:
- a String
-
getConfigEntries
public Collection<ConfigEntry<?>> getConfigEntries()
Gets a collection of configuration entries containied in this configurator.- Returns:
- a collection of configuration entries
-
getConfigEntry
public ConfigEntry<?> getConfigEntry(String key)
Gets the configuration entry corresponding to the given key- Parameters:
key
- the key of the entry to get- Returns:
- the entry
- Throws:
IllegalArgumentException
- if the key does not match any entry
-
saveConfig
public reactor.core.publisher.Mono<Void> saveConfig(DatabaseService database)
Saves in the given database the data object reflecting all modifications performed through the entries of this configurator.- Parameters:
database
- the database where to save data- Returns:
- a Mono completing when saving to database is successful
-
resetConfig
public reactor.core.publisher.Mono<D> resetConfig(DatabaseService database)
Resets the configuration to its default value and saves the data with the default values in the given database.- Parameters:
database
- the database where to save the reset data- Returns:
- a Mono emitting the data after reset
-
getGuildId
public discord4j.common.util.Snowflake getGuildId()
Gets the ID of the guild this configurator is atttached to.- Returns:
- the guild ID
-
builder
public static <D extends GuildConfigData<D>> GuildConfigurator.Builder<D> builder(String name, D initialData, Class<? extends GuildConfigDao<D>> daoType)
Creates a new configurator builder with the given name and initial data.- Type Parameters:
D
- the type of the data object- Parameters:
name
- the name of the configurator to buildinitialData
- the data to initialize the configuratordaoType
- a daoType class compatible with the data object type- Returns:
- a new builder
-
-