From 7849efd866940ab19aeb3cc84bef0182e4fe9d25 Mon Sep 17 00:00:00 2001 From: Govindass Date: Sat, 24 Oct 2020 17:59:48 +0300 Subject: [PATCH] Little questionable improvements (shouldn't hurt anything anyway) --- .../limework/core/managers/RedisManager.java | 1 + .../core/skript/elements/EffSendMessage.java | 33 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/net/limework/core/managers/RedisManager.java b/src/main/java/net/limework/core/managers/RedisManager.java index ff1d2d8..7fbbf92 100644 --- a/src/main/java/net/limework/core/managers/RedisManager.java +++ b/src/main/java/net/limework/core/managers/RedisManager.java @@ -145,6 +145,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable { if (this.subscribeJedis != null) { this.unsubscribe(); this.subscribeJedis.close(); + this.subscribeJedis.getClient().close(); this.jedisPool.getResource().close(); } this.RedisService.shutdown(); diff --git a/src/main/java/net/limework/core/skript/elements/EffSendMessage.java b/src/main/java/net/limework/core/skript/elements/EffSendMessage.java index 58b4b79..384baa1 100644 --- a/src/main/java/net/limework/core/skript/elements/EffSendMessage.java +++ b/src/main/java/net/limework/core/skript/elements/EffSendMessage.java @@ -12,6 +12,7 @@ import org.bukkit.ChatColor; import org.bukkit.event.Event; import org.json.JSONObject; import redis.clients.jedis.BinaryJedis; +import redis.clients.jedis.exceptions.JedisConnectionException; import java.nio.charset.StandardCharsets; @@ -42,33 +43,37 @@ public class EffSendMessage extends Effect { return; } assert plugin != null; + JSONObject json = new JSONObject(); + json.put("Message", message); + json.put("Type", "Skript"); + json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations + byte[] msg; RedisManager manager = plugin.getRm(); - //manager.getRedisService().execute(() -> { + + if (manager.getEncryption().isEncryptionEnabled()) { + msg = manager.getEncryption().encrypt(json.toString()); + } else { + msg = json.toString().getBytes(StandardCharsets.UTF_8); + } + try { BinaryJedis j = manager.getJedisPool().getResource(); - JSONObject json = new JSONObject(); - json.put("Message", message); - json.put("Type", "Skript"); - json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations - byte[] msg; - if (manager.getEncryption().isEncryptionEnabled()) { - msg = manager.getEncryption().encrypt(json.toString()); - } else { - msg = json.toString().getBytes(StandardCharsets.UTF_8); - } + j.publish(channel.getBytes(StandardCharsets.UTF_8), msg); j.close(); - //}); + } catch (JedisConnectionException exception) { + exception.printStackTrace(); + } } @Override - public String toString(Event event, boolean b) { + public String toString(Event event, boolean debug) { return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event); } @SuppressWarnings("unchecked") @Override - public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { + public boolean init(final Expression[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parser) { this.message = (Expression) expressions[0]; this.channel = (Expression) expressions[1]; return true;