-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f9e774
commit 5f5d9ec
Showing
11 changed files
with
119 additions
and
5 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
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
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/org/strassburger/lifestealz/util/EliminatedPlayersCache.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,61 @@ | ||
package org.strassburger.lifestealz.util; | ||
|
||
import org.strassburger.lifestealz.LifeStealZ; | ||
|
||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class EliminatedPlayersCache { | ||
private final Set<String> eliminatedPlayers; | ||
private final LifeStealZ plugin; | ||
|
||
/** | ||
* A cache for eliminated players to avoid unnecessary database queries on tab completion | ||
*/ | ||
public EliminatedPlayersCache(LifeStealZ plugin) { | ||
this.plugin = plugin; | ||
this.eliminatedPlayers = Collections.synchronizedSet(new HashSet<>()); | ||
reloadCache(); | ||
} | ||
|
||
/** | ||
* Reload the cache from the database | ||
*/ | ||
public void reloadCache() { | ||
synchronized (eliminatedPlayers) { | ||
eliminatedPlayers.clear(); | ||
eliminatedPlayers.addAll(plugin.getStorage().getEliminatedPlayerNames()); | ||
} | ||
} | ||
|
||
/** | ||
* Get a set of all eliminated players | ||
* @return A set of all eliminated players | ||
*/ | ||
public Set<String> getEliminatedPlayers() { | ||
synchronized (eliminatedPlayers) { | ||
return new HashSet<>(eliminatedPlayers); | ||
} | ||
} | ||
|
||
/** | ||
* Add a player to the cache | ||
* @param username The username of the player to add | ||
*/ | ||
public void addEliminatedPlayer(String username) { | ||
synchronized (eliminatedPlayers) { | ||
eliminatedPlayers.add(username); | ||
} | ||
} | ||
|
||
/** | ||
* Remove a player from the cache | ||
* @param username The username of the player to remove | ||
*/ | ||
public void removeEliminatedPlayer(String username) { | ||
synchronized (eliminatedPlayers) { | ||
eliminatedPlayers.remove(username); | ||
} | ||
} | ||
} |
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