From 86c1ebab5ca1895e0087813ac777e7b1b4a7cb77 Mon Sep 17 00:00:00 2001 From: Govindas Date: Thu, 22 Oct 2020 13:30:41 +0300 Subject: [PATCH] Further fixes & refactoring for release --- src/main/java/META-INF/MANIFEST.MF | 2 +- .../{LimeworkSpigotCore.java => RediSkript.java} | 2 +- .../java/net/limework/core/hooks/SkriptHook.java | 4 ++-- .../net/limework/core/managers/RedisManager.java | 11 ++++++----- .../core/skript/elements/EffSendMessage.java | 14 ++++++-------- src/main/java/net/limework/data/Encryption.java | 4 ++-- src/main/resources/config.yml | 1 - src/main/resources/plugin.yml | 6 +++--- 8 files changed, 21 insertions(+), 23 deletions(-) rename src/main/java/net/limework/core/{LimeworkSpigotCore.java => RediSkript.java} (93%) diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF index 89effaf..2e5c799 100644 --- a/src/main/java/META-INF/MANIFEST.MF +++ b/src/main/java/META-INF/MANIFEST.MF @@ -1,3 +1,3 @@ Manifest-Version: 1.0 -Main-Class: net.limework.core.LimeworkSpigotCore +Main-Class: net.limework.core.RediSkript diff --git a/src/main/java/net/limework/core/LimeworkSpigotCore.java b/src/main/java/net/limework/core/RediSkript.java similarity index 93% rename from src/main/java/net/limework/core/LimeworkSpigotCore.java rename to src/main/java/net/limework/core/RediSkript.java index c22b39c..64d4c14 100644 --- a/src/main/java/net/limework/core/LimeworkSpigotCore.java +++ b/src/main/java/net/limework/core/RediSkript.java @@ -5,7 +5,7 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.Objects; -public class LimeworkSpigotCore extends JavaPlugin { +public class RediSkript extends JavaPlugin { //Redis manager private RedisManager rm; diff --git a/src/main/java/net/limework/core/hooks/SkriptHook.java b/src/main/java/net/limework/core/hooks/SkriptHook.java index 7622f55..ed41627 100644 --- a/src/main/java/net/limework/core/hooks/SkriptHook.java +++ b/src/main/java/net/limework/core/hooks/SkriptHook.java @@ -5,7 +5,7 @@ import ch.njol.skript.SkriptAddon; import ch.njol.skript.lang.ExpressionType; import ch.njol.skript.registrations.EventValues; import ch.njol.skript.util.Getter; -import net.limework.core.LimeworkSpigotCore; +import net.limework.core.RediSkript; import net.limework.core.events.RedisMessageEvent; import net.limework.core.skript.elements.EvtRedis; import net.limework.core.skript.elements.ExprChannel; @@ -16,7 +16,7 @@ import java.io.IOException; public class SkriptHook { private SkriptAddon addon; - public SkriptHook(LimeworkSpigotCore plugin) { + public SkriptHook(RediSkript plugin) { addon = Skript.registerAddon(plugin); try { addon.loadClasses("net.limework.core.skript", "elements"); diff --git a/src/main/java/net/limework/core/managers/RedisManager.java b/src/main/java/net/limework/core/managers/RedisManager.java index 54b4666..ed32cb1 100644 --- a/src/main/java/net/limework/core/managers/RedisManager.java +++ b/src/main/java/net/limework/core/managers/RedisManager.java @@ -1,7 +1,7 @@ package net.limework.core.managers; +import net.limework.core.RediSkript; 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; @@ -27,7 +27,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public class RedisManager extends BinaryJedisPubSub implements Runnable, CommandExecutor { - private LimeworkSpigotCore plugin; + private RediSkript plugin; private JedisPool jedisPool; private ExecutorService RedisService; @@ -43,7 +43,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command private Encryption encryption; - public RedisManager(LimeworkSpigotCore plugin) { + public RedisManager(RediSkript plugin) { this.plugin = plugin; Configuration config = this.plugin.getConfig(); JedisPoolConfig JConfig = new JedisPoolConfig(); @@ -123,7 +123,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command @Override public void onMessage(byte[] channel, byte[] message) { - String channelString = new String(channel); + String channelString = new String(channel, StandardCharsets.UTF_8); try { String receivedMessage = null; //if encryption is enabled, decrypt the message, else just convert binary to string @@ -137,6 +137,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command } else { //encryption is disabled, so let's just get the string receivedMessage = new String(message, StandardCharsets.UTF_8); + System.out.println(receivedMessage); } if (receivedMessage != null) { @@ -146,7 +147,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command } } catch (Exception e) { e.printStackTrace(); - Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRedisk&a] &cI got a message that was empty from channel " + channel + " please check your code that you used to send the message. ^ ignore the error.")); + Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRedisk&a] &cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. ^ ignore the error.")); } } 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 bd8a439..3302797 100644 --- a/src/main/java/net/limework/core/skript/elements/EffSendMessage.java +++ b/src/main/java/net/limework/core/skript/elements/EffSendMessage.java @@ -5,7 +5,7 @@ import ch.njol.skript.lang.Effect; import ch.njol.skript.lang.Expression; import ch.njol.skript.lang.SkriptParser; import ch.njol.util.Kleenean; -import net.limework.core.LimeworkSpigotCore; +import net.limework.core.RediSkript; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.event.Event; @@ -15,7 +15,6 @@ import redis.clients.jedis.BinaryJedis; import java.nio.charset.StandardCharsets; public class EffSendMessage extends Effect { - //"hi" static { Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with message %string%"); } @@ -27,7 +26,7 @@ public class EffSendMessage extends Effect { @Override protected void execute(Event event) { - LimeworkSpigotCore plugin = (LimeworkSpigotCore) Bukkit.getPluginManager().getPlugin("LimeworkSpigotCore"); + RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript"); String message = this.message.getSingle(event); String channel = this.channel.getSingle(event); if (message == null) {//checks if message equals null if true does not execute. @@ -40,15 +39,14 @@ public class EffSendMessage extends Effect { JSONObject json = new JSONObject(); json.put("Message", message); json.put("Type", "Skript"); - json.put("Date", System.nanoTime()); //for unique string every time & PING calculations + json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations byte[] msg; if (plugin.getRm().getEncryption().isEncryptionEnabled()) { msg = plugin.getRm().getEncryption().encrypt(json.toString()); } else { - msg = message.getBytes(StandardCharsets.UTF_8); + msg = json.toString().getBytes(StandardCharsets.UTF_8); } - j.publish(channel.getBytes(), msg); - //System.out.println("SkriptSide sent MESSAGE: ["+ message + "] to channel: " + channel + " and json: \n" + json.toString()); + j.publish(channel.getBytes(StandardCharsets.UTF_8), msg); j.close(); }); @@ -56,7 +54,7 @@ public class EffSendMessage extends Effect { @Override public String toString(Event event, boolean b) { - return null; + return "send redis message to channel " + channel.getSingle(event) + " with message " + message.getSingle(event); } @SuppressWarnings("unchecked") diff --git a/src/main/java/net/limework/data/Encryption.java b/src/main/java/net/limework/data/Encryption.java index 162ba7c..a2cdc79 100644 --- a/src/main/java/net/limework/data/Encryption.java +++ b/src/main/java/net/limework/data/Encryption.java @@ -26,11 +26,11 @@ public class Encryption { public boolean isEncryptionEnabled() { return encryptionEnabled; } public String decrypt(byte[] message) throws UnauthenticCiphertextException, IllegalBlockSizeException { - return new String(AES_SIV.decrypt(encryptionKey.getBytes(), macKey.getBytes(), message), StandardCharsets.UTF_8); + return new String(AES_SIV.decrypt(encryptionKey.getBytes(StandardCharsets.UTF_8), macKey.getBytes(StandardCharsets.UTF_8), message), StandardCharsets.UTF_8); } public byte[] encrypt(String message) { - return AES_SIV.encrypt(encryptionKey.getBytes(), macKey.getBytes(), message.getBytes()); + return AES_SIV.encrypt(encryptionKey.getBytes(StandardCharsets.UTF_8), macKey.getBytes(StandardCharsets.UTF_8), message.getBytes(StandardCharsets.UTF_8)); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 83adb40..b40b84b 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,7 +14,6 @@ Redis: useSSL: false #may be useful if you cannot use SSL due to use of older version of Redis #however this will not encrypt the initial authentication password, only the messages sent - #also currently EncryptMessages is broken, meaning it must always be true or else it won't work EncryptMessages: true EncryptionKey: "16CHARACTERS KEY" MacKey: "16CHARACTERS KEY" diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0dc2ca5..b91fd7d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ -main: net.limework.core.LimeworkSpigotCore -name: LimeworkSpigotCore +main: net.limework.core.Redisk +name: Redisk version: ${project.version} -author: limework.net +authors: [Govindas, ham1255, DaemonicKing] api-version: 1.13 softdepend: - Skript