Interface ComponentRegistry<V>

Type Parameters:
V - The visual object type used by the ComponentPreviewHandler (e.g., org.bukkit.inventory.ItemStack for Spigot).
All Known Implementing Classes:
ComponentRegistryImpl

public interface ComponentRegistry<V>
Project Tachyon Interface ComponentRegistry

The central hub for managing and resolving all Protobuf components within the Tachyon ecosystem.

This registry acts as the dictionary that bridges raw Protobuf data with concrete Java objects and their associated graphical user interfaces (Preview Handlers). It handles the dynamic unpacking of byte arrays into typed Message instances.

Since:
1.0.0-SNAPSHOT
Version:
1.0
Author:
Jimmy (vSKAH) - 18/04/2026
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    componentFullNameRegistered(@NotNull String componentFullName)
    Checks if a component is registered using its full descriptor name.
    boolean
    componentShortNameRegistered(@NotNull String componentName)
    Checks if a component is registered using its short descriptor name.
    @Nullable String
    getComponentShortName(@NotNull String componentFullName)
    Resolves the short name of a component from its full descriptor name.
    getPreviewHandler(@NotNull String componentFullName)
    Retrieves the UI preview handler associated with a specific component.
    @NotNull Set<String>
    Retrieves an immutable set containing the full names of all currently registered components.
    @NotNull Set<String>
    Retrieves an immutable set containing the short names of all currently registered components.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    void
    registerComponent(T defaultInstance)
    Registers a new Protobuf component without a UI preview handler.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    void
    registerComponent(T defaultInstance, @Nullable ComponentPreviewHandler<V> previewHandler)
    Registers a new Protobuf component into the ecosystem along with its UI preview handler.
    int
    Gets the total number of components successfully loaded into the registry.
    @Nullable tech.skworks.tachyon.libs.com.google.protobuf.Message
    unpack(tech.skworks.tachyon.libs.com.google.protobuf.Any any)
    Unpacks a Any wrapper into its concrete Java Message instance.
    @Nullable tech.skworks.tachyon.libs.com.google.protobuf.Message
    unpackRawBytes(@NotNull String componentFullName, byte[] rawData)
    Deserializes a raw byte array directly into a concrete Java Message instance, using the provided full component name to determine the correct parser.
  • Method Details

    • registerComponent

      <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> void registerComponent(T defaultInstance, @Nullable @Nullable ComponentPreviewHandler<V> previewHandler)
      Registers a new Protobuf component into the ecosystem along with its UI preview handler.

      This method extracts the descriptor from the provided default instance to map both its short name and full name for future deserialization and UI lookups.

      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      defaultInstance - The default, empty instance of the Protobuf message (usually obtained via MyComponent.getDefaultInstance()).
      previewHandler - The UI handler responsible for rendering this component in menus.
    • registerComponent

      <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> void registerComponent(T defaultInstance)
      Registers a new Protobuf component without a UI preview handler.
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      defaultInstance - The default, empty instance of the Protobuf message.
    • unpack

      @Nullable @Nullable tech.skworks.tachyon.libs.com.google.protobuf.Message unpack(tech.skworks.tachyon.libs.com.google.protobuf.Any any)
      Unpacks a Any wrapper into its concrete Java Message instance.

      The registry extracts the Type URL from the Any object, matches it against registered components, and uses the correct parser to decode the inner bytes.

      Parameters:
      any - The Protobuf Any container received from the back-end.
      Returns:
      The fully parsed concrete message, or null if the type is not registered.
    • unpackRawBytes

      @Nullable @Nullable tech.skworks.tachyon.libs.com.google.protobuf.Message unpackRawBytes(@NotNull @NotNull String componentFullName, byte[] rawData)
      Deserializes a raw byte array directly into a concrete Java Message instance, using the provided full component name to determine the correct parser.
      Parameters:
      componentFullName - The exact full name of the Protobuf descriptor (e.g., "tech.skworks.cookies.components.CookieComponent").
      rawData - The raw byte array (uncompressed) to parse.
      Returns:
      The fully parsed concrete message, or null if the name is not registered or the byte sequence is invalid.
    • componentFullNameRegistered

      boolean componentFullNameRegistered(@NotNull @NotNull String componentFullName)
      Checks if a component is registered using its full descriptor name.
      Parameters:
      componentFullName - The full name to check (e.g., "tech.skworks.cookies.components.CookieComponent").
      Returns:
      true if the component is registered, false otherwise.
    • componentShortNameRegistered

      boolean componentShortNameRegistered(@NotNull @NotNull String componentName)
      Checks if a component is registered using its short descriptor name.
      Parameters:
      componentName - The short name to check (e.g., "CookieComponent").
      Returns:
      true if the component is registered, false otherwise.
    • getComponentShortName

      @Nullable @Nullable String getComponentShortName(@NotNull @NotNull String componentFullName)
      Resolves the short name of a component from its full descriptor name.
      Parameters:
      componentFullName - The full name of the component.
      Returns:
      The short name (e.g., "CookieComponent"), or null if the full name is unknown.
    • getRegisteredComponentsFullNames

      @NotNull @NotNull Set<String> getRegisteredComponentsFullNames()
      Retrieves an immutable set containing the full names of all currently registered components.
      Returns:
      A set of registered full descriptor names.
    • getRegisteredComponentsShortsNames

      @NotNull @NotNull Set<String> getRegisteredComponentsShortsNames()
      Retrieves an immutable set containing the short names of all currently registered components.
      Returns:
      A set of registered short descriptor names.
    • getPreviewHandler

      @Nullable @Nullable ComponentPreviewHandler<V> getPreviewHandler(@NotNull @NotNull String componentFullName)
      Retrieves the UI preview handler associated with a specific component.

      This is primarily used by the Snapshot GUI system to determine how to visually display the decoded data of a target component.

      Parameters:
      componentFullName - The full name of the component.
      Returns:
      The associated ComponentPreviewHandler, or null if none was provided during registration or if the component is unknown.
    • registeredCount

      int registeredCount()
      Gets the total number of components successfully loaded into the registry.
      Returns:
      The count of registered components.