diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..ae1a6b1 --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/SkLimework_jar.xml b/.idea/artifacts/SkLimework_jar.xml new file mode 100644 index 0000000..70e6a47 --- /dev/null +++ b/.idea/artifacts/SkLimework_jar.xml @@ -0,0 +1,16 @@ + + + C:/Complie + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..fcbb6d1 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4b661a5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..b03bf91 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1585752189522 + + + + \ No newline at end of file diff --git a/SkLimework.iml b/SkLimework.iml new file mode 100644 index 0000000..78b2cc5 --- /dev/null +++ b/SkLimework.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ceeef94 --- /dev/null +++ b/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + net.limework.addon + SkLimework + 1.0-SNAPSHOT + jar> + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + 1.8 + 1.8 + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + org.spigotmc + spigot-api + 1.15.2-R0.1-SNAPSHOT + provided + + + org.bukkit + bukkit + 1.15.2-R0.1-SNAPSHOT + provided + + + com.google.code.gson + gson + 2.8.6 + + + redis.clients + jedis + 3.3.0 + + + org.json + json + 20190722 + + + \ No newline at end of file diff --git a/src/main/java/net/limework/skLimework/AddonPlugin.java b/src/main/java/net/limework/skLimework/AddonPlugin.java new file mode 100644 index 0000000..8ca0b06 --- /dev/null +++ b/src/main/java/net/limework/skLimework/AddonPlugin.java @@ -0,0 +1,96 @@ +package net.limework.skLimework; + +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.Getter; +import net.limework.skLimework.Events.RedisSub; +import net.limework.skLimework.Events.onRedisMessage; +import net.limework.skLimework.elements.EvtRedis; +import net.limework.skLimework.elements.ExprChannel; +import net.limework.skLimework.elements.ExprMessage; +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +import java.beans.Expression; +import java.io.IOException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +public class AddonPlugin extends JavaPlugin { + private AddonPlugin instance; + private SkriptAddon addon; + private JedisPool jedisPool; + private RedisSub redisSub; + private ExecutorService service; + + + @Override + public void onEnable(){ + instance = this; + this.saveDefaultConfig(); + 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"); + EventValues.registerEventValue(onRedisMessage.class, String.class, new Getter() { + @Override + public String get(onRedisMessage e) { + return e.getChannelName(); + } + }, 0); + Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message"); + EventValues.registerEventValue(onRedisMessage.class, String.class, new Getter() { + @Override + public String get(onRedisMessage e) { + return e.getMessage(); + } + }, 0); + + + + + } catch (IOException e) { e.printStackTrace(); } + JedisPoolConfig jconfig = new JedisPoolConfig(); + jconfig.setMaxTotal(this.getConfig().getInt("Redis.MaxConnections")); + jconfig.setMaxIdle(this.getConfig().getInt("Redis.MaxConnections")); + jconfig.setMinIdle(1); + jedisPool = new JedisPool(jconfig, + this.getConfig().getString("Redis.Host"), + this.getConfig().getInt("Redis.Port") , + this.getConfig().getInt("Redis.TimeOut"), + this.getConfig().getString("Redis.Password"), + this.getConfig().getBoolean("Redis.useSSL")); + redisSub = new RedisSub(this, jedisPool.getResource(), this.getConfig().getStringList("Channels")); + service = Executors.newFixedThreadPool(this.getConfig().getInt("Redis.Threads")); + + Bukkit.getLogger().info("[Govindas limework Addon] was enabled!"); + } + + + @Override + public void onDisable(){ + redisSub.unSubAndCloseConnection(); + service.shutdown(); + try { service.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); } catch (InterruptedException e) { e.printStackTrace(); } + jedisPool.close(); + } + + public AddonPlugin getInstance() { + return instance; + } + + public SkriptAddon getAddonInstance() { + return addon; + } + + public ExecutorService getJedisExecutionService() { + return service; + } + + public JedisPool getJedisPool() { return jedisPool; } +} diff --git a/src/main/java/net/limework/skLimework/DoNotUse/Tester.java b/src/main/java/net/limework/skLimework/DoNotUse/Tester.java new file mode 100644 index 0000000..4b11c22 --- /dev/null +++ b/src/main/java/net/limework/skLimework/DoNotUse/Tester.java @@ -0,0 +1,29 @@ +package net.limework.skLimework.DoNotUse; + +import org.json.JSONObject; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; +import redis.clients.jedis.JedisPubSub; + +public class Tester { + public static void main(String[] args) throws InterruptedException { + JedisPoolConfig jconfig = new JedisPoolConfig(); + jconfig.setMaxTotal(100); + jconfig.setMaxIdle(100); + jconfig.setMinIdle(1); + JedisPool d = new JedisPool(jconfig, "192.168.0.112", 6379, 400, "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL6XMU"); + Jedis dd = d.getResource(); + JSONObject J = new JSONObject(); + J.put("Message", "something::something::something"); + int x = 0; + while (true) { + x++; + System.out.println(x); + dd.publish("fs", J.toString() ); + if (x == 1000) break; + Thread.sleep(1000); + + } + } +} diff --git a/src/main/java/net/limework/skLimework/Events/RedisSub.java b/src/main/java/net/limework/skLimework/Events/RedisSub.java new file mode 100644 index 0000000..85fa73e --- /dev/null +++ b/src/main/java/net/limework/skLimework/Events/RedisSub.java @@ -0,0 +1,40 @@ +package net.limework.skLimework.Events; + +import net.limework.skLimework.AddonPlugin; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.json.JSONObject; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPubSub; + +import java.util.List; + +public class RedisSub extends JedisPubSub { + private AddonPlugin plugin; + private Jedis j; + public RedisSub(AddonPlugin plugin, Jedis j, List channels) { + this.plugin = plugin; + this.j = j; + String[] ss = channels.toArray(new String[0]); + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, + () -> this.j.subscribe(this, ss)); + } + + @Override + public void onMessage(String channel, String message) { + try { + JSONObject json = new JSONObject(message); + //System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString()); + plugin.getServer().getPluginManager().callEvent(new onRedisMessage(channel, json.getString("Message"))); + } catch (Exception e) { + e.printStackTrace(); + Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cI Got a Message that Was empty from channel "+ channel +" Please check your code that you used to send the message. ^ ignore the error.")); + } + + } + + public void unSubAndCloseConnection(){ + this.unsubscribe(); + j.close(); + } +} diff --git a/src/main/java/net/limework/skLimework/Events/onRedisMessage.java b/src/main/java/net/limework/skLimework/Events/onRedisMessage.java new file mode 100644 index 0000000..388caae --- /dev/null +++ b/src/main/java/net/limework/skLimework/Events/onRedisMessage.java @@ -0,0 +1,40 @@ +package net.limework.skLimework.Events; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + + +public class onRedisMessage extends Event { + private final static HandlerList HANDLERS = new HandlerList(); + + private String channelName; + private String message; + + onRedisMessage(String channelName , String message) { + super(true); + this.channelName = channelName; + this.message = message; + } + + + @Override + public String getEventName() { + return super.getEventName(); + } + + @Override + public HandlerList getHandlers() { + return HANDLERS; + } + public static HandlerList getHandlerList() { + return HANDLERS; + } + + public String getChannelName() { + return channelName; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/net/limework/skLimework/elements/EffSendMessage.java b/src/main/java/net/limework/skLimework/elements/EffSendMessage.java new file mode 100644 index 0000000..1fdbcfe --- /dev/null +++ b/src/main/java/net/limework/skLimework/elements/EffSendMessage.java @@ -0,0 +1,61 @@ +package net.limework.skLimework.elements; + +import ch.njol.skript.Skript; +import ch.njol.skript.SkriptAPIException; +import ch.njol.skript.lang.Effect; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import net.limework.skLimework.AddonPlugin; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.event.Event; +import org.json.JSONObject; +import redis.clients.jedis.Jedis; + +public class EffSendMessage extends Effect { +//"hi" + static { + Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with message %string%"); + } + + + private Expression channel; + private Expression message; + + + @Override + protected void execute(Event event) { + AddonPlugin plugin = (AddonPlugin) Bukkit.getPluginManager().getPlugin("SKLimework"); + String message = this.message.getSingle(event); + String channel = this.channel.getSingle(event); + if (message == null){//checks if message equals null if true does not execute. + Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aGBot&a] &cMessage Was empty Please check your code.")); + return; + } + plugin.getJedisExecutionService().execute(() -> { + Jedis j = plugin.getJedisPool().getResource(); + JSONObject json = new JSONObject(); + try { + json.put("Message", message); + json.put("Type", "Skript"); + j.publish(channel, json.toString()); + //System.out.println("SkriptSide sent MESSAGE: ["+ message + "] to channel: " + channel + " and json: \n" + json.toString()); + }catch (Exception e){e.printStackTrace();} + j.close(); + }); + + } + + @Override + public String toString(Event event, boolean b) { + return null; + } + @SuppressWarnings("unchecked") + @Override + public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { + this.channel = (Expression) expressions[0]; + this.message = (Expression) expressions[1]; + return true; + } +} diff --git a/src/main/java/net/limework/skLimework/elements/EvtRedis.java b/src/main/java/net/limework/skLimework/elements/EvtRedis.java new file mode 100644 index 0000000..a08e6a1 --- /dev/null +++ b/src/main/java/net/limework/skLimework/elements/EvtRedis.java @@ -0,0 +1,32 @@ +package net.limework.skLimework.elements; + +import ch.njol.skript.Skript; +import ch.njol.skript.lang.ExpressionType; +import ch.njol.skript.lang.Literal; +import ch.njol.skript.lang.SkriptEvent; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.registrations.EventValues; +import ch.njol.skript.util.Getter; +import net.limework.skLimework.Events.onRedisMessage; +import org.bukkit.event.Event; + +public class EvtRedis extends SkriptEvent { + + + + @Override + public boolean init(Literal[] literals, int i, SkriptParser.ParseResult parseResult) { + + return true; + } + + @Override + public boolean check(Event event) { + return true; + } + + @Override + public String toString(Event event, boolean b) { + return "redis message"; + } +} diff --git a/src/main/java/net/limework/skLimework/elements/ExprChannel.java b/src/main/java/net/limework/skLimework/elements/ExprChannel.java new file mode 100644 index 0000000..6133d1a --- /dev/null +++ b/src/main/java/net/limework/skLimework/elements/ExprChannel.java @@ -0,0 +1,42 @@ +package net.limework.skLimework.elements; + + +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import net.limework.skLimework.Events.onRedisMessage; +import org.bukkit.event.Event; + +public class ExprChannel extends SimpleExpression { + + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public String toString(Event event, boolean b) { + return "redis channel"; + } + + @Override + public boolean init(Expression[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + return true; + } + + + @Override + protected String[] get(Event e) { + if (e instanceof onRedisMessage){ + return new String[]{((onRedisMessage) e).getChannelName()}; + } + return null; + } +} diff --git a/src/main/java/net/limework/skLimework/elements/ExprMessage.java b/src/main/java/net/limework/skLimework/elements/ExprMessage.java new file mode 100644 index 0000000..c523360 --- /dev/null +++ b/src/main/java/net/limework/skLimework/elements/ExprMessage.java @@ -0,0 +1,42 @@ +package net.limework.skLimework.elements; + + +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.skript.lang.util.SimpleExpression; +import ch.njol.util.Kleenean; +import net.limework.skLimework.Events.onRedisMessage; +import org.bukkit.event.Event; + +public class ExprMessage extends SimpleExpression { + + + @Override + public boolean isSingle() { + return true; + } + + @Override + public Class getReturnType() { + return String.class; + } + + @Override + public String toString(Event event, boolean b) { + return "redis message"; + } + + @Override + public boolean init(Expression[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + return true; + } + + + @Override + protected String[] get(Event e) { + if (e instanceof onRedisMessage){ + return new String[]{((onRedisMessage) e).getMessage()}; + } + return null; + } +} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..762accf --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,13 @@ +Redis: + Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL6XMU" + Host: "127.0.0.1" + MaxConnections: 20 + Threads: 10 + Port: 6379 + TimeOut: 40 + useSSL: true + +Channels: + - "Channel1" + - "Channel2" + - "Channel3" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..4cecdb6 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,6 @@ +main: net.limework.skLimework.AddonPlugin +name: SKLimework +version: 1.0 +author: limework.net +depend: + - Skript \ No newline at end of file diff --git a/target/classes/META-INF/SkLimework.kotlin_module b/target/classes/META-INF/SkLimework.kotlin_module new file mode 100644 index 0000000..2983af7 Binary files /dev/null and b/target/classes/META-INF/SkLimework.kotlin_module differ diff --git a/target/classes/config.yml b/target/classes/config.yml new file mode 100644 index 0000000..762accf --- /dev/null +++ b/target/classes/config.yml @@ -0,0 +1,13 @@ +Redis: + Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL6XMU" + Host: "127.0.0.1" + MaxConnections: 20 + Threads: 10 + Port: 6379 + TimeOut: 40 + useSSL: true + +Channels: + - "Channel1" + - "Channel2" + - "Channel3" \ No newline at end of file diff --git a/target/classes/net/limework/skLimework/AddonPlugin$1.class b/target/classes/net/limework/skLimework/AddonPlugin$1.class new file mode 100644 index 0000000..22579b8 Binary files /dev/null and b/target/classes/net/limework/skLimework/AddonPlugin$1.class differ diff --git a/target/classes/net/limework/skLimework/AddonPlugin$2.class b/target/classes/net/limework/skLimework/AddonPlugin$2.class new file mode 100644 index 0000000..30e339c Binary files /dev/null and b/target/classes/net/limework/skLimework/AddonPlugin$2.class differ diff --git a/target/classes/net/limework/skLimework/AddonPlugin.class b/target/classes/net/limework/skLimework/AddonPlugin.class new file mode 100644 index 0000000..61d5ddc Binary files /dev/null and b/target/classes/net/limework/skLimework/AddonPlugin.class differ diff --git a/target/classes/net/limework/skLimework/DoNotUse/Tester.class b/target/classes/net/limework/skLimework/DoNotUse/Tester.class new file mode 100644 index 0000000..f9bf290 Binary files /dev/null and b/target/classes/net/limework/skLimework/DoNotUse/Tester.class differ diff --git a/target/classes/net/limework/skLimework/Events/RedisSub.class b/target/classes/net/limework/skLimework/Events/RedisSub.class new file mode 100644 index 0000000..62e3a25 Binary files /dev/null and b/target/classes/net/limework/skLimework/Events/RedisSub.class differ diff --git a/target/classes/net/limework/skLimework/Events/onRedisMessage.class b/target/classes/net/limework/skLimework/Events/onRedisMessage.class new file mode 100644 index 0000000..b6799d4 Binary files /dev/null and b/target/classes/net/limework/skLimework/Events/onRedisMessage.class differ diff --git a/target/classes/net/limework/skLimework/elements/EffSendMessage.class b/target/classes/net/limework/skLimework/elements/EffSendMessage.class new file mode 100644 index 0000000..3b52735 Binary files /dev/null and b/target/classes/net/limework/skLimework/elements/EffSendMessage.class differ diff --git a/target/classes/net/limework/skLimework/elements/EvtRedis.class b/target/classes/net/limework/skLimework/elements/EvtRedis.class new file mode 100644 index 0000000..200be97 Binary files /dev/null and b/target/classes/net/limework/skLimework/elements/EvtRedis.class differ diff --git a/target/classes/net/limework/skLimework/elements/ExprChannel.class b/target/classes/net/limework/skLimework/elements/ExprChannel.class new file mode 100644 index 0000000..0192422 Binary files /dev/null and b/target/classes/net/limework/skLimework/elements/ExprChannel.class differ diff --git a/target/classes/net/limework/skLimework/elements/ExprMessage.class b/target/classes/net/limework/skLimework/elements/ExprMessage.class new file mode 100644 index 0000000..7e75860 Binary files /dev/null and b/target/classes/net/limework/skLimework/elements/ExprMessage.class differ diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml new file mode 100644 index 0000000..4cecdb6 --- /dev/null +++ b/target/classes/plugin.yml @@ -0,0 +1,6 @@ +main: net.limework.skLimework.AddonPlugin +name: SKLimework +version: 1.0 +author: limework.net +depend: + - Skript \ No newline at end of file