Class PreSpawnSpawnerAdapter

java.lang.Object
com.kamikazejam.kamicommon.nms.provider.event.PreSpawnSpawnerAdapter

public class PreSpawnSpawnerAdapter extends Object
Provider for version-specific spawner event adapters across different server implementations.

This provider automatically detects the current Minecraft version and server implementation to return the appropriate spawner event listener. Different server forks have implemented spawner pre-spawn events at different times and with different APIs, requiring version-specific adapters to provide consistent functionality.

The adapter system handles the complex landscape of spawner events across different server implementations:

  • TacoSpigot 1.8.8: Introduced SpawnerPreSpawnEvent early
  • Paper 1.9-1.12: Uses SpawnerSpawnEvent for pre-spawn detection
  • PaperSpigot 1.13+: Standardized on PreSpawnerSpawnEvent

Each adapter implements the same Listener interface but handles different underlying events, providing a unified PreSpawnSpawnerEvent abstraction for plugin developers.

Example usage:


 // Register the appropriate spawner adapter for the current server version
 Listener spawnerAdapter = PreSpawnSpawnerAdapter.getSpawnerAdapter();
 Bukkit.getPluginManager().registerEvents(spawnerAdapter, plugin);
 
 // The adapter will automatically convert server-specific events to unified events
 

  • Constructor Details

    • PreSpawnSpawnerAdapter

      public PreSpawnSpawnerAdapter()
  • Method Details

    • getSpawnerAdapter

      @NotNull public static @NotNull Listener getSpawnerAdapter()
      Retrieves the appropriate spawner event adapter for the current server version and implementation.

      This method analyzes the current Minecraft version to determine which server implementation is likely being used and returns the corresponding event adapter. The detection logic accounts for the historical evolution of spawner events across different server forks.

      Version detection logic:

      1. Minecraft 1.8.8: Assumes TacoSpigot fork, which introduced early spawner events
      2. Minecraft 1.9-1.12.2: Assumes Paper fork with SpawnerSpawnEvent
      3. Minecraft 1.13+: Assumes modern PaperSpigot with PreSpawnerSpawnEvent

      Each returned adapter will listen for the appropriate server-specific spawner events and convert them into the unified PreSpawnSpawnerEvent that can be handled consistently across all versions.

      Returns:
      a Listener that adapts server-specific spawner events to the unified API