From 38cd6cc98ba320e54754a270c889549b793b6b90 Mon Sep 17 00:00:00 2001 From: Cow Date: Tue, 28 Apr 2020 12:44:09 +0200 Subject: Added Tab-completable usernames for various commands - use /tabcompletablecommand for a full list of valid commands (e.g. party, msg, boop, ...) - list of supported commands can be modified via config --- .../eu/olli/cowmoonication/util/PlayerCache.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/eu/olli/cowmoonication/util/PlayerCache.java (limited to 'src/main/java/eu/olli/cowmoonication/util/PlayerCache.java') diff --git a/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java b/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java new file mode 100644 index 0000000..1b5251a --- /dev/null +++ b/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java @@ -0,0 +1,46 @@ +package eu.olli.cowmoonication.util; + +import com.google.common.collect.EvictingQueue; +import eu.olli.cowmoonication.Cowmoonication; + +import java.util.Set; +import java.util.TreeSet; + +public class PlayerCache { + @SuppressWarnings("UnstableApiUsage") + private final EvictingQueue nameCache = EvictingQueue.create(50); + @SuppressWarnings("UnstableApiUsage") + private final EvictingQueue bestFriendCache = EvictingQueue.create(50); + private final Cowmoonication main; + + public PlayerCache(Cowmoonication main) { + this.main = main; + } + + public void add(String name) { + // remove old entry (if exists) to 'push' name to the end of the queue + nameCache.remove(name); + nameCache.add(name); + } + + public void addBestFriend(String name) { + // remove old entry (if exists) to 'push' name to the end of the queue + bestFriendCache.remove(name); + bestFriendCache.add(name); + } + + public void removeBestFriend(String name) { + bestFriendCache.remove(name); + } + + public Set getAllNamesSorted() { + Set nameList = new TreeSet<>(bestFriendCache); + nameList.addAll(nameCache); + return nameList; + } + + public void clearAllCaches() { + nameCache.clear(); + bestFriendCache.clear(); + } +} -- cgit