2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-11-23 04:28:01 +00:00

This release adds support for BungeeCord 1.13 and later, as well as adding support for recovering pub/sub channels and a version bump.

This commit is contained in:
Chnkr 2019-04-19 20:51:10 +02:00
parent d5dcb7d3fc
commit 429ed39160
4 changed files with 20 additions and 7 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.imaginarycode.minecraft</groupId> <groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId> <artifactId>RedisBungee</artifactId>
<version>0.4</version> <version>0.5</version>
<repositories> <repositories>
<repository> <repository>

View File

@ -368,6 +368,7 @@ public final class RedisBungee extends Plugin {
} }
}, 0, 1, TimeUnit.MINUTES); }, 0, 1, TimeUnit.MINUTES);
} }
getProxy().registerChannel("legacy:RedisBungee");
getProxy().registerChannel("RedisBungee"); getProxy().registerChannel("RedisBungee");
} }
@ -501,13 +502,18 @@ public final class RedisBungee extends Plugin {
class PubSubListener implements Runnable { class PubSubListener implements Runnable {
private JedisPubSubHandler jpsh; private JedisPubSubHandler jpsh;
private Set<String> addedChannels = new HashSet<String>();
@Override @Override
public void run() { public void run() {
boolean broken = false; boolean broken = false;
try (Jedis rsc = pool.getResource()) { try (Jedis rsc = pool.getResource()) {
try { try {
jpsh = new JedisPubSubHandler(); jpsh = new JedisPubSubHandler();
rsc.subscribe(jpsh, "redisbungee-" + configuration.getServerId(), "redisbungee-allservers", "redisbungee-data"); addedChannels.add("redisbungee-" + configuration.getServerId());
addedChannels.add("redisbungee-allservers");
addedChannels.add("redisbungee-data");
rsc.subscribe(jpsh, addedChannels.toArray(new String[0]));
} catch (Exception e) { } catch (Exception e) {
// FIXME: Extremely ugly hack // FIXME: Extremely ugly hack
// Attempt to unsubscribe this instance and try again. // Attempt to unsubscribe this instance and try again.
@ -522,6 +528,9 @@ public final class RedisBungee extends Plugin {
} }
broken = true; broken = true;
} }
} catch (JedisConnectionException e) {
getLogger().log(Level.INFO, "PubSub error, attempting to recover in 5 secs.");
getProxy().getScheduler().schedule(RedisBungee.this, PubSubListener.this, 5, TimeUnit.SECONDS);
} }
if (broken) { if (broken) {
@ -530,14 +539,17 @@ public final class RedisBungee extends Plugin {
} }
public void addChannel(String... channel) { public void addChannel(String... channel) {
addedChannels.addAll(Arrays.asList(channel));
jpsh.subscribe(channel); jpsh.subscribe(channel);
} }
public void removeChannel(String... channel) { public void removeChannel(String... channel) {
addedChannels.removeAll(Arrays.asList(channel));
jpsh.unsubscribe(channel); jpsh.unsubscribe(channel);
} }
public void poison() { public void poison() {
addedChannels.clear();
jpsh.unsubscribe(); jpsh.unsubscribe();
} }
} }

View File

@ -148,7 +148,8 @@ public class RedisBungeeListener implements Listener {
@EventHandler @EventHandler
public void onPluginMessage(final PluginMessageEvent event) { public void onPluginMessage(final PluginMessageEvent event) {
if (event.getTag().equals("RedisBungee") && event.getSender() instanceof Server) { if ((event.getTag().equals("legacy:RedisBungee") || event.getTag().equals("RedisBungee")) && event.getSender() instanceof Server) {
final String currentChannel = event.getTag();
final byte[] data = Arrays.copyOf(event.getData(), event.getData().length); final byte[] data = Arrays.copyOf(event.getData(), event.getData().length);
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() { plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
@Override @Override
@ -244,7 +245,7 @@ public class RedisBungeeListener implements Listener {
return; return;
} }
((Server) event.getSender()).sendData("RedisBungee", out.toByteArray()); ((Server) event.getSender()).sendData(currentChannel, out.toByteArray());
} }
}); });
} }

View File

@ -1,6 +1,6 @@
name: RedisBungee name: RedisBungee
main: com.imaginarycode.minecraft.redisbungee.RedisBungee main: com.imaginarycode.minecraft.redisbungee.RedisBungee
version: 0.3.10 version: 0.5
author: tuxed author: chunkr
# This is used so that we can automagically override default BungeeCord behavior. # This is used so that we can automatically override default BungeeCord behavior.
softDepends: ["cmd_find", "cmd_list"] softDepends: ["cmd_find", "cmd_list"]