Class PingManager
java.lang.Object
java.util.TimerTask
me.remigio07.chatplugin.api.server.util.manager.PingManager
- All Implemented Interfaces:
Runnable
,ChatPluginManager
Manager that handles loaded players' pings.
- See Also:
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract String
formatPing
(int ms, Language language) Returns a string formatted with given ping'sPingManager.PingQuality
's colors.formatPing
(ChatPluginServerPlayer player) CallsformatPing(int, Language)
specifying argumentsChatPluginServerPlayer.getPing()
andChatPluginServerPlayer.getLanguage()
of given player.int
getCachedPing
(ChatPluginServerPlayer player) Returns a player's cached ping.static PingManager
Gets this manager's instance.abstract PingManager.PingQuality
getPingQuality
(int ms) Establishes whatPingManager.PingQuality
a ping belongs to according to the response time, expressed in milliseconds.Gets the loaded ping qualities list.abstract int
Deprecated.This method will return the ping directly from the player's connection class using reflection.long
Gets the update task's ID.long
Gets the timeout between ping updates, in milliseconds.boolean
Checks if this manager is enabled.abstract void
run()
Automatic online players' ping updater, called once everygetUpdateTimeout()
ms.Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface me.remigio07.chatplugin.api.common.util.manager.ChatPluginManager
checkAvailability, isReloadable, load, reload, unload
-
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 interfaceChatPluginManager
- Returns:
- Whether this manager is enabled
-
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
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 usegetRealTimePing(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
CallsformatPing(int, Language)
specifying argumentsChatPluginServerPlayer.getPing()
andChatPluginServerPlayer.getLanguage()
of given player.- Parameters:
player
- Player to get the ping for- Returns:
- Formatted ping with colors
-
getInstance
Gets this manager's instance.- Returns:
- Manager's instance
-
run
public abstract void run()Automatic online players' ping updater, called once everygetUpdateTimeout()
ms. -
getRealTimePing
Deprecated.This method will return the ping directly from the player's connection class using reflection. You should usegetCachedPing(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
Establishes whatPingManager.PingQuality
a ping belongs to according to the response time, expressed in milliseconds.- Parameters:
ms
- Ping to check- Returns:
- Resulting ping quality
-
formatPing
Returns a string formatted with given ping'sPingManager.PingQuality
's colors.If you want just a player's ping in milliseconds, use
getCachedPing(ChatPluginServerPlayer)
.- Parameters:
ms
- Latency, in millisecondslanguage
- Language to get the message for- Returns:
- Formatted ping with colors
-