Interface CooldownRepository<K>

Type Parameters:
K - type of the keys that identifies the profiles
All Known Implementing Classes:
CooldownRepository.AbstractCooldownRepository, CooldownRepository.CacheCooldownRepository, CooldownRepository.MapCooldownRepository, CooldownRepository.MappingCooldownRepository

@API(status=STABLE, since="1.0.0") public interface CooldownRepository<K>
Repository that stores cooldown profiles identifies by keys of type CooldownRepository.

If the command sender objects are temporary (such as game entities, etc) the keys map be mapped to a persistent identifier by using a mapping(Function, CooldownRepository) repository.

The CooldownProfile creation may be customized by passing a custom CooldownProfileFactory to CooldownConfiguration.profileFactory().

Since:
1.0.0
  • Method Details

    • mapping

      static <C, K> @NonNull CooldownRepository<C> mapping(@NonNull Function<C,K> mappingFunction, @NonNull CooldownRepository<K> otherRepository)
      Returns a new repository backed by the given otherRepository that maps requests for keys of type CooldownRepository to type CooldownRepository using the given mappingFunction.
      Type Parameters:
      C - command sender type
      K - repository key type
      Parameters:
      mappingFunction - function that maps between the types
      otherRepository - backing repository
      Returns:
      the repository
    • forCache

      static <K> @NonNull CooldownRepository<K> forCache(@NonNull CloudCache<K,CooldownProfile> cache)
      Returns a new repository backed by the given cache.
      Type Parameters:
      K - key type
      Parameters:
      cache - backing cache
      Returns:
      the repository
    • forMap

      static <K> @NonNull CooldownRepository<K> forMap(@NonNull Map<K,CooldownProfile> map)
      Returns a new repository backed by the given map.
      Type Parameters:
      K - key type
      Parameters:
      map - backing map
      Returns:
      the repository
    • getProfile

      Returns the profile for the given key.

      If no profile exists in the repository, a new profile will be persisted and returned.

      Parameters:
      key - key that identifies the profile
      profileFactory - factory that creates profiles
      Returns:
      the profile
    • getProfileIfExists

      @Nullable CooldownProfile getProfileIfExists(@NonNull K key)
      Returns the profile for the given key, if it exists.
      Parameters:
      key - key that identifies the profile
      Returns:
      the profile, or null
    • deleteProfile

      void deleteProfile(@NonNull K key)
      Deletes the profile identified by the given key.
      Parameters:
      key - the key
    • deleteCooldown

      void deleteCooldown(@NonNull K key, @NonNull CooldownGroup group)
      Deletes the cooldown identified by the given key belonging to the given group.

      If the profile is empty after the deletion, then the profile is deleted too.

      Parameters:
      key - key identifying the profile
      group - group to delete