diff --git a/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java new file mode 100644 index 000000000..bc064413b --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java @@ -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); + } + }); + } + +}