From 8f951757bcca3449f6b59a165410f5ec81a33ebc Mon Sep 17 00:00:00 2001 From: ham1255 Date: Tue, 30 Jun 2020 11:45:14 +0400 Subject: [PATCH] moved some stuff and fixed wrong usage --- pom.xml | 8 +++++++ .../net/limework/core/LimeworkSpigotCore.java | 11 ++++++---- .../core/Skript/elements/EffSendMessage.java | 21 +++++++++---------- .../core/Skript/elements/EvtRedis.java | 2 +- .../core/Skript/elements/ExprChannel.java | 2 +- .../core/Skript/elements/ExprMessage.java | 8 +++---- .../core/events/RedisMessageEvent.java | 3 --- .../{Managers => managers}/RedisManager.java | 2 +- src/main/resources/plugin.yml | 8 +++---- 9 files changed, 36 insertions(+), 29 deletions(-) rename src/main/java/net/limework/core/{Managers => managers}/RedisManager.java (99%) diff --git a/pom.xml b/pom.xml index 26491de..8b1b02e 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,14 @@ + + + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + ${project.basedir}/compile + diff --git a/src/main/java/net/limework/core/LimeworkSpigotCore.java b/src/main/java/net/limework/core/LimeworkSpigotCore.java index 620f2b1..dd3a9f1 100644 --- a/src/main/java/net/limework/core/LimeworkSpigotCore.java +++ b/src/main/java/net/limework/core/LimeworkSpigotCore.java @@ -5,9 +5,10 @@ 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.core.Managers.RedisManager; -import net.limework.core.Skript.elements.EvtRedis; -import net.limework.core.Skript.elements.ExprChannel; +import net.limework.core.managers.RedisManager; +import net.limework.core.skript.elements.EvtRedis; +import net.limework.core.skript.elements.ExprChannel; +import net.limework.core.skript.elements.ExprMessage; import net.limework.core.events.RedisMessageEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -49,7 +50,7 @@ public class LimeworkSpigotCore extends JavaPlugin { return e.getChannelName(); } }, 0); - Skript.registerExpression(net.limework.skLimework.elements.ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message"); + Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message"); EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter() { @Override public String get(RedisMessageEvent e) { @@ -65,6 +66,8 @@ public class LimeworkSpigotCore extends JavaPlugin { } + + public RedisManager getRm() { return rm; } diff --git a/src/main/java/net/limework/core/Skript/elements/EffSendMessage.java b/src/main/java/net/limework/core/Skript/elements/EffSendMessage.java index 504567b..fff0783 100644 --- a/src/main/java/net/limework/core/Skript/elements/EffSendMessage.java +++ b/src/main/java/net/limework/core/Skript/elements/EffSendMessage.java @@ -1,23 +1,21 @@ -package net.limework.skLimework.elements; +package net.limework.core.skript.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 net.limework.core.LimeworkSpigotCore; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.event.Event; import org.json.JSONObject; import redis.clients.jedis.BinaryJedis; -import redis.clients.jedis.exceptions.JedisConnectionException; import java.nio.charset.StandardCharsets; public class EffSendMessage extends Effect { -//"hi" + //"hi" static { Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with message %string%"); } @@ -29,23 +27,23 @@ public class EffSendMessage extends Effect { @Override protected void execute(Event event) { - AddonPlugin plugin = (AddonPlugin) Bukkit.getPluginManager().getPlugin("SKLimework"); + LimeworkSpigotCore plugin = (LimeworkSpigotCore) 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. + 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; } assert plugin != null; - plugin.getJedisExecutionService().execute(() -> { - BinaryJedis j = plugin.getJedisPool().getResource(); + plugin.getRm().getRedisService().execute(() -> { + BinaryJedis j = plugin.getRm().getJedisPool().getResource(); JSONObject json = new JSONObject(); json.put("Message", message); json.put("Type", "Skript"); json.put("Date", System.nanoTime()); //for unique string every time & PING calculations byte[] msg; - if (plugin.isEncryptionEnabled()) { - msg = plugin.encrypt(json.toString()); + if (plugin.getRm().getEncryption().isEncryptionEnabled()) { + msg = plugin.getRm().getEncryption().encrypt(json.toString()); } else { msg = message.getBytes(StandardCharsets.UTF_8); } @@ -60,6 +58,7 @@ public class EffSendMessage extends Effect { public String toString(Event event, boolean b) { return null; } + @SuppressWarnings("unchecked") @Override public boolean init(Expression[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) { diff --git a/src/main/java/net/limework/core/Skript/elements/EvtRedis.java b/src/main/java/net/limework/core/Skript/elements/EvtRedis.java index 4c0138e..12d6363 100644 --- a/src/main/java/net/limework/core/Skript/elements/EvtRedis.java +++ b/src/main/java/net/limework/core/Skript/elements/EvtRedis.java @@ -1,4 +1,4 @@ -package net.limework.core.Skript.elements; +package net.limework.core.skript.elements; ; import ch.njol.skript.lang.Literal; import ch.njol.skript.lang.SkriptEvent; diff --git a/src/main/java/net/limework/core/Skript/elements/ExprChannel.java b/src/main/java/net/limework/core/Skript/elements/ExprChannel.java index 36e54ac..481b9e2 100644 --- a/src/main/java/net/limework/core/Skript/elements/ExprChannel.java +++ b/src/main/java/net/limework/core/Skript/elements/ExprChannel.java @@ -1,4 +1,4 @@ -package net.limework.core.Skript.elements; +package net.limework.core.skript.elements; import ch.njol.skript.lang.Expression; diff --git a/src/main/java/net/limework/core/Skript/elements/ExprMessage.java b/src/main/java/net/limework/core/Skript/elements/ExprMessage.java index c523360..a0ee7b1 100644 --- a/src/main/java/net/limework/core/Skript/elements/ExprMessage.java +++ b/src/main/java/net/limework/core/Skript/elements/ExprMessage.java @@ -1,11 +1,11 @@ -package net.limework.skLimework.elements; +package net.limework.core.skript.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 net.limework.core.events.RedisMessageEvent; import org.bukkit.event.Event; public class ExprMessage extends SimpleExpression { @@ -34,8 +34,8 @@ public class ExprMessage extends SimpleExpression { @Override protected String[] get(Event e) { - if (e instanceof onRedisMessage){ - return new String[]{((onRedisMessage) e).getMessage()}; + if (e instanceof RedisMessageEvent){ + return new String[]{((RedisMessageEvent) e).getMessage()}; } return null; } diff --git a/src/main/java/net/limework/core/events/RedisMessageEvent.java b/src/main/java/net/limework/core/events/RedisMessageEvent.java index 33d2d4e..455854a 100644 --- a/src/main/java/net/limework/core/events/RedisMessageEvent.java +++ b/src/main/java/net/limework/core/events/RedisMessageEvent.java @@ -1,6 +1,5 @@ package net.limework.core.events; -import net.limework.skLimework.AddonPlugin; import org.bukkit.Bukkit; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -15,8 +14,6 @@ public class RedisMessageEvent extends Event { public RedisMessageEvent(String channelName , String message) { super(true); this.channelName = channelName; - AddonPlugin instance = (AddonPlugin) Bukkit.getPluginManager().getPlugin("SKLimework"); - assert instance != null; this.message = message; } diff --git a/src/main/java/net/limework/core/Managers/RedisManager.java b/src/main/java/net/limework/core/managers/RedisManager.java similarity index 99% rename from src/main/java/net/limework/core/Managers/RedisManager.java rename to src/main/java/net/limework/core/managers/RedisManager.java index e856777..7e7ed7a 100644 --- a/src/main/java/net/limework/core/Managers/RedisManager.java +++ b/src/main/java/net/limework/core/managers/RedisManager.java @@ -1,4 +1,4 @@ -package net.limework.core.Managers; +package net.limework.core.managers; import net.limework.Data.Encryption; import net.limework.core.LimeworkSpigotCore; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4cecdb6..a25aac6 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ -main: net.limework.skLimework.AddonPlugin -name: SKLimework -version: 1.0 +main: net.limework.core.LimeworkSpigotCore +name: LimeworkSpigotCore +version: 1.0.0 author: limework.net -depend: +softdepend: - Skript \ No newline at end of file