forked from Limework/RediSkript
Optimizations
This commit is contained in:
parent
01525e4d63
commit
6ea120a85a
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>net.limework.rediskript</groupId>
|
<groupId>net.limework.rediskript</groupId>
|
||||||
<artifactId>RediSkript</artifactId>
|
<artifactId>RediSkript</artifactId>
|
||||||
<version>1.2.5</version>
|
<version>1.3.0</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
package net.limework.rediskript;
|
package net.limework.rediskript;
|
||||||
|
|
||||||
import net.limework.rediskript.commands.CommandReloadRedis;
|
import net.limework.rediskript.commands.CommandReloadRedis;
|
||||||
import net.limework.rediskript.skript.SkriptHook;
|
|
||||||
import net.limework.rediskript.managers.RedisManager;
|
import net.limework.rediskript.managers.RedisManager;
|
||||||
import org.bukkit.Bukkit;
|
import net.limework.rediskript.skript.SkriptHook;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public class RediSkript extends JavaPlugin {
|
public class RediSkript extends JavaPlugin {
|
||||||
|
|
||||||
//Redis manager
|
//Redis manager
|
||||||
|
@ -174,41 +174,21 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
}
|
}
|
||||||
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")) {
|
||||||
//operations ARE UNFINISHED. because I do not yet know how to handle all the Long/Double conversions without issues.
|
case "ADD":
|
||||||
|
//I will add this once someone tells me how to remove from Skript variable
|
||||||
//first check if the variable is set
|
//because using SET operation has issues with inconvertible types (Double and Long)
|
||||||
|
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
|
||||||
if (Variables.getVariable(variableNames.get(i).toString(), null, false) != null) {
|
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
|
||||||
|
case "REMOVE":
|
||||||
//add to variable
|
//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)
|
||||||
if (j.getString("Operation").equals("ADD")) {
|
//variable = (Variable) Variables.getVariable(variableNames.get(i).toString(), null, false);
|
||||||
if (inputValue.getClass().getName().equals("java.lang.Long")) {
|
// variable.change(null, (Object[]) inputValue, Changer.ChangeMode.REMOVE);
|
||||||
inputValue = (Long) inputValue + (Long) Variables.getVariable(variableNames.get(i).toString(), null, false);
|
break;
|
||||||
} else if (inputValue.getClass().getName().equals("java.lang.Double")) {
|
case "SET":
|
||||||
inputValue = (Double) inputValue + (Double) Variables.getVariable(variableNames.get(i).toString(), null, false);
|
Variables.setVariable(variableNames.get(i).toString(), inputValue, null, false);
|
||||||
}
|
|
||||||
|
|
||||||
//remove from variable
|
|
||||||
|
|
||||||
} else if (j.getString("Operation").equals("REMOVE")) {
|
|
||||||
|
|
||||||
if (inputValue.getClass().getName().equals("java.lang.Long")) {
|
|
||||||
inputValue = (Long) Variables.getVariable(variableNames.get(i).toString(), null, false) - (Long) inputValue;
|
|
||||||
} else if (inputValue.getClass().getName().equals("java.lang.Double")) {
|
|
||||||
inputValue = (Double) Variables.getVariable(variableNames.get(i).toString(), null, false) - (Double) inputValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if variable isn't set and removing, we ned it to properly convert this
|
|
||||||
} else if (j.getString("Operation").equals("REMOVE")) {
|
|
||||||
if (inputValue.getClass().getName().equals("java.lang.Long")) {
|
|
||||||
inputValue = -(Long) inputValue;
|
|
||||||
} else if (inputValue.getClass().getName().equals("java.lang.Double")) {
|
|
||||||
inputValue = -(Double) inputValue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Variables.setVariable(variableNames.get(i).toString(), inputValue, null, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public class SkriptHook {
|
|||||||
try {
|
try {
|
||||||
addon.loadClasses("net.limework.rediskript.skript", "elements");
|
addon.loadClasses("net.limework.rediskript.skript", "elements");
|
||||||
Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
|
Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
|
||||||
Skript.registerExpression(ExprVariableInChannel.class, Object.class, ExpressionType.PROPERTY, "variable[s] %strings% in [redis] channel %string%");
|
Skript.registerExpression(ExprVariableInChannel.class, Object.class, ExpressionType.PROPERTY, "variable[s] %strings% in [redis] [channel] %string%");
|
||||||
|
|
||||||
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
|
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
|
||||||
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
|
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
|
||||||
|
@ -6,16 +6,9 @@ import ch.njol.skript.lang.Expression;
|
|||||||
import ch.njol.skript.lang.SkriptParser;
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
import ch.njol.util.Kleenean;
|
import ch.njol.util.Kleenean;
|
||||||
import net.limework.rediskript.RediSkript;
|
import net.limework.rediskript.RediSkript;
|
||||||
import net.limework.rediskript.managers.RedisManager;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.json.JSONArray;
|
|
||||||
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 {
|
public class EffSendMessage extends Effect {
|
||||||
static {
|
static {
|
||||||
|
@ -3,7 +3,6 @@ package net.limework.rediskript.skript.elements;
|
|||||||
import ch.njol.skript.classes.Changer;
|
import ch.njol.skript.classes.Changer;
|
||||||
import ch.njol.skript.lang.Expression;
|
import ch.njol.skript.lang.Expression;
|
||||||
import ch.njol.skript.lang.SkriptParser;
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
import ch.njol.skript.lang.Variable;
|
|
||||||
import ch.njol.skript.lang.util.SimpleExpression;
|
import ch.njol.skript.lang.util.SimpleExpression;
|
||||||
import ch.njol.skript.registrations.Classes;
|
import ch.njol.skript.registrations.Classes;
|
||||||
import ch.njol.skript.variables.SerializedVariable;
|
import ch.njol.skript.variables.SerializedVariable;
|
||||||
@ -20,13 +19,13 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
|
|||||||
private Expression<String> channel;
|
private Expression<String> channel;
|
||||||
@Override
|
@Override
|
||||||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
|
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
|
||||||
if (expressions[0] instanceof Variable) {
|
//if (expressions[0] instanceof Variable) {
|
||||||
Variable<?> variable = (Variable<?>) expressions[0];
|
// Variable<?> variable = (Variable<?>) expressions[0];
|
||||||
System.out.println(variable.getName().toString());
|
// System.out.println(variable.getName().toString());
|
||||||
String var = variable.getName().toString();
|
// String var = variable.getName().toString();
|
||||||
var = var.substring(1, var.length() - 1);
|
// var = var.substring(1, var.length() - 1);
|
||||||
|
|
||||||
}
|
//}
|
||||||
name = (Expression<String>) expressions[0];
|
name = (Expression<String>) expressions[0];
|
||||||
channel = (Expression<String>) expressions[1];
|
channel = (Expression<String>) expressions[1];
|
||||||
return true;
|
return true;
|
||||||
@ -71,7 +70,6 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String operation = mode.toString();
|
String operation = mode.toString();
|
||||||
System.out.println(operation);
|
|
||||||
plugin.getRm().sendVariables(name.getAll(e), values, channel.getSingle(e), operation);
|
plugin.getRm().sendVariables(name.getAll(e), values, channel.getSingle(e), operation);
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
@ -81,8 +79,10 @@ 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)
|
if (mode == Changer.ChangeMode.DELETE || mode == Changer.ChangeMode.SET)
|
||||||
return CollectionUtils.array(Object.class);
|
return CollectionUtils.array(Object.class);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user