diff --git a/api/src/main/java/me/lucko/luckperms/api/TemporaryDataMutateResult.java b/api/src/main/java/me/lucko/luckperms/api/TemporaryDataMutateResult.java index 8600a0809..6a394aa26 100644 --- a/api/src/main/java/me/lucko/luckperms/api/TemporaryDataMutateResult.java +++ b/api/src/main/java/me/lucko/luckperms/api/TemporaryDataMutateResult.java @@ -1,3 +1,28 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * 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.api; import javax.annotation.Nonnull; diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java index 03d1c782a..fb5d1ea9a 100644 --- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java +++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/BukkitConfigAdapter.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.bukkit; -import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -39,13 +38,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter { - +public class BukkitConfigAdapter implements ConfigurationAdapter { + private final LuckPermsPlugin plugin; private final File file; private YamlConfiguration configuration; public BukkitConfigAdapter(LuckPermsPlugin plugin, File file) { - super(plugin); + this.plugin = plugin; this.file = file; reload(); } @@ -61,7 +60,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public int getInt(String path, int def) { + public int getInteger(String path, int def) { return this.configuration.getInt(path, def); } @@ -71,7 +70,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getList(String path, List def) { + public List getStringList(String path, List def) { List ret = this.configuration.getStringList(path); return ret == null ? def : ret; } @@ -88,7 +87,7 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public Map getMap(String path, Map def) { + public Map getStringMap(String path, Map def) { Map map = new HashMap<>(); ConfigurationSection section = this.configuration.getConfigurationSection(path); if (section == null) { @@ -101,4 +100,9 @@ public class BukkitConfigAdapter extends AbstractConfigurationAdapter implements return map; } + + @Override + public LuckPermsPlugin getPlugin() { + return this.plugin; + } } diff --git a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java index c1eafb652..a0c8189c1 100644 --- a/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java +++ b/bungee/src/main/java/me/lucko/luckperms/bungee/BungeeConfigAdapter.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.bungee; -import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -41,13 +40,13 @@ import java.util.List; import java.util.Map; import java.util.Optional; -public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter { - +public class BungeeConfigAdapter implements ConfigurationAdapter { + private final LuckPermsPlugin plugin; private final File file; private Configuration configuration; public BungeeConfigAdapter(LuckPermsPlugin plugin, File file) { - super(plugin); + this.plugin = plugin; this.file = file; reload(); } @@ -67,7 +66,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public int getInt(String path, int def) { + public int getInteger(String path, int def) { return this.configuration.getInt(path, def); } @@ -77,7 +76,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getList(String path, List def) { + public List getStringList(String path, List def) { return Optional.ofNullable(this.configuration.getStringList(path)).orElse(def); } @@ -92,7 +91,7 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public Map getMap(String path, Map def) { + public Map getStringMap(String path, Map def) { Map map = new HashMap<>(); Configuration section = this.configuration.getSection(path); if (section == null) { @@ -105,4 +104,9 @@ public class BungeeConfigAdapter extends AbstractConfigurationAdapter implements return map; } + + @Override + public LuckPermsPlugin getPlugin() { + return this.plugin; + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/api/delegates/misc/ApiConfiguration.java b/common/src/main/java/me/lucko/luckperms/common/api/delegates/misc/ApiConfiguration.java index 6a5388b60..6eb4e5977 100644 --- a/common/src/main/java/me/lucko/luckperms/common/api/delegates/misc/ApiConfiguration.java +++ b/common/src/main/java/me/lucko/luckperms/common/api/delegates/misc/ApiConfiguration.java @@ -100,7 +100,7 @@ public class ApiConfiguration implements LPConfiguration { @Nonnull @Override public Object getObject(String key) { - ConfigKey configKey = ConfigKeys.getAllKeys().get(key.toUpperCase()); + ConfigKey configKey = ConfigKeys.getKeys().get(key.toUpperCase()); if (configKey == null) { throw new IllegalArgumentException("Unknown key: " + key); } 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 1bbd9408e..d9b5517cb 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 @@ -27,11 +27,8 @@ package me.lucko.luckperms.common.config; import me.lucko.luckperms.common.api.delegates.misc.ApiConfiguration; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; -import me.lucko.luckperms.common.config.keys.EnduringKey; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; -import java.util.Map; - /** * An abstract implementation of {@link LuckPermsConfiguration}. * @@ -70,22 +67,18 @@ public class AbstractConfiguration implements LuckPermsConfiguration { @Override public synchronized void load() { - // get the map of all keys - Map> keys = ConfigKeys.getAllKeys(); - // if this is a reload operation boolean reload = true; // if values are null, must be loading for the first time if (this.values == null) { - this.values = new Object[keys.size()]; + this.values = new Object[ConfigKeys.size()]; reload = false; } - // load a value for each key. - for (ConfigKey key : keys.values()) { + for (ConfigKey key : ConfigKeys.getKeys().values()) { // don't reload enduring keys. - if (reload && key instanceof EnduringKey) { + if (reload && key instanceof ConfigKeyTypes.EnduringKey) { continue; } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/BaseConfigKey.java b/common/src/main/java/me/lucko/luckperms/common/config/BaseConfigKey.java deleted file mode 100644 index 5c4deeabe..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/BaseConfigKey.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 abstract class BaseConfigKey implements ConfigKey { - int ordinal = -1; - - protected BaseConfigKey() { - - } - - @Override - public int ordinal() { - return this.ordinal; - } -} 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 index 1b5c369c9..7e18cde31 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKey.java @@ -37,8 +37,8 @@ public interface ConfigKey { /** * Gets the position of this key within the {@link ConfigKeys} enum. * - *

This is lazily set when the configuration is loaded for the first time, during the - * execution of {@link ConfigKeys#getAllKeys()}.

+ *

This is set shortly after the key is created, during the initialisation + * of {@link ConfigKeys}.

* * @return the position */ diff --git a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeyTypes.java b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeyTypes.java new file mode 100644 index 000000000..d6b174592 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeyTypes.java @@ -0,0 +1,136 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * 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 com.google.common.collect.ImmutableMap; + +import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; + +import java.util.Map; +import java.util.function.Function; + +public class ConfigKeyTypes { + + private static final KeyFactory BOOLEAN = ConfigurationAdapter::getBoolean; + private static final KeyFactory STRING = ConfigurationAdapter::getString; + private static final KeyFactory LOWERCASE_STRING = (adapter, path, def) -> adapter.getString(path, def).toLowerCase(); + private static final KeyFactory> STRING_MAP = (config, path, def) -> ImmutableMap.copyOf(config.getStringMap(path, ImmutableMap.of())); + + public static BaseConfigKey booleanKey(String path, boolean def) { + return BOOLEAN.createKey(path, def); + } + + public static BaseConfigKey stringKey(String path, String def) { + return STRING.createKey(path, def); + } + + public static BaseConfigKey lowercaseStringKey(String path, String def) { + return LOWERCASE_STRING.createKey(path, def); + } + + public static BaseConfigKey> mapKey(String path) { + return STRING_MAP.createKey(path, null); + } + + public static CustomKey customKey(Function function) { + return new CustomKey<>(function); + } + + public static EnduringKey enduringKey(ConfigKey delegate) { + return new EnduringKey<>(delegate); + } + + /** + * Functional interface that extracts values from a {@link ConfigurationAdapter}. + * + * @param the value type. + */ + @FunctionalInterface + public interface KeyFactory { + T getValue(ConfigurationAdapter config, String path, T def); + + default BaseConfigKey createKey(String path, T def) { + return new FunctionalKey<>(this, path, def); + } + } + + public abstract static class BaseConfigKey implements ConfigKey { + int ordinal = -1; + + BaseConfigKey() { + + } + + @Override + public int ordinal() { + return this.ordinal; + } + } + + private static class FunctionalKey extends BaseConfigKey implements ConfigKey { + private final KeyFactory factory; + private final String path; + private final T def; + + FunctionalKey(KeyFactory factory, String path, T def) { + this.factory = factory; + this.path = path; + this.def = def; + } + + @Override + public T get(ConfigurationAdapter adapter) { + return this.factory.getValue(adapter, this.path, this.def); + } + } + + public static class CustomKey extends BaseConfigKey { + private final Function function; + + private CustomKey(Function function) { + this.function = function; + } + + @Override + public T get(ConfigurationAdapter adapter) { + return this.function.apply(adapter); + } + } + + public static class EnduringKey extends BaseConfigKey { + private final ConfigKey delegate; + + private EnduringKey(ConfigKey delegate) { + this.delegate = delegate; + } + + @Override + public T get(ConfigurationAdapter adapter) { + return this.delegate.get(adapter); + } + } + +} 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 index e789f6fae..523d7f19d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/ConfigKeys.java @@ -35,12 +35,6 @@ import me.lucko.luckperms.api.context.ContextSet; import me.lucko.luckperms.api.metastacking.MetaStackDefinition; import me.lucko.luckperms.common.assignments.AssignmentRule; import me.lucko.luckperms.common.command.utils.ArgumentParser; -import me.lucko.luckperms.common.config.keys.BooleanKey; -import me.lucko.luckperms.common.config.keys.CustomKey; -import me.lucko.luckperms.common.config.keys.EnduringKey; -import me.lucko.luckperms.common.config.keys.LowercaseStringKey; -import me.lucko.luckperms.common.config.keys.MapKey; -import me.lucko.luckperms.common.config.keys.StringKey; import me.lucko.luckperms.common.graph.TraversalAlgorithm; import me.lucko.luckperms.common.metastacking.SimpleMetaStackDefinition; import me.lucko.luckperms.common.metastacking.StandardStackElements; @@ -61,20 +55,28 @@ import java.util.EnumSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; +import static me.lucko.luckperms.common.config.ConfigKeyTypes.booleanKey; +import static me.lucko.luckperms.common.config.ConfigKeyTypes.customKey; +import static me.lucko.luckperms.common.config.ConfigKeyTypes.enduringKey; +import static me.lucko.luckperms.common.config.ConfigKeyTypes.lowercaseStringKey; +import static me.lucko.luckperms.common.config.ConfigKeyTypes.mapKey; +import static me.lucko.luckperms.common.config.ConfigKeyTypes.stringKey; + /** * All of the {@link ConfigKey}s used by LuckPerms. * - *

The {@link #getAllKeys()} method and associated behaviour allows this class to behave - * a bit like an enum with generics.

+ *

The {@link #getKeys()} method and associated behaviour allows this class + * to function a bit like an enum, but with generics.

*/ public final class ConfigKeys { /** * The name of the server */ - public static final ConfigKey SERVER = CustomKey.of(c -> { + public static final ConfigKey SERVER = customKey(c -> { if (c.getBoolean("use-server-properties-name", false)) { String serverName = c.getPlugin().getBootstrap().getServerName(); if (serverName != null && !serverName.equals("Unknown Server")) { @@ -88,10 +90,10 @@ public final class ConfigKeys { /** * How many minutes to wait between syncs. A value <= 0 will disable syncing. */ - public static final ConfigKey SYNC_TIME = EnduringKey.wrap(CustomKey.of(c -> { - int val = c.getInt("sync-minutes", -1); + public static final ConfigKey SYNC_TIME = enduringKey(customKey(c -> { + int val = c.getInteger("sync-minutes", -1); if (val == -1) { - val = c.getInt("data.sync-minutes", -1); + val = c.getInteger("data.sync-minutes", -1); } return val; })); @@ -99,7 +101,7 @@ public final class ConfigKeys { /** * The lookup settings for contexts (care should be taken to not mutate this method) */ - public static final ConfigKey> LOOKUP_SETTINGS = CustomKey.of(c -> { + public static final ConfigKey> LOOKUP_SETTINGS = customKey(c -> { return EnumSet.copyOf(Contexts.of( ContextSet.empty(), c.getBoolean("include-global", true), @@ -114,27 +116,27 @@ public final class ConfigKeys { /** * # If the servers own UUID cache/lookup facility should be used when there is no record for a player in the LuckPerms cache. */ - public static final ConfigKey USE_SERVER_UUID_CACHE = BooleanKey.of("use-server-uuid-cache", false); + public static final ConfigKey USE_SERVER_UUID_CACHE = booleanKey("use-server-uuid-cache", false); /** * If LuckPerms should allow usernames with non alphanumeric characters. */ - public static final ConfigKey ALLOW_INVALID_USERNAMES = BooleanKey.of("allow-invalid-usernames", false); + public static final ConfigKey ALLOW_INVALID_USERNAMES = booleanKey("allow-invalid-usernames", false); /** * If LuckPerms should produce extra logging output when it handles logins. */ - public static final ConfigKey DEBUG_LOGINS = BooleanKey.of("debug-logins", false); + public static final ConfigKey DEBUG_LOGINS = booleanKey("debug-logins", false); /** * If LP should cancel login attempts for players whose permission data could not be loaded. */ - public static final ConfigKey CANCEL_FAILED_LOGINS = BooleanKey.of("cancel-failed-logins", false); + public static final ConfigKey CANCEL_FAILED_LOGINS = booleanKey("cancel-failed-logins", false); /** * Controls how temporary add commands should behave */ - public static final ConfigKey TEMPORARY_ADD_BEHAVIOUR = CustomKey.of(c -> { + public static final ConfigKey TEMPORARY_ADD_BEHAVIOUR = customKey(c -> { String option = c.getString("temporary-add-behaviour", "deny").toLowerCase(); if (!option.equals("deny") && !option.equals("replace") && !option.equals("accumulate")) { option = "deny"; @@ -146,7 +148,7 @@ public final class ConfigKeys { /** * How primary groups should be calculated. */ - public static final ConfigKey PRIMARY_GROUP_CALCULATION_METHOD = EnduringKey.wrap(CustomKey.of(c -> { + public static final ConfigKey PRIMARY_GROUP_CALCULATION_METHOD = enduringKey(customKey(c -> { String option = c.getString("primary-group-calculation", "stored").toLowerCase(); if (!option.equals("stored") && !option.equals("parents-by-weight") && !option.equals("all-parents-by-weight")) { option = "stored"; @@ -158,7 +160,7 @@ public final class ConfigKeys { /** * A function to create primary group holder instances based upon the {@link #PRIMARY_GROUP_CALCULATION_METHOD} setting. */ - public static final ConfigKey> PRIMARY_GROUP_CALCULATION = EnduringKey.wrap(CustomKey.of(c -> { + public static final ConfigKey> PRIMARY_GROUP_CALCULATION = enduringKey(customKey(c -> { String option = PRIMARY_GROUP_CALCULATION_METHOD.get(c); switch (option) { case "stored": @@ -174,83 +176,83 @@ public final class ConfigKeys { * If set to false, the plugin will allow a Users primary group to be removed with the * 'parent remove' command, and will set their primary group back to default. */ - public static final ConfigKey PREVENT_PRIMARY_GROUP_REMOVAL = BooleanKey.of("prevent-primary-group-removal", true); + public static final ConfigKey PREVENT_PRIMARY_GROUP_REMOVAL = booleanKey("prevent-primary-group-removal", true); /** * If the plugin should check for "extra" permissions with users run LP commands */ - public static final ConfigKey USE_ARGUMENT_BASED_COMMAND_PERMISSIONS = BooleanKey.of("argument-based-command-permissions", false); + public static final ConfigKey USE_ARGUMENT_BASED_COMMAND_PERMISSIONS = booleanKey("argument-based-command-permissions", false); /** * If the plugin should check whether senders are a member of a given group * before they're able to edit the groups permissions or add/remove it from other users. */ - public static final ConfigKey REQUIRE_SENDER_GROUP_MEMBERSHIP_TO_MODIFY = BooleanKey.of("require-sender-group-membership-to-modify", false); + public static final ConfigKey REQUIRE_SENDER_GROUP_MEMBERSHIP_TO_MODIFY = booleanKey("require-sender-group-membership-to-modify", false); /** * If wildcards are being applied */ - public static final ConfigKey APPLYING_WILDCARDS = EnduringKey.wrap(BooleanKey.of("apply-wildcards", true)); + public static final ConfigKey APPLYING_WILDCARDS = enduringKey(booleanKey("apply-wildcards", true)); /** * If regex permissions are being applied */ - public static final ConfigKey APPLYING_REGEX = EnduringKey.wrap(BooleanKey.of("apply-regex", true)); + public static final ConfigKey APPLYING_REGEX = enduringKey(booleanKey("apply-regex", true)); /** * If shorthand permissions are being applied */ - public static final ConfigKey APPLYING_SHORTHAND = EnduringKey.wrap(BooleanKey.of("apply-shorthand", true)); + public static final ConfigKey APPLYING_SHORTHAND = enduringKey(booleanKey("apply-shorthand", true)); /** * If Bukkit child permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_BUKKIT_CHILD_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-bukkit-child-permissions", true)); + public static final ConfigKey APPLY_BUKKIT_CHILD_PERMISSIONS = enduringKey(booleanKey("apply-bukkit-child-permissions", true)); /** * If Bukkit default permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_BUKKIT_DEFAULT_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-bukkit-default-permissions", true)); + public static final ConfigKey APPLY_BUKKIT_DEFAULT_PERMISSIONS = enduringKey(booleanKey("apply-bukkit-default-permissions", true)); /** * If Bukkit attachment permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_BUKKIT_ATTACHMENT_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-bukkit-attachment-permissions", true)); + public static final ConfigKey APPLY_BUKKIT_ATTACHMENT_PERMISSIONS = enduringKey(booleanKey("apply-bukkit-attachment-permissions", true)); /** * If Nukkit child permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_NUKKIT_CHILD_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-nukkit-child-permissions", true)); + public static final ConfigKey APPLY_NUKKIT_CHILD_PERMISSIONS = enduringKey(booleanKey("apply-nukkit-child-permissions", true)); /** * If Nukkit default permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_NUKKIT_DEFAULT_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-nukkit-default-permissions", true)); + public static final ConfigKey APPLY_NUKKIT_DEFAULT_PERMISSIONS = enduringKey(booleanKey("apply-nukkit-default-permissions", true)); /** * If Nukkit attachment permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_NUKKIT_ATTACHMENT_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-nukkit-attachment-permissions", true)); + public static final ConfigKey APPLY_NUKKIT_ATTACHMENT_PERMISSIONS = enduringKey(booleanKey("apply-nukkit-attachment-permissions", true)); /** * If BungeeCord configured permissions are being applied. This setting is ignored on other platforms. */ - public static final ConfigKey APPLY_BUNGEE_CONFIG_PERMISSIONS = EnduringKey.wrap(BooleanKey.of("apply-bungee-config-permissions", false)); + public static final ConfigKey APPLY_BUNGEE_CONFIG_PERMISSIONS = enduringKey(booleanKey("apply-bungee-config-permissions", false)); /** * If Sponge's implicit permission inheritance system should be applied */ - public static final ConfigKey APPLY_SPONGE_IMPLICIT_WILDCARDS = EnduringKey.wrap(BooleanKey.of("apply-sponge-implicit-wildcards", true)); + public static final ConfigKey APPLY_SPONGE_IMPLICIT_WILDCARDS = enduringKey(booleanKey("apply-sponge-implicit-wildcards", true)); /** * If Sponge default subjects should be applied */ - public static final ConfigKey APPLY_SPONGE_DEFAULT_SUBJECTS = EnduringKey.wrap(BooleanKey.of("apply-sponge-default-subjects", true)); + public static final ConfigKey APPLY_SPONGE_DEFAULT_SUBJECTS = enduringKey(booleanKey("apply-sponge-default-subjects", true)); /** * The algorithm LuckPerms should use when traversing the "inheritance tree" */ - public static final ConfigKey INHERITANCE_TRAVERSAL_ALGORITHM = CustomKey.of(c -> { + public static final ConfigKey INHERITANCE_TRAVERSAL_ALGORITHM = customKey(c -> { String value = c.getString("inheritance-traversal-algorithm", "depth-first-pre-order"); switch (value.toLowerCase()) { case "breadth-first": @@ -265,8 +267,8 @@ public final class ConfigKeys { /** * The configured group weightings */ - public static final ConfigKey> GROUP_WEIGHTS = CustomKey.of(c -> { - return c.getMap("group-weight", ImmutableMap.of()).entrySet().stream().collect(ImmutableCollectors.toMap( + public static final ConfigKey> GROUP_WEIGHTS = customKey(c -> { + return c.getStringMap("group-weight", ImmutableMap.of()).entrySet().stream().collect(ImmutableCollectors.toMap( e -> e.getKey().toLowerCase(), e -> { try { @@ -281,8 +283,8 @@ public final class ConfigKeys { /** * Creates a new prefix MetaStack element based upon the configured values. */ - public static final ConfigKey PREFIX_FORMATTING_OPTIONS = CustomKey.of(l -> { - List format = l.getList("meta-formatting.prefix.format", new ArrayList<>()); + public static final ConfigKey PREFIX_FORMATTING_OPTIONS = customKey(l -> { + List format = l.getStringList("meta-formatting.prefix.format", new ArrayList<>()); if (format.isEmpty()) { format.add("highest"); } @@ -296,8 +298,8 @@ public final class ConfigKeys { /** * Creates a new suffix MetaStack element based upon the configured values. */ - public static final ConfigKey SUFFIX_FORMATTING_OPTIONS = CustomKey.of(l -> { - List format = l.getList("meta-formatting.suffix.format", new ArrayList<>()); + public static final ConfigKey SUFFIX_FORMATTING_OPTIONS = customKey(l -> { + List format = l.getStringList("meta-formatting.suffix.format", new ArrayList<>()); if (format.isEmpty()) { format.add("highest"); } @@ -311,37 +313,37 @@ public final class ConfigKeys { /** * If log notifications are enabled */ - public static final ConfigKey LOG_NOTIFY = BooleanKey.of("log-notify", true); + public static final ConfigKey LOG_NOTIFY = booleanKey("log-notify", true); /** * If auto op is enabled. Only used by the Bukkit platform. */ - public static final ConfigKey AUTO_OP = EnduringKey.wrap(BooleanKey.of("auto-op", false)); + public static final ConfigKey AUTO_OP = enduringKey(booleanKey("auto-op", false)); /** * If server operators should be enabled. Only used by the Bukkit platform. */ - public static final ConfigKey OPS_ENABLED = EnduringKey.wrap(CustomKey.of(c -> !AUTO_OP.get(c) && c.getBoolean("enable-ops", true))); + public static final ConfigKey OPS_ENABLED = enduringKey(customKey(c -> !AUTO_OP.get(c) && c.getBoolean("enable-ops", true))); /** * If server operators should be able to use LuckPerms commands by default. Only used by the Bukkit platform. */ - public static final ConfigKey COMMANDS_ALLOW_OP = EnduringKey.wrap(BooleanKey.of("commands-allow-op", true)); + public static final ConfigKey COMMANDS_ALLOW_OP = enduringKey(booleanKey("commands-allow-op", true)); /** * If Vault lookups for offline players on the main server thread should be enabled */ - public static final ConfigKey VAULT_UNSAFE_LOOKUPS = BooleanKey.of("vault-unsafe-lookups", false); + public static final ConfigKey VAULT_UNSAFE_LOOKUPS = booleanKey("vault-unsafe-lookups", false); /** * If the vault server option should be used */ - public static final ConfigKey USE_VAULT_SERVER = BooleanKey.of("use-vault-server", true); + public static final ConfigKey USE_VAULT_SERVER = booleanKey("use-vault-server", true); /** * The name of the server to use for Vault. */ - public static final ConfigKey VAULT_SERVER = CustomKey.of(c -> { + public static final ConfigKey VAULT_SERVER = customKey(c -> { // default to true for backwards compatibility if (USE_VAULT_SERVER.get(c)) { return c.getString("vault-server", "global").toLowerCase(); @@ -353,23 +355,23 @@ public final class ConfigKeys { /** * If Vault should apply global permissions */ - public static final ConfigKey VAULT_INCLUDING_GLOBAL = BooleanKey.of("vault-include-global", true); + public static final ConfigKey VAULT_INCLUDING_GLOBAL = booleanKey("vault-include-global", true); /** * If any worlds provided with Vault lookups should be ignored */ - public static final ConfigKey VAULT_IGNORE_WORLD = BooleanKey.of("vault-ignore-world", false); + public static final ConfigKey VAULT_IGNORE_WORLD = booleanKey("vault-ignore-world", false); /** * If Vault debug mode is enabled */ - public static final ConfigKey VAULT_DEBUG = BooleanKey.of("vault-debug", false); + public static final ConfigKey VAULT_DEBUG = booleanKey("vault-debug", false); /** * The world rewrites map */ - public static final ConfigKey> WORLD_REWRITES = CustomKey.of(c -> { - return c.getMap("world-rewrite", ImmutableMap.of()).entrySet().stream() + public static final ConfigKey> WORLD_REWRITES = customKey(c -> { + return c.getStringMap("world-rewrite", ImmutableMap.of()).entrySet().stream() .collect(ImmutableCollectors.toMap( e -> e.getKey().toLowerCase(), e -> e.getValue().toLowerCase() @@ -379,18 +381,18 @@ public final class ConfigKeys { /** * The group name rewrites map */ - public static final ConfigKey> GROUP_NAME_REWRITES = MapKey.of("group-name-rewrite"); + public static final ConfigKey> GROUP_NAME_REWRITES = mapKey("group-name-rewrite"); /** * The default assignments being applied by the plugin */ - public static final ConfigKey> DEFAULT_ASSIGNMENTS = CustomKey.of(c -> { + public static final ConfigKey> DEFAULT_ASSIGNMENTS = customKey(c -> { return c.getKeys("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())); + List give = ImmutableList.copyOf(c.getStringList("default-assignments." + name + ".give", ImmutableList.of())); + List take = ImmutableList.copyOf(c.getStringList("default-assignments." + name + ".take", ImmutableList.of())); String pg = c.getString("default-assignments." + name + ".set-primary-group", null); return new AssignmentRule(hasTrue, hasFalse, lacks, give, take, pg); }).collect(ImmutableCollectors.toList()); @@ -399,12 +401,12 @@ public final class ConfigKeys { /** * The database settings, username, password, etc for use by any database */ - public static final ConfigKey DATABASE_VALUES = EnduringKey.wrap(CustomKey.of(c -> { - int maxPoolSize = c.getInt("data.pool-settings.maximum-pool-size", c.getInt("data.pool-size", 10)); - int minIdle = c.getInt("data.pool-settings.minimum-idle", maxPoolSize); - int maxLifetime = c.getInt("data.pool-settings.maximum-lifetime", 1800000); - int connectionTimeout = c.getInt("data.pool-settings.connection-timeout", 5000); - Map props = ImmutableMap.copyOf(c.getMap("data.pool-settings.properties", ImmutableMap.of())); + public static final ConfigKey DATABASE_VALUES = enduringKey(customKey(c -> { + int maxPoolSize = c.getInteger("data.pool-settings.maximum-pool-size", c.getInteger("data.pool-size", 10)); + int minIdle = c.getInteger("data.pool-settings.minimum-idle", maxPoolSize); + int maxLifetime = c.getInteger("data.pool-settings.maximum-lifetime", 1800000); + int connectionTimeout = c.getInteger("data.pool-settings.connection-timeout", 5000); + Map props = ImmutableMap.copyOf(c.getStringMap("data.pool-settings.properties", ImmutableMap.of())); return new StorageCredentials( c.getString("data.address", null), @@ -418,37 +420,37 @@ public final class ConfigKeys { /** * The prefix for any SQL tables */ - public static final ConfigKey SQL_TABLE_PREFIX = EnduringKey.wrap(StringKey.of("data.table_prefix", "luckperms_")); + public static final ConfigKey SQL_TABLE_PREFIX = enduringKey(stringKey("data.table_prefix", "luckperms_")); /** * The prefix for any MongoDB collections */ - public static final ConfigKey MONGODB_COLLECTION_PREFIX = EnduringKey.wrap(StringKey.of("data.mongodb_collection_prefix", "")); + public static final ConfigKey MONGODB_COLLECTION_PREFIX = enduringKey(stringKey("data.mongodb_collection_prefix", "")); /** * MongoDB ClientConnectionURI to override default connection options */ - public static final ConfigKey MONGODB_CONNECTION_URI = EnduringKey.wrap(StringKey.of("data.mongodb_connection_URI", "")); + public static final ConfigKey MONGODB_CONNECTION_URI = enduringKey(stringKey("data.mongodb_connection_URI", "")); /** * The name of the storage method being used */ - public static final ConfigKey STORAGE_METHOD = EnduringKey.wrap(LowercaseStringKey.of("storage-method", "h2")); + public static final ConfigKey STORAGE_METHOD = enduringKey(lowercaseStringKey("storage-method", "h2")); /** * If storage files should be monitored for changes */ - public static final ConfigKey WATCH_FILES = BooleanKey.of("watch-files", true); + public static final ConfigKey WATCH_FILES = booleanKey("watch-files", true); /** * If split storage is being used */ - public static final ConfigKey SPLIT_STORAGE = EnduringKey.wrap(BooleanKey.of("split-storage.enabled", false)); + public static final ConfigKey SPLIT_STORAGE = enduringKey(booleanKey("split-storage.enabled", false)); /** * The options for split storage */ - public static final ConfigKey> SPLIT_STORAGE_OPTIONS = EnduringKey.wrap(CustomKey.of(c -> { + public static final ConfigKey> SPLIT_STORAGE_OPTIONS = enduringKey(customKey(c -> { EnumMap map = new EnumMap<>(SplitStorageType.class); map.put(SplitStorageType.USER, c.getString("split-storage.methods.user", "h2").toLowerCase()); map.put(SplitStorageType.GROUP, c.getString("split-storage.methods.group", "h2").toLowerCase()); @@ -461,96 +463,105 @@ public final class ConfigKeys { /** * The name of the messaging service in use, or "none" if not enabled */ - public static final ConfigKey MESSAGING_SERVICE = EnduringKey.wrap(LowercaseStringKey.of("messaging-service", "none")); + public static final ConfigKey MESSAGING_SERVICE = enduringKey(lowercaseStringKey("messaging-service", "none")); /** * If updates should be automatically pushed by the messaging service */ - public static final ConfigKey AUTO_PUSH_UPDATES = EnduringKey.wrap(BooleanKey.of("auto-push-updates", true)); + public static final ConfigKey AUTO_PUSH_UPDATES = enduringKey(booleanKey("auto-push-updates", true)); /** * If LuckPerms should push logging entries to connected servers via the messaging service */ - public static final ConfigKey PUSH_LOG_ENTRIES = EnduringKey.wrap(BooleanKey.of("push-log-entries", true)); + public static final ConfigKey PUSH_LOG_ENTRIES = enduringKey(booleanKey("push-log-entries", true)); /** * If LuckPerms should broadcast received logging entries to players on this platform */ - public static final ConfigKey BROADCAST_RECEIVED_LOG_ENTRIES = EnduringKey.wrap(BooleanKey.of("broadcast-received-log-entries", false)); + public static final ConfigKey BROADCAST_RECEIVED_LOG_ENTRIES = enduringKey(booleanKey("broadcast-received-log-entries", false)); /** * If redis messaging is enabled */ - public static final ConfigKey REDIS_ENABLED = EnduringKey.wrap(BooleanKey.of("redis.enabled", false)); + public static final ConfigKey REDIS_ENABLED = enduringKey(booleanKey("redis.enabled", false)); /** * The address of the redis server */ - public static final ConfigKey REDIS_ADDRESS = EnduringKey.wrap(StringKey.of("redis.address", null)); + public static final ConfigKey REDIS_ADDRESS = enduringKey(stringKey("redis.address", null)); /** * The password in use by the redis server, or an empty string if there is no passworld */ - public static final ConfigKey REDIS_PASSWORD = EnduringKey.wrap(StringKey.of("redis.password", "")); + public static final ConfigKey REDIS_PASSWORD = enduringKey(stringKey("redis.password", "")); /** * The URL of the web editor */ - public static final ConfigKey WEB_EDITOR_URL_PATTERN = StringKey.of("web-editor-url", "https://luckperms.github.io/editor/"); + public static final ConfigKey WEB_EDITOR_URL_PATTERN = stringKey("web-editor-url", "https://luckperms.github.io/editor/"); /** * The URL of the verbose viewer */ - public static final ConfigKey VERBOSE_VIEWER_URL_PATTERN = StringKey.of("verbose-viewer-url", "https://luckperms.github.io/verbose/"); + public static final ConfigKey VERBOSE_VIEWER_URL_PATTERN = stringKey("verbose-viewer-url", "https://luckperms.github.io/verbose/"); /** * The URL of the tree viewer */ - public static final ConfigKey TREE_VIEWER_URL_PATTERN = StringKey.of("tree-viewer-url", "https://luckperms.github.io/treeview/"); + public static final ConfigKey TREE_VIEWER_URL_PATTERN = stringKey("tree-viewer-url", "https://luckperms.github.io/treeview/"); - private static Map> KEYS = null; + private static final AtomicInteger ORDINAL_COUNTER = new AtomicInteger(0); + private static final Map> KEYS; - /** - * Gets all of the possible config keys defined in this class - * - * @return all of the possible config keys defined in this class - */ - public static synchronized Map> getAllKeys() { - if (KEYS == null) { - Map> keys = new LinkedHashMap<>(); - - try { - Field[] values = ConfigKeys.class.getFields(); - int counter = 0; - - for (Field f : values) { - // ignore non-static fields - if (!Modifier.isStatic(f.getModifiers())) { - continue; - } - - // ignore fields that aren't configkeys - if (!ConfigKey.class.equals(f.getType())) { - continue; - } - - // get the key instance - BaseConfigKey key = (BaseConfigKey) f.get(null); - // set the ordinal value of the key. - key.ordinal = counter++; - // add the key to the return map - keys.put(f.getName(), key); - } - } catch (Exception e) { - e.printStackTrace(); + static { + Map> keys = new LinkedHashMap<>(); + Field[] values = ConfigKeys.class.getFields(); + for (Field f : values) { + // ignore non-static fields + if (!Modifier.isStatic(f.getModifiers())) { + continue; } - KEYS = ImmutableMap.copyOf(keys); - } + // ignore fields that aren't configkeys + if (!ConfigKey.class.equals(f.getType())) { + continue; + } + try { + // get the key instance + ConfigKeyTypes.BaseConfigKey key = (ConfigKeyTypes.BaseConfigKey) f.get(null); + // set the ordinal value of the key. + key.ordinal = ORDINAL_COUNTER.getAndIncrement(); + // add the key to the return map + keys.put(f.getName(), key); + } catch (IllegalAccessException e) { + throw new RuntimeException("Exception processing field: " + f, e); + } + } + KEYS = ImmutableMap.copyOf(keys); + } + + /** + * Gets a map of the keys defined in this class. + * + *

The string key in the map is the {@link Field#getName() field name} + * corresponding to each key.

+ * + * @return the defined keys + */ + public static Map> getKeys() { return KEYS; } + /** + * Gets the number of defined keys. + * + * @return how many keys are defined in this class + */ + public static int size() { + return ORDINAL_COUNTER.get(); + } + private ConfigKeys() {} } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/adapter/AbstractConfigurationAdapter.java b/common/src/main/java/me/lucko/luckperms/common/config/adapter/AbstractConfigurationAdapter.java deleted file mode 100644 index 699730d52..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/adapter/AbstractConfigurationAdapter.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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.adapter; - -import me.lucko.luckperms.common.plugin.LuckPermsPlugin; - -public abstract class AbstractConfigurationAdapter implements ConfigurationAdapter { - private final LuckPermsPlugin plugin; - - public AbstractConfigurationAdapter(LuckPermsPlugin plugin) { - this.plugin = plugin; - } - - @Override - public LuckPermsPlugin getPlugin() { - return this.plugin; - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurateConfigAdapter.java b/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurateConfigAdapter.java index 675df4b25..ff7ea68e0 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurateConfigAdapter.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurateConfigAdapter.java @@ -39,13 +39,13 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -public abstract class ConfigurateConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter { - +public abstract class ConfigurateConfigAdapter implements ConfigurationAdapter { + private final LuckPermsPlugin plugin; private final Path path; private ConfigurationNode root; public ConfigurateConfigAdapter(LuckPermsPlugin plugin, Path path) { - super(plugin); + this.plugin = plugin; this.path = path; reload(); } @@ -76,7 +76,7 @@ public abstract class ConfigurateConfigAdapter extends AbstractConfigurationAdap } @Override - public int getInt(String path, int def) { + public int getInteger(String path, int def) { return resolvePath(path).getInt(def); } @@ -86,7 +86,7 @@ public abstract class ConfigurateConfigAdapter extends AbstractConfigurationAdap } @Override - public List getList(String path, List def) { + public List getStringList(String path, List def) { ConfigurationNode node = resolvePath(path); if (node.isVirtual()) { return def; @@ -107,7 +107,7 @@ public abstract class ConfigurateConfigAdapter extends AbstractConfigurationAdap @SuppressWarnings("unchecked") @Override - public Map getMap(String path, Map def) { + public Map getStringMap(String path, Map def) { ConfigurationNode node = resolvePath(path); if (node.isVirtual()) { return def; @@ -116,4 +116,9 @@ public abstract class ConfigurateConfigAdapter extends AbstractConfigurationAdap Map m = (Map) node.getValue(Collections.emptyMap()); return m.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().toString())); } + + @Override + public LuckPermsPlugin getPlugin() { + return this.plugin; + } } diff --git a/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java b/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java index 6e71f6a8d..91c228f82 100644 --- a/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java +++ b/common/src/main/java/me/lucko/luckperms/common/config/adapter/ConfigurationAdapter.java @@ -38,14 +38,14 @@ public interface ConfigurationAdapter { String getString(String path, String def); - int getInt(String path, int def); + int getInteger(String path, int def); boolean getBoolean(String path, boolean def); - List getList(String path, List def); + List getStringList(String path, List def); List getKeys(String path, List def); - Map getMap(String path, Map def); + Map getStringMap(String path, Map def); } 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 deleted file mode 100644 index 6f2b033cd..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/BooleanKey.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -public class BooleanKey extends BaseConfigKey { - public static BooleanKey of(String path, boolean def) { - return new BooleanKey(path, def); - } - - private final String path; - private final boolean def; - - private BooleanKey(String path, boolean def) { - this.path = path; - this.def = def; - } - - @Override - public Boolean get(ConfigurationAdapter adapter) { - return adapter.getBoolean(this.path, this.def); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/CustomKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/CustomKey.java deleted file mode 100644 index 8f7a349eb..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/CustomKey.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -import java.util.function.Function; - -public class CustomKey extends BaseConfigKey { - public static CustomKey of(Function function) { - return new CustomKey<>(function); - } - - private final Function function; - - private CustomKey(Function function) { - this.function = function; - } - - @Override - public T get(ConfigurationAdapter adapter) { - return this.function.apply(adapter); - } -} 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 deleted file mode 100644 index a97d7d70e..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/EnduringKey.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.ConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -/** - * Wrapper class to mark a config key as enduring (doesn't change in the event of a reload) - * @param - */ -public class EnduringKey extends BaseConfigKey { - - public static EnduringKey wrap(ConfigKey delegate) { - return new EnduringKey<>(delegate); - } - - private final ConfigKey delegate; - - private EnduringKey(ConfigKey delegate) { - this.delegate = delegate; - } - - @Override - public T get(ConfigurationAdapter adapter) { - return this.delegate.get(adapter); - } -} 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 deleted file mode 100644 index 9daa58014..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/IntegerKey.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -public class IntegerKey extends BaseConfigKey { - public static IntegerKey of(String path, int def) { - return new IntegerKey(path, def); - } - - private final String path; - private final int def; - - private IntegerKey(String path, int def) { - this.path = path; - this.def = def; - } - - @Override - public Integer get(ConfigurationAdapter adapter) { - return adapter.getInt(this.path, this.def); - } -} diff --git a/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java b/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java deleted file mode 100644 index 828514da1..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -public class LowercaseStringKey extends BaseConfigKey { - public static LowercaseStringKey of(String path, String def) { - return new LowercaseStringKey(path, def); - } - - private final String path; - private final String def; - - private LowercaseStringKey(String path, String def) { - this.path = path; - this.def = def; - } - - @Override - public String get(ConfigurationAdapter adapter) { - return adapter.getString(this.path, this.def).toLowerCase(); - } -} 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 deleted file mode 100644 index c2829c3c2..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/MapKey.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 com.google.common.collect.ImmutableMap; - -import me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -import java.util.Map; - -public class MapKey extends BaseConfigKey> { - public static MapKey of(String path) { - return new MapKey(path); - } - - private final String path; - - private MapKey(String path) { - this.path = path; - } - - @Override - public Map get(ConfigurationAdapter adapter) { - return ImmutableMap.copyOf(adapter.getMap(this.path, ImmutableMap.of())); - } -} 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 deleted file mode 100644 index 191371a4b..000000000 --- a/common/src/main/java/me/lucko/luckperms/common/config/keys/StringKey.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of LuckPerms, licensed under the MIT License. - * - * Copyright (c) lucko (Luck) - * Copyright (c) contributors - * - * 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 me.lucko.luckperms.common.config.BaseConfigKey; -import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; - -public class StringKey extends BaseConfigKey { - public static StringKey of(String path, String def) { - return new StringKey(path, def); - } - - private final String path; - private final String def; - - private StringKey(String path, String def) { - this.path = path; - this.def = def; - } - - @Override - public String get(ConfigurationAdapter adapter) { - return adapter.getString(this.path, this.def); - } -} diff --git a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java index a3aa69ac4..af94f5c0b 100644 --- a/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java +++ b/nukkit/src/main/java/me/lucko/luckperms/nukkit/NukkitConfigAdapter.java @@ -25,7 +25,6 @@ package me.lucko.luckperms.nukkit; -import me.lucko.luckperms.common.config.adapter.AbstractConfigurationAdapter; import me.lucko.luckperms.common.config.adapter.ConfigurationAdapter; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; @@ -39,13 +38,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements ConfigurationAdapter { - +public class NukkitConfigAdapter implements ConfigurationAdapter { + private final LuckPermsPlugin plugin; private final File file; private Config configuration; public NukkitConfigAdapter(LuckPermsPlugin plugin, File file) { - super(plugin); + this.plugin = plugin; this.file = file; reload(); } @@ -61,7 +60,7 @@ public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public int getInt(String path, int def) { + public int getInteger(String path, int def) { return this.configuration.getInt(path, def); } @@ -71,7 +70,7 @@ public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public List getList(String path, List def) { + public List getStringList(String path, List def) { List ret = this.configuration.getStringList(path); return ret == null ? def : ret; } @@ -88,7 +87,7 @@ public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements } @Override - public Map getMap(String path, Map def) { + public Map getStringMap(String path, Map def) { Map map = new HashMap<>(); ConfigSection section = this.configuration.getSection(path); if (section == null) { @@ -101,4 +100,9 @@ public class NukkitConfigAdapter extends AbstractConfigurationAdapter implements return map; } + + @Override + public LuckPermsPlugin getPlugin() { + return this.plugin; + } } diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java index 4c16bcfe7..9bc164bd2 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/VelocityClassLoader.java @@ -1,3 +1,28 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * 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.velocity; import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader; diff --git a/velocity/src/main/java/me/lucko/luckperms/velocity/service/PlayerPermissionProvider.java b/velocity/src/main/java/me/lucko/luckperms/velocity/service/PlayerPermissionProvider.java index caaa70b92..71f86b53f 100644 --- a/velocity/src/main/java/me/lucko/luckperms/velocity/service/PlayerPermissionProvider.java +++ b/velocity/src/main/java/me/lucko/luckperms/velocity/service/PlayerPermissionProvider.java @@ -1,3 +1,28 @@ +/* + * This file is part of LuckPerms, licensed under the MIT License. + * + * Copyright (c) lucko (Luck) + * Copyright (c) contributors + * + * 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.velocity.service; import com.google.common.base.Preconditions;