From 9ecde41c2d478b2f492511d3c9c6b2858346615f Mon Sep 17 00:00:00 2001 From: mohammed jasem alaajel <34905970+ham1255@users.noreply.github.com> Date: Tue, 28 Jul 2020 10:44:00 +0400 Subject: [PATCH] added /reloadredis command --- pom.xml | 2 +- .../net/limework/core/LimeworkSpigotCore.java | 1 + .../limework/core/managers/RedisManager.java | 33 +++++++++++++++---- src/main/resources/plugin.yml | 3 ++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index b965f2e..2680196 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.limework.core LimeworkSpigotCore - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT jar diff --git a/src/main/java/net/limework/core/LimeworkSpigotCore.java b/src/main/java/net/limework/core/LimeworkSpigotCore.java index 1a8d58e..a843168 100644 --- a/src/main/java/net/limework/core/LimeworkSpigotCore.java +++ b/src/main/java/net/limework/core/LimeworkSpigotCore.java @@ -19,6 +19,7 @@ public class LimeworkSpigotCore extends JavaPlugin { public void onEnable() { saveDefaultConfig(); rm = new RedisManager(this); + getServer().getPluginCommand("reloadredis").setExecutor(rm); if (getServer().getPluginManager().getPlugin("Skript") != null) { new SkriptHook(this); } else { diff --git a/src/main/java/net/limework/core/managers/RedisManager.java b/src/main/java/net/limework/core/managers/RedisManager.java index a8d2e34..b79ec00 100644 --- a/src/main/java/net/limework/core/managers/RedisManager.java +++ b/src/main/java/net/limework/core/managers/RedisManager.java @@ -3,10 +3,16 @@ package net.limework.core.managers; import net.limework.Data.Encryption; import net.limework.core.LimeworkSpigotCore; import net.limework.core.events.RedisMessageEvent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; import org.bukkit.configuration.Configuration; +import org.bukkit.entity.Player; import org.cryptomator.siv.UnauthenticCiphertextException; +import org.jetbrains.annotations.NotNull; import org.json.JSONObject; import redis.clients.jedis.BinaryJedis; import redis.clients.jedis.BinaryJedisPubSub; @@ -19,7 +25,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicBoolean; -public class RedisManager extends BinaryJedisPubSub implements Runnable{ +public class RedisManager extends BinaryJedisPubSub implements Runnable, CommandExecutor { private LimeworkSpigotCore plugin; @@ -27,7 +33,6 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{ private ExecutorService RedisService; - //sub private BinaryJedis subscribeJedis; private List channels; @@ -51,13 +56,16 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{ config.getString("Redis.Password"), config.getBoolean("Redis.useSSL")); RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads")); - try{this.subscribeJedis = this.jedisPool.getResource(); }catch (Exception ignored){} + try { + this.subscribeJedis = this.jedisPool.getResource(); + } catch (Exception ignored) { + } this.channels = config.getStringList("Channels"); encryption = new Encryption(config); } - public void start(){ + public void start() { this.RedisService.execute(this); } @@ -92,7 +100,9 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{ } catch (Exception e) { message("&e[Jedis] &cConnection to redis has failed! &ereconnecting..."); - if (this.subscribeJedis != null){this.subscribeJedis.close();} + if (this.subscribeJedis != null) { + this.subscribeJedis.close(); + } isRedisOnline.set(false); } try { @@ -130,7 +140,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{ public void shutdown() { this.isShuttingDown.set(true); - if (this.subscribeJedis != null){ + if (this.subscribeJedis != null) { this.unsubscribe(); this.subscribeJedis.close(); } @@ -161,4 +171,15 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{ public Encryption getEncryption() { return encryption; } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String lable, String[] args) { + if (sender instanceof Player) { + sender.sendMessage(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&' + , "&c&lYou can not execute this command!!!!!!"))); + return true; + } + start(); + return false; + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5b5180a..f4d6de1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,5 +7,8 @@ softdepend: - Skript commands: control: + description: "server control" + permission: "admin.use" + reloadredis: description: "server control" permission: "admin.use" \ No newline at end of file