Compare commits

...

7 Commits

5 changed files with 237 additions and 195 deletions

View File

@ -1,18 +1,23 @@
[![RediSkript Build](https://github.com/Limework/RediSkript/actions/workflows/maven.yml/badge.svg?branch=master)](https://github.com/Limework/RediSkript/actions/workflows/maven.yml)
RediSkript allows you to communicate between your servers with use of Redis, it's very fast and easy to use.
## RediSkript
Allows you to communicate between your Minecraft servers with use of Redis and Skript, it's very fast and easy to use.
Skript: https://github.com/SkriptLang/Skript
RediSkript spigot page: https://www.spigotmc.org/resources/rediskript-communicate-between-servers-with-ease.85067/
RediSkript spigot page: https://www.spigotmc.org/resources/rediskript-communicate-between-servers-with-ease.85067/s
Jedis: https://github.com/redis/jedis
Minecraft server version supported: **1.8.8+** (On 1.8, may need to use a fork of Skript)
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 developed and maintained by Govindas & the team of Govindas Limework developers.
Redis Message:
There is only one command: **/reloadredis** it fully reloads the configuration, you can reload IP, password, channels and everything else.
You only need to have matching configuration in every server for communication and a Redis server to connect to. I recommend using a VPS for hosting redis server, but there also are free redis hosting options available.
### Redis Message
```
on redis message:
if redis channel is "world":
@ -24,7 +29,7 @@ command /sendredis <text> <text>:
send redis message arg 1 to channel arg 2
send redis message "hello world!" to channel "world"
```
Managing variables:
### Managing variables
```
set variables "test::1", "test::2", "test::3" in channel "global" to 100
#then use this in any server that listens to "global" redis channel and was online when the above line was executed:
@ -43,11 +48,8 @@ Syntax:
variable[s] %strings% in [redis] [channel] %string%
```
There is only one command: **/reloadredis** it fully reloads the configuration, you can reload IP, password, channels and everything else.
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:
### Configuration
plugins/RediSkript/config.yml
```
Redis:
#a secure password that cannot be cracked, please change it!

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>RediSkript</artifactId>
<groupId>net.limework</groupId>
<version>1.3.5</version>
<version>1.3.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -73,11 +73,6 @@
<version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>net.limework</groupId>
<artifactId>RediSkript-core</artifactId>

View File

@ -47,18 +47,30 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
int maxConnections = config.getInt("Redis.MaxConnections");
//do not allow less than 2 max connections as that causes issues
if (maxConnections < 2) { maxConnections = 2; }
if (maxConnections < 2) {
maxConnections = 2;
}
JConfig.setMaxTotal(maxConnections);
JConfig.setMaxIdle(maxConnections);
JConfig.setMinIdle(1);
JConfig.setBlockWhenExhausted(true);
final String password = config.getString("Redis.Password", "");
if (password.isEmpty()) {
this.jedisPool = new JedisPool(JConfig,
config.getString("Redis.Host"),
config.getInt("Redis.Port"),
config.getInt("Redis.TimeOut"),
config.getString("Redis.Password"),
config.getBoolean("Redis.useTLS"));
config.getString("Redis.Host", "127.0.0.1"),
config.getInt("Redis.Port", 6379),
config.getInt("Redis.TimeOut", 9000),
config.getBoolean("Redis.useTLS", false));
} else {
this.jedisPool = new JedisPool(JConfig,
config.getString("Redis.Host", "127.0.0.1"),
config.getInt("Redis.Port", 6379),
config.getInt("Redis.TimeOut", 9000),
password,
config.getBoolean("Redis.useTLS", false));
}
encryption = new Encryption(config.getBoolean("Redis.EncryptMessages"),
config.getString("Redis.EncryptionKey"),
config.getString("Redis.MacKey"));
@ -102,7 +114,7 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
}
@Override
public void onMessage(byte[] channel, byte[] message){
public void onMessage(byte[] channel, byte[] message) {
String channelString = new String(channel, StandardCharsets.UTF_8);
String receivedMessage = null;
try {
@ -167,8 +179,12 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
if (variable == null) {
Variables.setVariable(varName, inputValue, null, false);
} else if (variable instanceof Long) {
if (inputValue instanceof Integer) {
inputValue = Long.valueOf((Integer) inputValue);
}
if (inputValue instanceof Long) {
Variables.setVariable(varName, (Long) variable + (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Long variable to Double
@ -180,6 +196,9 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
continue;
}
} else if (variable instanceof Double) {
if (inputValue instanceof Integer) {
inputValue = Double.valueOf((Integer) inputValue);
}
if (inputValue instanceof Double) {
Variables.setVariable(varName, (Double) variable + (Double) inputValue, null, false);
} else if (inputValue instanceof Long) {
@ -189,6 +208,18 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
plugin.getLogger().log(Level.WARNING, "Unsupported add action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Integer) {
if (inputValue instanceof Integer) {
Variables.setVariable(varName, (Integer) variable + (Integer) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Integer variable to Double
variable = Double.valueOf((Integer) variable);
Variables.setVariable(varName, (Double) variable + (Double) inputValue, null, false);
} else if (inputValue instanceof Long) {
// convert Integer variable to Long
variable = Long.valueOf((Integer) variable);
Variables.setVariable(varName, (Long) variable + (Long) inputValue, null, false);
}
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported variable type in add action (" + variable.getClass().getName() + ") on variable: " + varName);
@ -206,12 +237,17 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
Variables.setVariable(varName, -(Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
Variables.setVariable(varName, -(Double) inputValue, null, false);
} else if (inputValue instanceof Integer) {
Variables.setVariable(varName, -(Integer) inputValue, null, false);
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported remove action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Long) {
if (inputValue instanceof Integer) {
inputValue = Long.valueOf((Integer) inputValue);
}
if (inputValue instanceof Long) {
Variables.setVariable(varName, (Long) variable - (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
@ -225,11 +261,26 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
continue;
}
} else if (variable instanceof Double) {
if (inputValue instanceof Integer) {
inputValue = Double.valueOf((Integer) inputValue);
}
if (inputValue instanceof Double) {
Variables.setVariable(varName, (Double) variable - (Double) inputValue, null, false);
} else if (inputValue instanceof Long) {
Variables.setVariable(varName, (Double) variable - ((Long) inputValue).doubleValue(), null, false);
}
} else if (variable instanceof Integer) {
if (inputValue instanceof Integer) {
Variables.setVariable(varName, (Integer) variable - (Integer) inputValue, null, false);
} else if (inputValue instanceof Long) {
// convert Integer variable to Long
variable = Long.valueOf((Integer) variable);
Variables.setVariable(varName, (Long) variable - (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Integer variable to Double
variable = Double.valueOf((Integer) variable);
Variables.setVariable(varName, (Double) variable - (Double) inputValue, null, false);
}
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported variable type in remove action (" + variable.getClass().getName() + ") on variable: " + varName);
@ -293,7 +344,7 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
//so to avoid issues, it's best to do it always on separate thread
if (plugin.isEnabled()) {
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
try (BinaryJedis j = jedisPool.getResource()) {
try (Jedis j = jedisPool.getResource()) {
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
} catch (Exception e) {
plugin.sendErrorLogs("Error sending redis message!");
@ -303,7 +354,7 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
} else {
//execute sending of redis message on the main thread if plugin is disabling
//so it can still process the sending
try (BinaryJedis j = jedisPool.getResource()) {
try (Jedis j = jedisPool.getResource()) {
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
} catch (Exception e) {
e.printStackTrace();

View File

@ -5,21 +5,10 @@
<parent>
<artifactId>RediSkript</artifactId>
<groupId>net.limework</groupId>
<version>1.3.5</version>
<version>1.3.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>RediSkript-core</artifactId>
<dependencies>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

13
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>net.limework</groupId>
<artifactId>RediSkript</artifactId>
<version>1.3.5</version>
<version>1.3.7-SNAPSHOT</version>
<modules>
<module>RediSkript-core</module>
<module>RediSkript-bukkit</module>
@ -43,18 +43,23 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20210307</version>
<version>20220320</version>
</dependency>
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>siv-mode</artifactId>
<version>1.4.4</version>
<version>1.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.2</version>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>4.4.6</version>
</dependency>
</dependencies>
</project>