mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-07-04 13:01:32 +00:00
Performance improvement by caching PPlayer Player reference
This commit is contained in:
parent
1c834c7bb6
commit
c2146c11b9
2 changed files with 20 additions and 3 deletions
|
@ -97,8 +97,11 @@ public class ParticleManager extends Manager implements Listener, Runnable {
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||||
PPlayer pplayer = this.playerParticles.getManager(DataManager.class).getPPlayer(e.getPlayer().getUniqueId());
|
PPlayer pplayer = this.playerParticles.getManager(DataManager.class).getPPlayer(e.getPlayer().getUniqueId());
|
||||||
if (pplayer != null && pplayer.getFixedEffectIds().isEmpty())
|
if (pplayer != null) {
|
||||||
this.particlePlayers.remove(pplayer.getUniqueId()); // Unload the PPlayer if they don't have any fixed effects
|
pplayer.clearCachedPlayer();
|
||||||
|
if (pplayer.getFixedEffectIds().isEmpty())
|
||||||
|
this.particlePlayers.remove(pplayer.getUniqueId()); // Unload the PPlayer if they don't have any fixed effects
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,6 +18,11 @@ public class PPlayer {
|
||||||
*/
|
*/
|
||||||
private final UUID playerUUID;
|
private final UUID playerUUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached instance of the player
|
||||||
|
*/
|
||||||
|
private Player cachedPlayer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map of ParticleGroups this player has, the active particle group has an id of null
|
* A map of ParticleGroups this player has, the active particle group has an id of null
|
||||||
*/
|
*/
|
||||||
|
@ -74,7 +79,16 @@ public class PPlayer {
|
||||||
* @return the underlying CommandSender who executed the command
|
* @return the underlying CommandSender who executed the command
|
||||||
*/
|
*/
|
||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return Bukkit.getPlayer(this.playerUUID);
|
if (this.cachedPlayer == null)
|
||||||
|
this.cachedPlayer = Bukkit.getPlayer(this.playerUUID);
|
||||||
|
return this.cachedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the cached player to prevent the reference from lingering
|
||||||
|
*/
|
||||||
|
public void clearCachedPlayer() {
|
||||||
|
this.cachedPlayer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue