mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Fix issues with Redis subscriber
This commit is contained in:
1 parent
2dd0bbb9d8
commit
840ebaf9ba
4 files changed
+27
-16
No files matched your search
@@ -266,6 +266,12 @@ public final class HuskHomes extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (HuskHomes.getSettings().doBungee()) {
|
||||
if (!HuskHomes.getSettings().getMessengerType().equalsIgnoreCase("pluginmessage")) {
|
||||
RedisReceiver.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
// Terminate the Hikari data source
|
||||
database.close();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import redis.clients.jedis.JedisPubSub;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class RedisReceiver {
|
||||
|
||||
@@ -20,12 +21,17 @@ public class RedisReceiver {
|
||||
return jedisPool.getResource();
|
||||
}
|
||||
|
||||
// Initialize Jedis. Note that due to the shading on DefaultEvictionPool we have to change the contextual ClassLoader here
|
||||
public static void initialize() {
|
||||
jedisPool = new JedisPool(new JedisPoolConfig(),
|
||||
HuskHomes.getSettings().getRedisHost(),
|
||||
HuskHomes.getSettings().getRedisPort());
|
||||
}
|
||||
|
||||
// Close the connection
|
||||
public static void terminate() {
|
||||
jedisPool.close();
|
||||
}
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
public static final String REDIS_CHANNEL = "HuskHomes";
|
||||
@@ -41,14 +47,12 @@ public class RedisReceiver {
|
||||
|
||||
public static void listen() {
|
||||
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
|
||||
try (Jedis jedis = getJedis()) {
|
||||
if (!jedisPassword.equals("")) {
|
||||
jedis.auth(jedisPassword);
|
||||
}
|
||||
jedis.connect();
|
||||
if (jedis.isConnected()) {
|
||||
plugin.getLogger().info("Enabled Redis listener successfully!");
|
||||
new Thread(() -> jedis.subscribe(new JedisPubSub() {
|
||||
new Thread(() -> {
|
||||
try (Jedis jedis = getJedis()) {
|
||||
if (!jedisPassword.equals("")) {
|
||||
jedis.auth(jedisPassword);
|
||||
}
|
||||
jedis.subscribe(new JedisPubSub() {
|
||||
@Override
|
||||
public void onMessage(String channel, String message) {
|
||||
if (!channel.equals(REDIS_CHANNEL)) {
|
||||
@@ -103,10 +107,10 @@ public class RedisReceiver {
|
||||
final String messageData = splitMessage[1];
|
||||
CrossServerMessageHandler.handlePluginMessage(new RedisMessage(clusterID, receiver.getName(), messageType, messageData), receiver);
|
||||
}
|
||||
}, REDIS_CHANNEL), "Redis Subscriber").start();
|
||||
} else {
|
||||
plugin.getLogger().severe("Failed to initialize the redis listener!");
|
||||
}, REDIS_CHANNEL);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().log(Level.SEVERE, "An exception occurred in the Jedis subscriber", e);
|
||||
}
|
||||
}
|
||||
}, "Redis Subscriber").start();
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,6 @@ authors: [William278]
|
||||
softdepend: [dynmap, Vault, BlueMap, Squaremap]
|
||||
description: A powerful, intuitive and flexible teleportation suite
|
||||
website: 'https://william278.net'
|
||||
libraries:
|
||||
- redis.clients:jedis:2.7.2
|
||||
|
||||
commands:
|
||||
home:
|
||||
usage: /<command> <home>
|
||||
|
||||
Reference in new issue
Block a user