-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added listeners to clean PlayerProvider cache
Alright so this is needed because PlayerProviders kept MCPlayer instances on cache indefinitely. This has been solved by adding a platform specific listener that removes MCPlayers fron the PlayerProvider cache whenever the Player leaves the server or proxy. I ended up using a "hacky" way to access the player cache by using protected methods on both SpigotPlayerProvider and VelocityPlayerProvider that call the super PlayerProvider method. This has been done so end users don't mess with the cache unintentionally, as they can only access this method by creating their own PlayerProvider.
- Loading branch information
Showing
7 changed files
with
189 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...rms/spigot/src/main/java/net/codersky/mcutils/spigot/player/SpigotPlayerQuitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.codersky.mcutils.spigot.player; | ||
|
||
import net.codersky.mcutils.spigot.SpigotUtils; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SpigotPlayerQuitListener implements Listener { | ||
|
||
private final SpigotUtils<?> utils; | ||
|
||
public SpigotPlayerQuitListener(@NotNull SpigotUtils<?> utils) { | ||
this.utils = utils; | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST) | ||
public void onQuit(PlayerQuitEvent e) { | ||
utils.getPlayerProvider().removeFromCache(e.getPlayer().getUniqueId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...locity/src/main/java/net/codersky/mcutils/velocity/player/VelocityPlayerQuitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package net.codersky.mcutils.velocity.player; | ||
|
||
import com.velocitypowered.api.event.PostOrder; | ||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.connection.DisconnectEvent; | ||
import net.codersky.mcutils.velocity.VelocityUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class VelocityPlayerQuitListener { | ||
|
||
private final VelocityUtils<?> utils; | ||
|
||
public VelocityPlayerQuitListener(@NotNull VelocityUtils<?> utils) { | ||
this.utils = utils; | ||
} | ||
|
||
@Subscribe(order = PostOrder.CUSTOM, priority = Short.MAX_VALUE) | ||
public void onDisconnect(DisconnectEvent event) { | ||
utils.getPlayerProvider().removeFromCache(event.getPlayer().getUniqueId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters