fixed conflict and removed hard coded channels

This commit is contained in:
ham1255 2020-06-26 17:02:39 +04:00
parent 37edb0d497
commit 39fcccefeb
2 changed files with 29 additions and 14 deletions

View File

@ -62,7 +62,7 @@ public class AddonPlugin extends JavaPlugin {
addon = Skript.registerAddon(this);
try { addon.loadClasses("net.limework.skLimework", "elements");
Skript.registerEvent("redis message", EvtRedis.class, onRedisMessage.class, "redis message");
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "channel");
Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
EventValues.registerEventValue(onRedisMessage.class, String.class, new Getter<String, onRedisMessage>() {
@Override
public String get(onRedisMessage e) {

View File

@ -36,12 +36,27 @@ public class RedisSub extends BinaryJedisPubSub implements Runnable{
if (!this.j.isConnected()) this.j = plugin.getJedisPool().getResource();
isRedisOnline.set(true);
message("&e[Jedis] &aRedis Connected");
this.j.subscribe(this,
channels.get(0).getBytes(),
channels.get(1).getBytes(),
channels.get(2).getBytes(),
channels.get(3).getBytes(),
channels.get(4).getBytes());
int byteArr2dSize = 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++) {
channelsInByte[x] = channels.get(x).getBytes();
}
} 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.j.subscribe(this, channelsInByte);
} catch (Exception e) {
message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
this.j.close();