Added ServerList StaffList and Broadcast (added sync but not implemented yet)
This commit is contained in:
parent
cfeb04fe6e
commit
c045aba112
|
|
@ -1,7 +1,6 @@
|
|||
package com.alttd.proxydiscordlink.bot.commandManager;
|
||||
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.commands.CommandLink;
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.commands.CommandUnlink;
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.commands.*;
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.commands.NickCommand.CommandNick;
|
||||
import com.alttd.proxydiscordlink.util.ALogger;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
|
|
@ -19,12 +18,15 @@ public class CommandManager extends ListenerAdapter {
|
|||
|
||||
private final List<DiscordCommand> commands;
|
||||
|
||||
public CommandManager(JDA jda/*, ChatListener chatListener*/) {
|
||||
public CommandManager(JDA jda) {
|
||||
ALogger.info("Loading commands...");
|
||||
commands = List.of(
|
||||
new CommandLink(jda),
|
||||
new CommandUnlink(jda),
|
||||
new CommandNick(jda)
|
||||
new CommandNick(jda),
|
||||
new CommandServerList(jda),
|
||||
new CommandStaffList(jda),
|
||||
new CommandBroadcast(jda)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package com.alttd.proxydiscordlink.bot.commandManager.commands;
|
||||
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.DiscordCommand;
|
||||
import com.alttd.proxydiscordlink.config.BotConfig;
|
||||
import com.alttd.proxydiscordlink.util.Utilities;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||
|
||||
public class CommandBroadcast extends DiscordCommand {
|
||||
|
||||
CommandData commandData;
|
||||
public CommandBroadcast(JDA jda) {
|
||||
commandData = Commands.slash(getName(), "")
|
||||
.addOption(OptionType.STRING, "text", "Broadcast a message to all online players", true)
|
||||
.setDefaultPermissions(DefaultMemberPermissions.DISABLED);
|
||||
Utilities.registerCommand(jda, commandData);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return "broadcast";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
String msg = event.getOption("text", OptionMapping::getAsString);
|
||||
if (msg == null) {
|
||||
Utilities.commandErrAutoRem("Couldn't find text", event);
|
||||
return;
|
||||
}
|
||||
event.replyEmbeds(Utilities.genericSuccessEmbed("Success", "Broadcast the following message:\n" + msg))
|
||||
.setEphemeral(true).queue();
|
||||
Utilities.broadcast(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getCommandData() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChannelId() {
|
||||
return BotConfig.DISCORD.STAFF_COMMAND_CHANNEL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package com.alttd.proxydiscordlink.bot.commandManager.commands;
|
||||
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.Bot;
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.DiscordCommand;
|
||||
import com.alttd.proxydiscordlink.config.BotConfig;
|
||||
import com.alttd.proxydiscordlink.util.Utilities;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.User;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CommandServerList extends DiscordCommand {
|
||||
|
||||
CommandData commandData;
|
||||
private final DiscordLink plugin;
|
||||
private final Bot bot;
|
||||
public CommandServerList(JDA jda) {
|
||||
plugin = DiscordLink.getPlugin();
|
||||
bot = plugin.getBot();
|
||||
commandData = Commands.slash(getName(), "Lists all online players on the server or a specific server")
|
||||
.addOption(OptionType.STRING, "server", "Server to check online players on", false)
|
||||
.setDefaultPermissions(DefaultMemberPermissions.DISABLED);
|
||||
Utilities.registerCommand(jda, commandData);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
@Override
|
||||
public String getName() {
|
||||
return "serverlist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
String serverName = "Altitude";
|
||||
String tmp;
|
||||
Collection<Player> onlinePlayer = plugin.getProxy().getAllPlayers();
|
||||
ServerInfo server;
|
||||
if ((tmp = event.getOption("server", OptionMapping::getAsString)) != null) {
|
||||
Optional<RegisteredServer> registeredServer = plugin.getProxy().getServer(tmp);
|
||||
if (registeredServer.isEmpty()) {
|
||||
Utilities.commandErrAutoRem("This server does not exist " + tmp, event);
|
||||
return;
|
||||
}
|
||||
onlinePlayer = registeredServer.get().getPlayersConnected();
|
||||
serverName = registeredServer.get().getServerInfo().getName();
|
||||
}
|
||||
LuckPerms luckPerms = Utilities.getLuckPerms();
|
||||
List<User> players = onlinePlayer
|
||||
.stream()
|
||||
.map(player -> luckPerms.getUserManager().getUser(player.getUniqueId()))
|
||||
.sorted((o1, o2) -> {
|
||||
int i = Integer.compare(luckPerms.getGroupManager().getGroup(o2.getPrimaryGroup()).getWeight().orElse(0), luckPerms.getGroupManager().getGroup(o1.getPrimaryGroup()).getWeight().orElse(0));
|
||||
return i != 0 ? i : o1.getUsername().compareToIgnoreCase(o2.getUsername());
|
||||
})
|
||||
.toList();
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
String title = "Players online on " + serverName + ": " + players.size();
|
||||
embedBuilder.setTitle(title);
|
||||
String separator = "\n";
|
||||
String rankname = "";
|
||||
StringBuilder currentFieldText = new StringBuilder();
|
||||
int entryCounter = 0;
|
||||
int totalCharacters = title.length();
|
||||
int fieldCounter = 0;
|
||||
|
||||
for (User user : players) {
|
||||
if (user != null) {
|
||||
if (!rankname.equalsIgnoreCase(user.getPrimaryGroup())) {
|
||||
if (currentFieldText.length() != 0) {
|
||||
totalCharacters += rankname.length() + currentFieldText.length();
|
||||
fieldCounter++;
|
||||
if (totalCharacters > 6000 || fieldCounter > 25) {
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, 300);
|
||||
embedBuilder.clearFields();
|
||||
totalCharacters = title.length() + rankname.length() + currentFieldText.length();
|
||||
fieldCounter = 1;
|
||||
}
|
||||
embedBuilder.addField(rankname, currentFieldText.toString(), true);
|
||||
entryCounter = 0;
|
||||
currentFieldText = new StringBuilder();
|
||||
}
|
||||
rankname = Utilities.capitalize(user.getPrimaryGroup());
|
||||
} else if (rankname.equalsIgnoreCase(user.getPrimaryGroup())) {
|
||||
currentFieldText.append(separator);
|
||||
}
|
||||
if (entryCounter <= 50) {
|
||||
Optional<Player> optionalPlayer = plugin.getProxy().getPlayer(user.getUniqueId());
|
||||
if (optionalPlayer.isPresent()) {
|
||||
Player player = optionalPlayer.get();
|
||||
currentFieldText.append("`").append(player.getUsername()).append("`");
|
||||
}
|
||||
} else if (entryCounter == 51) {
|
||||
currentFieldText.append("...");
|
||||
}
|
||||
entryCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentFieldText.length() > 0) {
|
||||
totalCharacters = title.length() + rankname.length() + currentFieldText.length();
|
||||
fieldCounter++;
|
||||
if (totalCharacters > 6000 || fieldCounter > 25) {
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, 300);
|
||||
embedBuilder.clearFields();
|
||||
}
|
||||
embedBuilder.addField(rankname, currentFieldText.toString(), true);
|
||||
}
|
||||
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, 300);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getCommandData() {
|
||||
return commandData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChannelId() {
|
||||
return BotConfig.DISCORD.STAFF_COMMAND_CHANNEL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
package com.alttd.proxydiscordlink.bot.commandManager.commands;
|
||||
|
||||
import com.alttd.proxydiscordlink.DiscordLink;
|
||||
import com.alttd.proxydiscordlink.bot.Bot;
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.DiscordCommand;
|
||||
import com.alttd.proxydiscordlink.config.BotConfig;
|
||||
import com.alttd.proxydiscordlink.util.Utilities;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.Commands;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.user.User;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CommandStaffList extends DiscordCommand {
|
||||
|
||||
CommandData commandData;
|
||||
private final DiscordLink plugin;
|
||||
private final Bot bot;
|
||||
public CommandStaffList(JDA jda) {
|
||||
plugin = DiscordLink.getPlugin();
|
||||
bot = plugin.getBot();
|
||||
commandData = Commands.slash(getName(), "Lists all online players on the server or a specific server")
|
||||
.addOption(OptionType.STRING, "server", "Server to check online players on", false)
|
||||
.setDefaultPermissions(DefaultMemberPermissions.DISABLED);
|
||||
Utilities.registerCommand(jda, commandData);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SpellCheckingInspection")
|
||||
@Override
|
||||
public String getName() {
|
||||
return "stafflist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
LuckPerms luckPerms = Utilities.getLuckPerms();
|
||||
List<User> staff = plugin.getProxy().getAllPlayers()
|
||||
.stream().filter(player-> player.hasPermission("group." + BotConfig.SL_MINIMUMRANK))
|
||||
.map(player -> luckPerms.getUserManager().getUser(player.getUniqueId()))
|
||||
.sorted((o1, o2) -> {
|
||||
int i = Integer.compare(luckPerms.getGroupManager().getGroup(o2.getPrimaryGroup()).getWeight().orElse(0), luckPerms.getGroupManager().getGroup(o1.getPrimaryGroup()).getWeight().orElse(0));
|
||||
return i != 0 ? i : o1.getUsername().compareToIgnoreCase(o2.getUsername());
|
||||
})
|
||||
.toList();
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
String title = "Online Staff: " + staff.size() + " - Online Players: " + plugin.getProxy().getAllPlayers().size();
|
||||
embedBuilder.setTitle(title);
|
||||
String separator = "\n";
|
||||
String rankname = "";
|
||||
|
||||
Map<String, Integer> onlineStaff = new HashMap<>();
|
||||
StringBuilder currentFieldText = new StringBuilder();
|
||||
int entryCounter = 0;
|
||||
int totalCharacters = title.length();
|
||||
int fieldCounter = 0;
|
||||
|
||||
for (User user : staff) {
|
||||
if (user != null) {
|
||||
if (!rankname.equalsIgnoreCase(user.getPrimaryGroup())) {
|
||||
if (currentFieldText.length() != 0) {
|
||||
totalCharacters += rankname.length() + currentFieldText.length();
|
||||
fieldCounter++;
|
||||
if (totalCharacters > 6000 || fieldCounter > 25) {
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, -1);
|
||||
embedBuilder.clearFields();
|
||||
totalCharacters = title.length() + rankname.length() + currentFieldText.length();
|
||||
fieldCounter = 1;
|
||||
}
|
||||
embedBuilder.addField(rankname, currentFieldText.toString(), true);
|
||||
entryCounter = 0;
|
||||
currentFieldText = new StringBuilder();
|
||||
}
|
||||
rankname = Utilities.capitalize(user.getPrimaryGroup());
|
||||
} else if (rankname.equalsIgnoreCase(user.getPrimaryGroup())) {
|
||||
currentFieldText.append(separator);
|
||||
}
|
||||
|
||||
Optional<Player> optionalPlayer = plugin.getProxy().getPlayer(user.getUniqueId());
|
||||
if (optionalPlayer.isPresent()) {
|
||||
Player player = optionalPlayer.get();
|
||||
String currentServerName = player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "";
|
||||
if (onlineStaff.containsKey(currentServerName)) {
|
||||
onlineStaff.put(currentServerName, onlineStaff.get(currentServerName) + 1);
|
||||
} else {
|
||||
onlineStaff.put(currentServerName, 1);
|
||||
}
|
||||
|
||||
if (entryCounter <= 50) {
|
||||
currentFieldText.append("`").append(player.getUsername()).append("`");
|
||||
} else if (entryCounter == 51) {
|
||||
currentFieldText.append("...");
|
||||
}
|
||||
entryCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (currentFieldText.length() > 0) {
|
||||
totalCharacters = title.length() + rankname.length() + currentFieldText.length();
|
||||
fieldCounter++;
|
||||
if (totalCharacters > 6000 || fieldCounter > 25) {
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, -1);
|
||||
embedBuilder.clearFields();
|
||||
}
|
||||
embedBuilder.addField(rankname, currentFieldText.toString(), true);
|
||||
currentFieldText = new StringBuilder();
|
||||
}
|
||||
|
||||
for (Map.Entry<String, Integer> entry : onlineStaff.entrySet()){
|
||||
String serverName = entry.getKey();
|
||||
Integer amountOfStaff = entry.getValue();
|
||||
// this might error:/
|
||||
int playerCount = plugin.getProxy().getServer(serverName).isPresent() ? plugin.getProxy().getServer(serverName).get().getPlayersConnected().size() - amountOfStaff : 1;
|
||||
currentFieldText.append(serverName).append(" online staff per player ")
|
||||
.append(amountOfStaff).append(" / ").append(Math.max(playerCount, 0)).append(" = ")
|
||||
.append(playerCount > 0 ? Math.round(((double)amountOfStaff / playerCount) * 100.0) / 100.0 : "-").append("\n");
|
||||
}
|
||||
|
||||
if (currentFieldText.length() > 0) {
|
||||
rankname = "Staff per server";
|
||||
totalCharacters = title.length() + rankname.length() + currentFieldText.length();
|
||||
fieldCounter++;
|
||||
if (totalCharacters > 6000 || fieldCounter > 25) {
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, -1);
|
||||
embedBuilder.clearFields();
|
||||
}
|
||||
embedBuilder.addField(rankname, currentFieldText.toString(), true);
|
||||
}
|
||||
|
||||
bot.sendEmbedToDiscord(getChannelId(), embedBuilder, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getCommandData() {
|
||||
return commandData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChannelId() {
|
||||
return BotConfig.DISCORD.STAFF_COMMAND_CHANNEL;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package com.alttd.proxydiscordlink.bot.commandManager.commands;
|
||||
|
||||
import com.alttd.proxydiscordlink.bot.commandManager.DiscordCommand;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
|
||||
|
||||
public class DiscordSync extends DiscordCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "sync";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) { //TODO implement
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandData getCommandData() { //TODO implement
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getChannelId() { //TODO implement
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user