diff --git a/pom.xml b/pom.xml
index 8b1b02e..be30191 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,6 +10,12 @@
jar
+
+
+ src/main/resources
+ true
+
+
org.apache.maven.plugins
@@ -77,7 +83,7 @@
org.spigotmc
spigot-api
- 1.15.2-R0.1-SNAPSHOT
+ 1.16.1-R0.1-SNAPSHOT
provided
@@ -100,5 +106,11 @@
siv-mode
1.4.0
+
+ org.jetbrains
+ annotations
+ 19.0.0
+ compile
+
\ No newline at end of file
diff --git a/src/main/java/net/limework/core/LimeworkSpigotCore.java b/src/main/java/net/limework/core/LimeworkSpigotCore.java
index b9f178b..7aec165 100644
--- a/src/main/java/net/limework/core/LimeworkSpigotCore.java
+++ b/src/main/java/net/limework/core/LimeworkSpigotCore.java
@@ -1,35 +1,36 @@
package net.limework.core;
-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.core.guis.TestGui;
+import net.limework.core.guis.ControlGui;
+import net.limework.core.hooks.SkriptHook;
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;
-import java.io.IOException;
-
public class LimeworkSpigotCore extends JavaPlugin {
//Redis manager
private RedisManager rm;
- //Skript
- private SkriptAddon addon;
-
@Override
public void onEnable() {
saveDefaultConfig();
rm = new RedisManager(this);
- try {loadSkript();} catch (Exception e){ this.getLogger().info("Skript wasn't found."); }
+ 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();
+ }
+
+
}
@Override
@@ -37,41 +38,8 @@ public class LimeworkSpigotCore extends JavaPlugin {
rm.shutdown();
}
- private void loadSkript() {
- addon = Skript.registerAddon(this);
- try {
- addon.loadClasses("net.limework.core.Skript", "elements");
- Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
- Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
- EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter() {
- @Override
- public String get(RedisMessageEvent e) {
- return e.getChannelName();
- }
- }, 0);
- Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message");
- EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter() {
- @Override
- public String get(RedisMessageEvent e) {
- return e.getMessage();
- }
- }, 0);
-
-
- } catch (IOException e) {
- e.printStackTrace();
- }
-
-
- }
-
-
public RedisManager getRm() {
return rm;
}
-
- public SkriptAddon getAddon() {
- return addon;
- }
-}
+}
\ No newline at end of file
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 fff0783..bd8a439 100644
--- a/src/main/java/net/limework/core/Skript/elements/EffSendMessage.java
+++ b/src/main/java/net/limework/core/Skript/elements/EffSendMessage.java
@@ -27,7 +27,7 @@ public class EffSendMessage extends Effect {
@Override
protected void execute(Event event) {
- LimeworkSpigotCore plugin = (LimeworkSpigotCore) Bukkit.getPluginManager().getPlugin("SKLimework");
+ LimeworkSpigotCore plugin = (LimeworkSpigotCore) Bukkit.getPluginManager().getPlugin("LimeworkSpigotCore");
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.
diff --git a/src/main/java/net/limework/core/usefulstuff/Gui.java b/src/main/java/net/limework/core/abstraction/Gui.java
similarity index 58%
rename from src/main/java/net/limework/core/usefulstuff/Gui.java
rename to src/main/java/net/limework/core/abstraction/Gui.java
index 9c042bf..6fd60ad 100644
--- a/src/main/java/net/limework/core/usefulstuff/Gui.java
+++ b/src/main/java/net/limework/core/abstraction/Gui.java
@@ -1,5 +1,6 @@
-package net.limework.core.usefulstuff;
+package net.limework.core.abstraction;
+import ch.njol.skript.Skript;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@@ -20,7 +21,7 @@ public abstract class Gui {
protected void setup(String name, int rows) {
- if (loaded){
+ if (loaded) {
return;
}
loaded = true;
@@ -30,26 +31,36 @@ public abstract class Gui {
}
- protected void makeItem(int slot, Material material, String name, String... prelore) {
+ 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));
- List lore = new ArrayList();
- for (String s : prelore) {
+ 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 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 x = -1;
- while (x <= (this.rows - 2)) {
- x++;
- makeItem(x, material, "&1.", "");
+ int slot = -1;
+ while (slot <= (this.rows - 2)) {
+ slot++;
+ makeItem(material, 1, slot , "&1.", "");
}
}
diff --git a/src/main/java/net/limework/core/guis/ControlGui.java b/src/main/java/net/limework/core/guis/ControlGui.java
new file mode 100644
index 0000000..f1462ae
--- /dev/null
+++ b/src/main/java/net/limework/core/guis/ControlGui.java
@@ -0,0 +1,90 @@
+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;
+ }
+ }
+
+
+ }
+
+ }
+
+
+}
diff --git a/src/main/java/net/limework/core/hooks/SkriptHook.java b/src/main/java/net/limework/core/hooks/SkriptHook.java
new file mode 100644
index 0000000..7622f55
--- /dev/null
+++ b/src/main/java/net/limework/core/hooks/SkriptHook.java
@@ -0,0 +1,46 @@
+package net.limework.core.hooks;
+
+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.core.LimeworkSpigotCore;
+import net.limework.core.events.RedisMessageEvent;
+import net.limework.core.skript.elements.EvtRedis;
+import net.limework.core.skript.elements.ExprChannel;
+import net.limework.core.skript.elements.ExprMessage;
+
+import java.io.IOException;
+
+public class SkriptHook {
+
+ private SkriptAddon addon;
+ public SkriptHook(LimeworkSpigotCore plugin) {
+ addon = Skript.registerAddon(plugin);
+ try {
+ addon.loadClasses("net.limework.core.skript", "elements");
+ Skript.registerEvent("redis message", EvtRedis.class, RedisMessageEvent.class, "redis message");
+ Skript.registerExpression(ExprChannel.class, String.class, ExpressionType.SIMPLE, "redis channel");
+ EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter() {
+ @Override
+ public String get(RedisMessageEvent e) {
+ return e.getChannelName();
+ }
+ }, 0);
+ Skript.registerExpression(ExprMessage.class, String.class, ExpressionType.SIMPLE, "redis message");
+ EventValues.registerEventValue(RedisMessageEvent.class, String.class, new Getter() {
+ @Override
+ public String get(RedisMessageEvent e) {
+ return e.getMessage();
+ }
+ }, 0);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public SkriptAddon getAddon() {
+ return addon;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/net/limework/core/managers/RedisManager.java b/src/main/java/net/limework/core/managers/RedisManager.java
index 7e7ed7a..a8d2e34 100644
--- a/src/main/java/net/limework/core/managers/RedisManager.java
+++ b/src/main/java/net/limework/core/managers/RedisManager.java
@@ -51,7 +51,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
config.getString("Redis.Password"),
config.getBoolean("Redis.useSSL"));
RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads"));
- this.subscribeJedis = this.jedisPool.getResource();
+ try{this.subscribeJedis = this.jedisPool.getResource(); }catch (Exception ignored){}
this.channels = config.getStringList("Channels");
encryption = new Encryption(config);
@@ -92,7 +92,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
} catch (Exception e) {
message("&e[Jedis] &cConnection to redis has failed! &ereconnecting...");
- this.subscribeJedis.close();
+ if (this.subscribeJedis != null){this.subscribeJedis.close();}
isRedisOnline.set(false);
}
try {
@@ -130,9 +130,12 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
public void shutdown() {
this.isShuttingDown.set(true);
- this.unsubscribe();
+ if (this.subscribeJedis != null){
+ this.unsubscribe();
+ this.subscribeJedis.close();
+ }
this.RedisService.shutdown();
- subscribeJedis.close();
+
}
public boolean IsRedisOnline() {
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 1ad2ede..54dfb9d 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -5,7 +5,7 @@ Redis:
Threads: 10
Port: 6379
TimeOut: 40000
- useSSL: FALSE
+ useSSL: false
#useful if SSL is disabled
EncryptMessages: false
EncryptionKey: "16CHARACTERS KEY"
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index a25aac6..5b5180a 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,6 +1,11 @@
main: net.limework.core.LimeworkSpigotCore
name: LimeworkSpigotCore
-version: 1.0.0
+version: ${project.version}
author: limework.net
+api-version: 1.13
softdepend:
- - Skript
\ No newline at end of file
+ - Skript
+commands:
+ control:
+ description: "server control"
+ permission: "admin.use"
\ No newline at end of file