new changes.
This commit is contained in:
parent
35af0d3b0a
commit
9b24e49f43
14
pom.xml
14
pom.xml
@ -10,6 +10,12 @@
|
|||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@ -77,7 +83,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>spigot-api</artifactId>
|
||||||
<version>1.15.2-R0.1-SNAPSHOT</version>
|
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -100,5 +106,11 @@
|
|||||||
<artifactId>siv-mode</artifactId>
|
<artifactId>siv-mode</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations</artifactId>
|
||||||
|
<version>19.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -1,35 +1,36 @@
|
|||||||
package net.limework.core;
|
package net.limework.core;
|
||||||
|
|
||||||
import ch.njol.skript.Skript;
|
import net.limework.core.guis.ControlGui;
|
||||||
import ch.njol.skript.SkriptAddon;
|
import net.limework.core.hooks.SkriptHook;
|
||||||
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.managers.RedisManager;
|
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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class LimeworkSpigotCore extends JavaPlugin {
|
public class LimeworkSpigotCore extends JavaPlugin {
|
||||||
|
|
||||||
//Redis manager
|
//Redis manager
|
||||||
private RedisManager rm;
|
private RedisManager rm;
|
||||||
|
|
||||||
//Skript
|
|
||||||
private SkriptAddon addon;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
rm = new RedisManager(this);
|
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();
|
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
|
@Override
|
||||||
@ -37,41 +38,8 @@ public class LimeworkSpigotCore extends JavaPlugin {
|
|||||||
rm.shutdown();
|
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<String, RedisMessageEvent>() {
|
|
||||||
@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<String, RedisMessageEvent>() {
|
|
||||||
@Override
|
|
||||||
public String get(RedisMessageEvent e) {
|
|
||||||
return e.getMessage();
|
|
||||||
}
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public RedisManager getRm() {
|
public RedisManager getRm() {
|
||||||
return rm;
|
return rm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkriptAddon getAddon() {
|
|
||||||
return addon;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ public class EffSendMessage extends Effect {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void execute(Event event) {
|
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 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.
|
if (message == null) {//checks if message equals null if true does not execute.
|
||||||
|
@ -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.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -20,7 +21,7 @@ public abstract class Gui {
|
|||||||
|
|
||||||
|
|
||||||
protected void setup(String name, int rows) {
|
protected void setup(String name, int rows) {
|
||||||
if (loaded){
|
if (loaded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
loaded = true;
|
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);
|
ItemStack item = new ItemStack(material, 1);
|
||||||
ItemMeta item_meta = item.getItemMeta();
|
ItemMeta item_meta = item.getItemMeta();
|
||||||
item_meta.setDisplayName(translateAlternateColorCodes('&', name));
|
item_meta.setDisplayName(translateAlternateColorCodes('&', name));
|
||||||
List<String> lore = new ArrayList<String>();
|
item.setItemMeta(item_meta);
|
||||||
for (String s : prelore) {
|
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));
|
lore.add(translateAlternateColorCodes('&', s));
|
||||||
}
|
}
|
||||||
item_meta.setLore(lore);
|
item_meta.setLore(lore);
|
||||||
item.setItemMeta(item_meta);
|
item.setItemMeta(item_meta);
|
||||||
|
item.setAmount(howMany);
|
||||||
this.gui.clear(slot);
|
this.gui.clear(slot);
|
||||||
this.gui.setItem(slot, item);
|
this.gui.setItem(slot, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void fillGUI(Material material) {
|
protected void fillGUI(Material material) {
|
||||||
int x = -1;
|
int slot = -1;
|
||||||
while (x <= (this.rows - 2)) {
|
while (slot <= (this.rows - 2)) {
|
||||||
x++;
|
slot++;
|
||||||
makeItem(x, material, "&1.", "");
|
makeItem(material, 1, slot , "&1.", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
90
src/main/java/net/limework/core/guis/ControlGui.java
Normal file
90
src/main/java/net/limework/core/guis/ControlGui.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
46
src/main/java/net/limework/core/hooks/SkriptHook.java
Normal file
46
src/main/java/net/limework/core/hooks/SkriptHook.java
Normal file
@ -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<String, RedisMessageEvent>() {
|
||||||
|
@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<String, RedisMessageEvent>() {
|
||||||
|
@Override
|
||||||
|
public String get(RedisMessageEvent e) {
|
||||||
|
return e.getMessage();
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public SkriptAddon getAddon() {
|
||||||
|
return addon;
|
||||||
|
}
|
||||||
|
}
|
@ -51,7 +51,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
config.getString("Redis.Password"),
|
config.getString("Redis.Password"),
|
||||||
config.getBoolean("Redis.useSSL"));
|
config.getBoolean("Redis.useSSL"));
|
||||||
RedisService = Executors.newFixedThreadPool(config.getInt("Redis.Threads"));
|
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");
|
this.channels = config.getStringList("Channels");
|
||||||
encryption = new Encryption(config);
|
encryption = new Encryption(config);
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
|
|
||||||
} 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.subscribeJedis.close();
|
if (this.subscribeJedis != null){this.subscribeJedis.close();}
|
||||||
isRedisOnline.set(false);
|
isRedisOnline.set(false);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -130,9 +130,12 @@ public class RedisManager extends BinaryJedisPubSub implements Runnable{
|
|||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
this.isShuttingDown.set(true);
|
this.isShuttingDown.set(true);
|
||||||
this.unsubscribe();
|
if (this.subscribeJedis != null){
|
||||||
|
this.unsubscribe();
|
||||||
|
this.subscribeJedis.close();
|
||||||
|
}
|
||||||
this.RedisService.shutdown();
|
this.RedisService.shutdown();
|
||||||
subscribeJedis.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean IsRedisOnline() {
|
public boolean IsRedisOnline() {
|
||||||
|
@ -5,7 +5,7 @@ Redis:
|
|||||||
Threads: 10
|
Threads: 10
|
||||||
Port: 6379
|
Port: 6379
|
||||||
TimeOut: 40000
|
TimeOut: 40000
|
||||||
useSSL: FALSE
|
useSSL: false
|
||||||
#useful if SSL is disabled
|
#useful if SSL is disabled
|
||||||
EncryptMessages: false
|
EncryptMessages: false
|
||||||
EncryptionKey: "16CHARACTERS KEY"
|
EncryptionKey: "16CHARACTERS KEY"
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
main: net.limework.core.LimeworkSpigotCore
|
main: net.limework.core.LimeworkSpigotCore
|
||||||
name: LimeworkSpigotCore
|
name: LimeworkSpigotCore
|
||||||
version: 1.0.0
|
version: ${project.version}
|
||||||
author: limework.net
|
author: limework.net
|
||||||
|
api-version: 1.13
|
||||||
softdepend:
|
softdepend:
|
||||||
- Skript
|
- Skript
|
||||||
|
commands:
|
||||||
|
control:
|
||||||
|
description: "server control"
|
||||||
|
permission: "admin.use"
|
Loading…
Reference in New Issue
Block a user