Class GrpcTachyonProfile

java.lang.Object
tech.skworks.tachyon.plugin.internal.player.GrpcTachyonProfile
All Implemented Interfaces:
TachyonProfile

public class GrpcTachyonProfile extends Object implements TachyonProfile
Project Tachyon Class PlayerProfile

Component lifecycle:

- initComponent() : called at load time — sets value, does NOT mark dirty.

- setComponent() : called by plugins — sets value AND marks dirty.

- saveComponent() : marks dirty + immediately enqueues a gRPC save.

- saveProfile() : flushes only dirty components to the backend.

The dirty set acts as a safety net: if a saveComponent() gRPC call hasn't been confirmed yet when the player disconnects, saveProfile() will catch it.

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

    Constructors
    Constructor
    Description
    GrpcTachyonProfile(UUID uuid, GrpcComponentService grpcComponentService)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    CompletableFuture<Void>
    deleteComponent(T component)
    Removes a component from memory and enqueues a delete via gRPC.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    T
    getComponent(@NotNull Class<T> clazz, T defaultValue)
    Returns the current in-memory value of a component, or default value if not loaded.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    T
    getComponent(@NotNull String componentShortName)
    Returns the current in-memory value of a component, or null if not loaded.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    T
    getComponent(@NonNull Class<T> clazz)
    Returns the current in-memory value of a component, or null if not loaded.
    Gets the unique identifier of the player who owns this profile.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    void
    initComponent(T component)
    Sets a component received from the backend at load time.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    CompletableFuture<Void>
    saveComponent(T component)
    Saves a component immediately via gRPC AND marks it dirty as a safety net.
    Flushes only dirty components to the backend.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message>
    void
    setComponent(@NonNull T component)
    Updates a component in memory and marks it dirty.
    <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message, B extends tech.skworks.tachyon.libs.com.google.protobuf.Message.Builder>
    void
    updateComponent(@NonNull Class<T> clazz, @NonNull Consumer<B> modifier)
    Applies a mutation to an existing component and marks it dirty.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • initComponent

      public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> void initComponent(@NotNull T component)
      Sets a component received from the backend at load time. Does NOT mark the component as dirty — avoids unnecessary saves at disconnect. Called exclusively by ProfileManager.load().
    • setComponent

      public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> void setComponent(@NonNull T component)
      Updates a component in memory and marks it dirty. The component will be saved during the next saveProfile() call (e.g. at disconnect). Does NOT trigger an immediate gRPC save — use saveComponent() for that.
      Specified by:
      setComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      component - The new Protobuf component instance to store.
    • updateComponent

      public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message, B extends tech.skworks.tachyon.libs.com.google.protobuf.Message.Builder> void updateComponent(@NonNull Class<T> clazz, @NonNull Consumer<B> modifier)
      Applies a mutation to an existing component and marks it dirty. No-op if the component is not loaded.
      Specified by:
      updateComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      B - The specific type of the Protobuf message's Builder.
      Parameters:
      clazz - The class of the component to update.
      modifier - A consumer applying the changes to the component's builder.
    • getComponent

      @Nullable public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> T getComponent(@NonNull Class<T> clazz)
      Returns the current in-memory value of a component, or null if not loaded.
      Specified by:
      getComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      clazz - The class of the component to retrieve.
      Returns:
      The current component instance, or null if not found.
    • getComponent

      @Nullable public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> T getComponent(@NotNull @NotNull String componentShortName)
      Returns the current in-memory value of a component, or null if not loaded.
      Specified by:
      getComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      componentShortName - The exact short name of the Protobuf descriptor.
      Returns:
      The current component instance, or null if not found.
    • getComponent

      public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> T getComponent(@NotNull @NotNull Class<T> clazz, @NotNull T defaultValue)
      Returns the current in-memory value of a component, or default value if not loaded.
      Specified by:
      getComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      clazz - The class of the component to retrieve.
      defaultValue - The value to return if the player does not have this component loaded.
      Returns:
      The current component instance, or the provided default value.
    • saveComponent

      public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> CompletableFuture<Void> saveComponent(@NotNull T component)
      Saves a component immediately via gRPC AND marks it dirty as a safety net. If the gRPC call hasn't completed by disconnect time, saveProfile() will retry it.
      Specified by:
      saveComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      component - The component to save immediately.
      Returns:
      A CompletableFuture that completes when the backend acknowledges the save.
    • deleteComponent

      public <T extends tech.skworks.tachyon.libs.com.google.protobuf.Message> CompletableFuture<Void> deleteComponent(@NotNull T component)
      Removes a component from memory and enqueues a delete via gRPC.
      Specified by:
      deleteComponent in interface TachyonProfile
      Type Parameters:
      T - The specific type of the Protobuf message.
      Parameters:
      component - The component to remove immediately.
      Returns:
      A CompletableFuture that completes when the backend acknowledges the deletion.
    • saveProfile

      public CompletableFuture<Void> saveProfile()
      Flushes only dirty components to the backend. Clears the dirty set on success. On failure, components remain dirty so the next attempt (e.g. retry scheduler) will pick them up.
      Specified by:
      saveProfile in interface TachyonProfile
      Returns:
      A CompletableFuture that completes when all dirty components are saved.
    • getUuid

      public UUID getUuid()
      Description copied from interface: TachyonProfile
      Gets the unique identifier of the player who owns this profile.
      Specified by:
      getUuid in interface TachyonProfile
      Returns:
      The player's UUID.