Class InMemeryTeleportService

java.lang.Object
com.ultikits.ultitools.services.impl.InMemeryTeleportService
All Implemented Interfaces:
BaseService, TeleportService

public class InMemeryTeleportService extends Object implements TeleportService
Teleport service implementation.
Version:
1.0.0
Author:
wisdomme
  • Field Details

    • teleportingPlayers

      private static final Map<UUID,Boolean> teleportingPlayers
    • locationMap

      private static final Map<UUID,String> locationMap
    • inMemoryLocationRecord

      private static final Map<UUID,org.bukkit.Location> inMemoryLocationRecord
    • schedulerInitialized

      private static volatile boolean schedulerInitialized
    • playerCacheRegistered

      private static volatile boolean playerCacheRegistered
      True once ANY instance of this class has registered teleportingPlayers/locationMap/inMemoryLocationRecord -- static fields shared by every instance -- with the live PlayerCacheManager for quit-based sweeping (GEN-08, D-03). A STATIC flag, not per-instance, mirroring the identical rationale on InMemoryNotificationService#playerCacheRegistered: only the first instance to reach delayTeleport(Player, Location, int) registers. Set lazily rather than in a constructor for the same reason as CooldownValidator's field of the same name: a bare new InMemeryTeleportService() must never attempt contact with a core plugin that may not exist yet.
  • Constructor Details

    • InMemeryTeleportService

      public InMemeryTeleportService()
  • Method Details

    • ensurePlayerCacheRegistered

      private void ensurePlayerCacheRegistered()
      Attempts lazy first-use registration of THIS instance -- as the reference-identity handle for the three shared static fields above -- with the live PlayerCacheManager singleton. See playerCacheRegistered's javadoc for the static-flag rationale.
    • initScheduler

      static void initScheduler()
      Initialize the movement check scheduler. Called lazily to avoid static initializer issues in tests.
    • checkAllPlayersMovement

      static void checkAllPlayersMovement()
      Check movement for all teleporting players. This method is extracted from BukkitRunnable for testability.
    • checkPlayerMovement

      static boolean checkPlayerMovement(UUID playerUUID)
      Check if a single player has moved during teleport delay. This method is extracted from BukkitRunnable for testability.
      Parameters:
      playerUUID - the UUID of the player to check
      Returns:
      true if the player moved (teleport should be cancelled), false otherwise
    • teleport

      public void teleport(org.bukkit.entity.Player player, org.bukkit.Location location)
      Description copied from interface: TeleportService
      Teleport player instantly.
      Specified by:
      teleport in interface TeleportService
      Parameters:
      player - player
      location - location
    • delayTeleport

      public void delayTeleport(org.bukkit.entity.Player player, org.bukkit.Location location, int delay)
      Description copied from interface: TeleportService
      Delay teleport player.
      Specified by:
      delayTeleport in interface TeleportService
      Parameters:
      player - player
      location - location
      delay - delay
    • processDelayTeleportTick

      static InMemeryTeleportService.DelayTeleportResult processDelayTeleportTick(org.bukkit.entity.Player player, org.bukkit.Location location, float time)
      Process a single tick of the delay teleport countdown. This method is extracted from BukkitRunnable for testability.
      Parameters:
      player - the player being teleported
      location - the target location
      time - the current remaining time
      Returns:
      the result containing whether to cancel and the new remaining time
    • setTeleportingStatus

      static void setTeleportingStatus(UUID playerUUID, boolean status)
      Set a player's teleporting status. Used for testing.
    • getTeleportingStatus

      static Boolean getTeleportingStatus(UUID playerUUID)
      Get a player's teleporting status. Used for testing.
    • clearTeleportingData

      static void clearTeleportingData()
      Clear all teleporting data. Used for testing.
    • getLastTeleportLocation

      public Optional<org.bukkit.Location> getLastTeleportLocation(UUID uuid)
      Description copied from interface: TeleportService
      Get last teleport location of the player (before teleport).
      Specified by:
      getLastTeleportLocation in interface TeleportService
      Parameters:
      uuid - player uuid
      Returns:
      last teleport location
    • getName

      public String getName()
      The display name. English, named after the service interface, like DefaultEmailService's "EmailService"; it is no longer the folder name, see getResourceFolderName().
      Specified by:
      getName in interface BaseService
      Returns:
      Service name
    • getResourceFolderName

      public String getResourceFolderName()
      The resource folder name, kept at its pre-6.3.0 value so an existing install keeps its folder. BaseService.getResourceFolderName() defaults to getName(), which changed; this override pins the folder instead. It is an identifier, not text shown to anyone.
      Specified by:
      getResourceFolderName in interface BaseService
      Returns:
      service resource folder 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