Compare commits

..

3 Commits
1.3.4 ... 1.3.5

Author SHA1 Message Date
5db2e01eab Update README.md 2022-03-22 12:10:17 +02:00
7effb90baa Support add/remove actions with numbers on variables & Update dependencies 2022-03-22 11:58:41 +02:00
f0edb1cd21 Update dependencies 2022-01-23 11:44:36 +02:00
7 changed files with 111 additions and 43 deletions

View File

@@ -30,6 +30,8 @@ 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:
send "%{test::*}%" #outputs 100, 100 and 100
add 100 to variables "test::1" and "test::2" in channel "global"
remove 10 from variable "test::1" in channel "global"
delete variables "test::*" in channel "global"
set variable "test::%uuid of player%" in channel "playerdata" to tool of player
@@ -72,13 +74,12 @@ Redis:
#the encryption configuration must be the same across all servers in order to communicate
#use 16 characters long key for AES-128 encryption
#32 characters long key for AES-256 encryption
#AES-128 is faster, but less secure (but it is not crackable by today's technology as of 2020, may be crackable by quantum computers)
#32 characters long key for AES-256 encryption (recommended)
#the AES implementation used in RediSkript uses SIV mode, which makes the same key resistant to cracking for a big count of messages without the need of changing the key very often
EncryptMessages: true
#EncryptionKey and MacKey must be different
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
EncryptionKey: "32CHARACTERS KEY"
MacKey: "32CHARACTERS KEY"
#the channels from which this server can receive messages

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>RediSkript</artifactId>
<groupId>net.limework</groupId>
<version>1.3.4</version>
<version>1.3.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -57,7 +57,7 @@
<dependency>
<groupId>com.github.SkriptLang</groupId>
<artifactId>Skript</artifactId>
<version>2.5.3</version>
<version>2.6.1</version>
<type>jar</type>
<exclusions>
<exclusion>
@@ -76,7 +76,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.7.0</version>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>net.limework</groupId>

View File

