forked from Limework/RediSkript
Support add/remove actions with numbers on variables & Update dependencies
This commit is contained in:
parent
f0edb1cd21
commit
7effb90baa
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>RediSkript</artifactId>
|
<artifactId>RediSkript</artifactId>
|
||||||
<groupId>net.limework</groupId>
|
<groupId>net.limework</groupId>
|
||||||
<version>1.3.4</version>
|
<version>1.3.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -57,7 +57,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.SkriptLang</groupId>
|
<groupId>com.github.SkriptLang</groupId>
|
||||||
<artifactId>Skript</artifactId>
|
<artifactId>Skript</artifactId>
|
||||||
<version>2.5.3</version>
|
<version>2.6.1</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
|
@ -19,6 +19,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class RedisController extends BinaryJedisPubSub implements Runnable {
|
public class RedisController extends BinaryJedisPubSub implements Runnable {
|
||||||
|
|
||||||
@ -134,51 +135,117 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
|
|||||||
|
|
||||||
//Transfer variables between servers
|
//Transfer variables between servers
|
||||||
|
|
||||||
JSONArray variableNames = j.getJSONArray("Names");
|
JSONArray varNames = j.getJSONArray("Names");
|
||||||
Object inputValue;
|
Object inputValue;
|
||||||
String changeValue = null;
|
String changeValue = null;
|
||||||
JSONArray variableValues = null;
|
JSONArray varValues = null;
|
||||||
if (!j.isNull("Values")) {
|
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")) {
|
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")) {
|
if (j.getString("Operation").equals("SET")) {
|
||||||
Variables.setVariable(variableNames.get(i).toString(), null, null, false);
|
Variables.setVariable(varName, null, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!variableValues.isNull(i)) {
|
if (!varValues.isNull(i)) {
|
||||||
changeValue = variableValues.get(i).toString();
|
changeValue = varValues.get(i).toString();
|
||||||
}
|
}
|
||||||
String[] inputs = changeValue.split("\\^", 2);
|
String[] inputs = changeValue.split("\\^", 2);
|
||||||
inputValue = Classes.deserialize(inputs[0], Base64.getDecoder().decode(inputs[1]));
|
inputValue = Classes.deserialize(inputs[0], Base64.getDecoder().decode(inputs[1]));
|
||||||
switch (j.getString("Operation")) {
|
switch (j.getString("Operation")) {
|
||||||
case "ADD":
|
case "ADD":
|
||||||
//I will add this once someone tells me how to remove from Skript variable
|
if (varName.charAt(varName.length() - 1) == '*') {
|
||||||
//because using SET operation has issues with inconvertible types (Double and Long)
|
plugin.getLogger().log(Level.WARNING, "Adding to {::*} variables in RediSkript is not supported. Variable name: " + varName);
|
||||||
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
|
continue;
|
||||||
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
|
}
|
||||||
|
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":
|
case "REMOVE":
|
||||||
//I will add this once someone tells me how to remove from Skript variable
|
if (varName.charAt(varName.length() - 1) == '*') {
|
||||||
//because using SET operation has issues with inconvertible types (Double and Long)
|
plugin.getLogger().log(Level.WARNING, "Removing from {::*} variables in RediSkript is not supported. Variable name: " + varName);
|
||||||
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
|
continue;
|
||||||
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
|
}
|
||||||
|
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;
|
break;
|
||||||
case "SET":
|
case "SET":
|
||||||
String variableName = variableNames.get(i).toString();
|
|
||||||
|
|
||||||
//this is needed, because setting a {variable::*} causes weird behavior, like
|
//this is needed, because setting a {variable::*} causes weird behavior, like
|
||||||
//1st set operation is no data, 2nd has data, etc.
|
//1st set operation is no data, 2nd has data, etc.
|
||||||
//if you set it to null before action, it works correctly
|
//if you set it to null before action, it works correctly
|
||||||
|
if (varName.charAt(varName.length() - 1) == '*') {
|
||||||
if (variableName.charAt(variableName.length()-1) == '*') {
|
Variables.setVariable(varName, null, null, false);
|
||||||
Variables.setVariable(variableName, null, null, false);
|
}
|
||||||
}
|
Variables.setVariable(varNames.get(i).toString(), inputValue, null, false);
|
||||||
Variables.setVariable(variableNames.get(i).toString(), inputValue, null, false);
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
|
|||||||
@Override
|
@Override
|
||||||
public Class<?>[] acceptChange(Changer.ChangeMode mode) {
|
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 || 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 CollectionUtils.array(Object.class);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>RediSkript</artifactId>
|
<artifactId>RediSkript</artifactId>
|
||||||
<groupId>net.limework</groupId>
|
<groupId>net.limework</groupId>
|
||||||
<version>1.3.4</version>
|
<version>1.3.5</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>net.limework</groupId>
|
<groupId>net.limework</groupId>
|
||||||
<artifactId>RediSkript</artifactId>
|
<artifactId>RediSkript</artifactId>
|
||||||
<version>1.3.4</version>
|
<version>1.3.5</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>RediSkript-core</module>
|
<module>RediSkript-core</module>
|
||||||
<module>RediSkript-bukkit</module>
|
<module>RediSkript-bukkit</module>
|
||||||
@ -48,7 +48,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.cryptomator</groupId>
|
<groupId>org.cryptomator</groupId>
|
||||||
<artifactId>siv-mode</artifactId>
|
<artifactId>siv-mode</artifactId>
|
||||||
<version>1.4.1</version>
|
<version>1.4.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
|
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
Loading…
Reference in New Issue
Block a user