diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java index 195ed1f4a..3e412d14b 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitCalculatorFactory.java @@ -38,6 +38,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 java.util.UUID; @@ -57,10 +58,10 @@ public class BukkitCalculatorFactory extends AbstractCalculatorFactory { LPPermissible permissible = Injector.getPermissible(uuid); return permissible == null ? null : permissible.getAttachmentPermissions(); })); - if (plugin.getConfiguration().isApplyingWildcards()) { + 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(contexts.isOp(), plugin.getDefaultsProvider())); diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java index 139b8dac2..7fc560d10 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfig.java @@ -22,6 +22,8 @@ package me.lucko.luckperms.bukkit; +import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.common.config.AbstractConfiguration; import org.bukkit.configuration.ConfigurationSection; @@ -34,48 +36,45 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -class BukkitConfig extends AbstractConfiguration { +@RequiredArgsConstructor +public class BukkitConfig extends AbstractConfiguration { + private final LPBukkitPlugin plugin; private YamlConfiguration configuration; - BukkitConfig(LPBukkitPlugin plugin) { - super(plugin, "global", true, "sqlite"); - } - - @SuppressWarnings("ResultOfMethodCallIgnored") @Override - protected void init() { - File configFile = new File(getPlugin().getDataFolder(), "config.yml"); + public void init() { + File configFile = new File(plugin.getDataFolder(), "config.yml"); if (!configFile.exists()) { configFile.getParentFile().mkdirs(); - getPlugin().saveResource("config.yml", false); + plugin.saveResource("config.yml", false); } configuration = YamlConfiguration.loadConfiguration(configFile); } @Override - protected String getString(String path, String def) { + public String getString(String path, String def) { return configuration.getString(path, def); } @Override - protected int getInt(String path, int def) { + public int getInt(String path, int def) { return configuration.getInt(path, def); } @Override - protected boolean getBoolean(String path, boolean def) { + public boolean getBoolean(String path, boolean def) { return configuration.getBoolean(path, def); } @Override - protected List getList(String path, List def) { + public List getList(String path, List def) { return Optional.ofNullable(configuration.getStringList(path)).orElse(def); } @Override - protected List getObjectList(String path, List def) { + public List getObjectList(String path, List def) { ConfigurationSection section = configuration.getConfigurationSection(path); if (section == null) { return def; @@ -84,9 +83,8 @@ class BukkitConfig extends AbstractConfiguration { return Optional.ofNullable(section.getKeys(false).stream().collect(Collectors.toList())).orElse(def); } - @SuppressWarnings("unchecked") @Override - protected Map getMap(String path, Map def) { + public Map getMap(String path, Map def) { Map map = new HashMap<>(); ConfigurationSection section = configuration.getConfigurationSection(path); if (section == null) { diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java index dd0c9fd4b..286a92b69 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitListener.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.bukkit; import me.lucko.luckperms.bukkit.inject.Injector; import me.lucko.luckperms.bukkit.model.LPPermissible; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.core.model.User; import me.lucko.luckperms.common.utils.AbstractListener; @@ -149,7 +150,7 @@ class BukkitListener extends AbstractListener implements Listener { Injector.unInject(player, true, true); // Handle auto op - if (plugin.getConfiguration().isAutoOp()) { + if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) { player.setOp(false); } @@ -159,7 +160,7 @@ class BukkitListener extends AbstractListener implements Listener { @EventHandler public void onPlayerCommand(PlayerCommandPreprocessEvent e) { - if (plugin.getConfiguration().isOpsEnabled()) { + if (plugin.getConfiguration().get(ConfigKeys.AUTO_OP)) { return; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java index acba07e7b..448fbc627 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java @@ -43,6 +43,7 @@ import me.lucko.luckperms.common.api.ApiProvider; import me.lucko.luckperms.common.caching.handlers.CachedStateManager; import me.lucko.luckperms.common.calculators.CalculatorFactory; 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; @@ -153,6 +154,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { getLog().info("Loading configuration..."); configuration = new BukkitConfig(this); + configuration.init(); + configuration.loadAll(); Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); DependencyManager.loadDependencies(this, storageTypes); @@ -195,11 +198,11 @@ public class LPBukkitPlugin extends JavaPlugin 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..."); @@ -238,7 +241,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { // load internal managers getLog().info("Loading internal permission managers..."); - uuidCache = new UuidCache(getConfiguration().isOnlineMode()); + uuidCache = new UuidCache(this); userManager = new GenericUserManager(this); groupManager = new GenericGroupManager(this); trackManager = new GenericTrackManager(); @@ -250,7 +253,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { worldCalculator = new WorldCalculator(this); pm.registerEvents(worldCalculator, this); contextManager.registerCalculator(worldCalculator); - contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer())); + contextManager.registerCalculator(new ServerCalculator<>(getConfiguration())); // Provide vault support tryVaultHook(false); @@ -263,7 +266,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { // schedule update tasks - int mins = getConfiguration().getSyncTime(); + int mins = getConfiguration().get(ConfigKeys.SYNC_TIME); if (mins > 0) { long ticks = mins * 60 * 20; getServer().getScheduler().runTaskTimerAsynchronously(this, () -> updateTaskBuffer.request(), 40L, ticks); @@ -277,8 +280,8 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { getServer().getScheduler().runTaskTimerAsynchronously(this, new CacheHousekeepingTask(this), 2400L, 2400L); // register permissions - registerPermissions(getConfiguration().isCommandsAllowOp() ? PermissionDefault.OP : PermissionDefault.FALSE); - if (!getConfiguration().isOpsEnabled()) { + registerPermissions(getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE); + if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) { getServer().getScheduler().runTask(this, () -> getServer().getOperators().forEach(o -> o.setOp(false))); } @@ -324,7 +327,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { for (Player player : getServer().getOnlinePlayers()) { Injector.unInject(player, false, false); - if (getConfiguration().isAutoOp()) { + if (getConfiguration().get(ConfigKeys.AUTO_OP)) { player.setOp(false); } @@ -420,7 +423,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { } public void refreshAutoOp(Player player) { - if (getConfiguration().isAutoOp()) { + if (getConfiguration().get(ConfigKeys.AUTO_OP)) { try { LPPermissible permissible = Injector.getPermissible(player.getUniqueId()); if (permissible == null) { @@ -492,11 +495,11 @@ public class LPBukkitPlugin extends JavaPlugin 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), player.isOp() ); } @@ -537,14 +540,14 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { public Set getPreProcessContexts(boolean op) { Set c = new HashSet<>(); c.add(ContextSet.empty()); - c.add(ContextSet.singleton("server", getConfiguration().getServer())); + c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.SERVER))); // Pre process all worlds c.addAll(getServer().getWorlds().stream() .map(World::getName) .map(s -> { MutableContextSet set = MutableContextSet.create(); - set.add("server", getConfiguration().getServer()); + set.add("server", getConfiguration().get(ConfigKeys.SERVER)); set.add("world", s); return set.makeImmutable(); }) @@ -552,13 +555,13 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { ); // Pre process the separate Vault server, if any - if (!getConfiguration().getServer().equals(getConfiguration().getVaultServer())) { - c.add(ContextSet.singleton("server", getConfiguration().getVaultServer())); + if (!getConfiguration().get(ConfigKeys.SERVER).equals(getConfiguration().get(ConfigKeys.VAULT_SERVER))) { + c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.VAULT_SERVER))); c.addAll(getServer().getWorlds().stream() .map(World::getName) .map(s -> { MutableContextSet set = MutableContextSet.create(); - set.add("server", getConfiguration().getVaultServer()); + set.add("server", getConfiguration().get(ConfigKeys.VAULT_SERVER)); set.add("world", s); return set.makeImmutable(); }) @@ -572,25 +575,25 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { contexts.addAll(c.stream() .map(set -> new Contexts( set, - 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), op )) .collect(Collectors.toSet()) ); // Check for and include varying Vault config options - boolean vaultDiff = getConfiguration().isVaultIncludingGlobal() != getConfiguration().isIncludingGlobalPerms() || - !getConfiguration().isIncludingGlobalWorldPerms() || - !getConfiguration().isApplyingGlobalGroups() || - !getConfiguration().isApplyingGlobalWorldGroups(); + boolean vaultDiff = getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL) != getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_PERMS) || + !getConfiguration().get(ConfigKeys.INCLUDING_GLOBAL_WORLD_PERMS) || + !getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_GROUPS) || + !getConfiguration().get(ConfigKeys.APPLYING_GLOBAL_WORLD_GROUPS); if (vaultDiff) { contexts.addAll(c.stream() - .map(map -> new Contexts(map, getConfiguration().isVaultIncludingGlobal(), true, true, true, true, op)) + .map(map -> new Contexts(map, getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL), true, true, true, true, op)) .collect(Collectors.toSet()) ); } @@ -602,16 +605,16 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin { public LinkedHashMap getExtraInfo() { LinkedHashMap map = new LinkedHashMap<>(); map.put("Vault Enabled", vaultHook != null); - map.put("Vault Server", configuration.getVaultServer()); + map.put("Vault Server", configuration.get(ConfigKeys.VAULT_SERVER)); map.put("Bukkit Defaults count", defaultsProvider.size()); map.put("Bukkit Child Permissions count", childPermissionProvider.getPermissions().size()); - map.put("Vault Including Global", configuration.isVaultIncludingGlobal()); - map.put("Vault Ignoring World", configuration.isVaultIgnoreWorld()); - map.put("Vault Primary Group Overrides", configuration.isVaultPrimaryGroupOverrides()); - map.put("Vault Debug", configuration.isVaultDebug()); - map.put("OPs Enabled", configuration.isOpsEnabled()); - map.put("Auto OP", configuration.isAutoOp()); - map.put("Commands Allow OPs", configuration.isCommandsAllowOp()); + map.put("Vault Including Global", configuration.get(ConfigKeys.VAULT_INCLUDING_GLOBAL)); + map.put("Vault Ignoring World", configuration.get(ConfigKeys.VAULT_IGNORE_WORLD)); + map.put("Vault Primary Group Overrides", configuration.get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES)); + map.put("Vault Debug", configuration.get(ConfigKeys.VAULT_DEBUG)); + map.put("OPs Enabled", configuration.get(ConfigKeys.OPS_ENABLED)); + map.put("Auto OP", configuration.get(ConfigKeys.AUTO_OP)); + map.put("Commands Allow OPs", configuration.get(ConfigKeys.COMMANDS_ALLOW_OP)); return map; } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java index a6cd9aec6..e76d5fd24 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/WorldCalculator.java @@ -29,6 +29,7 @@ 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.LuckPermsPlugin; +import me.lucko.luckperms.common.config.ConfigKeys; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -64,6 +65,6 @@ public class WorldCalculator extends ContextCalculator implements Listen private String getWorld(Player player) { String world = player.getWorld().getName(); - return plugin.getConfiguration().getWorldRewrites().getOrDefault(world, world); + return plugin.getConfiguration().get(ConfigKeys.WORLD_REWRITES).getOrDefault(world, world); } } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java index 4beb0606c..544c1239c 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/model/LPPermissible.java @@ -29,6 +29,7 @@ import lombok.Setter; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.bukkit.LPBukkitPlugin; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.core.model.User; import org.bukkit.Bukkit; @@ -120,11 +121,11 @@ public class LPPermissible extends PermissibleBase { public Contexts calculateContexts() { return new Contexts( plugin.getContextManager().getApplicableContext(parent), - 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), parent.isOp() ); } diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java index 28cd7395f..9cf313b40 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/vault/VaultPermissionHook.java @@ -32,6 +32,7 @@ import me.lucko.luckperms.api.Tristate; import me.lucko.luckperms.api.caching.PermissionData; import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.bukkit.LPBukkitPlugin; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.core.model.Group; import me.lucko.luckperms.common.core.model.PermissionHolder; import me.lucko.luckperms.common.core.model.User; @@ -56,34 +57,17 @@ public class VaultPermissionHook extends Permission { private final String name = "LuckPerms"; - private String server = "global"; - private boolean includeGlobal = true; - private boolean ignoreWorld = false; - private boolean pgo = false; - private boolean pgoCheckInherited = false; - private boolean pgoCheckExists = true; - private boolean pgoCheckMemberOf = true; - - private Function WORLD_CORRECTION_FUNCTION = s -> ignoreWorld ? null : s; + private Function WORLD_CORRECTION_FUNCTION = s -> isIgnoreWorld() ? null : s; public VaultPermissionHook(LPBukkitPlugin plugin) { this.plugin = plugin; this.scheduler = new VaultScheduler(plugin); super.plugin = plugin; - - // Config options - this.server = plugin.getConfiguration().getVaultServer(); - this.includeGlobal = plugin.getConfiguration().isVaultIncludingGlobal(); - this.ignoreWorld = plugin.getConfiguration().isVaultIgnoreWorld(); - this.pgo = plugin.getConfiguration().isVaultPrimaryGroupOverrides(); - this.pgoCheckInherited = plugin.getConfiguration().isVaultPrimaryGroupOverridesCheckInherited(); - this.pgoCheckExists = plugin.getConfiguration().isVaultPrimaryGroupOverridesCheckExists(); - this.pgoCheckMemberOf = plugin.getConfiguration().isVaultPrimaryGroupOverridesCheckMemberOf(); } public void log(String s) { - if (plugin.getConfiguration().isVaultDebug()) { + if (plugin.getConfiguration().get(ConfigKeys.VAULT_DEBUG)) { plugin.getLog().info("[VAULT] " + s); } } @@ -109,9 +93,9 @@ public class VaultPermissionHook extends Permission { return CompletableFuture.runAsync(() -> { try { if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) { - holder.setPermission(permission, true, server, world); + holder.setPermission(permission, true, getServer(), world); } else { - holder.setPermission(permission, true, server); + holder.setPermission(permission, true, getServer()); } save(holder); @@ -130,9 +114,9 @@ public class VaultPermissionHook extends Permission { return CompletableFuture.runAsync(() -> { try { if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) { - holder.unsetPermission(permission, server, world); + holder.unsetPermission(permission, getServer(), world); } else { - holder.unsetPermission(permission, server); + holder.unsetPermission(permission, getServer()); } save(holder); @@ -161,14 +145,14 @@ public class VaultPermissionHook extends Permission { if (world != null && !world.equals("")) { context.put("world", world); } - context.put("server", server); + context.put("server", getServer()); return new Contexts(ContextSet.fromMap(context), isIncludeGlobal(), true, true, true, true, false); } @Override public boolean playerHas(String world, @NonNull String player, @NonNull String permission) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Checking if player " + player + " has permission: " + permission + " on world " + world + ", server " + server); + log("Checking if player " + player + " has permission: " + permission + " on world " + world + ", server " + getServer()); User user = plugin.getUserManager().getByUsername(player); if (user == null) return false; @@ -184,7 +168,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean playerAdd(String world, @NonNull String player, @NonNull String permission) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Adding permission to player " + player + ": '" + permission + "' on world " + world + ", server " + server); + log("Adding permission to player " + player + ": '" + permission + "' on world " + world + ", server " + getServer()); final User user = plugin.getUserManager().getByUsername(player); if (user == null) return false; @@ -196,7 +180,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean playerRemove(String world, @NonNull String player, @NonNull String permission) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Removing permission from player " + player + ": '" + permission + "' on world " + world + ", server " + server); + log("Removing permission from player " + player + ": '" + permission + "' on world " + world + ", server " + getServer()); final User user = plugin.getUserManager().getByUsername(player); if (user == null) return false; @@ -208,7 +192,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean groupHas(String world, @NonNull String groupName, @NonNull String permission) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Checking if group " + groupName + " has permission: " + permission + " on world " + world + ", server " + server); + log("Checking if group " + groupName + " has permission: " + permission + " on world " + world + ", server " + getServer()); final Group group = plugin.getGroupManager().getIfLoaded(groupName); if (group == null) return false; @@ -221,7 +205,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean groupAdd(String world, @NonNull String groupName, @NonNull String permission) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Adding permission to group " + groupName + ": '" + permission + "' on world " + world + ", server " + server); + log("Adding permission to group " + groupName + ": '" + permission + "' on world " + world + ", server " + getServer()); final Group group = plugin.getGroupManager().getIfLoaded(groupName); if (group == null) return false; @@ -233,7 +217,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean groupRemove(String world, @NonNull String groupName, @NonNull String permission) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Removing permission from group " + groupName + ": '" + permission + "' on world " + world + ", server " + server); + log("Removing permission from group " + groupName + ": '" + permission + "' on world " + world + ", server " + getServer()); final Group group = plugin.getGroupManager().getIfLoaded(groupName); if (group == null) return false; @@ -245,7 +229,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean playerInGroup(String world, @NonNull String player, @NonNull String group) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Checking if player " + player + " is in group: " + group + " on world " + world + ", server " + server); + log("Checking if player " + player + " is in group: " + group + " on world " + world + ", server " + getServer()); final User user = plugin.getUserManager().getByUsername(player); if (user == null) return false; @@ -253,7 +237,7 @@ public class VaultPermissionHook extends Permission { String w = world; // screw effectively final return user.getNodes().stream() .filter(Node::isGroupNode) - .filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false)) + .filter(n -> n.shouldApplyOnServer(getServer(), isIncludeGlobal(), false)) .filter(n -> n.shouldApplyOnWorld(w, true, false)) .map(Node::getGroupName) .anyMatch(s -> s.equalsIgnoreCase(group)); @@ -262,7 +246,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean playerAddGroup(String world, @NonNull String player, @NonNull String groupName) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Adding player " + player + " to group: '" + groupName + "' on world " + world + ", server " + server); + log("Adding player " + player + " to group: '" + groupName + "' on world " + world + ", server " + getServer()); final User user = plugin.getUserManager().getByUsername(player); if (user == null) return false; @@ -274,9 +258,9 @@ public class VaultPermissionHook extends Permission { scheduler.execute(() -> { try { if (w != null && !w.equals("") && !w.equalsIgnoreCase("global")) { - user.setInheritGroup(group, server, w); + user.setInheritGroup(group, getServer(), w); } else { - user.setInheritGroup(group, server); + user.setInheritGroup(group, getServer()); } save(user); @@ -288,7 +272,7 @@ public class VaultPermissionHook extends Permission { @Override public boolean playerRemoveGroup(String world, @NonNull String player, @NonNull String groupName) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Removing player " + player + " from group: '" + groupName + "' on world " + world + ", server " + server); + log("Removing player " + player + " from group: '" + groupName + "' on world " + world + ", server " + getServer()); final User user = plugin.getUserManager().getByUsername(player); if (user == null) return false; @@ -300,9 +284,9 @@ public class VaultPermissionHook extends Permission { scheduler.execute(() -> { try { if (w != null && !w.equals("") && !w.equalsIgnoreCase("global")) { - user.unsetInheritGroup(group, server, w); + user.unsetInheritGroup(group, getServer(), w); } else { - user.unsetInheritGroup(group, server); + user.unsetInheritGroup(group, getServer()); } save(user); @@ -314,7 +298,7 @@ public class VaultPermissionHook extends Permission { @Override public String[] getPlayerGroups(String world, @NonNull String player) { world = WORLD_CORRECTION_FUNCTION.apply(world); - log("Getting groups of player: " + player + ", on world " + world + ", server " + server); + log("Getting groups of player: " + player + ", on world " + world + ", server " + getServer()); User user = plugin.getUserManager().getByUsername(player); if (user == null) return new String[0]; @@ -322,7 +306,7 @@ public class VaultPermissionHook extends Permission { String w = world; // screw effectively final return user.getNodes().stream() .filter(Node::isGroupNode) - .filter(n -> n.shouldApplyOnServer(server, isIncludeGlobal(), false)) + .filter(n -> n.shouldApplyOnServer(getServer(), isIncludeGlobal(), false)) .filter(n -> n.shouldApplyOnWorld(w, true, false)) .map(Node::getGroupName) .toArray(String[]::new); @@ -338,12 +322,12 @@ public class VaultPermissionHook extends Permission { return null; } - if (!pgo) { + if (!isPgo()) { String g = user.getPrimaryGroup(); - return plugin.getConfiguration().getGroupNameRewrites().getOrDefault(g, g); + return plugin.getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(g, g); } - if (pgoCheckInherited) { + if (isPgoCheckInherited()) { PermissionData data = user.getUserData().getPermissionData(createContextForWorld(world)); for (Map.Entry e : data.getImmutableBacking().entrySet()) { if (!e.getValue()) { @@ -355,13 +339,13 @@ public class VaultPermissionHook extends Permission { } String group = e.getKey().substring("vault.primarygroup.".length()); - if (pgoCheckExists) { + if (isPgoCheckExists()) { if (!plugin.getGroupManager().isLoaded(group)) { continue; } } - if (pgoCheckMemberOf) { + if (isPgoCheckMemberOf()) { if (data.getPermissionValue("group." + group) != Tristate.TRUE) { continue; } @@ -379,7 +363,7 @@ public class VaultPermissionHook extends Permission { continue; } - if (!node.shouldApplyOnServer(server, isIncludeGlobal(), false)) { + if (!node.shouldApplyOnServer(getServer(), isIncludeGlobal(), false)) { continue; } @@ -388,14 +372,14 @@ public class VaultPermissionHook extends Permission { } String group = node.getPermission().substring("vault.primarygroup.".length()); - if (pgoCheckExists) { + if (isPgoCheckExists()) { if (!plugin.getGroupManager().isLoaded(group)) { continue; } } - if (pgoCheckMemberOf) { - if (!user.getLocalGroups(server, world, isIncludeGlobal()).contains(group.toLowerCase())) { + if (isPgoCheckMemberOf()) { + if (!user.getLocalGroups(getServer(), world, isIncludeGlobal()).contains(group.toLowerCase())) { continue; } } @@ -406,7 +390,7 @@ public class VaultPermissionHook extends Permission { // Fallback String g = user.getPrimaryGroup(); - return plugin.getConfiguration().getGroupNameRewrites().getOrDefault(g, g); + return plugin.getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(g, g); } @Override @@ -418,4 +402,32 @@ public class VaultPermissionHook extends Permission { public boolean hasGroupSupport() { return true; } + + public String getServer() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_SERVER); + } + + public boolean isIncludeGlobal() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_INCLUDING_GLOBAL); + } + + public boolean isIgnoreWorld() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_IGNORE_WORLD); + } + + public boolean isPgo() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES); + } + + public boolean isPgoCheckInherited() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_INHERITED); + } + + public boolean isPgoCheckExists() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_EXISTS); + } + + public boolean isPgoCheckMemberOf() { + return plugin.getConfiguration().get(ConfigKeys.VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF); + } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java index 224b1c69f..3b554a52c 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCalculatorFactory.java @@ -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; @AllArgsConstructor @@ -43,10 +44,10 @@ public class BungeeCalculatorFactory extends AbstractCalculatorFactory { public PermissionCalculator build(Contexts contexts, User user) { ImmutableList.Builder processors = ImmutableList.builder(); processors.add(new MapProcessor()); - if (plugin.getConfiguration().isApplyingWildcards()) { + 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()); } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java index 64be1be99..c5dd11d2d 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeCommand.java @@ -40,7 +40,7 @@ class BungeeCommand extends Command implements TabExecutor { private final CommandManager manager; BungeeCommand(LPBungeePlugin plugin, CommandManager manager) { - super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bp", "bperm"); + super("luckpermsbungee", null, "bperms", "lpb", "bpermissions", "bperm"); this.plugin = plugin; this.manager = manager; } @@ -49,7 +49,7 @@ class BungeeCommand extends Command implements TabExecutor { public void execute(CommandSender sender, String[] args) { manager.onCommand( plugin.getSenderFactory().wrap(sender), - "bperms", + "lpb", Util.stripQuotes(Splitter.on(Patterns.COMMAND_SEPARATOR).omitEmptyStrings().splitToList(Joiner.on(' ').join(args))) ); } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java index 11fd5ddf1..ebb1b2ca5 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfig.java @@ -22,6 +22,8 @@ package me.lucko.luckperms.bungee; +import lombok.RequiredArgsConstructor; + import me.lucko.luckperms.common.config.AbstractConfiguration; import net.md_5.bungee.config.Configuration; @@ -38,20 +40,18 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -class BungeeConfig extends AbstractConfiguration { +@RequiredArgsConstructor +public class BungeeConfig extends AbstractConfiguration { + private final LPBungeePlugin plugin; private Configuration configuration; - BungeeConfig(LPBungeePlugin plugin) { - super(plugin, "bungee", false, "flatfile"); - } - @SuppressWarnings("ResultOfMethodCallIgnored") private File makeFile(String file) throws IOException { - File cfg = new File(getPlugin().getDataFolder(), file); + File cfg = new File(plugin.getDataFolder(), file); if (!cfg.exists()) { - getPlugin().getDataFolder().mkdir(); - try (InputStream is = getPlugin().getResourceAsStream(file)) { + plugin.getDataFolder().mkdir(); + try (InputStream is = plugin.getResourceAsStream(file)) { Files.copy(is, cfg.toPath()); } } @@ -60,7 +60,7 @@ class BungeeConfig extends AbstractConfiguration { } @Override - protected void init() { + public void init() { try { configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(makeFile("config.yml")); } catch (IOException e) { @@ -69,27 +69,27 @@ class BungeeConfig extends AbstractConfiguration { } @Override - protected String getString(String path, String def) { + public String getString(String path, String def) { return configuration.getString(path, def); } @Override - protected int getInt(String path, int def) { + public int getInt(String path, int def) { return configuration.getInt(path, def); } @Override - protected boolean getBoolean(String path, boolean def) { + public boolean getBoolean(String path, boolean def) { return configuration.getBoolean(path, def); } @Override - protected List getList(String path, List def) { + public List getList(String path, List def) { return Optional.ofNullable(configuration.getStringList(path)).orElse(def); } @Override - protected List getObjectList(String path, List def) { + public List getObjectList(String path, List def) { Configuration section = configuration.getSection(path); if (section == null) { return def; @@ -99,7 +99,7 @@ class BungeeConfig extends AbstractConfiguration { } @Override - protected Map getMap(String path, Map def) { + public Map getMap(String path, Map def) { Map map = new HashMap<>(); Configuration section = configuration.getSection(path); if (section == null) { diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java index 8b183bf32..38288b505 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeListener.java @@ -24,6 +24,7 @@ package me.lucko.luckperms.bungee; import me.lucko.luckperms.api.Contexts; import me.lucko.luckperms.api.event.events.UserFirstLoginEvent; +import me.lucko.luckperms.common.config.ConfigKeys; import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.core.UuidCache; import me.lucko.luckperms.common.core.model.User; @@ -75,11 +76,11 @@ public class BungeeListener extends AbstractListener implements Listener { Contexts contexts = new Contexts( plugin.getContextManager().getApplicableContext(player), - 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 ); @@ -97,7 +98,7 @@ public class BungeeListener extends AbstractListener implements Listener { final UuidCache cache = plugin.getUuidCache(); final PendingConnection c = e.getConnection(); - if (!cache.isOnlineMode()) { + if (!plugin.getConfiguration().get(ConfigKeys.ONLINE_MODE)) { UUID uuid = plugin.getStorage().getUUID(c.getName()).join(); if (uuid != null) { cache.addToCache(c.getUniqueId(), uuid); @@ -126,7 +127,7 @@ public class BungeeListener extends AbstractListener implements Listener { } 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; } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java index d2f3c1094..18bf77d3d 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/LPBungeePlugin.java @@ -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.CommandManager; 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.contexts.ContextManager; import me.lucko.luckperms.common.contexts.ServerCalculator; @@ -116,6 +117,8 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { getLog().info("Loading configuration..."); configuration = new BungeeConfig(this); + configuration.init(); + configuration.loadAll(); Set storageTypes = StorageFactory.getRequiredTypes(this, StorageType.H2); DependencyManager.loadDependencies(this, storageTypes); @@ -127,11 +130,11 @@ public class LPBungeePlugin extends Plugin 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..."); @@ -170,7 +173,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { // load internal managers getLog().info("Loading internal permission managers..."); - uuidCache = new UuidCache(getConfiguration().isOnlineMode()); + uuidCache = new UuidCache(this); userManager = new GenericUserManager(this); groupManager = new GenericGroupManager(this); trackManager = new GenericTrackManager(); @@ -182,7 +185,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { BackendServerCalculator serverCalculator = new BackendServerCalculator(); getProxy().getPluginManager().registerListener(this, serverCalculator); contextManager.registerCalculator(serverCalculator); - contextManager.registerCalculator(new ServerCalculator<>(getConfiguration().getServer())); + contextManager.registerCalculator(new ServerCalculator<>(configuration)); // register with the LP API getLog().info("Registering API..."); @@ -190,7 +193,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { ApiHandler.registerProvider(apiProvider); // schedule update tasks - int mins = getConfiguration().getSyncTime(); + int mins = getConfiguration().get(ConfigKeys.SYNC_TIME); if (mins > 0) { getProxy().getScheduler().schedule(this, new UpdateTask(this), mins, mins, TimeUnit.MINUTES); } @@ -267,11 +270,11 @@ public class LPBungeePlugin extends Plugin 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 ); } @@ -312,12 +315,12 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { public Set getPreProcessContexts(boolean op) { Set c = new HashSet<>(); c.add(ContextSet.empty()); - c.add(ContextSet.singleton("server", getConfiguration().getServer())); + c.add(ContextSet.singleton("server", getConfiguration().get(ConfigKeys.SERVER))); c.addAll(getProxy().getServers().values().stream() .map(ServerInfo::getName) .map(s -> { MutableContextSet set = MutableContextSet.create(); - set.add("server", getConfiguration().getServer()); + set.add("server", getConfiguration().get(ConfigKeys.SERVER)); set.add("world", s); return set.makeImmutable(); }) @@ -327,11 +330,11 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin { return c.stream() .map(set -> new Contexts( set, - 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 )) .collect(Collectors.toSet()); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java index 2431c09a3..79145fb25 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/DatastoreDelegate.java @@ -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 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 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()); diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java index e3fcfdd53..e7fe8408d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/LPConfigurationDelegate.java @@ -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 getSplitStorageOptions() { - return master.getSplitStorageOptions(); + return master.get(ConfigKeys.SPLIT_STORAGE_OPTIONS); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java b/common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java index 7c603180e..c1778062d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegate/StorageDelegate.java @@ -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 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()); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java index 32c7d08a4..3018d006b 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/group/DeleteGroup.java @@ -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; } diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java index ce91902c0..a3d2e3a3c 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/misc/InfoCommand.java @@ -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 platformInfo = plugin.getExtraInfo(); diff --git a/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java b/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java index 3f08fdae1..50b93eb8d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java +++ b/common/src/main/java/me/lucko/luckperms/common/commands/sender/Sender.java @@ -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 */ diff --git a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java index 37597cbad..3b65a7bd2 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/AbstractConfiguration.java @@ -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, Object> cache = CacheBuilder.newBuilder() + .build(new CacheLoader, Object>() { + @Override + public Object load(ConfigKey key) { + return key.get(AbstractConfiguration.this); + } -/** - * A thread-safe config abstraction - * - * @param the plugin type - */ -@Getter -public abstract class AbstractConfiguration implements LPConfiguration { + @Override + public ListenableFuture 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 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 worldRewrites; - private Map groupNameRewrites; - private List defaultAssignments; - private DatastoreConfiguration databaseValues; - private String sqlTablePrefix; - private String storageMethod; - private boolean splitStorage; - private Map 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 get(ConfigKey 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 getList(String path, List def); - - protected abstract List getObjectList(String path, List def); - - protected abstract Map getMap(String path, Map 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 weights = getMap("group-weight", Collections.emptyMap()); - ImmutableMap.Builder mb = ImmutableMap.builder(); - for (Map.Entry 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 defs = ImmutableList.builder(); - List 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 give = getList("default-assignments." + ruleName + ".give", new ArrayList<>()); - List 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.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> keys = cache.asMap().keySet(); + keys.forEach(cache::refresh); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java new file mode 100644 index 000000000..4ad6d3520 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 get(LPConfiguration config); + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java new file mode 100644 index 000000000..ffd757942 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 SERVER = StringKey.of("server", "global"); + public static final ConfigKey SYNC_TIME = EnduringKey.wrap(IntegerKey.of("data.sync-minutes", 3)); + public static final ConfigKey DEFAULT_GROUP_NODE = StaticKey.of("group.default"); // constant since 2.6 + public static final ConfigKey DEFAULT_GROUP_NAME = StaticKey.of("default"); // constant since 2.6 + public static final ConfigKey INCLUDING_GLOBAL_PERMS = BooleanKey.of("include-global", true); + public static final ConfigKey INCLUDING_GLOBAL_WORLD_PERMS = BooleanKey.of("include-global-world", true); + public static final ConfigKey APPLYING_GLOBAL_GROUPS = BooleanKey.of("apply-global-groups", true); + public static final ConfigKey APPLYING_GLOBAL_WORLD_GROUPS = BooleanKey.of("apply-global-world-groups", true); + public static final ConfigKey ONLINE_MODE = BooleanKey.of("online-mode", true); + public static final ConfigKey APPLYING_WILDCARDS = EnduringKey.wrap(BooleanKey.of("apply-wildcards", true)); + public static final ConfigKey APPLYING_REGEX = EnduringKey.wrap(BooleanKey.of("apply-regex", true)); + public static final ConfigKey APPLYING_SHORTHAND = EnduringKey.wrap(BooleanKey.of("apply-shorthand", true)); + public static final ConfigKey> 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 LOG_NOTIFY = BooleanKey.of("log-notify", true); + public static final ConfigKey AUTO_OP = EnduringKey.wrap(BooleanKey.of("auto-op", false)); + public static final ConfigKey OPS_ENABLED = EnduringKey.wrap(AbstractKey.of(c -> !AUTO_OP.get(c) && c.getBoolean("enable-ops", true))); + public static final ConfigKey COMMANDS_ALLOW_OP = EnduringKey.wrap(BooleanKey.of("commands-allow-op", true)); + public static final ConfigKey VAULT_SERVER = StringKey.of("vault-server", "global"); + public static final ConfigKey VAULT_INCLUDING_GLOBAL = BooleanKey.of("vault-include-global", true); + public static final ConfigKey VAULT_IGNORE_WORLD = BooleanKey.of("vault-ignore-world", false); + public static final ConfigKey VAULT_PRIMARY_GROUP_OVERRIDES = BooleanKey.of("vault-primary-groups-overrides.enabled", false); + public static final ConfigKey VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_INHERITED = BooleanKey.of("vault-primary-groups-overrides.check-inherited-permissions", false); + public static final ConfigKey VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_EXISTS = BooleanKey.of("vault-primary-groups-overrides.check-group-exists", true); + public static final ConfigKey VAULT_PRIMARY_GROUP_OVERRIDES_CHECK_MEMBER_OF = BooleanKey.of("vault-primary-groups-overrides.check-user-member-of", true); + public static final ConfigKey VAULT_DEBUG = BooleanKey.of("vault-debug", false); + public static final ConfigKey> WORLD_REWRITES = MapKey.of("world-rewrite"); + public static final ConfigKey> GROUP_NAME_REWRITES = MapKey.of("group-name-rewrite"); + public static final ConfigKey> 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 give = ImmutableList.copyOf(c.getList("default-assignments." + name + ".give", ImmutableList.of())); + List 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 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 SQL_TABLE_PREFIX = EnduringKey.wrap(StringKey.of("data.table_prefix", "luckperms_")); + public static final ConfigKey STORAGE_METHOD = EnduringKey.wrap(StringKey.of("storage-method", "h2")); + public static final ConfigKey SPLIT_STORAGE = EnduringKey.wrap(BooleanKey.of("split-storage.enabled", false)); + public static final ConfigKey> SPLIT_STORAGE_OPTIONS = EnduringKey.wrap(AbstractKey.of(c -> { + return ImmutableMap.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 REDIS_ENABLED = EnduringKey.wrap(BooleanKey.of("redis.enabled", false)); + public static final ConfigKey REDIS_ADDRESS = EnduringKey.wrap(StringKey.of("redis.address", null)); + public static final ConfigKey REDIS_PASSWORD = EnduringKey.wrap(StringKey.of("redis.password", "")); + + public static List> getAllKeys() { + return ImmutableList.>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(); + } + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java index 6e62483cb..31d10804f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/LPConfiguration.java @@ -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 getList(String path, List def); - boolean isApplyingGlobalWorldGroups(); + List getObjectList(String path, List def); - boolean isOnlineMode(); + Map getMap(String path, Map def); - boolean isApplyingWildcards(); - - boolean isApplyingRegex(); - - boolean isApplyingShorthand(); - - Map 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 getWorldRewrites(); - - Map getGroupNameRewrites(); - - List getDefaultAssignments(); - - DatastoreConfiguration getDatabaseValues(); - - String getSqlTablePrefix(); - - String getStorageMethod(); - - boolean isSplitStorage(); - - Map getSplitStorageOptions(); - - boolean isRedisEnabled(); - - String getRedisAddress(); - - String getRedisPassword(); + T get(ConfigKey key); } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java new file mode 100644 index 000000000..509d2a0d6 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/AbstractKey.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 implements ConfigKey { + private final Function function; + + @Override + public T get(LPConfiguration config) { + return function.apply(config); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java new file mode 100644 index 000000000..28fa770e7 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 { + private final String path; + private final boolean def; + + @Override + public Boolean get(LPConfiguration config) { + return config.getBoolean(path, def); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/EnduringKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/EnduringKey.java new file mode 100644 index 000000000..e405300d8 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/EnduringKey.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 + */ +@AllArgsConstructor(staticName = "wrap") +public class EnduringKey implements ConfigKey { + + @Delegate + private final ConfigKey delegate; + +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java new file mode 100644 index 000000000..b84cbbbbd --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 { + private final String path; + private final int def; + + @Override + public Integer get(LPConfiguration config) { + return config.getInt(path, def); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java new file mode 100644 index 000000000..41391e50c --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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> { + private final String path; + + @Override + public Map get(LPConfiguration config) { + return ImmutableMap.copyOf(config.getMap(path, ImmutableMap.of())); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java new file mode 100644 index 000000000..b64a0ae9a --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/StaticKey.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 implements ConfigKey { + private final T val; + + @Override + public T get(LPConfiguration config) { + return val; + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java new file mode 100644 index 000000000..65d6a7b63 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 Lucko (Luck) + * + * 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 { + private final String path; + private final String def; + + @Override + public String get(LPConfiguration config) { + return config.getString(path, def); + } +} diff --git a/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java b/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java index 244b33519..82e1daad4 100644 --- a/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/contexts/ServerCalculator.java @@ -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 extends ContextCalculator { - 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 context) { - return context.getKey().equals("server") && server.equalsIgnoreCase(context.getValue()); + return context.getKey().equals("server") && config.get(ConfigKeys.SERVER).equalsIgnoreCase(context.getValue()); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java b/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java index b00f59ab5..009a923c9 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/UuidCache.java @@ -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 cache; - - public UuidCache(boolean onlineMode) { - this.onlineMode = onlineMode; - - if (!onlineMode) { - cache = Maps.synchronizedBiMap(HashBiMap.create()); - } - } + private final BiMap 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(); } } diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java b/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java index d32f26d87..4929001fe 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/Group.java @@ -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 { } public String getRawDisplayName() { - return getPlugin().getConfiguration().getGroupNameRewrites().getOrDefault(name, name); + return getPlugin().getConfiguration().get(ConfigKeys.GROUP_NAME_REWRITES).getOrDefault(name, name); } public String getDisplayName() { diff --git a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java index e9631475c..9cdc6e41d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java +++ b/common/src/main/java/me/lucko/luckperms/common/core/model/PermissionHolder.java @@ -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 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); } diff --git a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java index cd1c5b740..e74ca6352 100644 --- a/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java +++ b/common/src/main/java/me/lucko/luckperms/common/data/LogEntry.java @@ -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; diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java index 61f74b6f0..8ff1b8cc7 100644 --- a/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/DependencyManager.java @@ -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); } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java index 1de1be413..1ae94ff79 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/StorageFactory.java @@ -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 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 types = new HashMap<>(plugin.getConfiguration().getSplitStorageOptions()); + Map 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 types = new HashMap<>(plugin.getConfiguration().getSplitStorageOptions()); + Map 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: diff --git a/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java b/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java index d06b9ae4c..e0f8ba344 100644 --- a/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java +++ b/common/src/main/java/me/lucko/luckperms/common/tasks/UpdateTask.java @@ -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(); } diff --git a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java index bf81ab627..16dd4dc48 100644 --- a/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java +++ b/common/src/main/java/me/lucko/luckperms/common/utils/AbstractListener.java @@ -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; } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java index 6d2226fde..84409abf6 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/LPSpongePlugin.java @@ -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 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 ); } diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java index d23519897..fc7924544 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeCalculatorFactory.java @@ -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 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())); diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java index bda74a98c..be7d397f8 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/SpongeConfig.java @@ -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 { +@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 { } @Override - protected void init() { + public void init() { try { ConfigurationLoader 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 { } @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 getList(String path, List def) { + public List getList(String path, List def) { ConfigurationNode node = getNode(path); if (node.isVirtual()) { return def; @@ -112,7 +112,7 @@ class SpongeConfig extends AbstractConfiguration { } @Override - protected List getObjectList(String path, List def) { + public List getObjectList(String path, List def) { ConfigurationNode node = getNode(path); if (node.isVirtual()) { return def; @@ -123,7 +123,7 @@ class SpongeConfig extends AbstractConfiguration { @SuppressWarnings("unchecked") @Override - protected Map getMap(String path, Map def) { + public Map getMap(String path, Map def) { ConfigurationNode node = getNode(path); if (node.isVirtual()) { return def; diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java index 27224698b..1b6fe6f5c 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/LuckPermsService.java @@ -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 ); }