mirror of
				https://github.com/proxiodev/RedisBungee.git
				synced 2025-11-04 01:28:02 +00:00 
			
		
		
		
	Merge pull request #7 from mccore/master
Added an api method to send messages to a custom PubSub channel.
This commit is contained in:
		
						commit
						bf2d305be9
					
				@ -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;
 | 
			
		||||
@ -310,6 +311,20 @@ public final class RedisBungee extends Plugin {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    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() {
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
@ -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.
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user