Refactor config handling - towards #100

This commit is contained in:
Luck
2017-01-21 15:36:13 +00:00
Unverified
parent 7430013cc3
commit b7cf0e6bc7
42 changed files with 814 additions and 494 deletions
@@ -33,6 +33,7 @@ import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.api.data.Callback;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.storage.Storage;
import java.util.Set;
@@ -162,7 +163,7 @@ public class DatastoreDelegate implements Datastore {
@Override
public void deleteGroup(@NonNull Group group, Callback<Boolean> callback) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
registerCallback(master.force().deleteGroup(((GroupDelegate) group).getMaster()), callback);
@@ -279,7 +280,7 @@ public class DatastoreDelegate implements Datastore {
@Override
public boolean deleteGroup(@NonNull Group group) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
return master.force().deleteGroup(((GroupDelegate) group).getMaster()).join();
@@ -392,7 +393,7 @@ public class DatastoreDelegate implements Datastore {
@Override
public java.util.concurrent.Future<Boolean> deleteGroup(@NonNull Group group) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
return master.force().deleteGroup(((GroupDelegate) group).getMaster());
@@ -27,6 +27,7 @@ import lombok.AllArgsConstructor;
import me.lucko.luckperms.api.LPConfiguration;
import me.lucko.luckperms.api.data.DatastoreConfiguration;
import me.lucko.luckperms.api.data.MySQLConfiguration;
import me.lucko.luckperms.common.config.ConfigKeys;
import java.util.Map;
@@ -39,67 +40,67 @@ public class LPConfigurationDelegate implements LPConfiguration {
@Override
public String getServer() {
return master.getServer();
return master.get(ConfigKeys.SERVER);
}
@Override
public int getSyncTime() {
return master.getSyncTime();
return master.get(ConfigKeys.SYNC_TIME);
}
@Override
public String getDefaultGroupNode() {
return master.getDefaultGroupNode();
return master.get(ConfigKeys.DEFAULT_GROUP_NODE);
}
@Override
public String getDefaultGroupName() {
return master.getDefaultGroupName();
return master.get(ConfigKeys.DEFAULT_GROUP_NAME);
}
@Override
public boolean getIncludeGlobalPerms() {
return master.isIncludingGlobalPerms();
return master.get(ConfigKeys.INCLUDING_GLOBAL_PERMS);
}
@Override
public boolean getIncludeGlobalWorldPerms() {
return master.isIncludingGlobalWorldPerms();
return master.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS);
}
@Override
public boolean getApplyGlobalGroups() {
return master.isApplyingGlobalGroups();
return master.get(ConfigKeys.APPLYING_GLOBAL_GROUPS);
}
@Override
public boolean getApplyGlobalWorldGroups() {
return master.isApplyingGlobalWorldGroups();
return master.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS);
}
@Override
public boolean getOnlineMode() {
return master.isOnlineMode();
return master.get(ConfigKeys.ONLINE_MODE);
}
@Override
public boolean getApplyWildcards() {
return master.isApplyingWildcards();
return master.get(ConfigKeys.APPLYING_WILDCARDS);
}
@Override
public boolean getApplyRegex() {
return master.isApplyingRegex();
return master.get(ConfigKeys.APPLYING_REGEX);
}
@Override
public boolean getApplyShorthand() {
return master.isApplyingShorthand();
return master.get(ConfigKeys.APPLYING_SHORTHAND);
}
@Override
public boolean getLogNotify() {
return master.isLogNotify();
return master.get(ConfigKeys.LOG_NOTIFY);
}
@Override
@@ -109,27 +110,27 @@ public class LPConfigurationDelegate implements LPConfiguration {
@Override
public boolean getEnableOps() {
return master.isOpsEnabled();
return master.get(ConfigKeys.OPS_ENABLED);
}
@Override
public boolean getCommandsAllowOp() {
return master.isCommandsAllowOp();
return master.get(ConfigKeys.COMMANDS_ALLOW_OP);
}
@Override
public boolean getAutoOp() {
return master.isAutoOp();
return master.get(ConfigKeys.AUTO_OP);
}
@Override
public String getVaultServer() {
return master.getVaultServer();
return master.get(ConfigKeys.VAULT_SERVER);
}
@Override
public boolean getVaultIncludeGlobal() {
return master.isVaultIncludingGlobal();
return master.get(ConfigKeys.VAULT_INCLUDING_GLOBAL);
}
@SuppressWarnings("deprecation")
@@ -140,21 +141,21 @@ public class LPConfigurationDelegate implements LPConfiguration {
@Override
public DatastoreConfiguration getDatastoreConfig() {
return master.getDatabaseValues();
return master.get(ConfigKeys.DATABASE_VALUES);
}
@Override
public String getStorageMethod() {
return master.getStorageMethod();
return master.get(ConfigKeys.STORAGE_METHOD);
}
@Override
public boolean getSplitStorage() {
return master.isSplitStorage();
return master.get(ConfigKeys.SPLIT_STORAGE);
}
@Override
public Map<String, String> getSplitStorageOptions() {
return master.getSplitStorageOptions();
return master.get(ConfigKeys.SPLIT_STORAGE_OPTIONS);
}
}
@@ -33,6 +33,7 @@ import me.lucko.luckperms.api.Storage;
import me.lucko.luckperms.api.Track;
import me.lucko.luckperms.api.User;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import java.util.List;
import java.util.Set;
@@ -134,7 +135,7 @@ public class StorageDelegate implements Storage {
@Override
public CompletableFuture<Boolean> deleteGroup(Group group) {
checkGroup(group);
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
if (group.getName().equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
throw new IllegalArgumentException("Cannot delete the default group.");
}
return master.force().deleteGroup(((GroupDelegate) group).getMaster());
@@ -27,6 +27,7 @@ import me.lucko.luckperms.common.commands.Arg;
import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group;
@@ -56,7 +57,7 @@ public class DeleteGroup extends SingleCommand {
String groupName = args.get(0).toLowerCase();
if (groupName.equalsIgnoreCase(plugin.getConfiguration().getDefaultGroupName())) {
if (groupName.equalsIgnoreCase(plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME))) {
Message.DELETE_GROUP_ERROR_DEFAULT.send(sender);
return CommandResult.INVALID_ARGS;
}
@@ -27,6 +27,7 @@ import me.lucko.luckperms.common.commands.CommandResult;
import me.lucko.luckperms.common.commands.SingleCommand;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LPConfiguration;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
@@ -64,8 +65,8 @@ public class InfoCommand extends SingleCommand {
plugin.getVersion(),
plugin.getType().getFriendlyName(),
plugin.getStorage().getName(),
c.getServer(),
c.getSyncTime(),
c.get(ConfigKeys.SERVER),
c.get(ConfigKeys.SYNC_TIME),
plugin.getPlayerCount(),
plugin.getUserManager().getAll().size(),
plugin.getGroupManager().getAll().size(),
@@ -75,15 +76,15 @@ public class InfoCommand extends SingleCommand {
plugin.getLocaleManager().getSize(),
plugin.getPreProcessContexts(false).size(),
plugin.getContextManager().getCalculatorsSize(),
formatBoolean(c.isOnlineMode()),
formatBoolean(c.isRedisEnabled()),
formatBoolean(c.isIncludingGlobalPerms()),
formatBoolean(c.isIncludingGlobalWorldPerms()),
formatBoolean(c.isApplyingGlobalGroups()),
formatBoolean(c.isApplyingGlobalWorldGroups()),
formatBoolean(c.isApplyingWildcards()),
formatBoolean(c.isApplyingRegex()),
formatBoolean(c.isApplyingShorthand())
formatBoolean(c.get(ConfigKeys.ONLINE_MODE)),
formatBoolean(c.get(ConfigKeys.REDIS_ENABLED)),
formatBoolean(c.get(ConfigKeys.INCLUDING_GLOBAL_PERMS)),
formatBoolean(c.get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS)),
formatBoolean(c.get(ConfigKeys.APPLYING_GLOBAL_GROUPS)),
formatBoolean(c.get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS)),
formatBoolean(c.get(ConfigKeys.APPLYING_WILDCARDS)),
formatBoolean(c.get(ConfigKeys.APPLYING_REGEX)),
formatBoolean(c.get(ConfigKeys.APPLYING_SHORTHAND))
);
LinkedHashMap<String, Object> platformInfo = plugin.getExtraInfo();
@@ -50,7 +50,7 @@ public interface Sender {
String getName();
/**
* Gets the sender's unique id. See {@link Constants#getConsoleUUID()} for the console's UUID representation.
* Gets the sender's unique id. See {@link Constants#CONSOLE_UUID} for the console's UUID representation.
*
* @return the sender's uuid
*/
@@ -22,168 +22,49 @@
package me.lucko.luckperms.common.config;
import lombok.AccessLevel;
import lombok.Getter;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.config.keys.EnduringKey;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.constants.Patterns;
import me.lucko.luckperms.common.defaults.Rule;
import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@SuppressWarnings("unchecked")
public abstract class AbstractConfiguration implements LPConfiguration {
private final LoadingCache<ConfigKey<?>, Object> cache = CacheBuilder.newBuilder()
.build(new CacheLoader<ConfigKey<?>, Object>() {
@Override
public Object load(ConfigKey<?> key) {
return key.get(AbstractConfiguration.this);
}
/**
* A thread-safe config abstraction
*
* @param <T> the plugin type
*/
@Getter
public abstract class AbstractConfiguration<T extends LuckPermsPlugin> implements LPConfiguration {
@Override
public ListenableFuture<Object> reload(ConfigKey<?> key, Object oldValue) {
if (key instanceof EnduringKey) {
return Futures.immediateFuture(key);
} else {
return Futures.immediateFuture(key.get(AbstractConfiguration.this));
}
}
});
@Getter(AccessLevel.PROTECTED)
private final T plugin;
// Values
private String server;
private int syncTime;
private String defaultGroupNode;
private String defaultGroupName;
private boolean includingGlobalPerms;
private boolean includingGlobalWorldPerms;
private boolean applyingGlobalGroups;
private boolean applyingGlobalWorldGroups;
private boolean onlineMode;
private boolean applyingWildcards;
private boolean applyingRegex;
private boolean applyingShorthand;
private Map<String, Integer> groupWeights;
private boolean logNotify;
private boolean opsEnabled;
private boolean commandsAllowOp;
private boolean autoOp;
private String vaultServer;
private boolean vaultIncludingGlobal;
private boolean vaultIgnoreWorld;
private boolean vaultPrimaryGroupOverrides;
private boolean vaultPrimaryGroupOverridesCheckInherited;
private boolean vaultPrimaryGroupOverridesCheckExists;
private boolean vaultPrimaryGroupOverridesCheckMemberOf;
private boolean vaultDebug;
private Map<String, String> worldRewrites;
private Map<String, String> groupNameRewrites;
private List<Rule> defaultAssignments;
private DatastoreConfiguration databaseValues;
private String sqlTablePrefix;
private String storageMethod;
private boolean splitStorage;
private Map<String, String> splitStorageOptions;
private boolean redisEnabled;
private String redisAddress;
private String redisPassword;
public AbstractConfiguration(T plugin, String defaultServerName, boolean defaultIncludeGlobal, String defaultStorage) {
this.plugin = plugin;
init();
load(defaultServerName, defaultIncludeGlobal, defaultStorage);
@Override
public <T> T get(ConfigKey<T> key) {
return (T) cache.getUnchecked(key);
}
protected abstract void init();
@Override
public void loadAll() {
ConfigKeys.getAllKeys().forEach(cache::getUnchecked);
}
protected abstract String getString(String path, String def);
protected abstract int getInt(String path, int def);
protected abstract boolean getBoolean(String path, boolean def);
protected abstract List<String> getList(String path, List<String> def);
protected abstract List<String> getObjectList(String path, List<String> def);
protected abstract Map<String, String> getMap(String path, Map<String, String> def);
public void load(String defaultServerName, boolean defaultIncludeGlobal, String defaultStorage) {
server = getString("server", defaultServerName);
syncTime = getInt("data.sync-minutes", 3);
defaultGroupNode = "group.default"; // constant since 2.6
defaultGroupName = "default"; // constant since 2.6
includingGlobalPerms = getBoolean("include-global", defaultIncludeGlobal);
includingGlobalWorldPerms = getBoolean("include-global-world", true);
applyingGlobalGroups = getBoolean("apply-global-groups", true);
applyingGlobalWorldGroups = getBoolean("apply-global-world-groups", true);
onlineMode = getBoolean("online-mode", true);
applyingWildcards = getBoolean("apply-wildcards", true);
applyingRegex = getBoolean("apply-regex", true);
applyingShorthand = getBoolean("apply-shorthand", true);
Map<String, String> weights = getMap("group-weight", Collections.emptyMap());
ImmutableMap.Builder<String, Integer> mb = ImmutableMap.builder();
for (Map.Entry<String, String> e : weights.entrySet()) {
try {
mb.put(e.getKey().toLowerCase(), Integer.parseInt(e.getValue()));
} catch (NumberFormatException ignored) {
}
}
groupWeights = mb.build();
logNotify = getBoolean("log-notify", true);
autoOp = getBoolean("auto-op", false);
opsEnabled = !isAutoOp() && getBoolean("enable-ops", true);
commandsAllowOp = getBoolean("commands-allow-op", true);
vaultServer = getString("vault-server", "global");
vaultIncludingGlobal = getBoolean("vault-include-global", true);
vaultIgnoreWorld = getBoolean("vault-ignore-world", false);
vaultPrimaryGroupOverrides = getBoolean("vault-primary-groups-overrides.enabled", false);
vaultPrimaryGroupOverridesCheckInherited = getBoolean("vault-primary-groups-overrides.check-inherited-permissions", false);
vaultPrimaryGroupOverridesCheckExists = getBoolean("vault-primary-groups-overrides.check-group-exists", true);
vaultPrimaryGroupOverridesCheckMemberOf = getBoolean("vault-primary-groups-overrides.check-user-member-of", true);
vaultDebug = getBoolean("vault-debug", false);
worldRewrites = ImmutableMap.copyOf(getMap("world-rewrite", Collections.emptyMap()));
groupNameRewrites = ImmutableMap.copyOf(getMap("group-name-rewrite", Collections.emptyMap()));
ImmutableList.Builder<Rule> defs = ImmutableList.builder();
List<String> ruleNames = getObjectList("default-assignments", new ArrayList<>());
for (String ruleName : ruleNames) {
String hasTrue = getString("default-assignments." + ruleName + ".if.has-true", null);
String hasFalse = getString("default-assignments." + ruleName + ".if.has-false", null);
String lacks = getString("default-assignments." + ruleName + ".if.lacks", null);
List<String> give = getList("default-assignments." + ruleName + ".give", new ArrayList<>());
List<String> take = getList("default-assignments." + ruleName + ".take", new ArrayList<>());
String pg = getString("default-assignments." + ruleName + ".set-primary-group", null);
defs.add(new Rule(hasTrue, hasFalse, lacks, give, take, pg));
}
defaultAssignments = defs.build();
databaseValues = new DatastoreConfiguration(
getString("data.address", null),
getString("data.database", null),
getString("data.username", null),
getString("data.password", null),
getInt("data.pool-size", 10)
);
sqlTablePrefix = getString("data.table_prefix", "luckperms_");
storageMethod = getString("storage-method", defaultStorage);
splitStorage = getBoolean("split-storage.enabled", false);
splitStorageOptions = ImmutableMap.<String, String>builder()
.put("user", getString("split-storage.methods.user", defaultStorage))
.put("group", getString("split-storage.methods.group", defaultStorage))
.put("track", getString("split-storage.methods.track", defaultStorage))
.put("uuid", getString("split-storage.methods.uuid", defaultStorage))
.put("log", getString("split-storage.methods.log", defaultStorage))
.build();
redisEnabled = getBoolean("redis.enabled", false);
redisAddress = getString("redis.address", null);
redisPassword = getString("redis.password", "");
if (Patterns.NON_ALPHA_NUMERIC.matcher(getServer()).find()) {
plugin.getLog().severe("Server name defined in config.yml contains invalid characters. Server names can " +
"only contain alphanumeric characters.\nDefined server name '" + getServer() + "' will be replaced with '" +
defaultServerName + "' (the default)");
server = defaultServerName;
}
@Override
public void reload() {
init();
Set<ConfigKey<?>> keys = cache.asMap().keySet();
keys.forEach(cache::refresh);
}
}
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config;
public interface ConfigKey<T> {
T get(LPConfiguration config);
}
@@ -0,0 +1,162 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config;
import lombok.experimental.UtilityClass;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.config.keys.AbstractKey;
import me.lucko.luckperms.common.config.keys.BooleanKey;
import me.lucko.luckperms.common.config.keys.EnduringKey;
import me.lucko.luckperms.common.config.keys.IntegerKey;
import me.lucko.luckperms.common.config.keys.MapKey;
import me.lucko.luckperms.common.config.keys.StaticKey;
import me.lucko.luckperms.common.config.keys.StringKey;
import me.lucko.luckperms.common.defaults.Rule;
import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import me.lucko.luckperms.common.utils.ImmutableCollectors;
import java.util.List;
import java.util.Map;
@UtilityClass
public class ConfigKeys {
public static final ConfigKey<String> SERVER = StringKey.of("server", "global");
public static final ConfigKey<Integer> SYNC_TIME = EnduringKey.wrap(IntegerKey.of("data.sync-minutes", 3));
public static final ConfigKey<String> DEFAULT_GROUP_NODE = StaticKey.of("group.default"); // constant since 2.6
public static final ConfigKey<String> DEFAULT_GROUP_NAME = StaticKey.of("default"); // constant since 2.6
public static final ConfigKey<Boolean> INCLUDING_GLOBAL_PERMS = BooleanKey.of("include-global", true);
public static final ConfigKey<Boolean> INCLUDING_GLOBAL_WORLD_PERMS = BooleanKey.of("include-global-world", true);
public static final ConfigKey<Boolean> APPLYING_GLOBAL_GROUPS = BooleanKey.of("apply-global-groups", true);
public static final ConfigKey<Boolean> APPLYING_GLOBAL_WORLD_GROUPS = BooleanKey.of("apply-global-world-groups", true);
public static final ConfigKey<Boolean> ONLINE_MODE = BooleanKey.of("online-mode", true);
public static final ConfigKey<Boolean> APPLYING_WILDCARDS = EnduringKey.wrap(BooleanKey.of("apply-wildcards", true));
public static final ConfigKey<Boolean> APPLYING_REGEX = EnduringKey.wrap(BooleanKey.of("apply-regex", true));
public static final ConfigKey<Boolean> APPLYING_SHORTHAND = EnduringKey.wrap(BooleanKey.of("apply-shorthand", true));
public static final ConfigKey<Map<String, Integer>> GROUP_WEIGHTS = AbstractKey.of(c -> {
return c.getMap("group-weight", ImmutableMap.of()).entrySet().stream().collect(ImmutableCollectors.toImmutableMap(
e -> e.getKey().toLowerCase(),
e -> {
try {
return Integer.parseInt(e.getValue());
} catch (NumberFormatException ex) {
return 0;
}
})
);
});
public static final ConfigKey<Boolean> LOG_NOTIFY = BooleanKey.of("log-notify", true);
public static final ConfigKey<Boolean> AUTO_OP = EnduringKey.wrap(BooleanKey.of("auto-op", false));
public static final ConfigKey<Boolean> OPS_ENABLED = EnduringKey.wrap(AbstractKey.of(c -> !AUTO_OP.get(c) && c.getBoolean("enable-ops", true)));
public static final ConfigKey<Boolean> COMMANDS_ALLOW_OP = EnduringKey.wrap(BooleanKey.of("commands-allow-op", true));
public static final ConfigKey<String> VAULT_SERVER = StringKey.of("vault-server", "global");
public static final ConfigKey<Boolean> VAULT_INCLUDING_GLOBAL = BooleanKey.of("vault-include-global", true);
public static final ConfigKey<Boolean> VAULT_IGNORE_WORLD = BooleanKey.of("vault-ignore-world", false);
public static final ConfigKey<Boolean> VAULT_PRIMARY_GROUP_OVERRIDES = BooleanKey.of("vault-primary-groups-overrides.enabled", false);
public static final ConfigKey<Boolean> VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_INHERITED = BooleanKey.of("vault-primary-groups-overrides.check-inherited-permissions", false);
public static final ConfigKey<Boolean> VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_EXISTS = BooleanKey.of("vault-primary-groups-overrides.check-group-exists", true);
public static final ConfigKey<Boolean> VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF = BooleanKey.of("vault-primary-groups-overrides.check-user-member-of", true);
public static final ConfigKey<Boolean> VAULT_DEBUG = BooleanKey.of("vault-debug", false);
public static final ConfigKey<Map<String, String>> WORLD_REWRITES = MapKey.of("world-rewrite");
public static final ConfigKey<Map<String, String>> GROUP_NAME_REWRITES = MapKey.of("group-name-rewrite");
public static final ConfigKey<List<Rule>> DEFAULT_ASSIGNMENTS = AbstractKey.of(c -> {
return c.getObjectList("default-assignments", ImmutableList.of()).stream().map(name -> {
String hasTrue = c.getString("default-assignments." + name + ".if.has-true", null);
String hasFalse = c.getString("default-assignments." + name + ".if.has-false", null);
String lacks = c.getString("default-assignments." + name + ".if.lacks", null);
List<String> give = ImmutableList.copyOf(c.getList("default-assignments." + name + ".give", ImmutableList.of()));
List<String> take = ImmutableList.copyOf(c.getList("default-assignments." + name + ".take", ImmutableList.of()));
String pg = c.getString("default-assignments." + name + ".set-primary-group", null);
return new Rule(hasTrue, hasFalse, lacks, give, take, pg);
}).collect(ImmutableCollectors.toImmutableList());
});
public static final ConfigKey<DatastoreConfiguration> DATABASE_VALUES = EnduringKey.wrap(AbstractKey.of(c -> {
return new DatastoreConfiguration(
c.getString("data.address", null),
c.getString("data.database", null),
c.getString("data.username", null),
c.getString("data.password", null),
c.getInt("data.pool-size", 10)
);
}));
public static final ConfigKey<String> SQL_TABLE_PREFIX = EnduringKey.wrap(StringKey.of("data.table_prefix", "luckperms_"));
public static final ConfigKey<String> STORAGE_METHOD = EnduringKey.wrap(StringKey.of("storage-method", "h2"));
public static final ConfigKey<Boolean> SPLIT_STORAGE = EnduringKey.wrap(BooleanKey.of("split-storage.enabled", false));
public static final ConfigKey<Map<String, String>> SPLIT_STORAGE_OPTIONS = EnduringKey.wrap(AbstractKey.of(c -> {
return ImmutableMap.<String, String>builder()
.put("user", c.getString("split-storage.methods.user", "h2"))
.put("group", c.getString("split-storage.methods.group", "h2"))
.put("track", c.getString("split-storage.methods.track", "h2"))
.put("uuid", c.getString("split-storage.methods.uuid", "h2"))
.put("log", c.getString("split-storage.methods.log", "h2"))
.build();
}));
public static final ConfigKey<Boolean> REDIS_ENABLED = EnduringKey.wrap(BooleanKey.of("redis.enabled", false));
public static final ConfigKey<String> REDIS_ADDRESS = EnduringKey.wrap(StringKey.of("redis.address", null));
public static final ConfigKey<String> REDIS_PASSWORD = EnduringKey.wrap(StringKey.of("redis.password", ""));
public static List<ConfigKey<?>> getAllKeys() {
return ImmutableList.<ConfigKey<?>>builder()
.add(SERVER)
.add(SYNC_TIME)
.add(DEFAULT_GROUP_NODE)
.add(DEFAULT_GROUP_NAME)
.add(INCLUDING_GLOBAL_PERMS)
.add(INCLUDING_GLOBAL_WORLD_PERMS)
.add(APPLYING_GLOBAL_GROUPS)
.add(APPLYING_GLOBAL_WORLD_GROUPS)
.add(ONLINE_MODE)
.add(APPLYING_WILDCARDS)
.add(APPLYING_REGEX)
.add(APPLYING_SHORTHAND)
.add(GROUP_WEIGHTS)
.add(LOG_NOTIFY)
.add(AUTO_OP)
.add(OPS_ENABLED)
.add(COMMANDS_ALLOW_OP)
.add(VAULT_SERVER)
.add(VAULT_INCLUDING_GLOBAL)
.add(VAULT_IGNORE_WORLD)
.add(VAULT_PRIMARY_GROUP_OVERRIDES)
.add(VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_INHERITED)
.add(VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_EXISTS)
.add(VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF)
.add(VAULT_DEBUG)
.add(WORLD_REWRITES)
.add(GROUP_NAME_REWRITES)
.add(DEFAULT_ASSIGNMENTS)
.add(DATABASE_VALUES)
.add(SQL_TABLE_PREFIX)
.add(STORAGE_METHOD)
.add(SPLIT_STORAGE)
.add(SPLIT_STORAGE_OPTIONS)
.add(REDIS_ENABLED)
.add(REDIS_ADDRESS)
.add(REDIS_PASSWORD)
.build();
}
}
@@ -22,94 +22,29 @@
package me.lucko.luckperms.common.config;
import me.lucko.luckperms.common.defaults.Rule;
import me.lucko.luckperms.common.storage.DatastoreConfiguration;
import java.util.List;
import java.util.Map;
public interface LPConfiguration {
String getServer();
void init();
int getSyncTime();
void reload();
/**
* As of 2.6, this value is a constant
*
* @return the default group node
*/
String getDefaultGroupNode();
void loadAll();
/**
* As of 2.6, this value is a constant
*
* @return the name of the default group
*/
String getDefaultGroupName();
String getString(String path, String def);
boolean isIncludingGlobalPerms();
int getInt(String path, int def);
boolean isIncludingGlobalWorldPerms();
boolean getBoolean(String path, boolean def);
boolean isApplyingGlobalGroups();
List<String> getList(String path, List<String> def);
boolean isApplyingGlobalWorldGroups();
List<String> getObjectList(String path, List<String> def);
boolean isOnlineMode();
Map<String, String> getMap(String path, Map<String, String> def);
boolean isApplyingWildcards();
boolean isApplyingRegex();
boolean isApplyingShorthand();
Map<String, Integer> getGroupWeights();
boolean isLogNotify();
boolean isOpsEnabled();
boolean isCommandsAllowOp();
boolean isAutoOp();
String getVaultServer();
boolean isVaultIncludingGlobal();
boolean isVaultIgnoreWorld();
boolean isVaultPrimaryGroupOverrides();
boolean isVaultPrimaryGroupOverridesCheckInherited();
boolean isVaultPrimaryGroupOverridesCheckExists();
boolean isVaultPrimaryGroupOverridesCheckMemberOf();
boolean isVaultDebug();
Map<String, String> getWorldRewrites();
Map<String, String> getGroupNameRewrites();
List<Rule> getDefaultAssignments();
DatastoreConfiguration getDatabaseValues();
String getSqlTablePrefix();
String getStorageMethod();
boolean isSplitStorage();
Map<String, String> getSplitStorageOptions();
boolean isRedisEnabled();
String getRedisAddress();
String getRedisPassword();
<T> T get(ConfigKey<T> key);
}
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.LPConfiguration;
import java.util.function.Function;
@AllArgsConstructor(staticName = "of")
public class AbstractKey<T> implements ConfigKey<T> {
private final Function<LPConfiguration, T> function;
@Override
public T get(LPConfiguration config) {
return function.apply(config);
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.LPConfiguration;
@AllArgsConstructor(staticName = "of")
public class BooleanKey implements ConfigKey<Boolean> {
private final String path;
private final boolean def;
@Override
public Boolean get(LPConfiguration config) {
return config.getBoolean(path, def);
}
}
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import lombok.experimental.Delegate;
import me.lucko.luckperms.common.config.ConfigKey;
/**
* Wrapper class to mark a config key as enduring (doesn't change in the event of a reload)
* @param <T>
*/
@AllArgsConstructor(staticName = "wrap")
public class EnduringKey<T> implements ConfigKey<T> {
@Delegate
private final ConfigKey<T> delegate;
}
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.LPConfiguration;
@AllArgsConstructor(staticName = "of")
public class IntegerKey implements ConfigKey<Integer> {
private final String path;
private final int def;
@Override
public Integer get(LPConfiguration config) {
return config.getInt(path, def);
}
}
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import com.google.common.collect.ImmutableMap;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.LPConfiguration;
import java.util.Map;
@AllArgsConstructor(staticName = "of")
public class MapKey implements ConfigKey<Map<String, String>> {
private final String path;
@Override
public Map<String, String> get(LPConfiguration config) {
return ImmutableMap.copyOf(config.getMap(path, ImmutableMap.of()));
}
}
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.LPConfiguration;
@AllArgsConstructor(staticName = "of")
public class StaticKey<T> implements ConfigKey<T> {
private final T val;
@Override
public T get(LPConfiguration config) {
return val;
}
}
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package me.lucko.luckperms.common.config.keys;
import lombok.AllArgsConstructor;
import me.lucko.luckperms.common.config.ConfigKey;
import me.lucko.luckperms.common.config.LPConfiguration;
@AllArgsConstructor(staticName = "of")
public class StringKey implements ConfigKey<String> {
private final String path;
private final String def;
@Override
public String get(LPConfiguration config) {
return config.getString(path, def);
}
}
@@ -28,21 +28,23 @@ import com.google.common.collect.Maps;
import me.lucko.luckperms.api.context.ContextCalculator;
import me.lucko.luckperms.api.context.MutableContextSet;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.config.LPConfiguration;
import java.util.Map;
@AllArgsConstructor
public class ServerCalculator<T> extends ContextCalculator<T> {
private final String server;
private final LPConfiguration config;
@Override
public MutableContextSet giveApplicableContext(T subject, MutableContextSet accumulator) {
accumulator.add(Maps.immutableEntry("server", server));
accumulator.add(Maps.immutableEntry("server", config.get(ConfigKeys.SERVER)));
return accumulator;
}
@Override
public boolean isContextApplicable(T subject, Map.Entry<String, String> context) {
return context.getKey().equals("server") && server.equalsIgnoreCase(context.getValue());
return context.getKey().equals("server") && config.get(ConfigKeys.SERVER).equalsIgnoreCase(context.getValue());
}
}
@@ -22,52 +22,47 @@
package me.lucko.luckperms.common.core;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import java.util.UUID;
/**
* @see me.lucko.luckperms.api.UuidCache for docs
*/
@RequiredArgsConstructor
public class UuidCache {
private final LuckPermsPlugin plugin;
@Getter
private final boolean onlineMode;
// External UUID --> Internal UUID
private BiMap<UUID, UUID> cache;
public UuidCache(boolean onlineMode) {
this.onlineMode = onlineMode;
if (!onlineMode) {
cache = Maps.synchronizedBiMap(HashBiMap.create());
}
}
private final BiMap<UUID, UUID> cache = Maps.synchronizedBiMap(HashBiMap.create());
public UUID getUUID(UUID external) {
return onlineMode ? external : cache.getOrDefault(external, external);
return plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE) ? external : cache.getOrDefault(external, external);
}
public UUID getExternalUUID(UUID internal) {
return onlineMode ? internal : cache.inverse().getOrDefault(internal, internal);
return plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE) ? internal : cache.inverse().getOrDefault(internal, internal);
}
public void addToCache(UUID external, UUID internal) {
if (onlineMode) return;
if (plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE)) return;
cache.forcePut(external, internal);
}
public void clearCache(UUID external) {
if (onlineMode) return;
if (plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE)) return;
cache.remove(external);
}
public int getSize() {
return onlineMode ? 0 : cache.size();
return plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE) ? 0 : cache.size();
}
}
@@ -29,6 +29,7 @@ import lombok.ToString;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.caching.handlers.GroupReference;
import me.lucko.luckperms.common.caching.handlers.HolderReference;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.utils.Identifiable;
@ToString(of = {"name"})
@@ -52,7 +53,7 @@ public class Group extends PermissionHolder implements Identifiable<String> {
}
public String getRawDisplayName() {
return getPlugin().getConfiguration().getGroupNameRewrites().getOrDefault(name, name);
return getPlugin().getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(name, name);
}
public String getDisplayName() {
@@ -54,6 +54,7 @@ import me.lucko.luckperms.common.caching.handlers.HolderReference;
import me.lucko.luckperms.common.caching.holder.ExportNodesHolder;
import me.lucko.luckperms.common.caching.holder.GetAllNodesRequest;
import me.lucko.luckperms.common.commands.utils.Util;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.core.InheritanceInfo;
import me.lucko.luckperms.common.core.NodeBuilder;
import me.lucko.luckperms.common.core.NodeFactory;
@@ -281,8 +282,8 @@ public abstract class PermissionHolder {
.map(LocalizedNode::getNode)
.filter(Node::getValue)
.filter(Node::isGroupNode)
.filter(n -> n.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()))
.filter(n -> n.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()))
.filter(n -> n.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)))
.filter(n -> n.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)))
.filter(n -> n.shouldApplyWithContext(contexts.getContextSet(), false))
.collect(Collectors.toSet());
@@ -329,8 +330,8 @@ public abstract class PermissionHolder {
allNodes.removeIf(node ->
!node.isGroupNode() && (
!node.shouldApplyOnServer(server, context.isIncludeGlobal(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnServer(server, context.isIncludeGlobal(), plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ||
!node.shouldApplyOnWorld(world, context.isIncludeGlobalWorld(), plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ||
!node.shouldApplyWithContext(contexts.getContextSet(), false)
)
);
@@ -363,7 +364,7 @@ public abstract class PermissionHolder {
perms.put(lowerCase ? node.getPermission().toLowerCase() : node.getPermission(), node.getValue());
if (plugin.getConfiguration().isApplyingShorthand()) {
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_SHORTHAND)) {
List<String> sh = node.resolveShorthand();
if (!sh.isEmpty()) {
sh.stream().map(s -> lowerCase ? s.toLowerCase() : s)
@@ -499,8 +500,8 @@ public abstract class PermissionHolder {
.collect(Collectors.toSet());
parents.removeIf(node ->
!node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().isApplyingRegex()) ||
!node.shouldApplyOnServer(server, context.isApplyGlobalGroups(), plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ||
!node.shouldApplyOnWorld(world, context.isApplyGlobalWorldGroups(), plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) ||
!node.shouldApplyWithContext(contexts.getContextSet(), false)
);
@@ -1099,7 +1100,7 @@ public abstract class PermissionHolder {
} catch (Exception ignored) {}
if (!weight.isPresent()) {
Integer w = plugin.getConfiguration().getGroupWeights().get(getObjectName().toLowerCase());
Integer w = plugin.getConfiguration().get(ConfigKeys.GROUP_WEIGHTS).get(getObjectName().toLowerCase());
if (w != null) {
weight = OptionalInt.of(w);
}
@@ -25,6 +25,7 @@ package me.lucko.luckperms.common.data;
import me.lucko.luckperms.api.event.events.LogNotifyEvent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.sender.Sender;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.constants.Message;
import me.lucko.luckperms.common.constants.Permission;
import me.lucko.luckperms.common.core.model.Group;
@@ -51,7 +52,7 @@ public class LogEntry extends me.lucko.luckperms.api.LogEntry {
plugin.getStorage().logAction(this);
LogNotifyEvent event = new LogNotifyEvent(this);
event.setCancelled(!plugin.getConfiguration().isLogNotify());
event.setCancelled(!plugin.getConfiguration().get(ConfigKeys.LOG_NOTIFY));
plugin.getApiProvider().fireEvent(event);
if (event.isCancelled()) return;
@@ -30,6 +30,7 @@ import com.google.common.collect.Maps;
import me.lucko.luckperms.api.PlatformType;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.storage.StorageType;
import java.io.File;
@@ -73,7 +74,7 @@ public class DependencyManager {
dependencies.addAll(STORAGE_DEPENDENCIES.get(storageType));
}
if (plugin.getConfiguration().isRedisEnabled()) {
if (plugin.getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
dependencies.add(Dependency.APACHE_COMMONS_POOL);
dependencies.add(Dependency.JEDIS);
}
@@ -27,6 +27,7 @@ import lombok.experimental.UtilityClass;
import com.google.common.collect.ImmutableSet;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.storage.backing.AbstractBacking;
import me.lucko.luckperms.common.storage.backing.JSONBacking;
import me.lucko.luckperms.common.storage.backing.MongoDBBacking;
@@ -49,10 +50,10 @@ public class StorageFactory {
public static Set<StorageType> getRequiredTypes(LuckPermsPlugin plugin, StorageType defaultMethod) {
plugin.getLog().info("Detecting storage method...");
if (plugin.getConfiguration().isSplitStorage()) {
if (plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE)) {
plugin.getLog().info("Loading split storage options.");
Map<String, String> types = new HashMap<>(plugin.getConfiguration().getSplitStorageOptions());
Map<String, String> types = new HashMap<>(plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE_OPTIONS));
types.entrySet().stream()
.filter(e -> StorageType.parse(e.getValue()) == null)
.forEach(e -> {
@@ -66,7 +67,7 @@ public class StorageFactory {
return neededTypes.stream().map(StorageType::parse).collect(ImmutableCollectors.toImmutableSet());
} else {
String method = plugin.getConfiguration().getStorageMethod();
String method = plugin.getConfiguration().get(ConfigKeys.STORAGE_METHOD);
StorageType type = StorageType.parse(method);
if (type == null) {
plugin.getLog().severe("Storage method '" + method + "' not recognised. Using the default instead.");
@@ -80,10 +81,10 @@ public class StorageFactory {
Storage storage;
plugin.getLog().info("Initializing storage backings...");
if (plugin.getConfiguration().isSplitStorage()) {
if (plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE)) {
plugin.getLog().info("Using split storage.");
Map<String, String> types = new HashMap<>(plugin.getConfiguration().getSplitStorageOptions());
Map<String, String> types = new HashMap<>(plugin.getConfiguration().get(ConfigKeys.SPLIT_STORAGE_OPTIONS));
types.entrySet().stream()
.filter(e -> StorageType.parse(e.getValue()) == null)
.forEach(e -> e.setValue(defaultMethod.getIdentifiers().get(0)));
@@ -100,7 +101,7 @@ public class StorageFactory {
storage = AbstractStorage.wrap(plugin, new SplitBacking(plugin, backing, types));
} else {
String method = plugin.getConfiguration().getStorageMethod().toLowerCase();
String method = plugin.getConfiguration().get(ConfigKeys.STORAGE_METHOD);
StorageType type = StorageType.parse(method);
if (type == null) {
type = defaultMethod;
@@ -121,15 +122,15 @@ public class StorageFactory {
private static AbstractBacking makeBacking(StorageType method, LuckPermsPlugin plugin) {
switch (method) {
case MYSQL:
return new SQLBacking(plugin, new MySQLProvider(plugin.getConfiguration().getDatabaseValues()), plugin.getConfiguration().getSqlTablePrefix());
return new SQLBacking(plugin, new MySQLProvider(plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES)), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
case SQLITE:
return new SQLBacking(plugin, new SQLiteProvider(new File(plugin.getDataFolder(), "luckperms.sqlite")), plugin.getConfiguration().getSqlTablePrefix());
return new SQLBacking(plugin, new SQLiteProvider(new File(plugin.getDataFolder(), "luckperms.sqlite")), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
case H2:
return new SQLBacking(plugin, new H2Provider(new File(plugin.getDataFolder(), "luckperms.db")), plugin.getConfiguration().getSqlTablePrefix());
return new SQLBacking(plugin, new H2Provider(new File(plugin.getDataFolder(), "luckperms.db")), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
case POSTGRESQL:
return new SQLBacking(plugin, new PostgreSQLProvider(plugin.getConfiguration().getDatabaseValues()), plugin.getConfiguration().getSqlTablePrefix());
return new SQLBacking(plugin, new PostgreSQLProvider(plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES)), plugin.getConfiguration().get(ConfigKeys.SQL_TABLE_PREFIX));
case MONGODB:
return new MongoDBBacking(plugin, plugin.getConfiguration().getDatabaseValues());
return new MongoDBBacking(plugin, plugin.getConfiguration().get(ConfigKeys.DATABASE_VALUES));
case YAML:
return new YAMLBacking(plugin, plugin.getDataFolder());
default:
@@ -27,6 +27,7 @@ import lombok.AllArgsConstructor;
import me.lucko.luckperms.api.event.events.PostSyncEvent;
import me.lucko.luckperms.api.event.events.PreSyncEvent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
@AllArgsConstructor
public class UpdateTask implements Runnable {
@@ -43,7 +44,7 @@ public class UpdateTask implements Runnable {
// Reload all groups
plugin.getStorage().loadAllGroups().join();
String defaultGroup = plugin.getConfiguration().getDefaultGroupName();
String defaultGroup = plugin.getConfiguration().get(ConfigKeys.DEFAULT_GROUP_NAME);
if (!plugin.getGroupManager().isLoaded(defaultGroup)) {
plugin.getStorage().createAndLoadGroup(defaultGroup).join();
}
@@ -26,6 +26,7 @@ import lombok.AllArgsConstructor;
import me.lucko.luckperms.api.event.events.UserFirstLoginEvent;
import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.config.ConfigKeys;
import me.lucko.luckperms.common.core.UuidCache;
import me.lucko.luckperms.common.core.model.User;
import me.lucko.luckperms.common.defaults.Rule;
@@ -43,7 +44,7 @@ public class AbstractListener {
final long startTime = System.currentTimeMillis();
final UuidCache cache = plugin.getUuidCache();
if (!cache.isOnlineMode()) {
if (!plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE)) {
UUID uuid = plugin.getStorage().force().getUUID(username).join();
if (uuid != null) {
cache.addToCache(u, uuid);
@@ -70,7 +71,7 @@ public class AbstractListener {
} else {
// Setup defaults for the user
boolean save = false;
for (Rule rule : plugin.getConfiguration().getDefaultAssignments()) {
for (Rule rule : plugin.getConfiguration().get(ConfigKeys.DEFAULT_ASSIGNMENTS)) {
if (rule.apply(user)) {
save = true;
}