forked from Limework/RediSkript
Fix encryption disabling & some refactoring
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package net.limework.core.events;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.limework.core.managers;
|
||||
|
||||
import net.limework.Data.Encryption;
|
||||
import net.limework.data.Encryption;
|
||||
import net.limework.core.LimeworkSpigotCore;
|
||||
import net.limework.core.events.RedisMessageEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
@@ -12,7 +12,6 @@ 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;
|
||||
@@ -20,6 +19,7 @@ import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -125,19 +125,28 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
|
||||
public void onMessage(byte[] channel, byte[] message) {
|
||||
String channelString = new String(channel);
|
||||
try {
|
||||
String decrypted = null;
|
||||
try {
|
||||
decrypted = encryption.decrypt(message);
|
||||
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
|
||||
e.printStackTrace();
|
||||
String receivedMessage = null;
|
||||
//if encryption is enabled, decrypt the message, else just convert binary to string
|
||||
if (this.encryption.isEncryptionEnabled()) {
|
||||
try {
|
||||
receivedMessage = encryption.decrypt(message);
|
||||
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
//encryption is disabled, so let's just get the string
|
||||
receivedMessage = new String(message, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
if (receivedMessage != null) {
|
||||
JSONObject j = new JSONObject(receivedMessage);
|
||||
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
|
||||
plugin.getServer().getPluginManager().callEvent(new RedisMessageEvent(channelString, j.getString("Message")));
|
||||
}
|
||||
assert decrypted != null;
|
||||
JSONObject j = new JSONObject(decrypted);
|
||||
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
|
||||
plugin.getServer().getPluginManager().callEvent(new RedisMessageEvent(channelString, j.getString("Message")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&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 " + channel + " please check your code that you used to send the message. ^ ignore the error."));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,11 +185,12 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
|
||||
return encryption;
|
||||
}
|
||||
|
||||
// the /reloadredis command
|
||||
@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!!!!!!")));
|
||||
, "&cYou cannot execute this command.")));
|
||||
return true;
|
||||
}
|
||||
isKilled.set(true);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
package net.limework.core.skript.elements;
|
||||
;
|
||||
import ch.njol.skript.lang.Literal;
|
||||
import ch.njol.skript.lang.SkriptEvent;
|
||||
import ch.njol.skript.lang.SkriptParser;
|
||||
@@ -7,11 +6,8 @@ import org.bukkit.event.Event;
|
||||
|
||||
public class EvtRedis extends SkriptEvent {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean init(Literal<?>[] literals, int i, SkriptParser.ParseResult parseResult) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.limework.Data;
|
||||
package net.limework.data;
|
||||
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.cryptomator.siv.SivMode;
|
||||
Reference in New Issue
Block a user