mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-23 07:34:56 +00:00
Merge pull request #2 from TheDeus-Group/development
Optimize discord list command
This commit is contained in:
commit
8e8d95ce9b
5 changed files with 105 additions and 81 deletions
2
pom.xml
2
pom.xml
|
@ -41,7 +41,7 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>bukkit</artifactId>
|
<artifactId>craftbukkit</artifactId>
|
||||||
<version>1.8.8-R0.1-SNAPSHOT</version>
|
<version>1.8.8-R0.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class Announcer
|
||||||
current = 0;
|
current = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utilities.bcastMsg(prefix + ANNOUNCEMENTS.get(current));
|
Utilities.bcastMsg(prefix + ANNOUNCEMENTS.get(current), false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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,76 +49,33 @@ 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()));
|
||||||
ArrayList<String> seniorAdmins = new ArrayList<>();
|
|
||||||
ArrayList<String> developers = new ArrayList<>();
|
|
||||||
ArrayList<String> impostors = new ArrayList<>();
|
|
||||||
ArrayList<String> deopped = new ArrayList<>();
|
|
||||||
ArrayList<String> operators = new ArrayList<>();
|
|
||||||
ArrayList<String> superAdmins = new ArrayList<>();
|
|
||||||
ArrayList<String> superTelnetAdmins = new ArrayList<>();
|
|
||||||
ArrayList<String> owners = new ArrayList<>();
|
|
||||||
|
|
||||||
for (org.bukkit.entity.Player player : Bukkit.getOnlinePlayers()) {
|
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);
|
PlayerRank rank = PlayerRank.fromSender(player);
|
||||||
|
|
||||||
if (EssentialsBridge.getEssentialsUser(player.getName()).isVanished()) {
|
if(!inGameRanks.contains(rank)) inGameRanks.add(rank);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rank.equals(PlayerRank.IMPOSTOR)) {
|
Collections.sort(inGameRanks);
|
||||||
impostors.add(player.getName());
|
Collections.reverse(inGameRanks);
|
||||||
} else if (rank.equals(PlayerRank.DEVELOPER)) {
|
|
||||||
developers.add(player.getName());
|
|
||||||
} else if (rank.equals(PlayerRank.NON_OP)) {
|
|
||||||
deopped.add(player.getName());
|
|
||||||
} else if (rank.equals(PlayerRank.SENIOR)) {
|
|
||||||
seniorAdmins.add(player.getName());
|
|
||||||
} else if (rank.equals(PlayerRank.OWNER)) {
|
|
||||||
owners.add(player.getName());
|
|
||||||
} else if (rank.equals(PlayerRank.OP)) {
|
|
||||||
operators.add(player.getName());
|
|
||||||
} else if (rank.equals(PlayerRank.SUPER)) {
|
|
||||||
superAdmins.add(player.getName());
|
|
||||||
} else if (rank.equals(PlayerRank.TELNET)) {
|
|
||||||
superTelnetAdmins.add(player.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (owners.size() > 0) {
|
for (PlayerRank inGameRank : inGameRanks) {
|
||||||
builder.addField(String.format("Owners (%s)", owners.size()), String.join(", ", owners));
|
List<String> inGame = inGameRank.getInGameUsernames();
|
||||||
}
|
|
||||||
|
|
||||||
if (seniorAdmins.size() > 0) {
|
if(inGame.size() > 0) {
|
||||||
builder.addField(String.format("Senior Admins (%s)", seniorAdmins.size()), String.join(", ", seniorAdmins));
|
builder.addField(String.format("%s (%s)", inGameRank.getPlural(), inGame.size()), String.join(", ", inGame));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (developers.size() > 0) {
|
|
||||||
builder.addField(String.format("Developers (%s)", developers.size()), String.join(", ", developers));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (superTelnetAdmins.size() > 0) {
|
|
||||||
builder.addField(String.format("Super Telnet Admins (%s)", superTelnetAdmins.size()), String.join(", ", superTelnetAdmins));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (superAdmins.size() > 0) {
|
|
||||||
builder.addField(String.format("Super Admins (%s)", superAdmins.size()), String.join(", ", seniorAdmins));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (operators.size() > 0) {
|
|
||||||
builder.addField(String.format("Operators (%s)", operators.size()), String.join(", ", operators));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deopped.size() > 0) {
|
|
||||||
builder.addField(String.format("Non-Operators (%s)", deopped.size()), String.join(", ", deopped));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (impostors.size() > 0) {
|
|
||||||
builder.addField(String.format("Impostors (%s)", impostors.size()), String.join(", ", impostors));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CHANNEL.sendMessage(builder);
|
CHANNEL.sendMessage(builder);
|
||||||
|
|
|
@ -1,33 +1,53 @@
|
||||||
package me.StevenLawson.TotalFreedomMod.player;
|
package me.StevenLawson.TotalFreedomMod.player;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
import me.StevenLawson.TotalFreedomMod.admin.Admin;
|
import me.StevenLawson.TotalFreedomMod.admin.Admin;
|
||||||
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
||||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static me.StevenLawson.TotalFreedomMod.util.Utilities.DEVELOPERS;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public enum PlayerRank
|
import static me.StevenLawson.TotalFreedomMod.util.Utilities.DEVELOPERS;
|
||||||
|
import static me.StevenLawson.TotalFreedomMod.util.Utilities.getPluginFile;
|
||||||
|
|
||||||
|
public enum PlayerRank implements Comparator<PlayerRank>, Comparable<PlayerRank>
|
||||||
{
|
{
|
||||||
DEVELOPER("a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[Dev]"),
|
IMPOSTOR("an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "Impostor", ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + "[IMP]", "Impostors", 0),
|
||||||
IMPOSTOR("an " + ChatColor.YELLOW + ChatColor.UNDERLINE + "Impostor", ChatColor.YELLOW.toString() + ChatColor.UNDERLINE + "[IMP]"),
|
NON_OP("a " + ChatColor.GREEN + "Non-OP", ChatColor.GREEN.toString(), "Non-Operators", 1),
|
||||||
NON_OP("a " + ChatColor.GREEN + "Non-OP", ChatColor.GREEN.toString()),
|
OP("an " + ChatColor.RED + "OP", ChatColor.RED + "[OP]", "Operators" ,2),
|
||||||
OP("an " + ChatColor.RED + "OP", ChatColor.RED + "[OP]"),
|
SUPER("a " + ChatColor.GOLD + "Super Admin", ChatColor.GOLD + "[SA]", "Super Admins", 3),
|
||||||
SUPER("a " + ChatColor.GOLD + "Super Admin", ChatColor.GOLD + "[SA]"),
|
TELNET("a " + ChatColor.DARK_GREEN + "Super Telnet Admin", ChatColor.DARK_GREEN + "[STA]", "Super Telnet Admins", 4),
|
||||||
TELNET("a " + ChatColor.DARK_GREEN + "Super Telnet Admin", ChatColor.DARK_GREEN + "[STA]"),
|
SENIOR("a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]", "Senior Admins", 5),
|
||||||
SENIOR("a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"),
|
DEVELOPER("a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[Dev]", "Developers", 6),
|
||||||
OWNER("the " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]"),
|
OWNER("the " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]", "Owners", 7),
|
||||||
CONSOLE("The " + ChatColor.DARK_PURPLE + "Console", ChatColor.DARK_PURPLE + "[Console]");
|
CONSOLE("The " + ChatColor.DARK_PURPLE + "Console", ChatColor.DARK_PURPLE + "[Console]", 8);
|
||||||
private final String loginMessage;
|
private final String loginMessage;
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
|
|
||||||
private PlayerRank(String loginMessage, String prefix)
|
private final String plural;
|
||||||
|
private final int ordinal;
|
||||||
|
|
||||||
|
|
||||||
|
PlayerRank(String loginMessage, String prefix, int ordinal) {
|
||||||
|
this.loginMessage = loginMessage;
|
||||||
|
this.prefix = prefix;
|
||||||
|
this.plural = "";
|
||||||
|
this.ordinal = ordinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerRank(String loginMessage, String prefix, String plural, int ordinal)
|
||||||
{
|
{
|
||||||
this.loginMessage = loginMessage;
|
this.loginMessage = loginMessage;
|
||||||
this.prefix = prefix;
|
this.prefix = prefix;
|
||||||
|
this.plural = plural;
|
||||||
|
this.ordinal = ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLoginMessage(CommandSender sender)
|
public static String getLoginMessage(CommandSender sender)
|
||||||
|
@ -122,4 +142,39 @@ public enum PlayerRank
|
||||||
{
|
{
|
||||||
return loginMessage;
|
return loginMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getPlural() {
|
||||||
|
return plural;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrdinal() {
|
||||||
|
return ordinal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Player> getWithRank() {
|
||||||
|
List<Player> inGame = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if(fromSender(onlinePlayer).equals(this)) inGame.add(onlinePlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImmutableList.copyOf(inGame);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getInGameUsernames() {
|
||||||
|
List<String> inGame = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if(fromSender(onlinePlayer).equals(this)) inGame.add(onlinePlayer.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ImmutableList.copyOf(inGame);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(PlayerRank o1, PlayerRank o2) {
|
||||||
|
return o1.ordinal - o2.ordinal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,15 +84,25 @@ public class Utilities
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void bcastMsg(String message, ChatColor color) {
|
public static void bcastMsg(String message, ChatColor color, boolean transmitToDiscord) {
|
||||||
Log.info(message, true);
|
Log.info(message, true);
|
||||||
|
|
||||||
for (org.bukkit.entity.Player player : Bukkit.getOnlinePlayers()) {
|
for (org.bukkit.entity.Player player : Bukkit.getOnlinePlayers()) {
|
||||||
player.sendMessage((color == null ? "" : color) + message);
|
player.sendMessage((color == null ? "" : color) + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(transmitToDiscord) {
|
||||||
DiscordBridge.transmitMessage(message);
|
DiscordBridge.transmitMessage(message);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void bcastMsg(String message, ChatColor color) {
|
||||||
|
bcastMsg(message, color, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void bcastMsg(String message, boolean transmitToDiscord) {
|
||||||
|
bcastMsg(message, null, transmitToDiscord);
|
||||||
|
}
|
||||||
|
|
||||||
public static void bcastMsg(String message)
|
public static void bcastMsg(String message)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue