From 14cb34ac9517104816a27ec840a3138bec2faa03 Mon Sep 17 00:00:00 2001 From: Luck Date: Sat, 25 Mar 2017 23:23:20 +0000 Subject: [PATCH] Force some config options to be read as lower case --- .../luckperms/common/config/ConfigKeys.java | 19 ++++----- .../config/keys/LowercaseStringKey.java | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.java 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 ccd82b79a..63fb27df9 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 @@ -33,6 +33,7 @@ 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.LowercaseStringKey; import me.lucko.luckperms.common.config.keys.MapKey; import me.lucko.luckperms.common.config.keys.StaticKey; import me.lucko.luckperms.common.config.keys.StringKey; @@ -56,7 +57,7 @@ import java.util.function.Function; @UtilityClass public class ConfigKeys { - public static final ConfigKey SERVER = StringKey.of("server", "global"); + public static final ConfigKey SERVER = LowercaseStringKey.of("server", "global"); public static final ConfigKey SYNC_TIME = EnduringKey.wrap(IntegerKey.of("data.sync-minutes", -1)); 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 @@ -136,7 +137,7 @@ public class ConfigKeys { 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_SERVER = LowercaseStringKey.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); @@ -167,19 +168,19 @@ public class ConfigKeys { ); })); 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 STORAGE_METHOD = EnduringKey.wrap(LowercaseStringKey.of("storage-method", "h2")); public static final ConfigKey WATCH_FILES = BooleanKey.of("watch-files", true); 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")) + .put("user", c.getString("split-storage.methods.user", "h2").toLowerCase()) + .put("group", c.getString("split-storage.methods.group", "h2").toLowerCase()) + .put("track", c.getString("split-storage.methods.track", "h2").toLowerCase()) + .put("uuid", c.getString("split-storage.methods.uuid", "h2").toLowerCase()) + .put("log", c.getString("split-storage.methods.log", "h2").toLowerCase()) .build(); })); - public static final ConfigKey MESSAGING_SERVICE = EnduringKey.wrap(StringKey.of("messaging-service", "none")); + public static final ConfigKey MESSAGING_SERVICE = EnduringKey.wrap(LowercaseStringKey.of("messaging-service", "none")); public static final ConfigKey AUTO_PUSH_UPDATES = EnduringKey.wrap(BooleanKey.of("auto-push-updates", true)); 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)); 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 new file mode 100644 index 000000000..29f6b7d87 --- /dev/null +++ b/common/src/main/java/me/lucko/luckperms/common/config/keys/LowercaseStringKey.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.LuckPermsConfiguration; + +@AllArgsConstructor(staticName = "of") +public class LowercaseStringKey implements ConfigKey { + private final String path; + private final String def; + + @Override + public String get(LuckPermsConfiguration config) { + return config.getString(path, def).toLowerCase(); + } +}