java.lang.Object
java.util.TimerTask
me.remigio07.chatplugin.api.server.util.manager.PingManager
All Implemented Interfaces:
Runnable, ChatPluginManager

public abstract class PingManager extends TimerTask implements ChatPluginManager
Manager that handles loaded players' pings.
See Also:
  • Constructor Details

    • PingManager

      public PingManager()
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Description copied from interface: ChatPluginManager
      Checks if this manager is enabled.
      Specified by:
      isEnabled in interface ChatPluginManager
      Returns:
      Whether this manager is enabled
    • getQualities

      public List<PingManager.PingQuality> getQualities()
      Gets the loaded ping qualities list.
      Returns:
      Ping qualities
      See Also:
    • getUpdateTimeout

      public long getUpdateTimeout()
      Gets the timeout between ping updates, in milliseconds.

      Found at: "ping.update-timeout-ms" in ConfigurationType.CONFIG

      Returns:
      Time between updates
    • getTimerTaskID

      public long getTimerTaskID()
      Gets the update task's ID.

      You can interact with it through TaskManager's methods.

      Returns:
      Update task's ID
    • getCachedPing

      public int getCachedPing(ChatPluginServerPlayer player)
      Returns a player's cached ping.

      Latencies are cached in a map updated once every getUpdateTimeout() ms. If you need a real time ping (just a little more precise), you can use getRealTimePing(ChatPluginServerPlayer), but it's not recommended, as many calls of that method could be heavy to handle.

      Parameters:
      player - Player to get the ping for
      Returns:
      Player's cached ping, in milliseconds
    • formatPing

      public String formatPing(ChatPluginServerPlayer player)
      Parameters:
      player - Player to get the ping for
      Returns:
      Formatted ping with colors
    • getInstance

      public static PingManager getInstance()
      Gets this manager's instance.
      Returns:
      Manager's instance
    • run

      public abstract void run()
      Automatic online players' ping updater, called once every getUpdateTimeout() ms.
      Specified by:
      run in interface Runnable
      Specified by:
      run in class TimerTask
    • getRealTimePing

      @Deprecated public abstract int getRealTimePing(ChatPluginServerPlayer player)
      Deprecated.
      This method will return the ping directly from the player's connection class using reflection. You should use getCachedPing(ChatPluginServerPlayer) instead for a cached and less resource demanding ping request if performing multiple calls of this method.
      Gets a player's real time ping.
      Parameters:
      player - Player to get the ping for
      Returns:
      Player's real time ping, in milliseconds
    • getPingQuality

      public abstract PingManager.PingQuality getPingQuality(int ms)
      Establishes what PingManager.PingQuality a ping belongs to according to the response time, expressed in milliseconds.
      Parameters:
      ms - Ping to check
      Returns:
      Resulting ping quality
    • formatPing

      public abstract String formatPing(int ms, Language language)
      Returns a string formatted with given ping's PingManager.PingQuality's colors.

      If you want just a player's ping in milliseconds, use getCachedPing(ChatPluginServerPlayer).

      Parameters:
      ms - Latency, in milliseconds
      language - Language to get the message for
      Returns:
      Formatted ping with colors