Further fixes & refactoring for release

This commit is contained in:
Govindass 2020-10-22 13:30:41 +03:00
parent df8608802d
commit 216b2635b3
8 changed files with 21 additions and 23 deletions

View File

@ -1,3 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.limework.core.LimeworkSpigotCore
Main-Class: net.limework.core.RediSkript

View File

@ -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;

View File

@ -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");

View File

@ -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."));
}
}

View File

@ -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")

View File

@ -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));
}

View File

@ -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"

View File

@ -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