mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2026-11-24 10:34:24 +00:00
Add complete offline-mode support
This commit is contained in:
1 parent
df209f6515
commit
9ad40be210
14 files changed
+185
-36
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package me.lucko.luckperms.utils;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class UuidCache {
|
||||
|
||||
private Map<String, UUID> cache;
|
||||
|
||||
@Getter
|
||||
private final boolean onlineMode;
|
||||
|
||||
public UuidCache(boolean onlineMode) {
|
||||
this.onlineMode = onlineMode;
|
||||
|
||||
if (!onlineMode) {
|
||||
cache = new ConcurrentHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUUID(String name, UUID fallback) {
|
||||
return onlineMode ? fallback : (cache.containsKey(name) ? cache.get(name) : fallback);
|
||||
}
|
||||
|
||||
public void addToCache(String name, UUID uuid) {
|
||||
if (onlineMode) return;
|
||||
cache.put(name, uuid);
|
||||
}
|
||||
|
||||
public void clearCache(String name) {
|
||||
if (onlineMode) return;
|
||||
cache.remove(name);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user