forked from Limework/RediSkript
Little questionable improvements (shouldn't hurt anything anyway)
This commit is contained in:
parent
0d5ba1c874
commit
3bddfe8d36
@ -145,6 +145,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
|||||||
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();
|
this.jedisPool.getResource().close();
|
||||||
}
|
}
|
||||||
this.RedisService.shutdown();
|
this.RedisService.shutdown();
|
||||||
|
@ -12,6 +12,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import redis.clients.jedis.BinaryJedis;
|
import redis.clients.jedis.BinaryJedis;
|
||||||
|
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
@ -42,33 +43,37 @@ public class EffSendMessage extends Effect {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert plugin != null;
|
assert plugin != null;
|
||||||
RedisManager manager = plugin.getRm();
|
|
||||||
//manager.getRedisService().execute(() -> {
|
|
||||||
BinaryJedis j = manager.getJedisPool().getResource();
|
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("Message", message);
|
json.put("Message", message);
|
||||||
json.put("Type", "Skript");
|
json.put("Type", "Skript");
|
||||||
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
||||||
byte[] msg;
|
byte[] msg;
|
||||||
|
RedisManager manager = plugin.getRm();
|
||||||
|
|
||||||
if (manager.getEncryption().isEncryptionEnabled()) {
|
if (manager.getEncryption().isEncryptionEnabled()) {
|
||||||
msg = manager.getEncryption().encrypt(json.toString());
|
msg = manager.getEncryption().encrypt(json.toString());
|
||||||
} else {
|
} else {
|
||||||
msg = json.toString().getBytes(StandardCharsets.UTF_8);
|
msg = json.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
BinaryJedis j = manager.getJedisPool().getResource();
|
||||||
|
|
||||||
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
|
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
|
||||||
j.close();
|
j.close();
|
||||||
//});
|
} catch (JedisConnectionException exception) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Event event, boolean b) {
|
public String toString(Event event, boolean debug) {
|
||||||
return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event);
|
return "send redis message " + message.getSingle(event) + " to channel " + channel.getSingle(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
|
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parser) {
|
||||||
this.message = (Expression<String>) expressions[0];
|
this.message = (Expression<String>) expressions[0];
|
||||||
this.channel = (Expression<String>) expressions[1];
|
this.channel = (Expression<String>) expressions[1];
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user