mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2024-12-23 10:38:01 +00:00
update to config handling, fix null pointer in pubsub handler, config changes
rename config in jar, config api, fixed null pointer in pubsub listener, use map allow muiltable port and hosts for the cluster
This commit is contained in:
parent
5d1167c20f
commit
0408e2923b
@ -22,59 +22,31 @@ public class PubSubListener implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
RedisTask<Void> subTask = new RedisTask<Void>(plugin.getApi()) {
|
||||
RedisTask<Void> subTask = new RedisTask<Void>(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);
|
||||
}
|
||||
|
@ -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<P> extends EventsPlatform {
|
||||
public interface RedisBungeePlugin<P> extends EventsPlatform, ConfigLoader {
|
||||
|
||||
default void initialize() {
|
||||
|
||||
@ -92,8 +94,6 @@ public interface RedisBungeePlugin<P> extends EventsPlatform {
|
||||
|
||||
long getRedisTime(List<String> timeRes);
|
||||
|
||||
void loadConfig() throws Exception;
|
||||
|
||||
void kickPlayer(UUID playerUniqueId, String message);
|
||||
|
||||
void kickPlayer(String playerName, String message);
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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<InetAddress> exemptAddresses;
|
||||
private final boolean overrideBungeeCommands;
|
||||
private static RedisBungeeConfiguration config;
|
||||
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean overrideBungeeCommands) {
|
||||
private final boolean registerLegacyCommands;
|
||||
|
||||
private final boolean overrideBungeeCommands;
|
||||
|
||||
public RedisBungeeConfiguration(String proxyId, List<String> exemptAddresses, boolean registerLegacyCommands, boolean overrideBungeeCommands) {
|
||||
this.proxyId = proxyId;
|
||||
|
||||
ImmutableList.Builder<InetAddress> 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;
|
||||
}
|
||||
}
|
@ -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.
|
Loading…
Reference in New Issue
Block a user