From 4ce9c908394de84430e96ca9c694c86d4e6d9ed3 Mon Sep 17 00:00:00 2001 From: TadahTech Date: Sun, 5 Jun 2016 00:32:04 -0500 Subject: [PATCH] Party Redis init. Wrap for 6/4/2016. Total time: 9.3 hrs. --- .../core/party/redis/PartyRedisManager.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/party/redis/PartyRedisManager.java 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); + } + }); + } + +}