diff --git a/pom.xml b/pom.xml
index c33c8230..43b51c88 100644
--- a/pom.xml
+++ b/pom.xml
@@ -58,6 +58,10 @@
com.zaxxer.hikari
me.william278.huskhomes2.libraries.hikari
+
+ redis.clients
+ me.william278.huskhomes2.libraries.jedis
+
@@ -188,7 +192,7 @@
jedis
4.0.1
jar
- provided
+ compile
com.zaxxer
diff --git a/src/main/java/me/william278/huskhomes2/HuskHomes.java b/src/main/java/me/william278/huskhomes2/HuskHomes.java
index 8004ca20..6fd04e5f 100644
--- a/src/main/java/me/william278/huskhomes2/HuskHomes.java
+++ b/src/main/java/me/william278/huskhomes2/HuskHomes.java
@@ -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();
diff --git a/src/main/java/me/william278/huskhomes2/data/message/redis/RedisReceiver.java b/src/main/java/me/william278/huskhomes2/data/message/redis/RedisReceiver.java
index 9939b072..eb16ac65 100644
--- a/src/main/java/me/william278/huskhomes2/data/message/redis/RedisReceiver.java
+++ b/src/main/java/me/william278/huskhomes2/data/message/redis/RedisReceiver.java
@@ -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();
}
}
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 81b33bf5..b1b5b4c5 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -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: /