From bcf7f08d812238ef77a7e468c7d61b686beac940 Mon Sep 17 00:00:00 2001 From: ham1255 Date: Sun, 10 May 2020 21:44:10 +0400 Subject: [PATCH] Check if error will occure when redis fails --- .idea/artifacts/SkLimework_jar.xml | 2 +- .idea/vcs.xml | 6 +++ .idea/workspace.xml | 29 ++++++++++- pom.xml | 50 +++++++++++++++---- .../limework/skLimework/Events/RedisSub.java | 13 ++++- .../skLimework/elements/EffSendMessage.java | 7 ++- src/main/resources/config.yml | 2 +- 7 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/artifacts/SkLimework_jar.xml b/.idea/artifacts/SkLimework_jar.xml index 70e6a47..394f97a 100644 --- a/.idea/artifacts/SkLimework_jar.xml +++ b/.idea/artifacts/SkLimework_jar.xml @@ -1,6 +1,6 @@ - C:/Complie + $PROJECT_DIR$/../FallBack/plugins diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b03bf91..2636830 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,7 +6,15 @@ - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index ceeef94..fb09dcd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,9 +6,9 @@ net.limework.addon SkLimework - 1.0-SNAPSHOT - jar> - + 1.0.0 + jar + @@ -18,29 +18,57 @@ 1.8 1.8 + UTF-8 + + org.apache.maven.plugins + maven-shade-plugin + 3.2.3 + + false + + + + package + + shade + + + + - - - + + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + jitpack.io + https://jitpack.io + + + PaperMC + https://repo.destroystokyo.com/repository/maven-public/ + + + sk89q + http://maven.sk89q.com/repo + - org.spigotmc - spigot-api - 1.15.2-R0.1-SNAPSHOT + com.github.skriptlang + Skript + 2.4.1 provided - org.bukkit - bukkit + org.spigotmc + spigot-api 1.15.2-R0.1-SNAPSHOT provided diff --git a/src/main/java/net/limework/skLimework/Events/RedisSub.java b/src/main/java/net/limework/skLimework/Events/RedisSub.java index 85fa73e..b15d9d3 100644 --- a/src/main/java/net/limework/skLimework/Events/RedisSub.java +++ b/src/main/java/net/limework/skLimework/Events/RedisSub.java @@ -6,6 +6,7 @@ import org.bukkit.ChatColor; import org.json.JSONObject; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPubSub; +import redis.clients.jedis.exceptions.JedisConnectionException; import java.util.List; @@ -17,7 +18,17 @@ public class RedisSub extends JedisPubSub { this.j = j; String[] ss = channels.toArray(new String[0]); plugin.getServer().getScheduler().runTaskAsynchronously(plugin, - () -> this.j.subscribe(this, ss)); + () -> { + + try{ + this.j.subscribe(this, ss); + } catch (JedisConnectionException je){ + this.unSubAndCloseConnection(); + Bukkit.broadcastMessage("Redis Went down!"); + } + + }); + } @Override diff --git a/src/main/java/net/limework/skLimework/elements/EffSendMessage.java b/src/main/java/net/limework/skLimework/elements/EffSendMessage.java index 1fdbcfe..4e203bf 100644 --- a/src/main/java/net/limework/skLimework/elements/EffSendMessage.java +++ b/src/main/java/net/limework/skLimework/elements/EffSendMessage.java @@ -12,6 +12,7 @@ import org.bukkit.ChatColor; import org.bukkit.event.Event; import org.json.JSONObject; import redis.clients.jedis.Jedis; +import redis.clients.jedis.exceptions.JedisConnectionException; public class EffSendMessage extends Effect { //"hi" @@ -34,7 +35,11 @@ public class EffSendMessage extends Effect { return; } plugin.getJedisExecutionService().execute(() -> { - Jedis j = plugin.getJedisPool().getResource(); + Jedis j; + try {j = plugin.getJedisPool().getResource();}catch (JedisConnectionException e){ + Bukkit.broadcastMessage("Redis is down!!! dont send messages"); + return; + } JSONObject json = new JSONObject(); try { json.put("Message", message); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 762accf..69fec52 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,7 +4,7 @@ Redis: MaxConnections: 20 Threads: 10 Port: 6379 - TimeOut: 40 + TimeOut: 40000 useSSL: true Channels: