forked from Limework/RediSkript
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d5d281fe4 | ||
|
|
5699b9445f | ||
|
|
053bb04918 | ||
|
|
2140cd67ff | ||
|
|
e9ae0bd50b | ||
|
|
6ea120a85a | ||
|
|
01525e4d63 | ||
|
|
c63495e201 | ||
|
|
265dbfa84d | ||
|
|
6f600cc96e | ||
|
|
1b151dfbbe | ||
|
|
afdb0c3e59 | ||
|
|
ca64ec19db | ||
|
|
c0bd63e3cd |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
target
|
target
|
||||||
out
|
out
|
||||||
.idea/workspace.xml
|
.idea
|
||||||
compile
|
compile
|
||||||
2
.idea/artifacts/RediSkript_jar.xml
generated
2
.idea/artifacts/RediSkript_jar.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<component name="ArtifactManager">
|
<component name="ArtifactManager">
|
||||||
<artifact type="jar" build-on-make="true" name="RediSkript:jar">
|
<artifact type="jar" build-on-make="true" name="RediSkript:jar">
|
||||||
<output-path>$PROJECT_DIR$/out/artifacts/RediSkript_jar</output-path>
|
<output-path>$PROJECT_DIR$/../../Govindo/testserver/plugins</output-path>
|
||||||
<root id="archive" name="RediSkript.jar">
|
<root id="archive" name="RediSkript.jar">
|
||||||
<element id="module-output" name="RediSkript" />
|
<element id="module-output" name="RediSkript" />
|
||||||
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/cryptomator/siv-mode/1.4.0/siv-mode-1.4.0.jar" path-in-jar="/" />
|
<element id="extracted-dir" path="$MAVEN_REPOSITORY$/org/cryptomator/siv-mode/1.4.0/siv-mode-1.4.0.jar" path-in-jar="/" />
|
||||||
|
|||||||
10
.idea/jarRepositories.xml
generated
10
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="PaperMC" />
|
||||||
|
<option name="name" value="PaperMC" />
|
||||||
|
<option name="url" value="https://repo.destroystokyo.com/repository/maven-public/" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="central" />
|
<option name="id" value="central" />
|
||||||
<option name="name" value="Central Repository" />
|
<option name="name" value="Central Repository" />
|
||||||
@@ -16,6 +21,11 @@
|
|||||||
<option name="name" value="commons-pool2" />
|
<option name="name" value="commons-pool2" />
|
||||||
<option name="url" value="https://mvnrepository.com/artifact/org.apache.commons/commons-pool2" />
|
<option name="url" value="https://mvnrepository.com/artifact/org.apache.commons/commons-pool2" />
|
||||||
</remote-repository>
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="sk89q" />
|
||||||
|
<option name="name" value="sk89q" />
|
||||||
|
<option name="url" value="http://maven.sk89q.com/repo" />
|
||||||
|
</remote-repository>
|
||||||
<remote-repository>
|
<remote-repository>
|
||||||
<option name="id" value="spigot-repo" />
|
<option name="id" value="spigot-repo" />
|
||||||
<option name="name" value="spigot-repo" />
|
<option name="name" value="spigot-repo" />
|
||||||
|
|||||||
27
README.md
27
README.md
@@ -1,14 +1,11 @@
|
|||||||
**To-do List**
|
|
||||||
1. Fix memory leak of /reloadredis (Not yet known how to fix it, it can be easily noticed by changing IP addresses and using NetworkInterceptor plugin, it'll show connections still being done to old IP address, aswell as the new one, even if it doesn't use old IP address for anything.)
|
|
||||||
|
|
||||||
|
|
||||||
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 servers with use of Redis, it's very fast and easy to use.
|
||||||
|
|
||||||
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!
|
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 originally developed by the team of Govindas Limework developers and is now maintained only by Govindas.
|
It is originally developed by the team of Govindas Limework developers and is now maintained only by Govindas.
|
||||||
Example:
|
|
||||||
|
Redis Message:
|
||||||
```
|
```
|
||||||
on redis message:
|
on redis message:
|
||||||
if redis channel is "world":
|
if redis channel is "world":
|
||||||
@@ -20,8 +17,26 @@ command /sendredis <text> <text>:
|
|||||||
send redis message arg 1 to channel arg 2
|
send redis message arg 1 to channel arg 2
|
||||||
send redis message "hello world!" to channel "world"
|
send redis message "hello world!" to channel "world"
|
||||||
```
|
```
|
||||||
|
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:
|
||||||
|
send "%{test::*}%" #outputs 100, 100 and 100
|
||||||
|
|
||||||
and that's all there is to this addon! 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.
|
delete variables "test::*" in channel "global"
|
||||||
|
|
||||||
|
set variable "test::%uuid of player%" in channel "playerdata" to tool of player
|
||||||
|
#then you can in any server that is listening to "playerdata" channel and was online when the above line was executed:
|
||||||
|
give {test::%uuid of player%} to player
|
||||||
|
```
|
||||||
|
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:
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -11,10 +11,56 @@
|
|||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.skriptlang:Skript:2.4.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.skriptlang:Skript:2.4.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.15-R0.1-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jsr305:1.3.9" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: junit:junit:4.10" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm:7.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-commons:7.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-tree:7.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-analysis:7.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:findbugs:3.0.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.jcip:jcip-annotations:1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:bcel-findbugs:6.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.findbugs:jFormatString:2.0.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: dom4j:dom4j:1.6.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: xml-apis:xml-apis:1.0.b2" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-debug-all:5.0.2" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.apple:AppleJavaExtensions:1.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: jaxen:jaxen:1.1.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-legacy:7.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bukkit:bukkit:1.13-R0.1-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-bukkit:7.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit:worldedit-core:7.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit.worldedit-libs:core:7.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: de.schlichtherle:truezip:6.8.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: rhino:js:1.7R2" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldedit.worldedit-libs:bukkit:7.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-slf4j-impl:2.8.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.logging.log4j:log4j-api:2.8.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.worldguard:worldguard-core:7.0.0-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q.intake:intake:4.2-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:squirrelid:0.2.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.flywaydb:flyway-core:3.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.khelekore:prtree:1.5.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.sk89q:commandbook:2.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.bstats:bstats-bukkit:1.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.marcelo-mason:PreciousStones:24e3d4bf67b7240ae36b32be10e99d4091938c5c" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: ant-contrib:ant-contrib:1.0b3" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.milkbowl.vault:Vault:1.7.1" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot-api:1.16.2-R0.1-SNAPSHOT" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-lang:commons-lang:2.6" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.16-R0.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||||
<orderEntry type="library" name="Maven: redis.clients:jedis:3.3.0" level="project" />
|
<orderEntry type="library" name="Maven: redis.clients:jedis:3.3.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.2" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.2" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
|
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.cryptomator:siv-mode:1.4.0" level="project" />
|
<orderEntry type="library" name="Maven: org.cryptomator:siv-mode:1.4.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
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,14 +1,18 @@
|
|||||||
package net.limework.rediskript;
|
package net.limework.rediskript;
|
||||||
|
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
|
import ch.njol.skript.SkriptAddon;
|
||||||
|
import ch.njol.skript.lang.ExpressionType;
|
||||||
|
import ch.njol.skript.registrations.EventValues;
|
||||||
|
import ch.njol.skript.util.Date;
|
||||||
|
import ch.njol.skript.util.Getter;
|
||||||
import net.limework.rediskript.commands.CommandReloadRedis;
|
import net.limework.rediskript.commands.CommandReloadRedis;
|
||||||
import net.limework.rediskript.skript.SkriptHook;
|
import net.limework.rediskript.events.RedisMessageEvent;
|
||||||
import net.limework.rediskript.managers.RedisManager;
|
import net.limework.rediskript.managers.RedisManager;
|
||||||
import org.bukkit.Bukkit;
|
import net.limework.rediskript.skript.elements.*;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class RediSkript extends JavaPlugin {
|
public class RediSkript extends JavaPlugin {
|
||||||
|
|
||||||
@@ -20,27 +24,52 @@ public class RediSkript extends JavaPlugin {
|
|||||||
rm = new RedisManager(this);
|
rm = new RedisManager(this);
|
||||||
rm.start();
|
rm.start();
|
||||||
}
|
}
|
||||||
|
public void registerSyntax() {
|
||||||
|
SkriptAddon addon = Skript.registerAddon(this);
|
||||||
|
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(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
|
||||||
|
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
|
||||||
|
@Override
|
||||||
|
public String get(RedisMessageEvent e) {
|
||||||
|
return e.getChannelName();
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message");
|
||||||
|
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
|
||||||
|
@Override
|
||||||
|
public String get(RedisMessageEvent e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
Skript.registerExpression(ExprMessageDate.class, Date.class, ExpressionType.SIMPLE, "redis message date");
|
||||||
|
EventValues.registerEventValue(RedisMessageEvent.class, Date.class, new Getter<Date, RedisMessageEvent>() {
|
||||||
|
@Override
|
||||||
|
public Date get(RedisMessageEvent e) {
|
||||||
|
return new Date(e.getDate());
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
startRedis(false);
|
startRedis(false);
|
||||||
|
getServer().getPluginCommand("reloadredis").setExecutor(new CommandReloadRedis(this));
|
||||||
PluginCommand command = getServer().getPluginCommand("reloadredis");
|
registerSyntax();
|
||||||
assert command != null;
|
|
||||||
command.setExecutor(new CommandReloadRedis(this));
|
|
||||||
|
|
||||||
new SkriptHook(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
//using HIGHEST event priority so it shuts down last and code can still execute well in "on script unload" and "on skript unload" events
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (rm != null) {
|
if (rm != null) rm.shutdown();
|
||||||
rm.shutdown();
|
|
||||||
}
|
}
|
||||||
}
|
public RedisManager getRedisManager() {
|
||||||
public RedisManager getRm() {
|
|
||||||
return rm;
|
return rm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,6 @@ import org.bukkit.command.Command;
|
|||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class CommandReloadRedis implements CommandExecutor {
|
public class CommandReloadRedis implements CommandExecutor {
|
||||||
private RediSkript plugin;
|
private RediSkript plugin;
|
||||||
public CommandReloadRedis(RediSkript plugin) {
|
public CommandReloadRedis(RediSkript plugin) {
|
||||||
@@ -18,12 +17,12 @@ public class CommandReloadRedis implements CommandExecutor {
|
|||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
//not using bungee TextComponent because it is not present in 1.8.8
|
//not using bungee TextComponent because it is not present in 1.8.8
|
||||||
sender.sendMessage((ChatColor.translateAlternateColorCodes('&'
|
sender.sendMessage((ChatColor.translateAlternateColorCodes('&'
|
||||||
, "&2[&aRediSkript&a] &cThis command can only be executed in console.")));
|
, "&2[&aRediSkript&2] &cThis command can only be executed in console.")));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
plugin.getRm().reload();
|
plugin.getRedisManager().reload();
|
||||||
//not sending to sender, because this command can only be executed via console
|
//not sending to sender, because this command can only be executed via console
|
||||||
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded via command! Note this command is not stable, it should only be used in urgent cases where you absolutely need to change config details without restarting the server."));
|
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&eReloaded channels, encryption and login details!"));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,33 @@
|
|||||||
package net.limework.rediskript.managers;
|
package net.limework.rediskript.managers;
|
||||||
|
|
||||||
|
import ch.njol.skript.registrations.Classes;
|
||||||
|
import ch.njol.skript.variables.Variables;
|
||||||
import net.limework.rediskript.RediSkript;
|
import net.limework.rediskript.RediSkript;
|
||||||
import net.limework.rediskript.events.RedisMessageEvent;
|
|
||||||
import net.limework.rediskript.data.Encryption;
|
import net.limework.rediskript.data.Encryption;
|
||||||
|
import net.limework.rediskript.events.RedisMessageEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.cryptomator.siv.UnauthenticCiphertextException;
|
import org.cryptomator.siv.UnauthenticCiphertextException;
|
||||||
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import redis.clients.jedis.BinaryJedis;
|
import redis.clients.jedis.BinaryJedis;
|
||||||
import redis.clients.jedis.BinaryJedisPubSub;
|
import redis.clients.jedis.BinaryJedisPubSub;
|
||||||
import redis.clients.jedis.JedisPool;
|
import redis.clients.jedis.JedisPool;
|
||||||
import redis.clients.jedis.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Base64;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
||||||
|
|
||||||
private final ExecutorService RedisReconnector;
|
private ExecutorService RedisReconnector;
|
||||||
private RediSkript plugin;
|
private RediSkript plugin;
|
||||||
|
|
||||||
private JedisPool jedisPool;
|
private JedisPool jedisPool;
|
||||||
@@ -58,8 +62,8 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
RedisService = Executors.newSingleThreadExecutor();
|
RedisService = Executors.newSingleThreadExecutor();
|
||||||
try {
|
try {
|
||||||
this.subscribeJedis = this.jedisPool.getResource();
|
this.subscribeJedis = this.jedisPool.getResource();
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {}
|
||||||
}
|
|
||||||
this.channels = config.getStringList("Channels");
|
this.channels = config.getStringList("Channels");
|
||||||
encryption = new Encryption(config);
|
encryption = new Encryption(config);
|
||||||
|
|
||||||
@@ -71,33 +75,22 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!isShuttingDown.get()) {
|
while (!isShuttingDown.get() && plugin.isEnabled()) {
|
||||||
try {
|
try {
|
||||||
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&cConnecting to redis..."));
|
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&cConnecting to redis..."));
|
||||||
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
|
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
|
||||||
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&aRedis connected!"));
|
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&aRedis connected!"));
|
||||||
int byteArr2dSize = 1;
|
byte[][] channelsInByte = new byte[channels.size()][1];
|
||||||
byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
|
|
||||||
boolean reInitializeByteArray;
|
|
||||||
// Loop that reInitialize array IF array size is not enough
|
|
||||||
do {
|
|
||||||
reInitializeByteArray = false;
|
|
||||||
try {
|
|
||||||
/* Data Initialization for channelsInByte array from List<String> channels */
|
|
||||||
for (int x = 0; x < channels.size(); x++) {
|
for (int x = 0; x < channels.size(); x++) {
|
||||||
channelsInByte[x] = channels.get(x).getBytes(StandardCharsets.UTF_8);
|
channelsInByte[x] = channels.get(x).getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
|
||||||
reInitializeByteArray = true;
|
|
||||||
/* Increase the current 2d array size to increase 1 and reinitialize the array*/
|
|
||||||
byteArr2dSize += 1;
|
|
||||||
channelsInByte = new byte[channels.size()][byteArr2dSize];
|
|
||||||
}
|
|
||||||
} while (reInitializeByteArray);
|
|
||||||
this.subscribeJedis.subscribe(this, channelsInByte);
|
this.subscribeJedis.subscribe(this, channelsInByte);
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
if (isShuttingDown.get() || !plugin.isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&cConnection to redis has failed! &cReconnecting..."));
|
plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&cConnection to redis has failed! &cReconnecting..."));
|
||||||
if (this.subscribeJedis != null) {
|
if (this.subscribeJedis != null) {
|
||||||
this.subscribeJedis.close();
|
this.subscribeJedis.close();
|
||||||
@@ -128,16 +121,62 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
//encryption is disabled, so let's just get the string
|
//encryption is disabled, so let's just get the string
|
||||||
receivedMessage = new String(message, StandardCharsets.UTF_8);
|
receivedMessage = new String(message, StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receivedMessage != null) {
|
if (receivedMessage != null) {
|
||||||
JSONObject j = new JSONObject(receivedMessage);
|
JSONObject j = new JSONObject(receivedMessage);
|
||||||
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
|
if (j.get("Type").equals("Skript")) {
|
||||||
RedisMessageEvent event = new RedisMessageEvent(channelString, j.getString("Message"), j.getLong("Date"));
|
JSONArray messages = j.getJSONArray("Messages");
|
||||||
|
RedisMessageEvent event;
|
||||||
|
for (int i = 0; i < messages.length(); i++) {
|
||||||
|
event = new RedisMessageEvent(channelString, messages.get(i).toString(), j.getLong("Date"));
|
||||||
//if plugin is disabling, don't call events anymore
|
//if plugin is disabling, don't call events anymore
|
||||||
|
|
||||||
if (plugin.isEnabled()) {
|
if (plugin.isEnabled()) {
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(event));
|
RedisMessageEvent finalEvent = event;
|
||||||
|
Bukkit.getScheduler().runTask(plugin, () -> plugin.getServer().getPluginManager().callEvent(finalEvent));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (j.get("Type").equals("SkriptVariables")) {
|
||||||
|
|
||||||
|
//Transfer variables between servers
|
||||||
|
|
||||||
|
JSONArray variableNames = j.getJSONArray("Names");
|
||||||
|
Object inputValue;
|
||||||
|
String changeValue = null;
|
||||||
|
JSONArray variableValues = null;
|
||||||
|
if (!j.isNull("Values")) {
|
||||||
|
variableValues = j.getJSONArray("Values");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < variableNames.length(); i++) {
|
||||||
|
|
||||||
|
if (j.isNull("Values")) {
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (!variableValues.isNull(i)) {
|
||||||
|
changeValue = variableValues.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);
|
||||||
|
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) {
|
} catch (Exception e) {
|
||||||
@@ -147,22 +186,71 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public void sendMessage(String[] message, String channel) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("Messages", new JSONArray(message));
|
||||||
|
json.put("Type", "Skript");
|
||||||
|
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
||||||
|
finishSendMessage(json, channel);
|
||||||
|
}
|
||||||
|
public void sendVariables(String[] variableNames, String[] variableValues, String channel, String operation) {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("Names", new JSONArray(variableNames));
|
||||||
|
if (variableValues != null) {
|
||||||
|
json.put("Values", new JSONArray(variableValues));
|
||||||
|
}
|
||||||
|
|
||||||
|
json.put("Type", "SkriptVariables");
|
||||||
|
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
||||||
|
json.put("Operation", operation);
|
||||||
|
finishSendMessage(json, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void finishSendMessage(JSONObject json, String channel) {
|
||||||
|
try {
|
||||||
|
byte[] message;
|
||||||
|
if (this.getEncryption().isEncryptionEnabled()) {
|
||||||
|
message = this.getEncryption().encrypt(json.toString());
|
||||||
|
} else {
|
||||||
|
message = json.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
//sending a redis message blocks main thread if there's no more connections available
|
||||||
|
//so to avoid issues, it's best to do it always on separate thread
|
||||||
|
if (plugin.isEnabled()) {
|
||||||
|
this.getRedisService().execute(() -> {
|
||||||
|
BinaryJedis j = this.getJedisPool().getResource();
|
||||||
|
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
|
||||||
|
j.close();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
//execute sending of redis message on the main thread if plugin is disabling
|
||||||
|
//so it can still process the sending
|
||||||
|
BinaryJedis j = this.getJedisPool().getResource();
|
||||||
|
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
|
||||||
|
j.close();
|
||||||
|
}
|
||||||
|
} catch (JedisConnectionException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
try {
|
|
||||||
this.RedisService.awaitTermination(1, TimeUnit.SECONDS);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
this.isShuttingDown.set(true);
|
this.isShuttingDown.set(true);
|
||||||
if (this.subscribeJedis != null) {
|
if (this.subscribeJedis != null) {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
this.subscribeJedis.close();
|
this.subscribeJedis.close();
|
||||||
this.subscribeJedis.getClient().close();
|
}
|
||||||
this.jedisPool.getResource().close();
|
|
||||||
|
if (this.jedisPool != null) {
|
||||||
|
jedisPool.close();
|
||||||
|
jedisPool = null;
|
||||||
}
|
}
|
||||||
this.RedisReconnector.shutdown();
|
this.RedisReconnector.shutdown();
|
||||||
this.RedisService.shutdown();
|
this.RedisService.shutdown();
|
||||||
|
this.RedisService = null;
|
||||||
|
this.RedisReconnector = null;
|
||||||
|
encryption = null;
|
||||||
|
|
||||||
}
|
}
|
||||||
public void reload() {
|
public void reload() {
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package net.limework.rediskript.skript;
|
|
||||||
|
|
||||||
import ch.njol.skript.Skript;
|
|
||||||
import ch.njol.skript.SkriptAddon;
|
|
||||||
import ch.njol.skript.lang.ExpressionType;
|
|
||||||
import ch.njol.skript.registrations.EventValues;
|
|
||||||
import ch.njol.skript.util.Date;
|
|
||||||
import ch.njol.skript.util.Getter;
|
|
||||||
import net.limework.rediskript.RediSkript;
|
|
||||||
import net.limework.rediskript.events.RedisMessageEvent;
|
|
||||||
import net.limework.rediskript.skript.elements.EvtRedis;
|
|
||||||
import net.limework.rediskript.skript.elements.ExprChannel;
|
|
||||||
import net.limework.rediskript.skript.elements.ExprMessage;
|
|
||||||
import net.limework.rediskript.skript.elements.ExprMessageDate;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class SkriptHook {
|
|
||||||
public SkriptHook(RediSkript plugin) {
|
|
||||||
SkriptAddon addon = Skript.registerAddon(plugin);
|
|
||||||
try {
|
|
||||||
addon.loadClasses("net.limework.rediskript.skript", "elements");
|
|
||||||
Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
|
|
||||||
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
|
|
||||||
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
|
|
||||||
@Override
|
|
||||||
public String get(RedisMessageEvent e) {
|
|
||||||
return e.getChannelName();
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message");
|
|
||||||
EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter<String, RedisMessageEvent>() {
|
|
||||||
@Override
|
|
||||||
public String get(RedisMessageEvent e) {
|
|
||||||
return e.getMessage();
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
Skript.registerExpression(ExprMessageDate.class, Date.class, ExpressionType.SIMPLE, "redis message date");
|
|
||||||
EventValues.registerEventValue(RedisMessageEvent.class, Date.class, new Getter<Date, RedisMessageEvent>() {
|
|
||||||
@Override
|
|
||||||
public Date get(RedisMessageEvent e) {
|
|
||||||
return new Date(e.getDate());
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,19 +6,13 @@ 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.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 {
|
||||||
Skript.registerEffect(EffSendMessage.class, "send redis message %string% to [channel] %string%");
|
Skript.registerEffect(EffSendMessage.class, "send redis message[s] %strings% to [channel] %string%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -31,10 +25,9 @@ public class EffSendMessage extends Effect {
|
|||||||
|
|
||||||
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
|
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
|
||||||
|
|
||||||
String message = this.message.getSingle(event);
|
String[] message = this.message.getAll(event);
|
||||||
String channel = this.channel.getSingle(event);
|
String channel = this.channel.getSingle(event);
|
||||||
|
if (message[0] == null) {
|
||||||
if (message == null) {
|
|
||||||
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cRedis message was empty. Please check your code."));
|
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cRedis message was empty. Please check your code."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -42,40 +35,7 @@ public class EffSendMessage extends Effect {
|
|||||||
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cChannel was empty. Please check your code."));
|
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cChannel was empty. Please check your code."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert plugin != null;
|
plugin.getRedisManager().sendMessage(message, channel);
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
json.put("Message", message);
|
|
||||||
json.put("Type", "Skript");
|
|
||||||
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
|
||||||
byte[] msg;
|
|
||||||
RedisManager manager = plugin.getRm();
|
|
||||||
if (manager.getEncryption().isEncryptionEnabled()) {
|
|
||||||
msg = manager.getEncryption().encrypt(json.toString());
|
|
||||||
} else {
|
|
||||||
msg = json.toString().getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
|
|
||||||
//execute sending of redis message on the main thread if plugin is disabling
|
|
||||||
//so it can still process the sending
|
|
||||||
|
|
||||||
//sending a redis message blocks main thread if there's no more connections available
|
|
||||||
//so to avoid issues, it's best to do it always on separate thread
|
|
||||||
if (plugin.isEnabled()) {
|
|
||||||
manager.getRedisService().execute(() -> {
|
|
||||||
BinaryJedis j = manager.getJedisPool().getResource();
|
|
||||||
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
|
|
||||||
j.close();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
BinaryJedis j = manager.getJedisPool().getResource();
|
|
||||||
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
|
|
||||||
j.close();
|
|
||||||
}
|
|
||||||
} catch (JedisConnectionException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ public class EvtRedis extends SkriptEvent {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean check(Event event) {
|
public boolean check(Event event) {
|
||||||
if (!(event instanceof RedisMessageEvent)) {
|
return (event instanceof RedisMessageEvent);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
package net.limework.rediskript.skript.elements;
|
||||||
|
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
|
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.log.ErrorQuality;
|
||||||
|
import ch.njol.skript.registrations.Classes;
|
||||||
|
import ch.njol.skript.variables.SerializedVariable;
|
||||||
|
import ch.njol.util.Kleenean;
|
||||||
|
import ch.njol.util.coll.CollectionUtils;
|
||||||
|
import net.limework.rediskript.RediSkript;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public class ExprVariableInChannel extends SimpleExpression<Object> {
|
||||||
|
private Expression<String> name;
|
||||||
|
private Expression<String> channel;
|
||||||
|
@Override
|
||||||
|
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
|
||||||
|
name = (Expression<String>) expressions[0];
|
||||||
|
channel = (Expression<String>) expressions[1];
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object[] get(Event event) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSingle() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Object> getReturnType() {
|
||||||
|
return Object.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(Event event, boolean debug) {
|
||||||
|
return "variable " + name.toString(event,debug) + " in redis channel " + channel.toString(event, debug);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void change(Event e, Object[] changer, Changer.ChangeMode mode) {
|
||||||
|
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
|
||||||
|
switch (mode) {
|
||||||
|
case ADD:
|
||||||
|
case SET:
|
||||||
|
case REMOVE:
|
||||||
|
SerializedVariable.Value serialized;
|
||||||
|
String encoded;
|
||||||
|
String[] values = new String[changer.length+1];
|
||||||
|
for( int i = 0; i < changer.length; i++) {
|
||||||
|
if (changer[i] != null) {
|
||||||
|
serialized = Classes.serialize(changer[i]);
|
||||||
|
encoded = Base64.getEncoder().encodeToString(serialized.data);
|
||||||
|
encoded = serialized.type + "^" + encoded;
|
||||||
|
values[i] = encoded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String operation = mode.toString();
|
||||||
|
plugin.getRedisManager().sendVariables(name.getAll(e), values, channel.getSingle(e), operation);
|
||||||
|
break;
|
||||||
|
case DELETE:
|
||||||
|
plugin.getRedisManager().sendVariables(name.getAll(e), null, channel.getSingle(e), "SET");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user