Skip to content

Commit

Permalink
This release adds support for BungeeCord 1.13 and later, as well as a…
Browse files Browse the repository at this point in the history
…dding support for recovering pub/sub channels and a version bump.
  • Loading branch information
chnkr committed Apr 19, 2019
1 parent d5dcb7d commit 429ed39
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.imaginarycode.minecraft</groupId>
<artifactId>RedisBungee</artifactId>
<version>0.4</version>
<version>0.5</version>

<repositories>
<repository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public void run() {
}
}, 0, 1, TimeUnit.MINUTES);
}
getProxy().registerChannel("legacy:RedisBungee");
getProxy().registerChannel("RedisBungee");
}

Expand Down Expand Up @@ -501,13 +502,18 @@ public Void call() throws Exception {
class PubSubListener implements Runnable {
private JedisPubSubHandler jpsh;

private Set<String> addedChannels = new HashSet<String>();

@Override
public void run() {
boolean broken = false;
try (Jedis rsc = pool.getResource()) {
try {
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) {
// FIXME: Extremely ugly hack
// Attempt to unsubscribe this instance and try again.
Expand All @@ -522,6 +528,9 @@ public void run() {
}
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) {
Expand All @@ -530,14 +539,17 @@ public void run() {
}

public void addChannel(String... channel) {
addedChannels.addAll(Arrays.asList(channel));
jpsh.subscribe(channel);
}

public void removeChannel(String... channel) {
addedChannels.removeAll(Arrays.asList(channel));
jpsh.unsubscribe(channel);
}

public void poison() {
addedChannels.clear();
jpsh.unsubscribe();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ public void onPing(final ProxyPingEvent event) {

@EventHandler
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);
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
@Override
Expand Down Expand Up @@ -244,7 +245,7 @@ public void run() {
return;
}

((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
((Server) event.getSender()).sendData(currentChannel, out.toByteArray());
}
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: RedisBungee
main: com.imaginarycode.minecraft.redisbungee.RedisBungee
version: 0.3.10
author: tuxed
# This is used so that we can automagically override default BungeeCord behavior.
version: 0.5
author: chunkr
# This is used so that we can automatically override default BungeeCord behavior.
softDepends: ["cmd_find", "cmd_list"]

0 comments on commit 429ed39

Please sign in to comment.