From 029222a068a62b326c760508ec79a17b26eb7177 Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel <34905970+ham1255@users.noreply.github.com> Date: Fri, 25 Dec 2020 21:43:20 +0400 Subject: [PATCH] added replacement for system prinltn messages --- .../java/net/limework/rediskript/RediSkript.java | 14 +++++++++++++- .../rediskript/managers/RedisController.java | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/limework/rediskript/RediSkript.java b/src/main/java/net/limework/rediskript/RediSkript.java index d65e5af..233f7d6 100644 --- a/src/main/java/net/limework/rediskript/RediSkript.java +++ b/src/main/java/net/limework/rediskript/RediSkript.java @@ -10,6 +10,7 @@ import net.limework.rediskript.commands.CommandReloadRedis; import net.limework.rediskript.events.RedisMessageEvent; import net.limework.rediskript.managers.RedisController; import net.limework.rediskript.skript.elements.*; +import org.bukkit.ChatColor; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; @@ -18,11 +19,21 @@ public class RediSkript extends JavaPlugin { private RedisController redisController; - public void reloadRedis(){ + public void reloadRedis() { redisController.shutdown(); redisController = new RedisController(this); } + public void sendLogs(String message) { + getLogger().info( + ChatColor.translateAlternateColorCodes('&', "&b[RediSkript]&e " + message) + ); + } + public void sendErrorLogs(String message) { + getLogger().severe( + ChatColor.translateAlternateColorCodes('&', "&b[RediSkript]&c " + message) + ); + } public void registerSyntax() { SkriptAddon addon = Skript.registerAddon(this); @@ -69,6 +80,7 @@ public class RediSkript extends JavaPlugin { public void onDisable() { if (redisController != null) redisController.shutdown(); } + public RedisController getRC() { return redisController; } diff --git a/src/main/java/net/limework/rediskript/managers/RedisController.java b/src/main/java/net/limework/rediskript/managers/RedisController.java index 204227a..1cb4b00 100644 --- a/src/main/java/net/limework/rediskript/managers/RedisController.java +++ b/src/main/java/net/limework/rediskript/managers/RedisController.java @@ -34,7 +34,7 @@ public class RedisController extends BinaryJedisPubSub implements Runnable { private final AtomicBoolean isConnectionBroken; private final RediSkript plugin; - private BukkitTask ConnectionTask; + private final BukkitTask ConnectionTask; public RedisController(RediSkript plugin) { @@ -67,15 +67,15 @@ public class RedisController extends BinaryJedisPubSub implements Runnable { if (!isConnectionBroken.get()) { return; } - System.out.println("connecting to redis!"); + plugin.sendLogs("Connecting to redis......"); try (Jedis jedis = jedisPool.getResource()) { isConnectionBroken.set(false); - System.out.println("connected to redis!"); + plugin.sendLogs("&aConnection to redis has established!"); jedis.subscribe(this, channelsInByte); } catch (Exception e) { isConnectionBroken.set(true); - e.printStackTrace(); + plugin.sendLogs("Connection has &kFAILED &cor Unable to connect to redis retrying to make connection..."); } }