Add TPS command (closes #7)

This commit is contained in:
business-goose 2022-03-21 14:41:08 +00:00
parent e1e466b454
commit dcac3e3822
2 changed files with 31 additions and 0 deletions

View file

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

View file

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