Class Gestalt

java.lang.Object
ovh.mythmc.gestalt.Gestalt

public abstract class Gestalt extends Object
The core abstract class of the Gestalt feature management framework.

Gestalt manages the lifecycle of Feature-annotated classes, including registration, initialization, enabling, disabling, and shutdown. Subclasses are expected to provide platform-specific initialization and supply themselves via GestaltSupplier.

The active instance can be retrieved globally via get().

  • Constructor Details

    • Gestalt

      protected Gestalt(String serverVersion)
      Constructs a new Gestalt instance with the given server version and auto-update flag.
      Parameters:
      serverVersion - the server version string, used for version-based conditions
      autoUpdate - whether the loader should auto-update features
  • Method Details

    • getServerVersion

      public String getServerVersion()
      Returns the server version string used for version-based feature conditions.
      Returns:
      the server version
    • getConditionProcessor

      public FeatureConditionProcessor getConditionProcessor()
      Returns the FeatureConditionProcessor responsible for evaluating whether a feature's conditions are satisfied before enabling it.
      Returns:
      the condition processor
    • getListenerProcessor

      public FeatureListenerProcessor getListenerProcessor()
      Returns the FeatureListenerProcessor responsible for processing and invoking methods annotated with FeatureListener.
      Returns:
      the listener processor
    • getConstructorParamsRegistry

      public FeatureConstructorParamsRegistry getConstructorParamsRegistry()
      Returns the FeatureConstructorParamsRegistry used to store custom constructor parameters for feature instantiation.
      Returns:
      the constructor parameters registry
    • getListenerRegistry

      public FeatureListenerRegistry getListenerRegistry()
      Returns the FeatureListenerRegistry used to register and dispatch feature lifecycle events to listener objects.
      Returns:
      the listener registry
    • get

      public static Gestalt get()
      Returns the globally active Gestalt instance.
      Returns:
      the active Gestalt instance
      See Also:
    • register

      public void register(@NotNull @NotNull Class<?>... classes)
      Registers one or more feature classes with Gestalt.

      Each class must be annotated with Feature. Upon registration, methods annotated with FeatureInitialize are invoked and a FeatureEvent.INITIALIZE event is dispatched to all registered listeners. Classes that are already registered are silently skipped.

      Parameters:
      classes - the feature classes to register
    • register

      public void register(@NotNull @NotNull GestaltFeature feature)
      Registers a feature described by a GestaltFeature wrapper.

      If the wrapper provides custom FeatureConstructorParams, they are stored in the constructor params registry before the feature class is registered.

      Parameters:
      feature - the feature descriptor containing the class and optional constructor params
    • unregister

      public void unregister(@NotNull @NotNull Class<?>... classes)
      Unregisters one or more feature classes from Gestalt.

      Methods annotated with FeatureShutdown are invoked on each class, the class is removed from the internal registry, its constructor params are cleared, and a FeatureEvent.SHUTDOWN event is dispatched to all listeners. Classes that are not registered are silently skipped.

      Parameters:
      classes - the feature classes to unregister
    • unregisterAllFeatures

      public void unregisterAllFeatures()
      Unregisters all currently registered feature classes.

      Each feature's FeatureShutdown methods are invoked and listeners are notified with FeatureEvent.SHUTDOWN.

    • enableFeature

      public void enableFeature(@NotNull @NotNull Class<?> clazz)
      Enables a single registered feature class.

      The feature is only enabled if it is currently disabled and all of its conditions are satisfied. Upon enabling, methods annotated with FeatureEnable are invoked and a FeatureEvent.ENABLE event is dispatched to listeners.

      Parameters:
      clazz - the feature class to enable
    • disableFeature

      public void disableFeature(@NotNull @NotNull Class<?> clazz)
      Disables a single registered feature class.

      The feature is only disabled if it is currently enabled. Methods annotated with FeatureDisable are invoked and a FeatureEvent.DISABLE event is dispatched to listeners.

      Parameters:
      clazz - the feature class to disable
    • enableAllFeatures

      public void enableAllFeatures()
      Enables all registered features, respecting their FeaturePriority order.
    • enableAllFeatures

      public void enableAllFeatures(@NotNull @NotNull String group)
      Enables all registered features belonging to the specified group, respecting their FeaturePriority order.
      Parameters:
      group - the feature group name to enable
    • disableAllFeatures

      public void disableAllFeatures()
      Disables all registered features, respecting their FeaturePriority order.
    • disableAllFeatures

      public void disableAllFeatures(@NotNull @NotNull String group)
      Disables all registered features belonging to the specified group, respecting their FeaturePriority order.
      Parameters:
      group - the feature group name to disable
    • getByGroup

      public List<Class<?>> getByGroup(@NotNull @NotNull String group)
      Returns all registered feature classes belonging to the given group (case-insensitive).
      Parameters:
      group - the group name to filter by
      Returns:
      a list of matching feature classes
    • getByIdentifier

      public List<Class<?>> getByIdentifier(@NotNull @NotNull String identifier)
      Returns all registered feature classes with the given identifier (case-insensitive).
      Parameters:
      identifier - the identifier to filter by
      Returns:
      a list of matching feature classes
    • getByPriority

      public List<Class<?>> getByPriority(@NotNull @NotNull FeaturePriority priority)
      Returns all registered feature classes with the given FeaturePriority.
      Parameters:
      priority - the priority to filter by
      Returns:
      a list of matching feature classes
    • getByGroupAndIdentifier

      public List<Class<?>> getByGroupAndIdentifier(@NotNull @NotNull String group, @NotNull @NotNull String identifier)
      Returns all registered feature classes matching both the given group and identifier (case-insensitive), sorted by FeaturePriority.
      Parameters:
      group - the group name to filter by
      identifier - the identifier to filter by
      Returns:
      a sorted list of matching feature classes
    • getSortedByPriority

      public List<Class<?>> getSortedByPriority()
      Returns all registered feature classes sorted by their FeaturePriority, from FeaturePriority.HIGHEST to FeaturePriority.LOWEST.
      Returns:
      a priority-ordered list of all registered feature classes
    • getEnabledClasses

      public List<Class<?>> getEnabledClasses()
      Returns all currently enabled feature classes.
      Returns:
      a list of enabled feature classes
    • getDisabledClasses

      public List<Class<?>> getDisabledClasses()
      Returns all currently disabled (but registered) feature classes.
      Returns:
      a list of disabled feature classes
    • isEnabled

      public boolean isEnabled(@NotNull @NotNull Class<?> clazz)
      Returns whether the given feature class is currently enabled.
      Parameters:
      clazz - the feature class to check
      Returns:
      true if the feature is enabled, false otherwise