mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-23 08:25:12 +00:00
Optimize the way we list players from Discord
This commit is contained in:
parent
3eb979e36b
commit
26275745d0
1 changed files with 33 additions and 5 deletions
|
@ -1,18 +1,20 @@
|
||||||
package me.StevenLawson.TotalFreedomMod.bridge;
|
package me.StevenLawson.TotalFreedomMod.bridge;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.User;
|
||||||
import me.StevenLawson.TotalFreedomMod.Log;
|
import me.StevenLawson.TotalFreedomMod.Log;
|
||||||
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
|
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.player.PlayerList;
|
||||||
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.javacord.api.DiscordApi;
|
import org.javacord.api.DiscordApi;
|
||||||
import org.javacord.api.DiscordApiBuilder;
|
import org.javacord.api.DiscordApiBuilder;
|
||||||
import org.javacord.api.entity.channel.TextChannel;
|
import org.javacord.api.entity.channel.TextChannel;
|
||||||
import org.javacord.api.entity.message.MessageAuthor;
|
import org.javacord.api.entity.message.MessageAuthor;
|
||||||
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class DiscordBridge {
|
public class DiscordBridge {
|
||||||
|
@ -47,11 +49,37 @@ public class DiscordBridge {
|
||||||
if (author.isBotUser() || content.isEmpty()) return;
|
if (author.isBotUser() || content.isEmpty()) return;
|
||||||
|
|
||||||
if (content.equalsIgnoreCase(String.format("%sl", MainConfig.getString(ConfigurationEntry.DISCORD_PREFIX)))) {
|
if (content.equalsIgnoreCase(String.format("%sl", MainConfig.getString(ConfigurationEntry.DISCORD_PREFIX)))) {
|
||||||
// TODO: Make this shitty code better (I was very tired from a blood test whilst writing this)
|
|
||||||
|
|
||||||
EmbedBuilder builder = new EmbedBuilder()
|
EmbedBuilder builder = new EmbedBuilder()
|
||||||
.setTitle(String.format("Player List - %s", MainConfig.getString(ConfigurationEntry.SERVER_NAME)))
|
.setTitle(String.format("Player List - %s", MainConfig.getString(ConfigurationEntry.SERVER_NAME)))
|
||||||
.setDescription(String.format("There are %s / %s online players", Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()));
|
.setDescription(String.format("There are %s / %s online players", Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()));
|
||||||
|
|
||||||
|
List<PlayerRank> inGameRanks = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
User essentialsUser = EssentialsBridge.getEssentialsUser(player.getDisplayName());
|
||||||
|
|
||||||
|
if(essentialsUser != null) {
|
||||||
|
if(essentialsUser.isVanished()) continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerRank rank = PlayerRank.fromSender(player);
|
||||||
|
|
||||||
|
if(!inGameRanks.contains(rank)) inGameRanks.add(rank);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(inGameRanks);
|
||||||
|
Collections.reverse(inGameRanks);
|
||||||
|
|
||||||
|
for (PlayerRank inGameRank : inGameRanks) {
|
||||||
|
List<String> inGame = inGameRank.getInGameUsernames();
|
||||||
|
|
||||||
|
if(inGame.size() > 0) {
|
||||||
|
builder.addField(String.format("%s (%s)", inGameRank.getPlural(), inGame.size()), String.join(", ", inGame));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*// TODO: Make this shitty code better (I was very tired from a blood test whilst writing this)
|
||||||
|
|
||||||
ArrayList<String> seniorAdmins = new ArrayList<>();
|
ArrayList<String> seniorAdmins = new ArrayList<>();
|
||||||
ArrayList<String> developers = new ArrayList<>();
|
ArrayList<String> developers = new ArrayList<>();
|
||||||
ArrayList<String> impostors = new ArrayList<>();
|
ArrayList<String> impostors = new ArrayList<>();
|
||||||
|
@ -117,7 +145,7 @@ public class DiscordBridge {
|
||||||
|
|
||||||
if (impostors.size() > 0) {
|
if (impostors.size() > 0) {
|
||||||
builder.addField(String.format("Impostors (%s)", impostors.size()), String.join(", ", impostors));
|
builder.addField(String.format("Impostors (%s)", impostors.size()), String.join(", ", impostors));
|
||||||
}
|
}*/
|
||||||
|
|
||||||
CHANNEL.sendMessage(builder);
|
CHANNEL.sendMessage(builder);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue