diff --git a/src/main/java/me/StevenLawson/TotalFreedomMod/discord/command/DiscordCommandManager.java b/src/main/java/me/StevenLawson/TotalFreedomMod/discord/command/DiscordCommandManager.java index e97fc2e..71ae80b 100644 --- a/src/main/java/me/StevenLawson/TotalFreedomMod/discord/command/DiscordCommandManager.java +++ b/src/main/java/me/StevenLawson/TotalFreedomMod/discord/command/DiscordCommandManager.java @@ -2,6 +2,7 @@ package me.StevenLawson.TotalFreedomMod.discord.command; import me.StevenLawson.TotalFreedomMod.discord.commands.HelpCommand; import me.StevenLawson.TotalFreedomMod.discord.commands.ListCommand; +import me.StevenLawson.TotalFreedomMod.discord.commands.TPSCommand; import org.javacord.api.entity.channel.TextChannel; import org.javacord.api.entity.message.MessageBuilder; import org.javacord.api.entity.message.embed.EmbedBuilder; @@ -19,6 +20,7 @@ public class DiscordCommandManager { public void init() { commands.add(new ListCommand("list", "Gives a list of online players.", "Server Commands", Collections.singletonList("l"), false)); + commands.add(new TPSCommand("tps", "Lag information regarding the server.", "Server Commands", false)); commands.add(new HelpCommand("help", "Displays the help command", "Help", false)); } diff --git a/src/main/java/me/StevenLawson/TotalFreedomMod/discord/commands/TPSCommand.java b/src/main/java/me/StevenLawson/TotalFreedomMod/discord/commands/TPSCommand.java new file mode 100644 index 0000000..e116392 --- /dev/null +++ b/src/main/java/me/StevenLawson/TotalFreedomMod/discord/commands/TPSCommand.java @@ -0,0 +1,29 @@ +package me.StevenLawson.TotalFreedomMod.discord.commands; + +import com.earth2me.essentials.utils.DateUtil; +import me.StevenLawson.TotalFreedomMod.Server; +import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand; +import org.bukkit.Bukkit; +import org.javacord.api.entity.message.MessageBuilder; +import org.javacord.api.entity.message.embed.EmbedBuilder; +import org.javacord.api.entity.user.User; + +import java.util.List; + +public class TPSCommand extends ExecutableDiscordCommand { + public TPSCommand(String command, String description, String category, boolean isAdmin) { + super(command, description, category, isAdmin); + } + + @Override + public MessageBuilder execute(User user, List args) { + EmbedBuilder builder = new EmbedBuilder(); + builder.setTitle("Server lag information"); + builder.addField("TPS", String.valueOf(Math.floor(Server.getTPS()))); + builder.addField("Uptime", Server.getUptime()); + builder.addField("Maximum Memory", String.format("%s MB", Math.ceil(Server.getMaxMem()))); + builder.addField("Allocated Memory", String.format("%s MB", Math.floor(Server.getTotalMem()))); + builder.addField("Free Memory", String.format("%s MB", Math.ceil(Server.getFreeMem()))); + return new MessageBuilder().addEmbed(builder); + } +}