forked from Limework/RediSkript
Various fixes and improvements
This commit is contained in:
parent
358aa66566
commit
0f3ab74d98
@ -17,6 +17,7 @@
|
|||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-analysis:7.1" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.ow2.asm:asm-analysis:7.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
|
<orderEntry type="library" name="Maven: org.jetbrains:annotations:19.0.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: redis.clients:jedis:3.4.0" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.SkriptLang:Skript:2.5.3" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.SkriptLang:Skript:2.5.3" level="project" />
|
||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.destroystokyo.paper:paper-api:1.16.4-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.google.code.findbugs:jsr305:1.3.9" level="project" />
|
||||||
@ -64,9 +65,9 @@
|
|||||||
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.0" level="project" />
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.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: 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" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.26" level="project" />
|
||||||
<orderEntry type="library" name="Maven: redis.clients:jedis:3.4.0" level="project" />
|
<orderEntry type="library" name="Maven: redis.clients:jedis:3.5.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.30" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.json:json:20190722" level="project" />
|
<orderEntry type="library" name="Maven: org.json:json:20201115" 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.apache.commons:commons-pool2:2.6.2" level="project" />
|
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.2" level="project" />
|
||||||
</component>
|
</component>
|
||||||
|
4
pom.xml
4
pom.xml
@ -93,13 +93,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
<version>3.4.1</version>
|
<version>3.5.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.json</groupId>
|
<groupId>org.json</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20190722</version>
|
<version>20201115</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -79,7 +79,11 @@ public class RediSkript extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (redisController != null) redisController.shutdown();
|
if (redisController != null) {
|
||||||
|
redisController.shutdown();
|
||||||
|
}
|
||||||
|
getServer().getPluginCommand("reloadredis").setExecutor(null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedisController getRC() {
|
public RedisController getRC() {
|
||||||
|
@ -6,7 +6,6 @@ import net.limework.rediskript.RediSkript;
|
|||||||
import net.limework.rediskript.data.Encryption;
|
import net.limework.rediskript.data.Encryption;
|
||||||
import net.limework.rediskript.events.RedisMessageEvent;
|
import net.limework.rediskript.events.RedisMessageEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.cryptomator.siv.UnauthenticCiphertextException;
|
import org.cryptomator.siv.UnauthenticCiphertextException;
|
||||||
@ -35,7 +34,6 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
|
|||||||
private final AtomicBoolean isConnectionBroken;
|
private final AtomicBoolean isConnectionBroken;
|
||||||
private final AtomicBoolean isConnecting;
|
private final AtomicBoolean isConnecting;
|
||||||
private final RediSkript plugin;
|
private final RediSkript plugin;
|
||||||
private final boolean debugMode = false; //todo: will be later in the config in future release.
|
|
||||||
private final BukkitTask ConnectionTask;
|
private final BukkitTask ConnectionTask;
|
||||||
|
|
||||||
|
|
||||||
@ -44,9 +42,10 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
|
|||||||
Configuration config = plugin.getConfig();
|
Configuration config = plugin.getConfig();
|
||||||
JedisPoolConfig JConfig = new JedisPoolConfig();
|
JedisPoolConfig JConfig = new JedisPoolConfig();
|
||||||
int maxConnections = config.getInt("Redis.MaxConnections");
|
int maxConnections = config.getInt("Redis.MaxConnections");
|
||||||
if (maxConnections < 2) {
|
|
||||||
maxConnections = 2;
|
//do not allow less than 2 max connections as that causes issues
|
||||||
}
|
if (maxConnections < 2) { maxConnections = 2; }
|
||||||
|
|
||||||
JConfig.setMaxTotal(maxConnections);
|
JConfig.setMaxTotal(maxConnections);
|
||||||
JConfig.setMaxIdle(maxConnections);
|
JConfig.setMaxIdle(maxConnections);
|
||||||
JConfig.setMinIdle(1);
|
JConfig.setMinIdle(1);
|
||||||
@ -70,33 +69,30 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
|
|||||||
if (!isConnectionBroken.get() || isConnecting.get()) {
|
if (!isConnectionBroken.get() || isConnecting.get()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.sendLogs("Connecting to redis......");
|
plugin.sendLogs("Connecting to Redis server...");
|
||||||
isConnecting.set(true);
|
isConnecting.set(true);
|
||||||
try (Jedis jedis = jedisPool.getResource()) {
|
try (Jedis jedis = jedisPool.getResource()) {
|
||||||
isConnectionBroken.set(false);
|
isConnectionBroken.set(false);
|
||||||
plugin.sendLogs("&aConnection to redis has established!");
|
plugin.sendLogs("&aConnection to Redis server has established! Success!");
|
||||||
jedis.subscribe(this, channelsInByte);
|
jedis.subscribe(this, channelsInByte);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
isConnecting.set(false);
|
isConnecting.set(false);
|
||||||
isConnectionBroken.set(true);
|
isConnectionBroken.set(true);
|
||||||
plugin.sendErrorLogs("Connection has &lFAILED &cor Unable to connect to redis retrying to make connection...");
|
plugin.sendErrorLogs("Connection to Redis server has failed! Please check your details in the configuration.");
|
||||||
if (debugMode) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
ConnectionTask.cancel();
|
ConnectionTask.cancel();
|
||||||
|
if (this.isSubscribed()) {
|
||||||
try {
|
try {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.sendErrorLogs("Something went wrong during unsubscribing...");
|
plugin.sendErrorLogs("Something went wrong during unsubscribing...");
|
||||||
if (debugMode) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jedisPool.close();
|
jedisPool.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,14 +173,11 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
plugin.sendErrorLogs("&cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:");
|
plugin.sendErrorLogs("&cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:");
|
||||||
if (debugMode) {
|
|
||||||
e.printStackTrace();
|
|
||||||
plugin.sendErrorLogs(receivedMessage);
|
plugin.sendErrorLogs(receivedMessage);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(String[] message, String channel) {
|
public void sendMessage(String[] message, String channel) {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("Messages", new JSONArray(message));
|
json.put("Messages", new JSONArray(message));
|
||||||
@ -222,12 +215,9 @@ public class RedisController extends BinaryJedisPubSub implements Runnable {
|
|||||||
try (BinaryJedis j = jedisPool.getResource()) {
|
try (BinaryJedis j = jedisPool.getResource()) {
|
||||||
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
|
j.publish(channel.getBytes(StandardCharsets.UTF_8), message);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error sending redis message!");
|
plugin.sendErrorLogs("Error sending redis message!");
|
||||||
if (debugMode) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
//execute sending of redis message on the main thread if plugin is disabling
|
//execute sending of redis message on the main thread if plugin is disabling
|
||||||
|
@ -25,9 +25,7 @@ public class ExprChannel extends SimpleExpression<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Event event, boolean b) {
|
public String toString(Event event, boolean b) { return "redis channel"; }
|
||||||
return "redis channel";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
|
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package net.limework.rediskript.skript.elements;
|
package net.limework.rediskript.skript.elements;
|
||||||
|
|
||||||
import ch.njol.skript.Skript;
|
|
||||||
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.log.ErrorQuality;
|
|
||||||
import ch.njol.skript.registrations.Classes;
|
import ch.njol.skript.registrations.Classes;
|
||||||
import ch.njol.skript.variables.SerializedVariable;
|
import ch.njol.skript.variables.SerializedVariable;
|
||||||
import ch.njol.util.Kleenean;
|
import ch.njol.util.Kleenean;
|
||||||
@ -49,7 +46,7 @@ public class ExprVariableInChannel extends SimpleExpression<Object> {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void change(Event e, Object[] changer, Changer.ChangeMode mode) {
|
public void change(Event e, Object[] changer, Changer.ChangeMode mode) {
|
||||||
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
|
RediSkript plugin = RediSkript.getPlugin(RediSkript.class);
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case ADD:
|
case ADD:
|
||||||
case SET:
|
case SET:
|
||||||
|
@ -8,8 +8,8 @@ Redis:
|
|||||||
#the default Redis port
|
#the default Redis port
|
||||||
Port: 6379
|
Port: 6379
|
||||||
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
|
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
|
||||||
#90000 = 90 seconds
|
#9000 = 9 seconds
|
||||||
TimeOut: 90000
|
TimeOut: 9000
|
||||||
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
|
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
|
||||||
#it encrypts your traffic and makes data exchange between distant servers completely secure
|
#it encrypts your traffic and makes data exchange between distant servers completely secure
|
||||||
useTLS: false
|
useTLS: false
|
||||||
|
Loading…
Reference in New Issue
Block a user