Compare commits
25 Commits
1.0.2-SNAP
...
1.2.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed3ea7b2c7 | ||
|
|
2b00f0908e | ||
|
|
f6c4bbcdce | ||
|
|
ba48fdc564 | ||
|
|
ce47af29f4 | ||
|
|
b93624bc49 | ||
|
|
6c5d580b16 | ||
|
|
a08ecd93b7 | ||
|
|
c720433c60 | ||
|
|
12ce69d68f | ||
|
|
efab085c47 | ||
|
|
31db51fce6 | ||
|
|
776ebc9780 | ||
|
|
1ef35dfb60 | ||
|
|
2049616f64 | ||
|
|
97aa663bfd | ||
|
|
4afd5a2dbc | ||
|
|
92d89ec76d | ||
|
|
0ca8712a1a | ||
|
|
216b2635b3 | ||
|
|
df8608802d | ||
|
|
157e2b08c7 | ||
|
|
5f4600546e | ||
|
|
f4ab43bcb8 | ||
|
|
542884dfe9 |
33
pom.xml
33
pom.xml
@@ -5,8 +5,8 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>net.limework.core</groupId>
|
<groupId>net.limework.core</groupId>
|
||||||
<artifactId>LimeworkSpigotCore</artifactId>
|
<artifactId>RediSkript</artifactId>
|
||||||
<version>1.0.2-SNAPSHOT</version>
|
<version>1.1.2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -64,12 +64,9 @@
|
|||||||
<url>https://jitpack.io</url>
|
<url>https://jitpack.io</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>PaperMC</id>
|
<id>commons-pool2</id>
|
||||||
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
|
<url>https://mvnrepository.com/artifact/org.apache.commons/commons-pool2</url>
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>sk89q</id>
|
|
||||||
<url>http://maven.sk89q.com/repo</url>
|
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
@@ -83,14 +80,9 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
<version>1.16.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.code.gson</groupId>
|
|
||||||
<artifactId>gson</artifactId>
|
|
||||||
<version>2.8.6</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>redis.clients</groupId>
|
<groupId>redis.clients</groupId>
|
||||||
<artifactId>jedis</artifactId>
|
<artifactId>jedis</artifactId>
|
||||||
@@ -106,16 +98,11 @@
|
|||||||
<artifactId>siv-mode</artifactId>
|
<artifactId>siv-mode</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-pool2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>commons-pool2</artifactId>
|
||||||
<version>19.0.0</version>
|
<version>2.6.2</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mongodb</groupId>
|
|
||||||
<artifactId>mongodb-driver-sync</artifactId>
|
|
||||||
<version>4.0.4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
3
src/main/java/META-INF/MANIFEST.MF
Normal file
3
src/main/java/META-INF/MANIFEST.MF
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: net.limework.core.RediSkript
|
||||||
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package net.limework.core;
|
|
||||||
|
|
||||||
import net.limework.core.guis.ControlGui;
|
|
||||||
import net.limework.core.hooks.SkriptHook;
|
|
||||||
import net.limework.core.managers.DataSourcesManager;
|
|
||||||
import net.limework.core.managers.RedisManager;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
public class LimeworkSpigotCore extends JavaPlugin {
|
|
||||||
|
|
||||||
//Redis manager
|
|
||||||
private RedisManager rm;
|
|
||||||
|
|
||||||
//data
|
|
||||||
private DataSourcesManager dsm;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
saveDefaultConfig();
|
|
||||||
rm = new RedisManager(this);
|
|
||||||
if (getServer().getPluginManager().getPlugin("Skript") != null) {
|
|
||||||
new SkriptHook(this);
|
|
||||||
} else {
|
|
||||||
getLogger().info("Skript wasn't found.");
|
|
||||||
}
|
|
||||||
rm.start();
|
|
||||||
try {
|
|
||||||
ControlGui controlGui = new ControlGui(this);
|
|
||||||
this.getServer().getPluginManager().registerEvents(controlGui, this);
|
|
||||||
this.getCommand("control").setExecutor(controlGui);
|
|
||||||
} catch (NoSuchFieldError e) {
|
|
||||||
getLogger().info("SOMETHING WENT WRONG WHEN LOADING control gui.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
dsm = new DataSourcesManager(this);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDisable() {
|
|
||||||
rm.shutdown();
|
|
||||||
dsm.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public RedisManager getRm() {
|
|
||||||
return rm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DataSourcesManager getDsm() {
|
|
||||||
return dsm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
45
src/main/java/net/limework/core/RediSkript.java
Normal file
45
src/main/java/net/limework/core/RediSkript.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package net.limework.core;
|
||||||
|
import net.limework.core.commands.ReloadRedis;
|
||||||
|
import net.limework.core.hooks.SkriptHook;
|
||||||
|
import net.limework.core.managers.RedisManager;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public class RediSkript extends JavaPlugin {
|
||||||
|
|
||||||
|
//Redis manager
|
||||||
|
private RedisManager rm;
|
||||||
|
|
||||||
|
public void startRedis(boolean reload) {
|
||||||
|
if (reload) { reloadConfig(); }
|
||||||
|
rm = new RedisManager(this);
|
||||||
|
rm.start();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
saveDefaultConfig();
|
||||||
|
if (getServer().getPluginManager().getPlugin("Skript") != null) {
|
||||||
|
startRedis(false);
|
||||||
|
|
||||||
|
PluginCommand command = getServer().getPluginCommand("reloadredis");
|
||||||
|
assert command != null;
|
||||||
|
command.setExecutor(new ReloadRedis(this));
|
||||||
|
|
||||||
|
new SkriptHook(this);
|
||||||
|
} else {
|
||||||
|
getLogger().info("Skript wasn't found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
if (rm != null) {
|
||||||
|
rm.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public RedisManager getRm() {
|
||||||
|
return rm;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
package net.limework.core.abstraction;
|
|
||||||
|
|
||||||
import ch.njol.skript.Skript;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.bukkit.ChatColor.translateAlternateColorCodes;
|
|
||||||
|
|
||||||
public abstract class Gui {
|
|
||||||
protected Inventory gui;
|
|
||||||
private int rows;
|
|
||||||
private boolean loaded = false;
|
|
||||||
protected String name;
|
|
||||||
|
|
||||||
|
|
||||||
protected void setup(String name, int rows) {
|
|
||||||
if (loaded) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
loaded = true;
|
|
||||||
this.rows = 9 * rows;
|
|
||||||
this.name = ChatColor.translateAlternateColorCodes('&', name);
|
|
||||||
gui = Bukkit.createInventory(null, this.rows, this.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected void makeItem(Material material, int howMany, int slot, String name) {
|
|
||||||
ItemStack item = new ItemStack(material, 1);
|
|
||||||
ItemMeta item_meta = item.getItemMeta();
|
|
||||||
item_meta.setDisplayName(translateAlternateColorCodes('&', name));
|
|
||||||
item.setItemMeta(item_meta);
|
|
||||||
item.setAmount(howMany);
|
|
||||||
this.gui.clear(slot);
|
|
||||||
this.gui.setItem(slot, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void makeItem(Material material, int howMany, int slot, String name, String... Lore) {
|
|
||||||
ItemStack item = new ItemStack(material, 1);
|
|
||||||
ItemMeta item_meta = item.getItemMeta();
|
|
||||||
item_meta.setDisplayName(translateAlternateColorCodes('&', name));
|
|
||||||
List<String> lore = new ArrayList<>();
|
|
||||||
for (String s : Lore) {
|
|
||||||
lore.add(translateAlternateColorCodes('&', s));
|
|
||||||
}
|
|
||||||
item_meta.setLore(lore);
|
|
||||||
item.setItemMeta(item_meta);
|
|
||||||
item.setAmount(howMany);
|
|
||||||
this.gui.clear(slot);
|
|
||||||
this.gui.setItem(slot, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void fillGUI(Material material) {
|
|
||||||
int slot = -1;
|
|
||||||
while (slot <= (this.rows - 2)) {
|
|
||||||
slot++;
|
|
||||||
makeItem(material, 1, slot , "&1.", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
30
src/main/java/net/limework/core/commands/ReloadRedis.java
Normal file
30
src/main/java/net/limework/core/commands/ReloadRedis.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package net.limework.core.commands;
|
||||||
|
|
||||||
|
import net.limework.core.RediSkript;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class ReloadRedis implements CommandExecutor {
|
||||||
|
private RediSkript plugin;
|
||||||
|
public ReloadRedis(RediSkript plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
//not using bungee TextComponent because it is not present in 1.8.8
|
||||||
|
sender.sendMessage((ChatColor.translateAlternateColorCodes('&'
|
||||||
|
, "&2[&aRediSkript&a] &cThis command can only be executed in console.")));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plugin.getRm().reload();
|
||||||
|
//not sending to sender, because this command can only be executed via console
|
||||||
|
Bukkit.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &eReloaded via command! Note this command is not stable, it should only be used in urgent cases where you absolutely need to change config details without restarting the server."));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.limework.core.events;
|
package net.limework.core.events;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
@@ -10,11 +9,13 @@ public class RedisMessageEvent extends Event {
|
|||||||
|
|
||||||
private String channelName;
|
private String channelName;
|
||||||
private String message;
|
private String message;
|
||||||
|
private long date;
|
||||||
|
|
||||||
public RedisMessageEvent(String channelName , String message) {
|
public RedisMessageEvent(String channelName , String message, long date) {
|
||||||
super(true);
|
super(true);
|
||||||
this.channelName = channelName;
|
this.channelName = channelName;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -35,6 +36,8 @@ public class RedisMessageEvent extends Event {
|
|||||||
return channelName;
|
return channelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getDate() { return date;}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
package net.limework.core.guis;
|
|
||||||
|
|
||||||
import net.limework.core.LimeworkSpigotCore;
|
|
||||||
import net.limework.core.abstraction.Gui;
|
|
||||||
import org.bukkit.*;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class ControlGui extends Gui implements Listener, CommandExecutor {
|
|
||||||
private LimeworkSpigotCore plugin;
|
|
||||||
|
|
||||||
public ControlGui(LimeworkSpigotCore plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
setup("&cServer Control", 6);
|
|
||||||
//fillGUI(Material.LIME_STAINED_GLASS_PANE);
|
|
||||||
makeItem(Material.CRAFTING_TABLE, 1, 10, "&eCreative mode", "&cClick this for creative mode.");
|
|
||||||
makeItem(Material.DIAMOND_SWORD, 1, 12, "&eSurvival Mode", "&bClick this for Survival mode.");
|
|
||||||
makeItem(Material.DIAMOND, 1, 14, "&eSpectator Mode", "&eClick this for Spectator mode.");
|
|
||||||
makeItem(Material.PUFFERFISH, 1, 16, "&eAdventure Mode", "&aClick this for Adventure mode.");
|
|
||||||
plugin.getServer().getScheduler().runTaskTimer(plugin, () -> {
|
|
||||||
makeItem(Material.OAK_SIGN, 1, 37, "&eRam: " + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000000) + "MB/" + (Runtime.getRuntime().totalMemory() / 1000000) + "MB");
|
|
||||||
makeItem(Material.PLAYER_HEAD, 1, 40, "&eOnline Players: " + plugin.getServer().getOnlinePlayers().size() + "/" + plugin.getServer().getMaxPlayers());
|
|
||||||
}, 0, 20);
|
|
||||||
makeItem(Material.RED_WOOL, 1, 53, "&c&lShutdown the server");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
Player p = ((Player) sender);
|
|
||||||
p.openInventory(gui);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventory(InventoryClickEvent e) {
|
|
||||||
if (e.getInventory() == gui) {
|
|
||||||
e.setCancelled(true);
|
|
||||||
Player p = (Player) e.getWhoClicked();
|
|
||||||
switch (e.getSlot()) {
|
|
||||||
case 10: {
|
|
||||||
p.setGameMode(GameMode.CREATIVE);
|
|
||||||
p.closeInventory();
|
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 12: {
|
|
||||||
p.setGameMode(GameMode.SURVIVAL);
|
|
||||||
p.closeInventory();
|
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 14: {
|
|
||||||
p.setGameMode(GameMode.SPECTATOR);
|
|
||||||
p.closeInventory();
|
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 16: {
|
|
||||||
p.setGameMode(GameMode.ADVENTURE);
|
|
||||||
p.closeInventory();
|
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1.0f, 2.0f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 53: {
|
|
||||||
p.closeInventory();
|
|
||||||
plugin.getServer().shutdown();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1.0f, 0.0f);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -4,19 +4,21 @@ import ch.njol.skript.Skript;
|
|||||||
import ch.njol.skript.SkriptAddon;
|
import ch.njol.skript.SkriptAddon;
|
||||||
import ch.njol.skript.lang.ExpressionType;
|
import ch.njol.skript.lang.ExpressionType;
|
||||||
import ch.njol.skript.registrations.EventValues;
|
import ch.njol.skript.registrations.EventValues;
|
||||||
|
import ch.njol.skript.util.Date;
|
||||||
import ch.njol.skript.util.Getter;
|
import ch.njol.skript.util.Getter;
|
||||||
import net.limework.core.LimeworkSpigotCore;
|
import net.limework.core.RediSkript;
|
||||||
import net.limework.core.events.RedisMessageEvent;
|
import net.limework.core.events.RedisMessageEvent;
|
||||||
import net.limework.core.skript.elements.EvtRedis;
|
import net.limework.core.skript.elements.EvtRedis;
|
||||||
import net.limework.core.skript.elements.ExprChannel;
|
import net.limework.core.skript.elements.ExprChannel;
|
||||||
import net.limework.core.skript.elements.ExprMessage;
|
import net.limework.core.skript.elements.ExprMessage;
|
||||||
|
import net.limework.core.skript.elements.ExprMessageDate;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class SkriptHook {
|
public class SkriptHook {
|
||||||
|
|
||||||
private SkriptAddon addon;
|
private SkriptAddon addon;
|
||||||
public SkriptHook(LimeworkSpigotCore plugin) {
|
public SkriptHook(RediSkript plugin) {
|
||||||
addon = Skript.registerAddon(plugin);
|
addon = Skript.registerAddon(plugin);
|
||||||
try {
|
try {
|
||||||
addon.loadClasses("net.limework.core.skript", "elements");
|
addon.loadClasses("net.limework.core.skript", "elements");
|
||||||
@@ -35,12 +37,15 @@ public class SkriptHook {
|
|||||||
return e.getMessage();
|
return e.getMessage();
|
||||||
}
|
}
|
||||||
}, 0);
|
}, 0);
|
||||||
|
Skript.registerExpression(ExprMessageDate.class, Date.class, ExpressionType.SIMPLE, "redis message date");
|
||||||
|
EventValues.registerEventValue(RedisMessageEvent.class, Date.class, new Getter<Date, RedisMessageEvent>() {
|
||||||
|
@Override
|
||||||
|
public Date get(RedisMessageEvent e) {
|
||||||
|
return new Date(e.getDate());
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkriptAddon getAddon() {
|
|
||||||
return addon;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package net.limework.core.managers;
|
|
||||||
|
|
||||||
import com.mongodb.client.MongoClient;
|
|
||||||
import com.mongodb.client.MongoClients;
|
|
||||||
import net.limework.core.LimeworkSpigotCore;
|
|
||||||
import org.bukkit.configuration.Configuration;
|
|
||||||
|
|
||||||
public class DataSourcesManager {
|
|
||||||
|
|
||||||
private MongoClient mongoClient;
|
|
||||||
|
|
||||||
|
|
||||||
public DataSourcesManager(LimeworkSpigotCore plugin) {
|
|
||||||
Configuration config = plugin .getConfig();
|
|
||||||
if (config.getBoolean("Mongodb.enabled")){
|
|
||||||
mongoClient = MongoClients.create(config.getString("Mongodb.url"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void shutdown(){
|
|
||||||
mongoClient.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public MongoClient getMongoClient() {
|
|
||||||
return mongoClient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package net.limework.core.managers;
|
package net.limework.core.managers;
|
||||||
|
|
||||||
import net.limework.Data.Encryption;
|
import net.limework.core.RediSkript;
|
||||||
import net.limework.core.LimeworkSpigotCore;
|
|
||||||
import net.limework.core.events.RedisMessageEvent;
|
import net.limework.core.events.RedisMessageEvent;
|
||||||
|
import net.limework.data.Encryption;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
@@ -14,34 +14,36 @@ import redis.clients.jedis.JedisPool;
|
|||||||
import redis.clients.jedis.JedisPoolConfig;
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
import javax.crypto.IllegalBlockSizeException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
public class RedisManager extends BinaryJedisPubSub implements Runnable {
|
||||||
|
|
||||||
private LimeworkSpigotCore plugin;
|
private RediSkript plugin;
|
||||||
|
|
||||||
private JedisPool jedisPool;
|
private JedisPool jedisPool;
|
||||||
private ExecutorService RedisService;
|
private ExecutorService RedisService;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//sub
|
//sub
|
||||||
private BinaryJedis subscribeJedis;
|
private BinaryJedis subscribeJedis;
|
||||||
private List<String> channels;
|
private List<String> channels;
|
||||||
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
|
private AtomicBoolean isShuttingDown = new AtomicBoolean(false);
|
||||||
private AtomicBoolean isRedisOnline = new AtomicBoolean();
|
|
||||||
private Encryption encryption;
|
private Encryption encryption;
|
||||||
|
|
||||||
|
|
||||||
public RedisManager(LimeworkSpigotCore plugin) {
|
public RedisManager(RediSkript plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
Configuration config = this.plugin.getConfig();
|
Configuration config = this.plugin.getConfig();
|
||||||
JedisPoolConfig JConfig = new JedisPoolConfig();
|
JedisPoolConfig JConfig = new JedisPoolConfig();
|
||||||
JConfig.setMaxTotal(config.getInt("Redis.MaxConnections"));
|
int maxConnections = config.getInt("Redis.MaxConnections");
|
||||||
JConfig.setMaxIdle(config.getInt("Redis.MaxConnections"));
|
if (maxConnections < 2) { maxConnections = 2; }
|
||||||
|
|
||||||
|
JConfig.setMaxTotal(maxConnections);
|
||||||
|
JConfig.setMaxIdle(maxConnections);
|
||||||
JConfig.setMinIdle(1);
|
JConfig.setMinIdle(1);
|
||||||
JConfig.setBlockWhenExhausted(true);
|
JConfig.setBlockWhenExhausted(true);
|
||||||
this.jedisPool = new JedisPool(JConfig,
|
this.jedisPool = new JedisPool(JConfig,
|
||||||
@@ -49,15 +51,18 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
config.getInt("Redis.Port"),
|
config.getInt("Redis.Port"),
|
||||||
config.getInt("Redis.TimeOut"),
|
config.getInt("Redis.TimeOut"),
|
||||||
config.getString("Redis.Password"),
|
config.getString("Redis.Password"),
|
||||||
config.getBoolean("Redis.useSSL"));
|
config.getBoolean("Redis.useTLS"));
|
||||||
RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads"));
|
RedisService = Executors.newSingleThreadExecutor();
|
||||||
try{this.subscribeJedis = this.jedisPool.getResource(); }catch (Exception ignored){}
|
try {
|
||||||
|
this.subscribeJedis = this.jedisPool.getResource();
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
this.channels = config.getStringList("Channels");
|
this.channels = config.getStringList("Channels");
|
||||||
encryption = new Encryption(config);
|
encryption = new Encryption(config);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start(){
|
public void start() {
|
||||||
this.RedisService.execute(this);
|
this.RedisService.execute(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,21 +70,19 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
public void run() {
|
public void run() {
|
||||||
while (!isShuttingDown.get()) {
|
while (!isShuttingDown.get()) {
|
||||||
try {
|
try {
|
||||||
message("&e[Jedis] &cConnecting to redis...........");
|
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnecting to redis..."));
|
||||||
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
|
if (!this.subscribeJedis.isConnected()) this.subscribeJedis = this.jedisPool.getResource();
|
||||||
isRedisOnline.set(true);
|
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &aRedis connected!"));
|
||||||
message("&e[Jedis] &aRedis Connected");
|
|
||||||
int byteArr2dSize = 1;
|
int byteArr2dSize = 1;
|
||||||
byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
|
byte[][] channelsInByte = new byte[channels.size()][byteArr2dSize];
|
||||||
boolean reInitializeByteArray;
|
boolean reInitializeByteArray;
|
||||||
|
|
||||||
// Loop that reInitialize array IF array size is not enough
|
// Loop that reInitialize array IF array size is not enough
|
||||||
do {
|
do {
|
||||||
reInitializeByteArray = false;
|
reInitializeByteArray = false;
|
||||||
try {
|
try {
|
||||||
/* Data Initialization for channelsInByte array from List<String> channels */
|
/* Data Initialization for channelsInByte array from List<String> channels */
|
||||||
for (int x = 0; x < channels.size(); x++) {
|
for (int x = 0; x < channels.size(); x++) {
|
||||||
channelsInByte[x] = channels.get(x).getBytes();
|
channelsInByte[x] = channels.get(x).getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
} catch (ArrayIndexOutOfBoundsException ex) {
|
} catch (ArrayIndexOutOfBoundsException ex) {
|
||||||
reInitializeByteArray = true;
|
reInitializeByteArray = true;
|
||||||
@@ -90,10 +93,12 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
} while (reInitializeByteArray);
|
} while (reInitializeByteArray);
|
||||||
this.subscribeJedis.subscribe(this, channelsInByte);
|
this.subscribeJedis.subscribe(this, channelsInByte);
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
|
plugin.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cConnection to redis has failed! &ereconnecting..."));
|
||||||
if (this.subscribeJedis != null){this.subscribeJedis.close();}
|
if (this.subscribeJedis != null) {
|
||||||
isRedisOnline.set(false);
|
this.subscribeJedis.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
@@ -103,61 +108,58 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void message(String message) {
|
|
||||||
plugin.getLogger().info(ChatColor.translateAlternateColorCodes('&', message));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(byte[] channel, byte[] message) {
|
public void onMessage(byte[] channel, byte[] message) {
|
||||||
String channelString = new String(channel);
|
String channelString = new String(channel, StandardCharsets.UTF_8);
|
||||||
|
String receivedMessage = null;
|
||||||
try {
|
try {
|
||||||
String decrypted = null;
|
//if encryption is enabled, decrypt the message, else just convert binary to string
|
||||||
|
if (this.encryption.isEncryptionEnabled()) {
|
||||||
try {
|
try {
|
||||||
decrypted = encryption.decrypt(message);
|
receivedMessage = encryption.decrypt(message);
|
||||||
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
|
} catch (UnauthenticCiphertextException | IllegalBlockSizeException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
assert decrypted != null;
|
|
||||||
JSONObject j = new JSONObject(decrypted);
|
} else {
|
||||||
|
//encryption is disabled, so let's just get the string
|
||||||
|
receivedMessage = new String(message, StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receivedMessage != null) {
|
||||||
|
JSONObject j = new JSONObject(receivedMessage);
|
||||||
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
|
//System.out.println("Message got from channel: "+channel +" and the Message: " +json.toString());
|
||||||
plugin.getServer().getPluginManager().callEvent(new RedisMessageEvent(channelString, j.getString("Message")));
|
RedisMessageEvent event = new RedisMessageEvent(channelString, j.getString("Message"), j.getLong("Date"));
|
||||||
|
|
||||||
|
plugin.getServer().getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
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."));
|
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cI got a message that was empty from channel " + channelString + " please check your code that you used to send the message. Message content:"));
|
||||||
|
Bukkit.getLogger().warning(receivedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
this.isShuttingDown.set(true);
|
this.isShuttingDown.set(true);
|
||||||
if (this.subscribeJedis != null){
|
if (this.subscribeJedis != null) {
|
||||||
this.unsubscribe();
|
this.unsubscribe();
|
||||||
this.subscribeJedis.close();
|
this.subscribeJedis.close();
|
||||||
|
this.jedisPool.getResource().close();
|
||||||
}
|
}
|
||||||
this.RedisService.shutdown();
|
this.RedisService.shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
public void reload() {
|
||||||
public boolean IsRedisOnline() {
|
this.shutdown();
|
||||||
return isRedisOnline.get();
|
plugin.startRedis(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JedisPool getJedisPool() {
|
public JedisPool getJedisPool() {
|
||||||
return jedisPool;
|
return jedisPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutorService getRedisService() {
|
|
||||||
return RedisService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AtomicBoolean getIsShuttingDown() {
|
|
||||||
return isShuttingDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AtomicBoolean getIsRedisOnline() {
|
|
||||||
return isRedisOnline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Encryption getEncryption() {
|
public Encryption getEncryption() {
|
||||||
return encryption;
|
return encryption;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import ch.njol.skript.lang.Effect;
|
|||||||
import ch.njol.skript.lang.Expression;
|
import ch.njol.skript.lang.Expression;
|
||||||
import ch.njol.skript.lang.SkriptParser;
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
import ch.njol.util.Kleenean;
|
import ch.njol.util.Kleenean;
|
||||||
import net.limework.core.LimeworkSpigotCore;
|
import net.limework.core.RediSkript;
|
||||||
|
import net.limework.core.managers.RedisManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@@ -15,9 +16,8 @@ import redis.clients.jedis.BinaryJedis;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class EffSendMessage extends Effect {
|
public class EffSendMessage extends Effect {
|
||||||
//"hi"
|
|
||||||
static {
|
static {
|
||||||
Skript.registerEffect(EffSendMessage.class, "send redis message to channel %string% with message %string%");
|
Skript.registerEffect(EffSendMessage.class, "send redis message %string% to [channel] %string%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -27,43 +27,50 @@ public class EffSendMessage extends Effect {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(Event event) {
|
protected void execute(Event event) {
|
||||||
LimeworkSpigotCore plugin = (LimeworkSpigotCore) Bukkit.getPluginManager().getPlugin("LimeworkSpigotCore");
|
|
||||||
|
RediSkript plugin = (RediSkript) Bukkit.getPluginManager().getPlugin("RediSkript");
|
||||||
|
|
||||||
String message = this.message.getSingle(event);
|
String message = this.message.getSingle(event);
|
||||||
String channel = this.channel.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."));
|
if (message == null) {
|
||||||
|
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cRedis message was empty. Please check your code."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (channel == null) {
|
||||||
|
Bukkit.getLogger().warning(ChatColor.translateAlternateColorCodes('&', "&2[&aRediSkript&a] &cChannel was empty. Please check your code."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
assert plugin != null;
|
assert plugin != null;
|
||||||
plugin.getRm().getRedisService().execute(() -> {
|
RedisManager manager = plugin.getRm();
|
||||||
BinaryJedis j = plugin.getRm().getJedisPool().getResource();
|
//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.nanoTime()); //for unique string every time & PING calculations
|
json.put("Date", System.currentTimeMillis()); //for unique string every time & PING calculations
|
||||||
byte[] msg;
|
byte[] msg;
|
||||||
if (plugin.getRm().getEncryption().isEncryptionEnabled()) {
|
if (manager.getEncryption().isEncryptionEnabled()) {
|
||||||
msg = plugin.getRm().getEncryption().encrypt(json.toString());
|
msg = manager.getEncryption().encrypt(json.toString());
|
||||||
} else {
|
} else {
|
||||||
msg = message.getBytes(StandardCharsets.UTF_8);
|
msg = json.toString().getBytes(StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
j.publish(channel.getBytes(), msg);
|
j.publish(channel.getBytes(StandardCharsets.UTF_8), msg);
|
||||||
//System.out.println("SkriptSide sent MESSAGE: ["+ message + "] to channel: " + channel + " and json: \n" + json.toString());
|
|
||||||
j.close();
|
j.close();
|
||||||
});
|
//});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Event event, boolean b) {
|
public String toString(Event event, boolean b) {
|
||||||
return null;
|
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(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parser) {
|
||||||
this.channel = (Expression<String>) expressions[0];
|
this.message = (Expression<String>) expressions[0];
|
||||||
this.message = (Expression<String>) expressions[1];
|
this.channel = (Expression<String>) expressions[1];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
package net.limework.core.skript.elements;
|
package net.limework.core.skript.elements;
|
||||||
;
|
|
||||||
import ch.njol.skript.lang.Literal;
|
import ch.njol.skript.lang.Literal;
|
||||||
import ch.njol.skript.lang.SkriptEvent;
|
import ch.njol.skript.lang.SkriptEvent;
|
||||||
import ch.njol.skript.lang.SkriptParser;
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
|
import net.limework.core.events.RedisMessageEvent;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
public class EvtRedis extends SkriptEvent {
|
public class EvtRedis extends SkriptEvent {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(Literal<?>[] literals, int i, SkriptParser.ParseResult parseResult) {
|
public boolean init(Literal<?>[] literals, int i, SkriptParser.ParseResult parseResult) {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean check(Event event) {
|
public boolean check(Event event) {
|
||||||
|
if (!(event instanceof RedisMessageEvent)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Event event, boolean b) {
|
public String toString(Event event, boolean debug) {
|
||||||
return "redis message";
|
return "redis message";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package net.limework.core.skript.elements;
|
package net.limework.core.skript.elements;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.njol.skript.ScriptLoader;
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
import ch.njol.skript.lang.Expression;
|
import ch.njol.skript.lang.Expression;
|
||||||
import ch.njol.skript.lang.SkriptParser;
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
import ch.njol.skript.lang.util.SimpleExpression;
|
import ch.njol.skript.lang.util.SimpleExpression;
|
||||||
|
import ch.njol.skript.log.ErrorQuality;
|
||||||
import ch.njol.util.Kleenean;
|
import ch.njol.util.Kleenean;
|
||||||
import net.limework.core.events.RedisMessageEvent;
|
import net.limework.core.events.RedisMessageEvent;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@@ -27,7 +30,11 @@ public class ExprChannel extends SimpleExpression<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
|
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
|
||||||
|
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
|
||||||
|
Skript.error("Cannot use 'redis channel' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package net.limework.core.skript.elements;
|
package net.limework.core.skript.elements;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.njol.skript.ScriptLoader;
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
import ch.njol.skript.lang.Expression;
|
import ch.njol.skript.lang.Expression;
|
||||||
import ch.njol.skript.lang.SkriptParser;
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
import ch.njol.skript.lang.util.SimpleExpression;
|
import ch.njol.skript.lang.util.SimpleExpression;
|
||||||
|
import ch.njol.skript.log.ErrorQuality;
|
||||||
import ch.njol.util.Kleenean;
|
import ch.njol.util.Kleenean;
|
||||||
import net.limework.core.events.RedisMessageEvent;
|
import net.limework.core.events.RedisMessageEvent;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
@@ -22,12 +25,16 @@ public class ExprMessage extends SimpleExpression<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(Event event, boolean b) {
|
public String toString(Event event, boolean debug) {
|
||||||
return "redis message";
|
return "redis message";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
|
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
|
||||||
|
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
|
||||||
|
Skript.error("Cannot use 'redis message' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package net.limework.core.skript.elements;
|
||||||
|
|
||||||
|
|
||||||
|
import ch.njol.skript.ScriptLoader;
|
||||||
|
import ch.njol.skript.Skript;
|
||||||
|
import ch.njol.skript.lang.Expression;
|
||||||
|
import ch.njol.skript.lang.SkriptParser;
|
||||||
|
import ch.njol.skript.lang.util.SimpleExpression;
|
||||||
|
import ch.njol.skript.log.ErrorQuality;
|
||||||
|
import ch.njol.skript.util.Date;
|
||||||
|
import ch.njol.util.Kleenean;
|
||||||
|
import net.limework.core.events.RedisMessageEvent;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
|
||||||
|
public class ExprMessageDate extends SimpleExpression<Date> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSingle() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<? extends Date> getReturnType() {
|
||||||
|
return Date.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(Event event, boolean b) {
|
||||||
|
return "redis message date";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean init(final Expression<?>[] expressions, final int matchedPattern, final Kleenean isDelayed, final SkriptParser.ParseResult parseResult) {
|
||||||
|
if (!ScriptLoader.isCurrentEvent(RedisMessageEvent.class)) {
|
||||||
|
Skript.error("Cannot use 'redis message date' outside of a redis message event", ErrorQuality.SEMANTIC_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Date[] get(Event e) {
|
||||||
|
if (e instanceof RedisMessageEvent){
|
||||||
|
long date = ((RedisMessageEvent) e).getDate();
|
||||||
|
return new Date[]{new Date(date)};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.limework.Data;
|
package net.limework.data;
|
||||||
|
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.cryptomator.siv.SivMode;
|
import org.cryptomator.siv.SivMode;
|
||||||
@@ -26,11 +26,11 @@ public class Encryption {
|
|||||||
public boolean isEncryptionEnabled() { return encryptionEnabled; }
|
public boolean isEncryptionEnabled() { return encryptionEnabled; }
|
||||||
|
|
||||||
public String decrypt(byte[] message) throws UnauthenticCiphertextException, IllegalBlockSizeException {
|
public String decrypt(byte[] message) throws UnauthenticCiphertextException, IllegalBlockSizeException {
|
||||||
return new String(AES_SIV.decrypt(encryptionKey.getBytes(), macKey.getBytes(), message), StandardCharsets.UTF_8);
|
return new String(AES_SIV.decrypt(encryptionKey.getBytes(StandardCharsets.UTF_8), macKey.getBytes(StandardCharsets.UTF_8), message), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] encrypt(String message) {
|
public byte[] encrypt(String message) {
|
||||||
return AES_SIV.encrypt(encryptionKey.getBytes(), macKey.getBytes(), message.getBytes());
|
return AES_SIV.encrypt(encryptionKey.getBytes(StandardCharsets.UTF_8), macKey.getBytes(StandardCharsets.UTF_8), message.getBytes(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,21 +1,29 @@
|
|||||||
Redis:
|
Redis:
|
||||||
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL6XMU"
|
#a secure password that cannot be cracked, please change it!
|
||||||
|
#it is also recommended to firewall your redis server with iptables so it can only be accessed by specific IP addresses
|
||||||
|
Password: "yHy0d2zdBlRmaSPj3CiBwEv5V3XxBTLTrCsGW7ntBnzhfxPxXJS6Q1aTtR6DSfAtCZr2VxWnsungXHTcF94a4bsWEpGAvjL9XMU"
|
||||||
Host: "127.0.0.1"
|
Host: "127.0.0.1"
|
||||||
MaxConnections: 20
|
#must be 2 or higher, if you set to lower, the addon will automatically use 2 as a minimum
|
||||||
Threads: 10
|
MaxConnections: 2
|
||||||
|
#the default Redis port
|
||||||
Port: 6379
|
Port: 6379
|
||||||
TimeOut: 40000
|
#time out in milliseconds, how long it should take before it decides that it is unable to connect when sending a message
|
||||||
useSSL: false
|
#90000 = 90 seconds
|
||||||
#useful if SSL is disabled
|
TimeOut: 90000
|
||||||
EncryptMessages: false
|
#also known as SSL, only use this if you're running Redis 6.0.6 or higher, older versions will not work correctly
|
||||||
|
#it encrypts your traffic and makes data exchange between distant servers completely secure
|
||||||
|
useTLS: false
|
||||||
|
#may be useful if you cannot use TLS due to use of older version of Redis
|
||||||
|
#however this will not encrypt the initial authentication password, only the messages sent
|
||||||
|
#it uses AES-128 SIV encryption which is secure enough for this
|
||||||
|
EncryptMessages: true
|
||||||
EncryptionKey: "16CHARACTERS KEY"
|
EncryptionKey: "16CHARACTERS KEY"
|
||||||
MacKey: "16CHARACTERS KEY"
|
MacKey: "16CHARACTERS KEY"
|
||||||
|
|
||||||
|
#the channels from which this server can receive messages
|
||||||
|
#you can always send messages to all channels!
|
||||||
|
#you can add as many channels as you wish!
|
||||||
Channels:
|
Channels:
|
||||||
- "Channel1"
|
- "Channel1"
|
||||||
- "Channel2"
|
- "Channel2"
|
||||||
- "Channel3"
|
- "Channel3"
|
||||||
|
|
||||||
Mongodb:
|
|
||||||
enabled: false
|
|
||||||
url: ""
|
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
main: net.limework.core.LimeworkSpigotCore
|
main: net.limework.core.RediSkript
|
||||||
name: LimeworkSpigotCore
|
name: RediSkript
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
author: limework.net
|
authors: [Govindas, ham1255, DaemonicKing]
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
softdepend:
|
depend:
|
||||||
- Skript
|
- Skript
|
||||||
commands:
|
commands:
|
||||||
control:
|
reloadredis:
|
||||||
description: "server control"
|
description: "Reload redis configuration & restart the connection."
|
||||||
permission: "admin.use"
|
|
||||||
Reference in New Issue
Block a user