Compare commits

..

21 Commits
1.1.1 ... 1.2.1

Author SHA1 Message Date
Govindass
7849efd866 Little questionable improvements (shouldn't hurt anything anyway) 2020-10-24 17:59:48 +03:00
Govindass
f80d9b36e7 Make on redis message a synchronous event for thread-safety 2020-10-24 15:19:10 +03:00
Govindass
0c20becfa1 Merge branch 'master' of https://github.com/Limework/RediSkript 2020-10-24 14:33:12 +03:00
Govindass
089fdfd1f3 Update pom.xml 2020-10-24 14:32:55 +03:00
Govindas
c4426a692e Update README.md 2020-10-24 14:32:48 +03:00
Govindass
ed3ea7b2c7 Remove unneeded threadpool (testing has shown for it to be unneeded) 2020-10-24 13:29:49 +03:00
Govindass
2b00f0908e change useSSL to useTLS, because redis itself refers to it as TLS 2020-10-24 12:35:35 +03:00
Govindass
f6c4bbcdce Revert "fixed reload but not tested"
This reverts commit a08ecd93b7.
2020-10-24 12:32:40 +03:00
Govindass
ba48fdc564 Revert "Update RedisManager.java"
This reverts commit 6c5d580b16.
2020-10-24 12:32:36 +03:00
Govindass
ce47af29f4 Revert "Update RedisManager.java"
This reverts commit b93624bc49.
2020-10-24 12:32:24 +03:00
mohammed jasem alaajel
b93624bc49 Update RedisManager.java 2020-10-23 21:01:57 +04:00
mohammed jasem alaajel
6c5d580b16 Update RedisManager.java 2020-10-23 20:45:53 +04:00
mohammed jasem alaajel
a08ecd93b7 fixed reload but not tested 2020-10-23 20:37:43 +04:00
Govindass
c720433c60 Re-word redis reload command information 2020-10-23 17:50:04 +03:00
Govindass
12ce69d68f Fix critical redis server shutdown bug 2020-10-23 17:48:22 +03:00
Govindass
efab085c47 Better 1.8 support & cleanup 2020-10-23 17:21:32 +03:00
Govindass
31db51fce6 Undo synchronous event, broke 1.8 servers completely 2020-10-23 16:55:04 +03:00
Govindass
776ebc9780 add redis message date expression & improve quality of existing expressions & make event guaranteedly synchronous 2020-10-23 16:49:25 +03:00
Govindass
1ef35dfb60 New /reloadredis fully restarts the plugin with reloaded configuration & some code improvements 2020-10-23 14:34:30 +03:00
Govindass
2049616f64 Make json errors easier to debug 2020-10-22 17:44:45 +03:00
Govindass
97aa663bfd Reduce jar size by removing unneeded dependencies 2020-10-22 17:28:00 +03:00
14 changed files with 266 additions and 134 deletions

View File

@@ -1 +1,57 @@
**To-do List**
1. Fix memory leak of /reloadredis (Not yet known how to fix it, it can be easily noticed by changing IP addresses and using NetworkInterceptor plugin, it'll show connections still being done to old IP address, aswell as the new one, even if it doesn't use old IP address for anything.
RediSkript allows you to communicate between your servers with use of Redis, it's very fast and easy to use.
You can transfer any data in the form of text between your servers, you can program it to execute a set of instructions on the server depending on the redis message, etc. This can be used for making scripts that sync data between all servers and much more!
It is originally developed by the team of Govindas Limework developers and is now maintained only by Govindas.
Example:
```
on redis message:
if redis channel is "world":
broadcast "%redis message% %redis channel% %redis message date%"
command /sendredis <text> <text>:
usage: /sendredis <message> <channel>
trigger:
send redis message arg 1 to channel arg 2
send redis message "hello world!" to channel "world"
```
and that's all there is to this addon! You only need to have matching configuration in every server for communication and a Redis server to connect to. I recommend using VPS for hosting redis server, I personally use VPS from humbleservers.com.
Configuration:
```
Redis:
#a secure password that cannot be cracked, please change it!
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
Host: "127.0.0.1"
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
MaxConnections: 2
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#90000 = 90 seconds
TimeOut: 90000
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
#it encrypts your traffic and makes data exchange between distant servers completely secure
useTLS: false
#may be useful if you cannot use TLS due to use of older version of Redis
#however this will not encrypt the initial authentication password, only the messages sent
#it uses AES-128 SIV encryption which is secure enough for this
EncryptMessages: true
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
#the channels from which this server can receive messages
#you can always send messages to all channels!
#you can add as many channels as you wish!
Channels:
- "Channel1"
- "Channel2"
- "Channel3"
```

24
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>net.limework.core</groupId>
<artifactId>RediSkript</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<packaging>jar</packaging>
<build>
@@ -64,12 +64,9 @@
<url>https://jitpack.io</url>
</repository>
<repository>
<id>PaperMC</id>
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
</repository>
<repository>
<id>sk89q</id>
<url>http://maven.sk89q.com/repo</url>
<id>commons-pool2</id>
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
</repository>
</repositories>
@@ -86,11 +83,6 @@
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
@@ -106,11 +98,11 @@
<artifactId>siv-mode</artifactId>
<version>1.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
<scope>compile</scope>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,37 +1,42 @@
package net.limework.core;
import net.limework.core.commands.ReloadRedis;
import net.limework.core.hooks.SkriptHook;
import net.limework.core.managers.RedisManager;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Objects;
public class RediSkript extends JavaPlugin {
//Redis manager
private RedisManager rm;
public void startRedis(boolean reload) {
if (reload) { reloadConfig(); }
rm = new RedisManager(this);
rm.start();
}
@Override
public void onEnable() {
saveDefaultConfig();
rm = new RedisManager(this);
Objects.requireNonNull(getServer().getPluginCommand("reloadredis")).setExecutor(rm);
if (getServer().getPluginManager().getPlugin("Skript") != null) {
startRedis(false);
PluginCommand command = getServer().getPluginCommand("reloadredis");
assert command != null;
command.setExecutor(new ReloadRedis(this));
new SkriptHook(this);
} else {
getLogger().info("Skript wasn't found.");
}
rm.start();
}
@Override
public void onDisable() {
if (rm != null) {
rm.shutdown();
}
}
public RedisManager getRm() {

View File

@@ -0,0 +1,30 @@
package net.limework.core.commands;
import net.limework.core.RediSkript;
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.entity.Player;
public class ReloadRedis implements CommandExecutor {
private RediSkript plugin;
public ReloadRedis(RediSkript plugin) {
this.plugin = plugin;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender instanceof Player) {
//not using bungee TextComponent because it is not present in 1.8.8
sender.sendMessage((ChatColor.translateAlternateColorCodes('&'
, "&2[&aRediSkript&a] &cThis command can only be executed in console.")));
return true;
}
plugin.getRm().reload();
//not sending to sender, because this command can only be executed via console
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &eReloaded via command! Note this command is not stable, it should only be used in urgent cases where you absolutely need to change config details without restarting the server."));
return false;
}
}

View File

@@ -9,11 +9,13 @@ public class RedisMessageEvent extends Event {
private String channelName;
private String message;
private long date;
public RedisMessageEvent(String channelName , String message) {
super(true);
public RedisMessageEvent(String channelName , String message, long date) {
super(false);
this.channelName = channelName;
this.message = message;
this.date = date;
}
@@ -34,6 +36,8 @@ public class RedisMessageEvent extends Event {
return channelName;
}
public long getDate() { return date;}
public String getMessage() {
return message;
}

View File

@@ -4,12 +4,14 @@ import ch.njol.skript.Skript;
import ch.njol.skript.SkriptAddon;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.registrations.EventValues;
import ch.njol.skript.util.Date;
import ch.njol.skript.util.Getter;
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;
import net.limework.core.skript.elements.ExprMessage;
import net.limework.core.skript.elements.ExprMessageDate;
import java.io.IOException;
@@ -35,12 +37,15 @@ public class SkriptHook {
return e.getMessage();
}
}, 0);
Skript.registerExpression(ExprMessageDate.class, Date.class, ExpressionType.SIMPLE, "redis message date");
EventValues.registerEventValue(RedisMessageEvent.class, Date.class, new Getter<Date, RedisMessageEvent>() {
@Override
public Date get(RedisMessageEvent e) {
return new Date(e.getDate());
}
}, 0);
} catch (IOException e) {
e.printStackTrace();
}
}
public SkriptAddon getAddon() {
return addon;
}
}

