Class InMemoryNotificationService

java.lang.Object
com.ultikits.ultitools.services.impl.InMemoryNotificationService
All Implemented Interfaces:
BaseService, NotificationService

public class InMemoryNotificationService extends Object implements NotificationService
  • Field Details

    • atedPlayer

      private static final Map<UUID,org.bukkit.boss.BossBar> atedPlayer
    • playerCacheRegistered

      private static volatile boolean playerCacheRegistered
      True once ANY instance of this class has registered atedPlayer -- a static field shared by every instance -- with the live PlayerCacheManager for quit-based sweeping (GEN-08, D-03). Deliberately a STATIC flag, not per-instance: registering the same static field once per constructed instance would track it once per instance too, sweeping it redundantly on every quit (harmless, since #registerBean removes the same map reference each time -- but silently relying on that idempotency rather than registering exactly once is worse than being explicit, per this migration's own plan). Set lazily from sendBossBarNotification(Player, String, int, BossBar, Sound) -- the write path -- rather than the constructor, mirroring CooldownValidator's identical lazy-first-use rationale.
  • Constructor Details

    • InMemoryNotificationService

      public InMemoryNotificationService()
  • Method Details

    • ensurePlayerCacheRegistered

      private void ensurePlayerCacheRegistered()
      Attempts lazy first-use registration of THIS instance -- as the reference-identity handle for the shared static atedPlayer field -- with the live PlayerCacheManager singleton. Guarded by the STATIC playerCacheRegistered flag so only the first instance to reach sendBossBarNotification(Player, String, int, BossBar, Sound) registers; every later instance's call is a cheap no-op. Safe to call unconditionally on every invocation: also a cheap, safely-no-op-on-failure retry when the core plugin is not yet live (see playerCacheRegistered's javadoc).
    • getName

      public String getName()
      Description copied from interface: BaseService
      Get service name, this name will appear in the console or in the game.
      Specified by:
      getName in interface BaseService
      Returns:
      Service name
    • getAuthor

      public String getAuthor()
      Specified by:
      getAuthor in interface BaseService
      Returns:
      Author name
    • getVersion

      public int getVersion()
      Description copied from interface: BaseService
      Version number, used to compare the version number of the registered service, currently not in use.
      Specified by:
      getVersion in interface BaseService
      Returns:
      service version
    • sendBossBarNotification

      public boolean sendBossBarNotification(org.bukkit.entity.Player player, String message)
      Description copied from interface: NotificationService
      Send a boss bar notification to a player
      Specified by:
      sendBossBarNotification in interface NotificationService
      Parameters:
      player - The player to send the boss bar to
      message - The message to send
      Returns:
      Whether the boss bar was sent successfully
    • sendBossBarNotification

      public boolean sendBossBarNotification(org.bukkit.entity.Player player, String message, int seconds)
      Description copied from interface: NotificationService
      Send a boss bar notification to a player
      Specified by:
      sendBossBarNotification in interface NotificationService
      Parameters:
      player - The player to send the boss bar to
      message - The message to send
      seconds - The duration of the boss bar in seconds
      Returns:
      Whether the boss bar was sent successfully
    • sendBossBarNotification

      public boolean sendBossBarNotification(org.bukkit.entity.Player player, String message, int seconds, org.bukkit.Sound sound)
      Description copied from interface: NotificationService
      Send a boss bar notification to a player
      Specified by:
      sendBossBarNotification in interface NotificationService
      Parameters:
      player - The player to send the boss bar to
      message - The message to send
      seconds - The duration of the boss bar in seconds
      sound - The sound to play when the boss bar is sent
      Returns:
      Whether the boss bar was sent successfully
    • sendBossBarNotification

      public boolean sendBossBarNotification(org.bukkit.entity.Player player, String message, int seconds, org.bukkit.boss.BossBar bossBar)
      Description copied from interface: NotificationService
      Send a boss bar notification to a player
      Specified by:
      sendBossBarNotification in interface NotificationService
      Parameters:
      player - The player to send the boss bar to
      message - The message to send
      seconds - The duration of the boss bar in seconds
      bossBar - The boss bar to send
      Returns:
      Whether the boss bar was sent successfully
    • sendBossBarNotification

      public boolean sendBossBarNotification(org.bukkit.entity.Player player, String message, int seconds, org.bukkit.boss.BossBar bossBar, org.bukkit.Sound sound)
      Description copied from interface: NotificationService
      Send a boss bar notification to a player
      Specified by:
      sendBossBarNotification in interface NotificationService
      Parameters:
      player - The player to send the boss bar to
      message - The message to send
      seconds - The duration of the boss bar in seconds
      bossBar - The boss bar to send
      sound - The sound to play when the boss bar is sent
      Returns:
      Whether the boss bar was sent successfully
    • processBossBarTick

      static InMemoryNotificationService.BossBarTickResult processBossBarTick(org.bukkit.boss.BossBar bossBar, org.bukkit.entity.Player player, int seconds)
      Process a single tick of the BossBar progress animation. This method is extracted from BukkitRunnable for testability.
      Parameters:
      bossBar - the BossBar to update
      player - the player viewing the BossBar
      seconds - the total duration in seconds
      Returns:
      the result containing whether to cancel and the new progress
    • getCachedBossBar

      static org.bukkit.boss.BossBar getCachedBossBar(UUID playerUUID)
      Get the cached BossBar for a player. Used for testing.
    • cacheBossBar

      static void cacheBossBar(UUID playerUUID, org.bukkit.boss.BossBar bossBar)
      Put a BossBar into cache. Used for testing.
    • clearBossBarCache

      static void clearBossBarCache()
      Clear all cached BossBars. Used for testing.
    • sendMessageNotification

      public boolean sendMessageNotification(org.bukkit.entity.Player player, String message)
      Description copied from interface: NotificationService
      Send a message notification to a player
      Specified by:
      sendMessageNotification in interface NotificationService
      Parameters:
      player - The player to send the message to
      message - The message to send
      Returns:
      Whether the message was sent successfully
    • sendMessageNotification

      public boolean sendMessageNotification(org.bukkit.entity.Player player, String message, org.bukkit.Sound sound)
      Description copied from interface: NotificationService
      Send a message notification to a player
      Specified by:
      sendMessageNotification in interface NotificationService
      Parameters:
      player - The player to send the message to
      message - The message to send
      sound - The sound to play when the message is sent
      Returns:
      Whether the message was sent successfully
    • sendSubTitleNotification

      public boolean sendSubTitleNotification(org.bukkit.entity.Player player, String subtitle)
      Description copied from interface: NotificationService
      Send a subtitle message notification to a player
      Specified by:
      sendSubTitleNotification in interface NotificationService
      Parameters:
      player - The player to send the subtitle to
      subtitle - The subtitle to send
      Returns:
      Whether the subtitle was sent successfully
    • sendSubTitleNotification

      public boolean sendSubTitleNotification(org.bukkit.entity.Player player, String subtitle, org.bukkit.Sound sound)
      Description copied from interface: NotificationService
      Send a subtitle message notification to a player
      Specified by:
      sendSubTitleNotification in interface NotificationService
      Parameters:
      player - The player to send the subtitle to
      subtitle - The subtitle to send
      sound - The sound to play when the subtitle is sent
      Returns:
      Whether the subtitle was sent successfully
    • sendTitleNotification

      public boolean sendTitleNotification(org.bukkit.entity.Player player, String title, String subtitle)
      Description copied from interface: NotificationService
      Send a title message notification to a player
      Specified by:
      sendTitleNotification in interface NotificationService
      Parameters:
      player - The player to send the title to
      title - The title to send
      subtitle - The subtitle to send
      Returns:
      Whether the title was sent successfully
    • sendTitleNotification

      public boolean sendTitleNotification(org.bukkit.entity.Player player, String title, String subtitle, org.bukkit.Sound sound)
      Description copied from interface: NotificationService
      Send a title message notification to a player
      Specified by:
      sendTitleNotification in interface NotificationService
      Parameters:
      player - The player to send the title to
      title - The title to send
      subtitle - The subtitle to send
      sound - The sound to play when the title is sent
      Returns:
      Whether the title was sent successfully
    • sendTitleNotification

      public boolean sendTitleNotification(org.bukkit.entity.Player player, String title, String subtitle, org.bukkit.Sound sound, int fadeIn, int stay, int fadeOut)
      Description copied from interface: NotificationService
      Send a title message notification to a player
      Specified by:
      sendTitleNotification in interface NotificationService
      Parameters:
      player - The player to send the title to
      title - The title to send
      subtitle - The subtitle to send
      sound - The sound to play when the title is sent
      fadeIn - The time in ticks for the title to fade in
      stay - The time in ticks for the title to stay
      fadeOut - The time in ticks for the title to fade out
      Returns:
      Whether the title was sent successfully
    • sendActionBarNotification

      public boolean sendActionBarNotification(org.bukkit.entity.Player player, String message)
      Specified by:
      sendActionBarNotification in interface NotificationService
    • sendToastNotification

      public boolean sendToastNotification(org.bukkit.entity.Player player, String icon, String message, Toast.Style style)
      Specified by:
      sendToastNotification in interface NotificationService