From bfbdd3fabcabfa60afeb0d9f92d1fd4437809d54 Mon Sep 17 00:00:00 2001 From: Govindas Date: Sun, 18 Oct 2020 17:07:37 +0300 Subject: [PATCH] Remove unneeded code --- pom.xml | 5 -- src/main/java/META-INF/MANIFEST.MF | 3 + .../net/limework/core/LimeworkSpigotCore.java | 24 +---- .../net/limework/core/abstraction/Gui.java | 69 -------------- .../net/limework/core/guis/ControlGui.java | 90 ------------------- .../core/managers/DataSourcesManager.java | 29 ------ src/main/resources/config.yml | 11 +-- src/main/resources/plugin.yml | 5 +- 8 files changed, 11 insertions(+), 225 deletions(-) create mode 100644 src/main/java/META-INF/MANIFEST.MF delete mode 100644 src/main/java/net/limework/core/abstraction/Gui.java delete mode 100644 src/main/java/net/limework/core/guis/ControlGui.java delete mode 100644 src/main/java/net/limework/core/managers/DataSourcesManager.java diff --git a/pom.xml b/pom.xml index 5ee9fc6..37a607d 100644 --- a/pom.xml +++ b/pom.xml @@ -112,10 +112,5 @@ 19.0.0 compile - - org.mongodb - mongodb-driver-sync - 4.0.4 - \ No newline at end of file diff --git a/src/main/java/META-INF/MANIFEST.MF b/src/main/java/META-INF/MANIFEST.MF new file mode 100644 index 0000000..89effaf --- /dev/null +++ b/src/main/java/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: net.limework.core.LimeworkSpigotCore + diff --git a/src/main/java/net/limework/core/LimeworkSpigotCore.java b/src/main/java/net/limework/core/LimeworkSpigotCore.java index a843168..c22b39c 100644 --- a/src/main/java/net/limework/core/LimeworkSpigotCore.java +++ b/src/main/java/net/limework/core/LimeworkSpigotCore.java @@ -1,40 +1,27 @@ 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; +import java.util.Objects; + public class LimeworkSpigotCore extends JavaPlugin { //Redis manager private RedisManager rm; - //data - private DataSourcesManager dsm; - @Override public void onEnable() { saveDefaultConfig(); rm = new RedisManager(this); - getServer().getPluginCommand("reloadredis").setExecutor(rm); + Objects.requireNonNull(getServer().getPluginCommand("reloadredis")).setExecutor(rm); 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); @@ -44,15 +31,10 @@ public class LimeworkSpigotCore extends JavaPlugin { @Override public void onDisable() { rm.shutdown(); - dsm.shutdown(); } public RedisManager getRm() { return rm; } - - public DataSourcesManager getDsm() { - return dsm; - } } \ No newline at end of file diff --git a/src/main/java/net/limework/core/abstraction/Gui.java b/src/main/java/net/limework/core/abstraction/Gui.java deleted file mode 100644 index 6fd60ad..0000000 --- a/src/main/java/net/limework/core/abstraction/Gui.java +++ /dev/null @@ -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 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.", ""); - } - - } - - -} diff --git a/src/main/java/net/limework/core/guis/ControlGui.java b/src/main/java/net/limework/core/guis/ControlGui.java deleted file mode 100644 index f1462ae..0000000 --- a/src/main/java/net/limework/core/guis/ControlGui.java +++ /dev/null @@ -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; - } - } - - - } - - } - - -} diff --git a/src/main/java/net/limework/core/managers/DataSourcesManager.java b/src/main/java/net/limework/core/managers/DataSourcesManager.java deleted file mode 100644 index 6c86a65..0000000 --- a/src/main/java/net/limework/core/managers/DataSourcesManager.java +++ /dev/null @@ -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; - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8d9da16..f114bc0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -4,18 +4,15 @@ Redis: MaxConnections: 20 Threads: 10 Port: 6379 - TimeOut: 40000 + TimeOut: 90000 useSSL: false #useful if SSL is disabled - EncryptMessages: false + #also currently EncryptMessages is broken, meaning it must always be true or else it won't work + EncryptMessages: true EncryptionKey: "16CHARACTERS KEY" MacKey: "16CHARACTERS KEY" Channels: - "Channel1" - "Channel2" - - "Channel3" - -Mongodb: - enabled: false - url: "" \ No newline at end of file + - "Channel3" \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f4d6de1..0dc2ca5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -6,9 +6,6 @@ api-version: 1.13 softdepend: - Skript commands: - control: - description: "server control" - permission: "admin.use" reloadredis: - description: "server control" + description: "Restart redis connection" permission: "admin.use" \ No newline at end of file