Remove unneeded code

This commit is contained in:
Govindass 2020-10-18 17:07:37 +03:00
parent 5f4600546e
commit 157e2b08c7
8 changed files with 11 additions and 225 deletions

View File

@ -112,10 +112,5 @@
<version>19.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: net.limework.core.LimeworkSpigotCore

View File

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

View File

@ -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.", "");
}
}
}

View File

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

View File

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

View File

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

View File

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