Refactor config handling - towards #100
This commit is contained in:
@@ -36,6 +36,7 @@ import me.lucko.luckperms.common.caching.handlers.CachedStateManager;
|
||||
import me.lucko.luckperms.common.calculators.CalculatorFactory;
|
||||
import me.lucko.luckperms.common.commands.BaseCommand;
|
||||
import me.lucko.luckperms.common.commands.sender.Sender;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.config.LPConfiguration;
|
||||
import me.lucko.luckperms.common.constants.Permission;
|
||||
import me.lucko.luckperms.common.contexts.ContextManager;
|
||||
@@ -172,6 +173,8 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
getLog().info("Loading configuration...");
|
||||
configuration = new SpongeConfig(this);
|
||||
configuration.init();
|
||||
configuration.loadAll();
|
||||
|
||||
Set<StorageType> storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2);
|
||||
DependencyManager.loadDependencies(this, storageTypes);
|
||||
@@ -183,11 +186,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
storage = StorageFactory.getInstance(this, StorageType.H2);
|
||||
|
||||
// initialise redis
|
||||
if (getConfiguration().isRedisEnabled()) {
|
||||
if (getConfiguration().get(ConfigKeys.REDIS_ENABLED)) {
|
||||
getLog().info("Loading redis...");
|
||||
redisMessaging = new RedisMessaging(this);
|
||||
try {
|
||||
redisMessaging.init(getConfiguration().getRedisAddress(), getConfiguration().getRedisPassword());
|
||||
redisMessaging.init(getConfiguration().get(ConfigKeys.REDIS_ADDRESS), getConfiguration().get(ConfigKeys.REDIS_PASSWORD));
|
||||
getLog().info("Loaded redis successfully...");
|
||||
} catch (Exception e) {
|
||||
getLog().info("Couldn't load redis...");
|
||||
@@ -225,7 +228,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
|
||||
// load internal managers
|
||||
getLog().info("Loading internal permission managers...");
|
||||
uuidCache = new UuidCache(getConfiguration().isOnlineMode());
|
||||
uuidCache = new UuidCache(this);
|
||||
userManager = new SpongeUserManager(this);
|
||||
groupManager = new SpongeGroupManager(this);
|
||||
trackManager = new GenericTrackManager();
|
||||
@@ -234,7 +237,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
cachedStateManager = new CachedStateManager(this);
|
||||
|
||||
contextManager = new ContextManager<>();
|
||||
contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer()));
|
||||
contextManager.registerCalculator(new ServerCalculator<>(configuration));
|
||||
contextManager.registerCalculator(new WorldCalculator(this));
|
||||
|
||||
// register the PermissionService with Sponge
|
||||
@@ -256,7 +259,7 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
game.getServiceManager().setProvider(this, LuckPermsApi.class, apiProvider);
|
||||
|
||||
// schedule update tasks
|
||||
int mins = getConfiguration().getSyncTime();
|
||||
int mins = getConfiguration().get(ConfigKeys.SYNC_TIME);
|
||||
if (mins > 0) {
|
||||
Task t = scheduler.createTaskBuilder().async().interval(mins, TimeUnit.MINUTES).execute(new UpdateTask(this))
|
||||
.submit(LPSpongePlugin.this);
|
||||
@@ -367,11 +370,11 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
||||
}
|
||||
return new Contexts(
|
||||
getContextManager().getApplicableContext(player),
|
||||
getConfiguration().isIncludingGlobalPerms(),
|
||||
getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
getConfiguration().isApplyingGlobalGroups(),
|
||||
getConfiguration().isApplyingGlobalWorldGroups(),
|
||||
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import me.lucko.luckperms.common.calculators.PermissionProcessor;
|
||||
import me.lucko.luckperms.common.calculators.processors.MapProcessor;
|
||||
import me.lucko.luckperms.common.calculators.processors.RegexProcessor;
|
||||
import me.lucko.luckperms.common.calculators.processors.WildcardProcessor;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.sponge.calculators.DefaultsProcessor;
|
||||
import me.lucko.luckperms.sponge.calculators.SpongeWildcardProcessor;
|
||||
@@ -45,11 +46,11 @@ public class SpongeCalculatorFactory extends AbstractCalculatorFactory {
|
||||
public PermissionCalculator build(Contexts contexts, User user) {
|
||||
ImmutableList.Builder<PermissionProcessor> processors = ImmutableList.builder();
|
||||
processors.add(new MapProcessor());
|
||||
if (plugin.getConfiguration().isApplyingWildcards()) {
|
||||
processors.add(new SpongeWildcardProcessor());
|
||||
processors.add(new SpongeWildcardProcessor());
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_WILDCARDS)) {
|
||||
processors.add(new WildcardProcessor());
|
||||
}
|
||||
if (plugin.getConfiguration().isApplyingRegex()) {
|
||||
if (plugin.getConfiguration().get(ConfigKeys.APPLYING_REGEX)) {
|
||||
processors.add(new RegexProcessor());
|
||||
}
|
||||
processors.add(new DefaultsProcessor(plugin.getService(), contexts.getContexts()));
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
package me.lucko.luckperms.sponge;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
|
||||
import me.lucko.luckperms.common.config.AbstractConfiguration;
|
||||
@@ -41,20 +43,18 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
|
||||
@RequiredArgsConstructor
|
||||
public class SpongeConfig extends AbstractConfiguration {
|
||||
private final LPSpongePlugin plugin;
|
||||
private ConfigurationNode root;
|
||||
|
||||
SpongeConfig(LPSpongePlugin plugin) {
|
||||
super(plugin, "global", true, "sqlite");
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
private Path makeFile(Path file) throws IOException {
|
||||
File cfg = file.toFile();
|
||||
cfg.getParentFile().mkdirs();
|
||||
|
||||
if (!cfg.exists()) {
|
||||
try (InputStream is = getPlugin().getClass().getClassLoader().getResourceAsStream("luckperms.conf")) {
|
||||
try (InputStream is = plugin.getClass().getClassLoader().getResourceAsStream("luckperms.conf")) {
|
||||
Files.copy(is, cfg.toPath());
|
||||
}
|
||||
}
|
||||
@@ -63,10 +63,10 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
public void init() {
|
||||
try {
|
||||
ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder()
|
||||
.setPath(makeFile(getPlugin().getConfigDir().resolve("luckperms.conf")))
|
||||
.setPath(makeFile(plugin.getConfigDir().resolve("luckperms.conf")))
|
||||
.build();
|
||||
|
||||
root = loader.load();
|
||||
@@ -87,22 +87,22 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getString(String path, String def) {
|
||||
public String getString(String path, String def) {
|
||||
return getNode(path).getString(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInt(String path, int def) {
|
||||
public int getInt(String path, int def) {
|
||||
return getNode(path).getInt(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean getBoolean(String path, boolean def) {
|
||||
public boolean getBoolean(String path, boolean def) {
|
||||
return getNode(path).getBoolean(def);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getList(String path, List<String> def) {
|
||||
public List<String> getList(String path, List<String> def) {
|
||||
ConfigurationNode node = getNode(path);
|
||||
if (node.isVirtual()) {
|
||||
return def;
|
||||
@@ -112,7 +112,7 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getObjectList(String path, List<String> def) {
|
||||
public List<String> getObjectList(String path, List<String> def) {
|
||||
ConfigurationNode node = getNode(path);
|
||||
if (node.isVirtual()) {
|
||||
return def;
|
||||
@@ -123,7 +123,7 @@ class SpongeConfig extends AbstractConfiguration<LPSpongePlugin> {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
public Map<String, String> getMap(String path, Map<String, String> def) {
|
||||
ConfigurationNode node = getNode(path);
|
||||
if (node.isVirtual()) {
|
||||
return def;
|
||||
|
||||
@@ -45,6 +45,7 @@ import me.lucko.luckperms.api.Tristate;
|
||||
import me.lucko.luckperms.api.context.ContextSet;
|
||||
import me.lucko.luckperms.api.context.ImmutableContextSet;
|
||||
import me.lucko.luckperms.common.caching.UserCache;
|
||||
import me.lucko.luckperms.common.config.ConfigKeys;
|
||||
import me.lucko.luckperms.common.core.model.Group;
|
||||
import me.lucko.luckperms.common.core.model.User;
|
||||
import me.lucko.luckperms.common.utils.ImmutableCollectors;
|
||||
@@ -255,11 +256,11 @@ public class LuckPermsService implements PermissionService {
|
||||
public Contexts calculateContexts(ContextSet contextSet) {
|
||||
return new Contexts(
|
||||
contextSet,
|
||||
plugin.getConfiguration().isIncludingGlobalPerms(),
|
||||
plugin.getConfiguration().isIncludingGlobalWorldPerms(),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS),
|
||||
plugin.getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS),
|
||||
true,
|
||||
plugin.getConfiguration().isApplyingGlobalGroups(),
|
||||
plugin.getConfiguration().isApplyingGlobalWorldGroups(),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS),
|
||||
plugin.getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user