Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Improved the GUI.
Browse files Browse the repository at this point in the history
Former-commit-id: dc7e6c3
  • Loading branch information
PolskiStevek committed May 31, 2020
1 parent 47a958f commit d245d34
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 46 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<groupId>me.ishift</groupId>
<artifactId>EpicGuard</artifactId>
<version>4.2.3</version>
<version>4.2.4</version>

<dependencies>
<dependency>
<groupId>com.github.PolskiStevek</groupId>
<artifactId>InventoryAPI</artifactId>
<version>1.3-SNAPSHOT</version>
<version>1.5-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/ishift/epicguard/bukkit/EpicGuardBukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -114,7 +114,7 @@ public void onEnable() {

@Override
public void onDisable() {
this.manager.getStorageManager().getStorage().save();
this.manager.getStorageManager().save();
}

public static EpicGuardBukkit getInstance() {
Expand Down
119 changes: 91 additions & 28 deletions src/main/java/me/ishift/epicguard/bukkit/inventory/MainInventory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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)" : ""))));
}

Expand All @@ -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);
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/me/ishift/epicguard/bukkit/util/Chat.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>
*/

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));
}
}
4 changes: 2 additions & 2 deletions src/main/java/me/ishift/epicguard/bungee/EpicGuardBungee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -85,7 +85,7 @@ public void onEnable() {

@Override
public void onDisable() {
this.manager.getStorageManager().getStorage().save();
this.manager.getStorageManager().save();
}

public static EpicGuardBungee getInstance() {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/me/ishift/epicguard/common/data/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d245d34

Please sign in to comment.