diff --git a/RedisBungee-API/pom.xml b/RedisBungee-API/pom.xml
index 7694afd..2c4adf4 100644
--- a/RedisBungee-API/pom.xml
+++ b/RedisBungee-API/pom.xml
@@ -61,6 +61,11 @@
4.13.2
test
+
+ org.spongepowered
+ configurate-yaml
+ 3.7.2
+
\ No newline at end of file
diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java
index 4f099ef..4ee7eb3 100644
--- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java
+++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java
@@ -1,15 +1,116 @@
package com.imaginarycode.minecraft.redisbungee.api.config;
+import com.google.common.reflect.TypeToken;
+import com.imaginarycode.minecraft.redisbungee.api.RedisBungeeMode;
+import com.imaginarycode.minecraft.redisbungee.api.RedisBungeePlugin;
+import com.imaginarycode.minecraft.redisbungee.api.summoners.ClusterJedisSummoner;
+import com.imaginarycode.minecraft.redisbungee.api.summoners.JedisSummoner;
+import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner;
+import ninja.leaping.configurate.ConfigurationNode;
+import ninja.leaping.configurate.objectmapping.ObjectMappingException;
+import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import redis.clients.jedis.*;
+
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
-import java.util.UUID;
+import java.util.*;
public interface ConfigLoader {
- void loadConfig() throws IOException;
+
+ default void loadConfig(RedisBungeePlugin> plugin, File dataFolder) throws IOException {
+ loadConfig(plugin, dataFolder.toPath());
+ }
+
+ default void loadConfig(RedisBungeePlugin> plugin, Path dataFolder) throws IOException {
+ Path configFile = createConfigFile(dataFolder);
+ final YAMLConfigurationLoader yamlConfigurationFileLoader = YAMLConfigurationLoader.builder().setPath(configFile).build();
+ ConfigurationNode node = yamlConfigurationFileLoader.load();
+ if (node.getNode("config-version").getInt(0) != RedisBungeeConfiguration.CONFIG_VERSION) {
+ handleOldConfig(dataFolder);
+ node = yamlConfigurationFileLoader.load();
+ }
+ final boolean useSSL = node.getNode("useSSL").getBoolean(false);
+ final boolean overrideBungeeCommands = node.getNode("override-bungee-commands").getBoolean(false);
+ final boolean registerLegacyCommands = node.getNode("register-legacy-commands").getBoolean(false);
+ String redisPassword = node.getNode("redis-password").getString(null);
+ String proxyId = node.getNode("proxy-id").getString("test-1");
+ final int maxConnections = node.getNode("max-redis-connections").getInt(10);
+ List exemptAddresses;
+ try {
+ exemptAddresses = node.getNode("exempt-ip-addresses").getList(TypeToken.of(String.class));
+ } catch (ObjectMappingException e) {
+ exemptAddresses = Collections.emptyList();
+ }
+
+ // check redis password
+ if (redisPassword != null && (redisPassword.isEmpty() || redisPassword.equals("none"))) {
+ redisPassword = null;
+ plugin.logWarn("INSECURE setup was detected Please set password for your redis instance.");
+ } else if (redisPassword == null) {
+ plugin.logWarn("INSECURE setup was detected Please set password for your redis instance.");
+ }
+ if (!useSSL) {
+ plugin.logWarn("INSECURE setup was detected Please setup ssl for your redis instance.");
+ }
+ // Configuration sanity checks.
+ if (proxyId == null || proxyId.isEmpty()) {
+ String genId = UUID.randomUUID().toString();
+ plugin.logInfo("Generated proxy id " + genId + " and saving it to config.");
+ node.getNode("proxy-id").setValue(genId);
+ yamlConfigurationFileLoader.save(node);
+ proxyId = genId;
+ plugin.logInfo("proxy id was generated: " + proxyId);
+ } else {
+ plugin.logInfo("Loaded proxy id " + proxyId);
+ }
+ RedisBungeeConfiguration configuration = new RedisBungeeConfiguration(proxyId, exemptAddresses, registerLegacyCommands, overrideBungeeCommands);
+ Summoner> summoner;
+ RedisBungeeMode redisBungeeMode;
+ if (node.getNode("cluster-mode-enabled").getBoolean(false)) {
+ plugin.logInfo("RedisBungee MODE: CLUSTER");
+ Set hostAndPortSet = new HashSet<>();
+ GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig<>();
+ poolConfig.setMaxTotal(maxConnections);
+ node.getNode("redis-cluster-servers").getChildrenList().forEach((childNode) -> {
+ Map