Optimizations

This commit is contained in:
Govindas 2020-11-28 10:02:14 +02:00
parent 3e4b6b78e7
commit e31773f6dd
6 changed files with 26 additions and 55 deletions

View File

@ -6,7 +6,7 @@
<groupId>net.limework.rediskript</groupId>
<artifactId>RediSkript</artifactId>
<version>1.2.5</version>
<version>1.3.0</version>
<packaging>jar</packaging>
<build>

View File

@ -1,15 +1,13 @@
package net.limework.rediskript;
import net.limework.rediskript.commands.CommandReloadRedis;
import net.limework.rediskript.skript.SkriptHook;
import net.limework.rediskript.managers.RedisManager;
import org.bukkit.Bukkit;
import net.limework.rediskript.skript.SkriptHook;
import org.bukkit.command.PluginCommand;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.concurrent.TimeUnit;
public class RediSkript extends JavaPlugin {
//Redis manager

View File

@ -174,45 +174,25 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
}
String[] inputs = changeValue.split("\\^", 2);
inputValue = Classes.deserialize(inputs[0], Base64.getDecoder().decode(inputs[1]));
//operations ARE UNFINISHED. because I do not yet know how to handle all the Long/Double conversions without issues.
//first check if the variable is set
if (Variables.getVariable(variableNames.get(i).toString(), null, false) != null) {
//add to variable
if (j.getString("Operation").equals("ADD")) {
if (inputValue.getClass().getName().equals("java.lang.Long")) {
inputValue = (Long) inputValue + (Long) Variables.getVariable(variableNames.get(i).toString(), null, false);
} else if (inputValue.getClass().getName().equals("java.lang.Double")) {
inputValue = (Double) inputValue + (Double) Variables.getVariable(variableNames.get(i).toString(), 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;
}
}
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);
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);
break;
case "SET":
Variables.setVariable(variableNames.get(i).toString(), inputValue, null, false);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:"));

View File

@ -19,7 +19,7 @@ public class SkriptHook {
try {
addon.loadClasses("net.limework.rediskript.skript", "elements");
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");
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {

View File

@ -6,16 +6,9 @@ import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.util.Kleenean;
import net.limework.rediskript.RediSkript;
import net.limework.rediskript.managers.RedisManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
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 {
static {

View File

@ -3,7 +3,6 @@ package net.limework.rediskript.skript.elements;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.SkriptParser;
import ch.njol.skript.lang.Variable;
import ch.njol.skript.lang.util.SimpleExpression;
import ch.njol.skript.registrations.Classes;
import ch.njol.skript.variables.SerializedVariable;
@ -20,13 +19,13 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
private Expression<String> channel;
@Override
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
if (expressions[0] instanceof Variable) {
Variable<?> variable = (Variable<?>) expressions[0];
System.out.println(variable.getName().toString());
String var = variable.getName().toString();
var = var.substring(1, var.length() - 1);
//if (expressions[0] instanceof Variable) {
// Variable<?> variable = (Variable<?>) expressions[0];
// System.out.println(variable.getName().toString());
// String var = variable.getName().toString();
// var = var.substring(1, var.length() - 1);
}
//}
name = (Expression<String>) expressions[0];
channel = (Expression<String>) expressions[1];
return true;
@ -71,7 +70,6 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
}
}
String operation = mode.toString();
System.out.println(operation);
plugin.getRm().sendVariables(name.getAll(e), values, channel.getSingle(e), operation);
break;
case DELETE:
@ -81,8 +79,10 @@ 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)
return CollectionUtils.array(Object.class);
return null;
}
}