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); addon = Skript.registerAddon(this);
try { addon.loadClasses("net.limework.skLimework", "elements"); try { addon.loadClasses("net.limework.skLimework", "elements");
Skript.registerEvent("redis message", EvtRedis.class, onRedisMessage.class, "redis message"); 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>() { EventValues.registerEventValue(onRedisMessage.class, String.class, new Getter<String, onRedisMessage>() {
@Override @Override
public String get(onRedisMessage e) { 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(); if (!this.j.isConnected()) this.j = plugin.getJedisPool().getResource();
isRedisOnline.set(true); isRedisOnline.set(true);
message("&e[Jedis] &aRedis Connected"); message("&e[Jedis] &aRedis Connected");
this.j.subscribe(this, int byteArr2dSize = 1;
channels.get(0).getBytes(), byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
channels.get(1).getBytes(), boolean reInitializeByteArray;
channels.get(2).getBytes(),
channels.get(3).getBytes(), // Loop that reInitialize array IF array size is not enough
channels.get(4).getBytes()); 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) { } catch (Exception e) {
message("&e[Jedis] &cConnection to redis has failed! &ereconnecting..."); message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
this.j.close(); this.j.close();