View File

@@ -1,16 +1,11 @@
package net.limework.core.managers;
import net.limework.core.RediSkript;
import net.limework.data.Encryption;
import net.limework.core.events.RedisMessageEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.limework.data.Encryption;
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.json.JSONObject;
import redis.clients.jedis.BinaryJedis;
@@ -25,21 +20,18 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
public class RedisManager extends BinaryJedisPubSub implements Runnable, CommandExecutor {
public class RedisManager extends BinaryJedisPubSub implements Runnable {
private RediSkript plugin;
private JedisPool jedisPool;
private ExecutorService RedisService;
private AtomicBoolean isKilled = new AtomicBoolean();
//sub
private BinaryJedis subscribeJedis;
private List<String> channels;
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
private AtomicBoolean isRedisOnline = new AtomicBoolean();
private Encryption encryption;
@@ -47,8 +39,11 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
this.plugin = plugin;
Configuration config = this.plugin.getConfig();
JedisPoolConfig JConfig = new JedisPoolConfig();
JConfig.setMaxTotal(config.getInt("Redis.MaxConnections"));
JConfig.setMaxIdle(config.getInt("Redis.MaxConnections"));
int maxConnections = config.getInt("Redis.MaxConnections");
if (maxConnections < 2) { maxConnections = 2; }
JConfig.setMaxTotal(maxConnections);
JConfig.setMaxIdle(maxConnections);
JConfig.setMinIdle(1);
JConfig.setBlockWhenExhausted(true);
this.jedisPool = new JedisPool(JConfig,
@@ -56,8 +51,8 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
config.getInt("Redis.Port"),
config.getInt("Redis.TimeOut"),
config.getString("Redis.Password"),
config.getBoolean("Redis.useSSL"));
RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads"));
config.getBoolean("Redis.useTLS"));
RedisService = Executors.newSingleThreadExecutor();
try {
this.subscribeJedis = this.jedisPool.getResource();
} catch (Exception ignored) {
@@ -74,16 +69,13 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
@Override
public void run() {
while (!isShuttingDown.get()) {
isKilled.set(false);
try {
message("&e[Jedis] &cConnecting to redis...........");
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnecting to redis..."));
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
isRedisOnline.set(true);
message("&e[Jedis] &aRedis Connected");
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &aRedis connected!"));
int byteArr2dSize = 1;
byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
boolean reInitializeByteArray;
// Loop that reInitialize array IF array size is not enough
do {
reInitializeByteArray = false;
@@ -101,31 +93,26 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
} while (reInitializeByteArray);
this.subscribeJedis.subscribe(this, channelsInByte);
} catch (Exception e) {
message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnection to redis has failed! &ereconnecting..."));
if (this.subscribeJedis != null) {
this.subscribeJedis.close();
}
isRedisOnline.set(false);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (isKilled.get()) break;
}
}
private void message(String message) {
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
}
@Override
public void onMessage(byte[] channel, byte[] message) {
String channelString = new String(channel, StandardCharsets.UTF_8);
try {
String receivedMessage = null;
try {
//if encryption is enabled, decrypt the message, else just convert binary to string
if (this.encryption.isEncryptionEnabled()) {
try {
@@ -142,11 +129,13 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
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")));
RedisMessageEvent event = new RedisMessageEvent(channelString, j.getString("Message"), j.getLong("Date"));
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(event));
}
} catch (Exception e) {
e.printStackTrace();
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."));
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:"));
Bukkit.getLogger().warning(receivedMessage);
}
}
@@ -156,53 +145,22 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable, Command
if (this.subscribeJedis != null) {
this.unsubscribe();
this.subscribeJedis.close();
this.subscribeJedis.getClient().close();
this.jedisPool.getResource().close();
}
this.RedisService.shutdown();
}
public boolean IsRedisOnline() {
return isRedisOnline.get();
public void reload() {
this.shutdown();
plugin.startRedis(true);
}
public JedisPool getJedisPool() {
return jedisPool;
}
public ExecutorService getRedisService() {
return RedisService;
}
public AtomicBoolean getIsShuttingDown() {
return isShuttingDown;
}
public AtomicBoolean getIsRedisOnline() {
return isRedisOnline;
}
public Encryption getEncryption() {
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('&'
, "&cYou cannot execute this command.")));
return true;
}
isKilled.set(true);
try {
if (this.subscribeJedis != null) {
this.unsubscribe();
this.subscribeJedis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
start();
return false;
}
}

View File

@@ -6,17 +6,19 @@ import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import net.limework.core.RediSkript;
import net.limework.core.managers.RedisManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.Event;
import org.json.JSONObject;
import redis.clients.jedis.BinaryJedis;
import redis.clients.jedis.exceptions.JedisConnectionException;
import java.nio.charset.StandardCharsets;
public class EffSendMessage extends Effect {
static {
Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with message %string%");
Skript.registerEffect(EffSendMessage.class, "send redis message %string% to [channel] %string%");
}
@@ -26,42 +28,54 @@ public class EffSendMessage extends Effect {
@Override
protected void execute(Event event) {
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.
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cMessage Was empty Please check your code."));
if (message == null) {
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cRedis message was empty. Please check your code."));
return;
}
if (channel == null) {
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cChannel was empty. Please check your code."));
return;
}
assert plugin != null;
plugin.getRm().getRedisService().execute(() -> {
BinaryJedis j = plugin.getRm().getJedisPool().getResource();
JSONObject json = new JSONObject();
json.put("Message", message);
json.put("Type", "Skript");
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());
RedisManager manager = plugin.getRm();
if (manager.getEncryption().isEncryptionEnabled()) {
msg = manager.getEncryption().encrypt(json.toString());
} else {
msg = json.toString().getBytes(StandardCharsets.UTF_8);
}
try {
BinaryJedis j = manager.getJedisPool().getResource();
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
j.close();
});
} catch (JedisConnectionException exception) {
exception.printStackTrace();
}
}
@Override
public String toString(Event event, boolean b) {
return "send redis message to channel " + channel.getSingle(event) + " with message " + message.getSingle(event);
public String toString(Event event, boolean debug) {
return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event);
}
@SuppressWarnings("unchecked")
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
this.channel = (Expression<String>) expressions[0];
this.message = (Expression<String>) expressions[1];
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parser) {
this.message = (Expression<String>) expressions[0];
this.channel = (Expression<String>) expressions[1];
return true;
}

View File

@@ -2,6 +2,7 @@ package net.limework.core.skript.elements;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
import net.limework.core.events.RedisMessageEvent;
import org.bukkit.event.Event;
public class EvtRedis extends SkriptEvent {
@@ -13,11 +14,14 @@ public class EvtRedis extends SkriptEvent {
@Override
public boolean check(Event event) {
if (!(event instanceof RedisMessageEvent)) {
return false;
}
return true;
}
@Override
public String toString(Event event, boolean b) {
public String toString(Event event, boolean debug) {
return "redis message";
}
}

View File

@@ -1,9 +1,12 @@
package net.limework.core.skript.elements;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
import net.limework.core.events.RedisMessageEvent;
import org.bukkit.event.Event;
@@ -27,7 +30,11 @@ public class ExprChannel extends SimpleExpression<String> {
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
Skript.error("Cannot use 'redis channel' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}

View File

@@ -1,9 +1,12 @@
package net.limework.core.skript.elements;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.util.Kleenean;
import net.limework.core.events.RedisMessageEvent;
import org.bukkit.event.Event;
@@ -22,12 +25,16 @@ public class ExprMessage extends SimpleExpression<String> {
}
@Override
public String toString(Event event, boolean b) {
public String toString(Event event, boolean debug) {
return "redis message";
}
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
Skript.error("Cannot use 'redis message' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}

View File

@@ -0,0 +1,49 @@
package net.limework.core.skript.elements;
import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.log.ErrorQuality;
import ch.njol.skript.util.Date;
import ch.njol.util.Kleenean;
import net.limework.core.events.RedisMessageEvent;
import org.bukkit.event.Event;
public class ExprMessageDate extends SimpleExpression<Date> {
@Override
public boolean isSingle() {
return true;
}
@Override
public Class<? extends Date> getReturnType() {
return Date.class;
}
@Override
public String toString(Event event, boolean b) {
return "redis message date";
}
@Override
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
Skript.error("Cannot use 'redis message date' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
return false;
}
return true;
}
@Override
protected Date[] get(Event e) {
if (e instanceof RedisMessageEvent){
long date = ((RedisMessageEvent) e).getDate();
return new Date[]{new Date(date)};
}
return null;
}
}

View File

@@ -3,17 +3,19 @@ Redis:
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
Host: "127.0.0.1"
MaxConnections: 20
Threads: 10
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
MaxConnections: 2
#the default Redis port
Port: 6379
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
#90000 = 90 seconds
TimeOut: 90000
#also known as TLS, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
useSSL: false
#may be useful if you cannot use SSL due to use of older version of Redis
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
#it encrypts your traffic and makes data exchange between distant servers completely secure
useTLS: false
#may be useful if you cannot use TLS due to use of older version of Redis
#however this will not encrypt the initial authentication password, only the messages sent
#it uses AES-128 SIV encryption which is secure enough for this
EncryptMessages: true
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"

View File

@@ -3,9 +3,8 @@ name: RediSkript
version: ${project.version}
authors: [Govindas, ham1255, DaemonicKing]
api-version: 1.13
softdepend:
depend:
- Skript
commands:
reloadredis:
description: "Restart redis connection"
permission: "admin.use"
description: "Reload redis configuration & restart the connection."