new changes.

This commit is contained in:
ham1255 2020-07-06 22:38:54 +04:00
parent b956363228
commit aca7ec2a13
9 changed files with 203 additions and 68 deletions

14
pom.xml
View File

@ -10,6 +10,12 @@
<packaging>jar</packaging>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -77,7 +83,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -100,5 +106,11 @@
<artifactId>siv-mode</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -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<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() {
return rm;
}
public SkriptAddon getAddon() {
return addon;
}
}

View File

@ -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.

View File

@ -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<String> lore = new ArrayList<String>();
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<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 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.", "");
}
}

View 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;
}
}
}
}
}

View 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;
}
}

View File

@ -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() {

View File

@ -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"

View File

@ -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
commands:
control:
description: "server control"
permission: "admin.use"