Class Provider<T>

java.lang.Object
com.kamikazejam.kamicommon.nms.provider.Provider<T>
Type Parameters:
T - the type of implementation provided by this provider
Direct Known Subclasses:
BlockUtilProvider, ChatColorProvider, CommandMapModifierProvider, EnchantIDProvider, EntityMethodsProvider, ItemEditorProvider, ItemTextProviderPre_1_17, MainHandProvider, MessageManagerProvider, NmsItemProvider, PacketHandlerProvider, TeleportProvider

public abstract class Provider<T> extends Object
Abstract base class for lazy-loading version-specific implementations.

This class provides a framework for creating version-specific providers that determine the appropriate implementation based on the current Minecraft/NMS version. The provider uses lazy initialization to defer the creation of the implementation until it's actually needed, improving startup performance.

Subclasses must implement the provide(int) method to return the appropriate implementation for the given NMS version. The implementation is cached after the first access for subsequent calls.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final int
    f(String mcVersion)
    Convenience method to convert a Minecraft version string to a formatted integer.
    final T
    get()
    Retrieves the version-specific implementation, creating it if necessary.
    protected abstract T
    provide(int formattedNmsInteger)
    Creates the appropriate implementation for the specified NMS version.

    Methods inherited from class java.lang.Object

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

    • Provider

      public Provider()
  • Method Details

    • get

      @NotNull public final T get()
      Retrieves the version-specific implementation, creating it if necessary.

      This method uses lazy initialization to create the implementation on first access. Subsequent calls return the cached instance. The implementation is determined by calling provide(int) with the current NMS version.

      Returns:
      the version-specific implementation instance
    • provide

      @NotNull protected abstract T provide(int formattedNmsInteger)
      Creates the appropriate implementation for the specified NMS version.

      This method must be implemented by subclasses to provide version-specific logic for creating the appropriate implementation. The method receives a formatted NMS integer that can be compared against known version thresholds to determine which implementation to create.

      Use the f(String) helper method to convert Minecraft version strings to formatted integers for comparison.

      Parameters:
      formattedNmsInteger - the formatted NMS version integer from NmsVersion.getFormattedNmsInteger()
      Returns:
      the implementation instance appropriate for the given version
    • f

      public final int f(String mcVersion)
      Convenience method to convert a Minecraft version string to a formatted integer.

      This helper method converts a Minecraft version string (e.g., "1.17.1", "1.13.2") to a formatted integer that can be used for version comparisons in the provide(int) method.

      This method is primarily intended for use within provide(int) implementations to create readable version threshold comparisons.

      Parameters:
      mcVersion - the Minecraft version string to convert (e.g., "1.17.1")
      Returns:
      the formatted integer representation of the version