Add complete offline-mode support

This commit is contained in:
Luck
2016-07-25 11:18:35 +01:00
Unverified
parent df209f6515
commit 9ad40be210
14 changed files with 185 additions and 36 deletions
@@ -5,6 +5,7 @@ import me.lucko.luckperms.groups.GroupManager;
import me.lucko.luckperms.tracks.TrackManager;
import me.lucko.luckperms.users.UserManager;
import me.lucko.luckperms.utils.LPConfiguration;
import me.lucko.luckperms.utils.UuidCache;
import java.util.List;
import java.util.UUID;
@@ -48,6 +49,12 @@ public interface LuckPermsPlugin {
*/
Logger getLogger();
/**
* Retrieves the {@link UuidCache} for the plugin
* @return the plugin's {@link UuidCache}
*/
UuidCache getUuidCache();
/**
* @return the version of the plugin
*/
@@ -20,7 +20,7 @@ public class InfoCommand extends MainCommand {
protected void execute(LuckPermsPlugin plugin, Sender sender, List<String> args, String label) {
final LPConfiguration c = plugin.getConfiguration();
Message.INFO.send(sender, plugin.getVersion(), plugin.getDatastore().getName(), c.getServer(),
c.getDefaultGroupName(), c.getSyncTime(), c.getIncludeGlobalPerms());
c.getDefaultGroupName(), c.getSyncTime(), c.getIncludeGlobalPerms(), c.getOnlineMode());
}
@Override
@@ -99,7 +99,8 @@ public enum Message {
PREFIX + "&eServer Name: &6%s" + "\n" +
PREFIX + "&eDefault Group: &6%s" + "\n" +
PREFIX + "&eSync Interval: &6%s minutes" + "\n" +
PREFIX + "&eInclude Global Perms: &6%s",
PREFIX + "&eInclude Global Perms: &6%s" + "\n" +
PREFIX + "&eOnline Mode: &6%s",
false
),
DEBUG(
@@ -61,6 +61,10 @@ public abstract class LPConfiguration<T extends LuckPermsPlugin> {
return getBoolean("include-global", defaultIncludeGlobal);
}
public boolean getOnlineMode() {
return getBoolean("online-mode", true);
}
public String getDatabaseValue(String value) {
return getString("sql." + value, null);
}
@@ -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);
}
}