2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-25 16:00:27 +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:
2022-07-22 12:29:39 +04:00
parent 5d1167c20f
commit 0408e2923b
5 changed files with 70 additions and 57 deletions

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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;
}
}