diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PubSubListener.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PubSubListener.java index 4396462..b083f8e 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PubSubListener.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/PubSubListener.java @@ -22,59 +22,31 @@ public class PubSubListener implements Runnable { @Override public void run() { - RedisTask subTask = new RedisTask(plugin.getApi()) { + RedisTask subTask = new RedisTask(plugin) { @Override public Void jedisTask(Jedis jedis) { - try { - jpsh = new JedisPubSubHandler(plugin); - addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId()); - addedChannels.add("redisbungee-allservers"); - addedChannels.add("redisbungee-data"); - jedis.subscribe(jpsh, addedChannels.toArray(new String[0])); - } catch (Exception e) { - // FIXME: Extremely ugly hack - // Attempt to unsubscribe this instance and try again. - plugin.logWarn("PubSub error, attempting to recover."); - try { - jpsh.unsubscribe(); - } catch (Exception e1) { - /* This may fail with - - java.net.SocketException: Broken pipe - - redis.clients.jedis.exceptions.JedisConnectionException: JedisPubSub was not subscribed to a Jedis instance - */ - } - } + jpsh = new JedisPubSubHandler(plugin); + addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId()); + addedChannels.add("redisbungee-allservers"); + addedChannels.add("redisbungee-data"); + jedis.subscribe(jpsh, addedChannels.toArray(new String[0])); return null; } @Override public Void clusterJedisTask(JedisCluster jedisCluster) { - try { - jpsh = new JedisPubSubHandler(plugin); - addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId()); - addedChannels.add("redisbungee-allservers"); - addedChannels.add("redisbungee-data"); - jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0])); - } catch (Exception e) { - // FIXME: Extremely ugly hack - // Attempt to unsubscribe this instance and try again. - plugin.logWarn("PubSub error, attempting to recover."); - try { - jpsh.unsubscribe(); - } catch (Exception e1) { - /* This may fail with - - java.net.SocketException: Broken pipe - - redis.clients.jedis.exceptions.JedisConnectionException: JedisPubSub was not subscribed to a Jedis instance - */ - } - } + jpsh = new JedisPubSubHandler(plugin); + addedChannels.add("redisbungee-" + plugin.getConfiguration().getProxyId()); + addedChannels.add("redisbungee-allservers"); + addedChannels.add("redisbungee-data"); + jedisCluster.subscribe(jpsh, addedChannels.toArray(new String[0])); return null; } }; - try { + try { subTask.execute(); - } catch (JedisConnectionException e) { + } catch (Exception e) { plugin.logWarn("PubSub error, attempting to recover in 5 secs."); plugin.executeAsyncAfter(this, TimeUnit.SECONDS, 5); } diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java index 9f50887..2d939c8 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeePlugin.java @@ -2,6 +2,8 @@ package com.imaginarycode.minecraft.redisbungee.api; import com.google.common.collect.Multimap; import com.imaginarycode.minecraft.redisbungee.RedisBungeeAPI; +import com.imaginarycode.minecraft.redisbungee.api.config.ConfigLoader; +import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration; import com.imaginarycode.minecraft.redisbungee.api.summoners.Summoner; import com.imaginarycode.minecraft.redisbungee.api.util.uuid.UUIDTranslator; @@ -18,7 +20,7 @@ import java.util.concurrent.TimeUnit; * @author Ham1255 * @since 0.7.0 */ -public interface RedisBungeePlugin

extends EventsPlatform { +public interface RedisBungeePlugin

extends EventsPlatform, ConfigLoader { default void initialize() { @@ -92,8 +94,6 @@ public interface RedisBungeePlugin

extends EventsPlatform { long getRedisTime(List timeRes); - void loadConfig() throws Exception; - void kickPlayer(UUID playerUniqueId, String message); void kickPlayer(String playerName, String message); 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 new file mode 100644 index 0000000..faf2639 --- /dev/null +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/ConfigLoader.java @@ -0,0 +1,14 @@ +package com.imaginarycode.minecraft.redisbungee.api.config; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +public interface ConfigLoader { + void loadConfig() throws IOException; + + Path createConfigFile() throws IOException; + + void handleOldConfig(Path path) throws IOException; + +} diff --git a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeeConfiguration.java b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java similarity index 71% rename from RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeeConfiguration.java rename to RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java index 4c504f4..204a69f 100644 --- a/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/RedisBungeeConfiguration.java +++ b/RedisBungee-API/src/main/java/com/imaginarycode/minecraft/redisbungee/api/config/RedisBungeeConfiguration.java @@ -1,4 +1,4 @@ -package com.imaginarycode.minecraft.redisbungee.api; +package com.imaginarycode.minecraft.redisbungee.api.config; import com.google.common.collect.ImmutableList; import com.google.common.net.InetAddresses; @@ -7,12 +7,15 @@ import java.net.InetAddress; import java.util.List; public class RedisBungeeConfiguration { + public static final int CONFIG_VERSION = 1; private final String proxyId; private final List exemptAddresses; - private final boolean overrideBungeeCommands; - private static RedisBungeeConfiguration config; - public RedisBungeeConfiguration(String proxyId, List exemptAddresses, boolean overrideBungeeCommands) { + private final boolean registerLegacyCommands; + + private final boolean overrideBungeeCommands; + + public RedisBungeeConfiguration(String proxyId, List exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands) { this.proxyId = proxyId; ImmutableList.Builder addressBuilder = ImmutableList.builder(); @@ -20,7 +23,7 @@ public class RedisBungeeConfiguration { addressBuilder.add(InetAddresses.forString(s)); } this.exemptAddresses = addressBuilder.build(); - config = this; + this.registerLegacyCommands = registerLegacyCommands; this.overrideBungeeCommands = overrideBungeeCommands; } @@ -32,11 +35,11 @@ public class RedisBungeeConfiguration { return exemptAddresses; } + public boolean doRegisterLegacyCommands() { + return registerLegacyCommands; + } + public boolean doOverrideBungeeCommands() { return overrideBungeeCommands; } - - public static RedisBungeeConfiguration getConfig() { - return config; - } } diff --git a/RedisBungee-API/src/main/resources/example_config.yml b/RedisBungee-API/src/main/resources/config.yml similarity index 66% rename from RedisBungee-API/src/main/resources/example_config.yml rename to RedisBungee-API/src/main/resources/config.yml index 0d8494c..f01352e 100644 --- a/RedisBungee-API/src/main/resources/example_config.yml +++ b/RedisBungee-API/src/main/resources/config.yml @@ -1,3 +1,6 @@ +# Config version DO NOT CHANGE!!!! +config-version: 1 + # RedisBungee configuration file. # PLEASE READ THE WIKI: https://github.com/ProxioDev/RedisBungee/wiki @@ -5,10 +8,27 @@ # enabling this option will enable cluster mode. cluster-mode-enabled: false -# The Redis server you use. +# FORMAT: +# redis-cluster-servers: +# - host: 127.0.0.1 +# port: 2020 +# - host: 127.0.0.1 +# port: 2021 +# - host: 127.0.0.1 +# port: 2021 + +# you can set single server and Jedis will automatically discover cluster nodes, +# but might fail if this single redis node is down when Proxy startup, its recommended put the all the nodes +redis-cluster-servers: + - host: 127.0.0.1 + port: 6379 + # Get Redis from http://redis.io/ +# The Redis server you use. +# these settings are ignored when cluster mode is enabled. redis-server: 127.0.0.1 redis-port: 6379 + # OPTIONAL but recommended: If your Redis server uses AUTH, set the password required. redis-password: "" # Maximum connections that will be maintained to the Redis server. @@ -21,8 +41,12 @@ max-redis-connections: 10 # in cluster mode using ssl without password is ignored due fact is not supported in Jedis lib useSSL: false -# An identifier for this BungeeCord instance. Will randomly generate if leaving it blank. -server-id: "test1" +# An identifier for this BungeeCord / Velocity instance. Will randomly generate if leaving it blank. +proxy-id: "test-1" + +# Register redis bungee legacy commands +# if this disabled override-bungee-commands will be ignored +register-legacy-commands: false # Whether or not RedisBungee should install its version of regular BungeeCord commands. # Often, the RedisBungee commands are desired, but in some cases someone may wish to @@ -33,7 +57,7 @@ server-id: "test1" # # Please note that with build 787+, most commands overridden by RedisBungee were moved to # modules, and these must be disabled or overridden yourself. -register-bungee-commands: true +override-bungee-commands: false # A list of IP addresses for which RedisBungee will not modify the response for, useful for automatic # restart scripts.