Party Redis init.
Wrap for 6/4/2016. Total time: 9.3 hrs.
This commit is contained in:
parent
8c3d5f66a2
commit
4ce9c90839
@ -0,0 +1,58 @@
|
||||
package mineplex.core.party.redis;
|
||||
|
||||
import mineplex.core.party.PartyManager;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* Redis system for Parties
|
||||
*/
|
||||
public class PartyRedisManager
|
||||
{
|
||||
protected static final String CHANNEL_BASE = "party-pubsub";
|
||||
protected static final String PLAYER_REQUEST_CHANNEL = "mineplex-player-locater";
|
||||
|
||||
private PartyManager _plugin;
|
||||
private JedisPool _writePool;
|
||||
private JedisPool _readPool;
|
||||
private String _channel;
|
||||
private String _serverName;
|
||||
|
||||
public PartyRedisManager(PartyManager plugin, String serverName, JedisPool writePool, JedisPool readPool)
|
||||
{
|
||||
_plugin = plugin;
|
||||
_serverName = serverName;
|
||||
_readPool = readPool;
|
||||
_writePool = writePool;
|
||||
_channel = CHANNEL_BASE + "-" + serverName;
|
||||
|
||||
plugin.runAsync(() -> {
|
||||
try (Jedis jedis = readPool.getResource())
|
||||
{
|
||||
jedis.subscribe(new PartyRedisListener(), _channel);
|
||||
jedis.subscribe(new PlayerFinderListener(), PLAYER_REQUEST_CHANNEL);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void findPlayer(String player)
|
||||
{
|
||||
_plugin.runAsync(() -> {
|
||||
try (Jedis jedis = _writePool.getResource())
|
||||
{
|
||||
jedis.publish(PLAYER_REQUEST_CHANNEL, player + ":" + _serverName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void publish(String message, String server)
|
||||
{
|
||||
_plugin.runAsync(() -> {
|
||||
try (Jedis jedis = _writePool.getResource())
|
||||
{
|
||||
jedis.publish(CHANNEL_BASE + "-" + server, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user