@@ -19,6 +19,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
public class RedisController extends BinaryJedisPubSub implements Runnable {
@@ -134,51 +135,117 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
//Transfer variables between servers
JSONArray variableNames = j.getJSONArray("Names");
JSONArray varNames = j.getJSONArray("Names");
Object inputValue;
String changeValue = null;
JSONArray variableValues = null;
JSONArray varValues = null;
if (!j.isNull("Values")) {
variableValues = j.getJSONArray("Values");
varValues = j.getJSONArray("Values");
}
for (int i = 0; i < variableNames.length(); i++) {
for (int i = 0; i < varNames.length(); i++) {
String varName = varNames.get(i).toString();
if (j.isNull("Values")) {
//only check for SET here, because null has to be ignored in all other cases
// only check for SET here, because null has to be ignored in all other cases
if (j.getString("Operation").equals("SET")) {
Variables.setVariable(variableNames.get(i).toString(), null, null, false);
Variables.setVariable(varName, null, null, false);
}
} else {
if (!variableValues.isNull(i)) {
changeValue = variableValues.get(i).toString();
}
if (!varValues.isNull(i)) {
changeValue = varValues.get(i).toString();
}
String[] inputs = changeValue.split("\\^", 2);
inputValue = Classes.deserialize(inputs[0], Base64.getDecoder().decode(inputs[1]));
switch (j.getString("Operation")) {
case "ADD":
//I will add this once someone tells me how to remove from Skript variable
//because using SET operation has issues with inconvertible types (Double and Long)
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
if (varName.charAt(varName.length() - 1) == '*') {
plugin.getLogger().log(Level.WARNING, "Adding to {::*} variables in RediSkript is not supported. Variable name: " + varName);
continue;
}
Object variable = Variables.getVariable(varName, null, false);
if (variable == null) {
Variables.setVariable(varName, inputValue, null, false);
} else if (variable instanceof Long) {
if (inputValue instanceof Long) {
Variables.setVariable(varName, (Long) variable + (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Long variable to Double
variable = Double.valueOf((Long) variable);
Variables.setVariable(varName, (Double) variable + (Double) inputValue, null, false);
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported add action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else if (variable instanceof Double) {
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 {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported add action of data type (" + inputValue.getClass().getName() + ") on variable: " + varName);
continue;
}
} else {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported variable type in add action (" + variable.getClass().getName() + ") on variable: " + varName);
continue;
}
break;
case "REMOVE":
//I will add this once someone tells me how to remove from Skript variable
//because using SET operation has issues with inconvertible types (Double and Long)
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
if (varName.charAt(varName.length() - 1) == '*') {
plugin.getLogger().log(Level.WARNING, "Removing from {::*} variables in RediSkript is not supported. Variable name: " + varName);
continue;
}
variable = Variables.getVariable(varName, null, false);
if (variable == null) {
if (inputValue instanceof Long) {
Variables.setVariable(varName, -(Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
Variables.setVariable(varName, -(Double) 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 Long) {
Variables.setVariable(varName, (Long) variable - (Long) inputValue, null, false);
} else if (inputValue instanceof Double) {
// convert Long variable to Double
variable = Double.valueOf((Long) variable);
Variables.setVariable(varName, (Double) variable - (Double) 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 Double) {
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 {
// Not supported input type
plugin.getLogger().log(Level.WARNING, "Unsupported variable type in remove action (" + variable.getClass().getName() + ") on variable: " + varName);
continue;
}
break;
case "SET":
String variableName = variableNames.get(i).toString();
//this is needed, because setting a {variable::*} causes weird behavior, like
//1st set operation is no data, 2nd has data, etc.
//if you set it to null before action, it works correctly
if (variableName.charAt(variableName.length()-1) == '*') {
Variables.setVariable(variableName, null, null, false);
}
Variables.setVariable(variableNames.get(i).toString(), inputValue, null, false);
if (varName.charAt(varName.length() - 1) == '*') {
Variables.setVariable(varName, null, null, false);
}
Variables.setVariable(varNames.get(i).toString(), inputValue, null, false);
break;
}
}

View File

@@ -73,7 +73,7 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
@Override
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
//if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE)
if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET)
if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET || mode == Changer.ChangeMode.ADD || mode == Changer.ChangeMode.REMOVE)
return CollectionUtils.array(Object.class);
return null;

View File

@@ -23,13 +23,13 @@ Redis:
#the encryption configuration must be the same across all servers in order to communicate
#use 16 characters long key for AES-128 encryption
#32 characters long key for AES-256 encryption
#32 characters long key for AES-256 encryption (recommended)
#AES-128 is faster, but less secure (but it is not crackable by today's technology as of 2020, may be crackable by quantum computers)
#the AES implementation used in RediSkript uses SIV mode, which makes the same key resistant to cracking for a big count of messages without the need of changing the key very often
EncryptMessages: true
#EncryptionKey and MacKey must be different
EncryptionKey: "16CHARACTERS KEY"
MacKey: "16CHARACTERS KEY"
EncryptionKey: "32CHARACTERS KEY"
MacKey: "32CHARACTERS KEY"
#the channels from which this server can receive messages
@@ -41,4 +41,4 @@ Redis:
Channels:
- "global"
- "servername"
- "Channel3"
- "Channel3"

View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>RediSkript</artifactId>
<groupId>net.limework</groupId>
<version>1.3.4</version>
<version>1.3.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -16,10 +16,10 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.5.1</version>
<version>3.8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
</project>

View File

@@ -6,7 +6,7 @@
<groupId>net.limework</groupId>
<artifactId>RediSkript</artifactId>
<version>1.3.4</version>
<version>1.3.5</version>
<modules>
<module>RediSkript-core</module>
<module>RediSkript-bukkit</module>
@@ -48,7 +48,7 @@
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>siv-mode</artifactId>
<version>1.4.1</version>
<version>1.4.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
<dependency>
@@ -57,4 +57,4 @@
<version>2.6.2</version>
</dependency>
</dependencies>
</project>
</project>