2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2024-12-23 18:48:02 +00:00

Added an api method to send messages to a custom PubSub channel. This makes the register channel feature a lot more useful.

This commit is contained in:
mc-core.com 2014-07-25 19:00:53 -04:00
parent 7a710c1ae0
commit a8a75723fb
2 changed files with 26 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import com.google.common.io.ByteStreams;
import com.google.gson.Gson;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import com.imaginarycode.minecraft.redisbungee.util.UUIDTranslator;
import lombok.Getter;
import lombok.NonNull;
import net.md_5.bungee.api.config.ServerInfo;
@ -309,6 +310,20 @@ public final class RedisBungee extends Plugin {
pool.returnResource(jedis);
}
}
final void sendChannelMessage(String channel, String message) {
Jedis jedis = pool.getResource();
try {
jedis.publish(channel, message);
} catch (JedisConnectionException e) {
// Redis server has disappeared!
getLogger().log(Level.SEVERE, "Unable to get connection from pool - did your Redis server go away?", e);
pool.returnBrokenResource(jedis);
throw new RuntimeException("Unable to publish channel message", e);
} finally {
pool.returnResource(jedis);
}
}
@Override
public void onEnable() {

View File

@ -157,6 +157,17 @@ public class RedisBungeeAPI {
plugin.sendProxyCommand(proxyId, command);
}
/**
* Sends a message to a PubSub channel. The channel has to be subscribed to on this, or another redisbungee instance for {@link com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent} to fire.
*
* @param channel The PubSub channel
* @param message the message body to send
* @since 0.3.3
*/
public final void sendChannelMessage(@NonNull String channel, @NonNull String message) {
plugin.sendChannelMessage(channel, message);
}
/**
* Get the current BungeeCord server ID for this server.
*