Package xyz.xenondevs.particle.utils
Class PlayerConnectionCache
java.lang.Object
xyz.xenondevs.particle.utils.PlayerConnectionCache
- All Implemented Interfaces:
org.bukkit.event.Listener
A cache for player connections to avoid calling reflective
methods for each packet.
- Author:
- ByteZ
-
Constructor Summary
ConstructorDescriptionCreates a newPlayerConnectionCache
and registers itself as an event listener. -
Method Summary
Modifier and TypeMethodDescriptiongetConnection
(org.bukkit.entity.Player player) Gets the PlayerConnection of the specifiedPlayer
from the cache.void
handlePlayerQuit
(org.bukkit.event.player.PlayerQuitEvent event) Removes a leaving player from thecache
.void
Registers the currentPlayerConnectionCache
instance as an eventListener
.
-
Constructor Details
-
PlayerConnectionCache
public PlayerConnectionCache()Creates a newPlayerConnectionCache
and registers itself as an event listener. The plugin is retrieved from the PluginClassLoader.
-
-
Method Details
-
registerListener
public void registerListener()Registers the currentPlayerConnectionCache
instance as an eventListener
. -
getConnection
Gets the PlayerConnection of the specifiedPlayer
from the cache. If the cache doesn't contain the PlayerConnection yet it uses reflective calls to retrieve the connection and adds it to the cache (If the player is online).- Parameters:
player
- the targetPlayer
- Returns:
- the PlayerConnection of the specified
Player
-
handlePlayerQuit
public void handlePlayerQuit(org.bukkit.event.player.PlayerQuitEvent event) Removes a leaving player from thecache
.- Parameters:
event
- ThePlayerQuitEvent
that should be handled
-