mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-03 22:16:34 +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
@@ -58,6 +58,10 @@
|
|||||||
<pattern>com.zaxxer.hikari</pattern>
|
<pattern>com.zaxxer.hikari</pattern>
|
||||||
<shadedPattern>me.william278.huskhomes2.libraries.hikari</shadedPattern>
|
<shadedPattern>me.william278.huskhomes2.libraries.hikari</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>redis.clients</pattern>
|
||||||
|
<shadedPattern>me.william278.huskhomes2.libraries.jedis</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@@ -188,7 +192,7 @@
|
|||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>4.0.1</version>
|
<version>4.0.1</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.zaxxer</groupId>
|
<groupId>com.zaxxer</groupId>
|
||||||
|
|||||||
@@ -266,6 +266,12 @@ public final class HuskHomes extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
if (HuskHomes.getSettings().doBungee()) {
|
||||||
|
if (!HuskHomes.getSettings().getMessengerType().equalsIgnoreCase("pluginmessage")) {
|
||||||
|
RedisReceiver.terminate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Terminate the Hikari data source
|
// Terminate the Hikari data source
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import redis.clients.jedis.JedisPubSub;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class RedisReceiver {
|
public class RedisReceiver {
|
||||||
|
|
||||||
@@ -20,12 +21,17 @@ public class RedisReceiver {
|
|||||||
return jedisPool.getResource();
|
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() {
|
public static void initialize() {
|
||||||
jedisPool = new JedisPool(new JedisPoolConfig(),
|
jedisPool = new JedisPool(new JedisPoolConfig(),
|
||||||
HuskHomes.getSettings().getRedisHost(),
|
HuskHomes.getSettings().getRedisHost(),
|
||||||
HuskHomes.getSettings().getRedisPort());
|
HuskHomes.getSettings().getRedisPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close the connection
|
||||||
|
public static void terminate() {
|
||||||
|
jedisPool.close();
|
||||||
|
}
|
||||||
|
|
||||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||||
public static final String REDIS_CHANNEL = "HuskHomes";
|
public static final String REDIS_CHANNEL = "HuskHomes";
|
||||||
@@ -41,14 +47,12 @@ public class RedisReceiver {
|
|||||||
|
|
||||||
public static void listen() {
|
public static void listen() {
|
||||||
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
|
final String jedisPassword = HuskHomes.getSettings().getRedisPassword();
|
||||||
try (Jedis jedis = getJedis()) {
|
new Thread(() -> {
|
||||||
if (!jedisPassword.equals("")) {
|
try (Jedis jedis = getJedis()) {
|
||||||
jedis.auth(jedisPassword);
|
if (!jedisPassword.equals("")) {
|
||||||
}
|
jedis.auth(jedisPassword);
|
||||||
jedis.connect();
|
}
|
||||||
if (jedis.isConnected()) {
|
jedis.subscribe(new JedisPubSub() {
|
||||||
plugin.getLogger().info("Enabled Redis listener successfully!");
|
|
||||||
new Thread(() -> jedis.subscribe(new JedisPubSub() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(String channel, String message) {
|
public void onMessage(String channel, String message) {
|
||||||
if (!channel.equals(REDIS_CHANNEL)) {
|
if (!channel.equals(REDIS_CHANNEL)) {
|
||||||
@@ -103,10 +107,10 @@ public class RedisReceiver {
|
|||||||
final String messageData = splitMessage[1];
|
final String messageData = splitMessage[1];
|
||||||
CrossServerMessageHandler.handlePluginMessage(new RedisMessage(clusterID, receiver.getName(), messageType, messageData), receiver);
|
CrossServerMessageHandler.handlePluginMessage(new RedisMessage(clusterID, receiver.getName(), messageType, messageData), receiver);
|
||||||
}
|
}
|
||||||
}, REDIS_CHANNEL), "Redis Subscriber").start();
|
}, REDIS_CHANNEL);
|
||||||
} else {
|
} catch (Exception e) {
|
||||||
plugin.getLogger().severe("Failed to initialize the redis listener!");
|
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]
|
softdepend: [dynmap, Vault, BlueMap, Squaremap]
|
||||||
description: A powerful, intuitive and flexible teleportation suite
|
description: A powerful, intuitive and flexible teleportation suite
|
||||||
website: 'https://william278.net'
|
website: 'https://william278.net'
|
||||||
libraries:
|
|
||||||
- redis.clients:jedis:2.7.2
|
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
home:
|
home:
|
||||||
usage: /<command> <home>
|
usage: /<command> <home>
|
||||||
|
|||||||
Reference in new issue
Block a user