From d245d343641d02e922312ea3144084e429be224b Mon Sep 17 00:00:00 2001 From: PolskiStevek Date: Sun, 31 May 2020 14:04:04 +0200 Subject: [PATCH] Improved the GUI. Former-commit-id: dc7e6c3bc2fe6704e5ab04ccb8c20d00fb289325 --- pom.xml | 4 +- .../epicguard/bukkit/EpicGuardBukkit.java | 4 +- .../bukkit/inventory/MainInventory.java | 119 +++++++++++++----- .../bukkit/inventory/PlayersInventory.java | 24 ++-- .../me/ishift/epicguard/bukkit/util/Chat.java | 26 ++++ .../epicguard/bungee/EpicGuardBungee.java | 4 +- .../epicguard/common/data/StorageManager.java | 11 ++ .../common/data/config/Messages.java | 8 ++ .../epicguard/common/data/storage/MySQL.java | 4 +- .../epicguard/velocity/EpicGuardVelocity.java | 2 +- 10 files changed, 160 insertions(+), 46 deletions(-) create mode 100644 src/main/java/me/ishift/epicguard/bukkit/util/Chat.java diff --git a/pom.xml b/pom.xml index 9964ae09..0a0d19ab 100644 --- a/pom.xml +++ b/pom.xml @@ -6,13 +6,13 @@ me.ishift EpicGuard - 4.2.3 + 4.2.4 com.github.PolskiStevek InventoryAPI - 1.3-SNAPSHOT + 1.5-SNAPSHOT diff --git a/src/main/java/me/ishift/epicguard/bukkit/EpicGuardBukkit.java b/src/main/java/me/ishift/epicguard/bukkit/EpicGuardBukkit.java index 82585164..184a67cc 100644 --- a/src/main/java/me/ishift/epicguard/bukkit/EpicGuardBukkit.java +++ b/src/main/java/me/ishift/epicguard/bukkit/EpicGuardBukkit.java @@ -82,7 +82,7 @@ public void onEnable() { pm.registerEvents(new PlayerChatListener(), this); final BukkitScheduler scheduler = this.getServer().getScheduler(); - scheduler.runTaskTimerAsynchronously(this, new AttackToggleTask(this.manager), 20L, Configuration.checkConditionsDelay * 20L); + scheduler.runTaskTimerAsynchronously(this, new AttackToggleTask(this.manager), 20L, Configuration.checkConditionsDelay * 40L); scheduler.runTaskTimerAsynchronously(this, new CounterTask(this.manager), 20L, 20L); scheduler.runTaskTimerAsynchronously(this, new MonitorTask(this.manager, Platform.BUKKIT), 20L, 5L); @@ -114,7 +114,7 @@ public void onEnable() { @Override public void onDisable() { - this.manager.getStorageManager().getStorage().save(); + this.manager.getStorageManager().save(); } public static EpicGuardBukkit getInstance() { diff --git a/src/main/java/me/ishift/epicguard/bukkit/inventory/MainInventory.java b/src/main/java/me/ishift/epicguard/bukkit/inventory/MainInventory.java index c572c6c3..ea2f9ff0 100644 --- a/src/main/java/me/ishift/epicguard/bukkit/inventory/MainInventory.java +++ b/src/main/java/me/ishift/epicguard/bukkit/inventory/MainInventory.java @@ -16,12 +16,16 @@ package me.ishift.epicguard.bukkit.inventory; import me.ishift.epicguard.bukkit.EpicGuardBukkit; +import me.ishift.epicguard.bukkit.util.Chat; import me.ishift.epicguard.bukkit.util.ItemBuilder; +import me.ishift.epicguard.bukkit.util.ServerTPS; import me.ishift.epicguard.bukkit.util.UMaterial; import me.ishift.epicguard.common.AttackManager; -import me.ishift.epicguard.common.data.StorageManager; +import me.ishift.epicguard.common.data.config.Messages; +import me.ishift.epicguard.common.util.MemoryHelper; import me.ishift.inventory.api.InventorySize; import me.ishift.inventory.api.inventories.ClickableInventory; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; @@ -32,59 +36,118 @@ public class MainInventory extends ClickableInventory { private final AttackManager manager; public MainInventory(AttackManager manager) { - super("EpicGuard v" + EpicGuardBukkit.getInstance().getDescription().getVersion() + " (Main GUI)", "MAIN", InventorySize.NORMAL); + super("EpicGuard v" + EpicGuardBukkit.getInstance().getDescription().getVersion() + " (Main GUI)", "MAIN", InventorySize.BIG); this.manager = manager; } + @Override + public boolean isRefreshable() { + return true; + } + @Override public void onOpen(Player player, Inventory inventory) { - final ItemStack i1 = new ItemBuilder(UMaterial.CHEST_MINECART.getMaterial()) - .setTitle("&cServer status.") - .addLore("&7See status of your server.") + final ItemStack status = new ItemBuilder(UMaterial.CHEST_MINECART.getMaterial()) + .setTitle("&6Server status.") + .addLore("") + .addLore(" &8● &7Attack mode&8: " + (manager.isAttackMode() ? "&cActive!" : "&aNot active.")) + .addLore(" &8● &7Currently blocked&8: &6" + manager.getTotalBots() + " bots") + .addLore("") + .addLore(" &8● &7Connections&8: &2" + manager.getConnectPerSecond() + "/s") + .addLore(" &8● &7Detections&8: &2" + manager.getDetectionsPerSecond() + "/s") + .addLore("") + .addLore(" &8» &cClick to toggle attack-mode.") + .build(); + + final ItemStack storage = new ItemBuilder(Material.CHEST) + .setTitle("&6Storage management.") + .addLore("") + .addLore(" &8● &7Storage mode: &6" + (this.manager.getStorageManager().isMysql() ? "MySQL" : "Flat (JSON)")) + .addLore(" &8● &7Last save&8: &6" + this.manager.getStorageManager().getLastSave()) + .addLore("") + .addLore(" &8● &7Blacklisted IPs&8: &c" + this.manager.getStorageManager().getStorage().getBlacklist().size()) + .addLore(" &8● &7Whitelisted IPs&8: &a" + this.manager.getStorageManager().getStorage().getWhitelist().size()) + .addLore("") + .addLore(" &8● &7Reconnect users&8: &2" + this.manager.getStorageManager().getStorage().getRejoinData().size()) + .addLore(" &8● &7PingData IPs&8: &2" + this.manager.getStorageManager().getStorage().getPingData().size()) + .addLore("") + .addLore(" &8» &cClick to save the data.") + .build(); + + final ItemStack players = new ItemBuilder(Material.ARMOR_STAND) + .setTitle("&6Player management menu.") + .addLore("") + .addLore(" &8● &7Online players: &6" + Bukkit.getOnlinePlayers().size() + "/" + Bukkit.getMaxPlayers()) .addLore("") - .addLore(" &8» &7Attack&8: " + (manager.isAttackMode() ? "&cDetected!" : "&aNot detected.")) - .addLore(" &8» &7Connections&8: &f" + manager.getConnectPerSecond() + "/s") + .addLore(" &8● &7This will show GUI with all players.") + .addLore(" &8● &7You can see their &6address, country") + .addLore(" &8● &6city, UUID and operator status&7!") .addLore("") - .addLore(" &8» &7Blacklisted IPs&8: &c" + this.manager.getStorageManager().getStorage().getBlacklist().size()) - .addLore(" &8» &7Whitelisted IPs&8: &a" + this.manager.getStorageManager().getStorage().getWhitelist().size()) + .addLore(" &8» &cClick to open the GUI.") .build(); - final ItemStack i2 = new ItemBuilder(UMaterial.BOOK_AND_QUILL.getMaterial()) - .setTitle("&cAbout EpicGuard") - .addLore("&7Plugin author, version etc.") + final ItemStack about = new ItemBuilder(UMaterial.BOOK_AND_QUILL.getMaterial()) + .setTitle("&6About EpicGuard.") .addLore("") - .addLore(" &8» &7Version&8: &e" + EpicGuardBukkit.getInstance().getDescription().getVersion()) - .addLore(" &8» &7Authors&8: &eiShift, rusekh") - .addLore(" &8» &7Author's Discord&8: &ciShift#0524") - .addLore(" &8» &7Support Server&8: &cdiscord.gg/VkfhFCv") + .addLore(" &8● &7Version&8: &e" + EpicGuardBukkit.getInstance().getDescription().getVersion()) + .addLore(" &8● &7Author&8: &eiShift") + .addLore(" &8● &7Support Server&8: &cdiscord.gg/VkfhFCv") + .addLore("") + .addLore(" &8» &cClick to join our discord.") .build(); - final ItemStack i3 = new ItemBuilder(Material.COMPASS) - .setTitle("&cPlayer management menu.") - .addLore("&7Get to know about your players.") + final ItemStack server = new ItemBuilder(UMaterial.EXP_BOTTLE.getMaterial()) + .setTitle("&6Server Information.") + .addLore("") + .addLore(" &8● &7Version&8: &c" + Bukkit.getVersion()) + .addLore(" &8● &7Plugins&8: &c" + Bukkit.getPluginManager().getPlugins().length) + .addLore(" &8● &7Online players: &6" + Bukkit.getOnlinePlayers().size() + "/" + Bukkit.getMaxPlayers()) .addLore("") - .addLore(" &8» &7You can see &6IP + history, country, city &7etc.") - .addLore(" &8» &fLeft Click &7to show GUI with all players.") + .addLore(" &8● &7Current TPS&8: &a" + ServerTPS.getTPS()) + .addLore(" &8● &7Memory usage&8: &a" + MemoryHelper.getUsage() + "MB / " + MemoryHelper.getTotal() + "MB") .build(); - final ItemStack i4 = new ItemBuilder(Material.BARRIER) - .setTitle("&cComing soon...") + final ItemStack info = new ItemBuilder(Material.PAPER) + .setTitle("&6GUI info.") .addLore("") + .addLore(" &8● &7This GUI is refreshed") + .addLore(" &8● &7every &f2 seconds&7!") + .addLore("") + .addLore(" &8● &7Powered by &6InventoryAPI v1.5") .build(); - inventory.setItem(10, i1); - inventory.setItem(12, i2); - inventory.setItem(14, i3); - inventory.setItem(16, i4); + inventory.setItem(11, status); + inventory.setItem(13, storage); + inventory.setItem(15, players); + inventory.setItem(21, server); + inventory.setItem(23, about); + inventory.setItem(27, info); } @Override public void onClick(InventoryClickEvent event) { final Player player = (Player) event.getWhoClicked(); event.setCancelled(true); - if (event.getSlot() == 14) { + + if (event.getSlot() == 11) { + this.manager.setAttackMode(!this.manager.isAttackMode()); + Chat.send(player, this.manager.isAttackMode() ? Messages.enabledAttackMode : Messages.disabledAttackMode); + } + + if (event.getSlot() == 15) { player.closeInventory(); EpicGuardBukkit.getInstance().getInventoryManager().open("PLAYERS", player); } + + if (event.getSlot() == 13) { + Chat.send(player, Messages.savingData); + this.manager.getStorageManager().save(); + Chat.send(player, Messages.savedData); + } + + if (event.getSlot() == 23) { + player.closeInventory(); + Chat.send(player, "discord.gg/VkfhFCv"); + } } } diff --git a/src/main/java/me/ishift/epicguard/bukkit/inventory/PlayersInventory.java b/src/main/java/me/ishift/epicguard/bukkit/inventory/PlayersInventory.java index 1084f971..8e8a0b8f 100644 --- a/src/main/java/me/ishift/epicguard/bukkit/inventory/PlayersInventory.java +++ b/src/main/java/me/ishift/epicguard/bukkit/inventory/PlayersInventory.java @@ -25,6 +25,7 @@ import me.ishift.inventory.api.InventorySize; import me.ishift.inventory.api.inventories.ClickableInventory; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; @@ -37,10 +38,15 @@ public class PlayersInventory extends ClickableInventory { private final AttackManager manager; public PlayersInventory(AttackManager manager) { - super("EpicGuard v" + EpicGuardBukkit.getInstance().getDescription().getVersion() + " (Player Management)", "PLAYERS", InventorySize.BIGGEST); + super("EpicGuard v" + EpicGuardBukkit.getInstance().getDescription().getVersion() + " (Players)", "PLAYERS", InventorySize.BIGGEST); this.manager = manager; } + @Override + public boolean isRefreshable() { + return true; + } + @Override public void onOpen(Player player, Inventory inventory) { int i = 0; @@ -49,16 +55,16 @@ public void onOpen(Player player, Inventory inventory) { final User user = EpicGuardBukkit.getInstance().getUserManager().getUser(entry); lore.add(""); - lore.add(MessageHelper.color(" &8» &7Name&8: &f" + entry.getName())); - lore.add(MessageHelper.color(" &8» &7UUID&8: &f" + entry.getUniqueId())); - lore.add(MessageHelper.color(" &8» &7OP&8: " + (entry.isOp() ? "&aYes" : "&cNo"))); - lore.add(MessageHelper.color(" &8» &7Country&8: &f" + manager.getGeoApi().getCountryCode(user.getAddress()))); - lore.add(MessageHelper.color(" &8» &7City&8: &f" + manager.getGeoApi().getCity(user.getAddress()))); - lore.add(""); + lore.add(MessageHelper.color("&8» &cBasic Information")); + lore.add(MessageHelper.color(" &8● &7Name&8: &f" + entry.getName())); + lore.add(MessageHelper.color(" &8● &7UUID&8: &f" + entry.getUniqueId())); + lore.add(MessageHelper.color(" &8● &7OP&8: " + (entry.isOp() ? "&2✔" : "&4✖"))); + lore.add(MessageHelper.color(" &8● &7Country&8: &f" + manager.getGeoApi().getCountryCode(user.getAddress()))); + lore.add(MessageHelper.color(" &8● &7City&8: &f" + manager.getGeoApi().getCity(user.getAddress()))); if (!user.getAddressHistory().isEmpty()) { lore.add(""); - lore.add(MessageHelper.color(" &8» &7IP History:")); + lore.add(MessageHelper.color(" &8» &cAddress History:")); user.getAddressHistory().forEach(address -> lore.add(MessageHelper.color(" &7- &f" + address + (user.getAddress().equals(address) ? " &8(&6Current&8)" : "")))); } @@ -67,7 +73,7 @@ public void onOpen(Player player, Inventory inventory) { i++; } - final ItemStack back = new ItemBuilder(UMaterial.FENCE_GATE.getMaterial()).setTitle("&cBack to main menu").addLore("&7Click to go back.").build(); + final ItemStack back = new ItemBuilder(Material.ARROW).setTitle("&cMain menu").addLore("&8» &7Click to go back.").build(); inventory.setItem(53, back); } diff --git a/src/main/java/me/ishift/epicguard/bukkit/util/Chat.java b/src/main/java/me/ishift/epicguard/bukkit/util/Chat.java new file mode 100644 index 00000000..3c483c6a --- /dev/null +++ b/src/main/java/me/ishift/epicguard/bukkit/util/Chat.java @@ -0,0 +1,26 @@ +/* + * EpicGuard is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * EpicGuard is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ + +package me.ishift.epicguard.bukkit.util; + +import me.ishift.epicguard.common.data.config.Messages; +import me.ishift.epicguard.common.util.MessageHelper; +import org.bukkit.entity.Player; + +public class Chat { + public static void send(Player player, String message) { + player.sendMessage(MessageHelper.color(Messages.prefix + message)); + } +} diff --git a/src/main/java/me/ishift/epicguard/bungee/EpicGuardBungee.java b/src/main/java/me/ishift/epicguard/bungee/EpicGuardBungee.java index a5197569..ca880982 100644 --- a/src/main/java/me/ishift/epicguard/bungee/EpicGuardBungee.java +++ b/src/main/java/me/ishift/epicguard/bungee/EpicGuardBungee.java @@ -64,7 +64,7 @@ public void onEnable() { pm.registerCommand(this, new GuardCommand("guard", this.manager)); - this.getProxy().getScheduler().schedule(this, new AttackToggleTask(this.manager), 1L, Configuration.checkConditionsDelay, TimeUnit.SECONDS); + this.getProxy().getScheduler().schedule(this, new AttackToggleTask(this.manager), 1L, Configuration.checkConditionsDelay * 2, TimeUnit.SECONDS); this.getProxy().getScheduler().schedule(this, new CounterTask(this.manager), 1L, 1L, TimeUnit.SECONDS); this.getProxy().getScheduler().schedule(this, new MonitorTask(this.manager, Platform.BUNGEE), 1L, 200L, TimeUnit.MILLISECONDS); @@ -85,7 +85,7 @@ public void onEnable() { @Override public void onDisable() { - this.manager.getStorageManager().getStorage().save(); + this.manager.getStorageManager().save(); } public static EpicGuardBungee getInstance() { diff --git a/src/main/java/me/ishift/epicguard/common/data/StorageManager.java b/src/main/java/me/ishift/epicguard/common/data/StorageManager.java index 6dea3488..0b0c61d3 100644 --- a/src/main/java/me/ishift/epicguard/common/data/StorageManager.java +++ b/src/main/java/me/ishift/epicguard/common/data/StorageManager.java @@ -20,12 +20,17 @@ import me.ishift.epicguard.common.data.storage.Flat; import me.ishift.epicguard.common.data.storage.MySQL; +import java.util.Date; + @Getter public class StorageManager { private final DataStorage storage; private final boolean mysql; private final Yaml config; + private Date lastSave; + + // MySQL section private final String host; private final int port; private final boolean ssl; @@ -52,6 +57,12 @@ public StorageManager() { this.storage = new Flat(); } + this.lastSave = new Date(System.currentTimeMillis()); this.storage.load(); } + + public void save() { + this.storage.save(); + this.lastSave = new Date(System.currentTimeMillis()); + } } diff --git a/src/main/java/me/ishift/epicguard/common/data/config/Messages.java b/src/main/java/me/ishift/epicguard/common/data/config/Messages.java index c46cdd65..774c3fb6 100644 --- a/src/main/java/me/ishift/epicguard/common/data/config/Messages.java +++ b/src/main/java/me/ishift/epicguard/common/data/config/Messages.java @@ -42,6 +42,10 @@ public class Messages { public static String unknownCommand; public static String statusOn; public static String statusOff; + public static String savingData; + public static String savedData; + public static String enabledAttackMode; + public static String disabledAttackMode; public static String operatorDisabled; public static String namespacedDisabled; @@ -73,6 +77,10 @@ public static void load() { unknownCommand = config.getOrSetDefault("other.unknown-command", "&cCommand not found! Use &6/guard"); statusOn = config.getOrSetDefault("other.status-on", "&7Attack status has been &aenabled."); statusOff = config.getOrSetDefault("other.status-off", "&7Attack status has been &cdisabled."); + savingData = config.getOrSetDefault("other.saving-data", "&7Data is saving..."); + savedData = config.getOrSetDefault("other.saved-data", "&7Data saving completed!"); + enabledAttackMode = config.getOrSetDefault("other.attack-mode-enabled", "&7Attack mode has been &aenabled&7!"); + disabledAttackMode = config.getOrSetDefault("other.attack-mode-disabled", "&7Attack mode has been &cdisabled&7!"); operatorDisabled = config.getOrSetDefault("other.operator-mechanics-disabled", "&cOperator mechanics has been disabled on this server."); namespacedDisabled = config.getOrSetDefault("other.namespaced-disabled", "&cNamespaced commands (with ':' symbol) has been disabled on this server!."); diff --git a/src/main/java/me/ishift/epicguard/common/data/storage/MySQL.java b/src/main/java/me/ishift/epicguard/common/data/storage/MySQL.java index ac841ff4..b2c44f15 100644 --- a/src/main/java/me/ishift/epicguard/common/data/storage/MySQL.java +++ b/src/main/java/me/ishift/epicguard/common/data/storage/MySQL.java @@ -36,12 +36,12 @@ public MySQL(StorageManager manager) { public void load() { this.executeUpdate("CREATE TABLE IF NOT EXISTS epicguard_blacklist(`address` TEXT NOT NULL);"); this.executeUpdate("CREATE TABLE IF NOT EXISTS epicguard_whitelist(`address` TEXT NOT NULL);"); - this.executeUpdate("CREATE TABLE IF NOT EXISTS epicguard_reconnectdata(`address` TEXT NOT NULL);"); + this.executeUpdate("CREATE TABLE IF NOT EXISTS epicguard_reconnectdata(`nickname` TEXT NOT NULL);"); this.executeUpdate("CREATE TABLE IF NOT EXISTS epicguard_pingdata(`address` TEXT NOT NULL);"); this.setBlacklist(this.getList("epicguard_blacklist", "address")); this.setWhitelist(this.getList("epicguard_whitelist", "address")); - this.setRejoinData(this.getList("epicguard_reconnectdata", "address")); + this.setRejoinData(this.getList("epicguard_reconnectdata", "nickname")); this.setPingData(this.getList("epicguard_pingdata", "address")); } diff --git a/src/main/java/me/ishift/epicguard/velocity/EpicGuardVelocity.java b/src/main/java/me/ishift/epicguard/velocity/EpicGuardVelocity.java index bf7e8982..bc957141 100644 --- a/src/main/java/me/ishift/epicguard/velocity/EpicGuardVelocity.java +++ b/src/main/java/me/ishift/epicguard/velocity/EpicGuardVelocity.java @@ -60,7 +60,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) { @Subscribe public void onProxyShutdown(ProxyShutdownEvent event) { - this.manager.getStorageManager().getStorage().save(); + this.manager.getStorageManager().save(); } public AttackManager getAttackManager() {