mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:24:56 +00:00
Ignore vanished players in list commands
This commit is contained in:
parent
85296bd864
commit
4769228fab
2 changed files with 77 additions and 65 deletions
|
@ -1,6 +1,9 @@
|
||||||
package me.StevenLawson.TotalFreedomMod.commands;
|
package me.StevenLawson.TotalFreedomMod.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.manager.VanishManager;
|
||||||
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
||||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -9,11 +12,9 @@ import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||||
public class Command_list extends FreedomCommand {
|
public class Command_list extends FreedomCommand {
|
||||||
|
|
||||||
private enum ListFilter {
|
private enum ListFilter {
|
||||||
ALL,
|
ALL,
|
||||||
ADMINS,
|
ADMINS,
|
||||||
|
@ -21,59 +22,58 @@ public class Command_list extends FreedomCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) {
|
public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd,
|
||||||
|
String commandLabel, String[] args, boolean senderIsConsole) {
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utilities.isFromHostConsole(sender.getName())) {
|
if (Utilities.isFromHostConsole(sender.getName())) {
|
||||||
final List<String> names = new ArrayList<String>();
|
final List<String> names = new ArrayList<String>();
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers()) {
|
||||||
{
|
if (VanishManager.isVanished(player)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
names.add(player.getName());
|
names.add(player.getName());
|
||||||
}
|
}
|
||||||
playerMsg(sender, "There are " + names.size() + "/" + server.getMaxPlayers() + " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE);
|
playerMsg(sender,
|
||||||
|
"There are " + names.size() + "/" + VanishManager.getFakeOnlinePlayers()
|
||||||
|
+ " players online:\n" + StringUtils.join(names, ", "), ChatColor.WHITE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ListFilter listFilter;
|
final ListFilter listFilter;
|
||||||
if (args.length == 1)
|
if (args.length == 1) {
|
||||||
{
|
if ("-a".equals(args[0])) {
|
||||||
if ("-a".equals(args[0]))
|
|
||||||
{
|
|
||||||
listFilter = ListFilter.ADMINS;
|
listFilter = ListFilter.ADMINS;
|
||||||
}
|
} else if ("-i".equals(args[0])) {
|
||||||
else if ("-i".equals(args[0]))
|
|
||||||
{
|
|
||||||
listFilter = ListFilter.IMPOSTORS;
|
listFilter = ListFilter.IMPOSTORS;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
listFilter = ListFilter.ALL;
|
listFilter = ListFilter.ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder onlineStats = new StringBuilder();
|
final StringBuilder onlineStats = new StringBuilder();
|
||||||
final StringBuilder onlineUsers = new StringBuilder();
|
final StringBuilder onlineUsers = new StringBuilder();
|
||||||
|
|
||||||
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED).append(server.getOnlinePlayers().size());
|
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED)
|
||||||
onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers());
|
.append(VanishManager.getFakeOnlinePlayers());
|
||||||
|
onlineStats.append(ChatColor.BLUE).append(" out of a maximum ").append(ChatColor.RED)
|
||||||
|
.append(server.getMaxPlayers());
|
||||||
onlineStats.append(ChatColor.BLUE).append(" players online.");
|
onlineStats.append(ChatColor.BLUE).append(" players online.");
|
||||||
|
|
||||||
final List<String> names = new ArrayList<String>();
|
final List<String> names = new ArrayList<String>();
|
||||||
for (Player player : server.getOnlinePlayers())
|
for (Player player : server.getOnlinePlayers()) {
|
||||||
{
|
if (VanishManager.isVanished(player))
|
||||||
if (listFilter == ListFilter.ADMINS && !AdminList.isSuperAdmin(player))
|
continue;
|
||||||
{
|
|
||||||
|
if (listFilter == ListFilter.ADMINS && !AdminList.isSuperAdmin(player)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listFilter == ListFilter.IMPOSTORS && !AdminList.isAdminImpostor(player))
|
if (listFilter == ListFilter.IMPOSTORS && !AdminList.isAdminImpostor(player)) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +84,10 @@ public class Command_list extends FreedomCommand {
|
||||||
onlineUsers.append(listFilter == ListFilter.ADMINS ? "admins: " : "players: ");
|
onlineUsers.append(listFilter == ListFilter.ADMINS ? "admins: " : "players: ");
|
||||||
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
|
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
|
||||||
|
|
||||||
if (senderIsConsole)
|
if (senderIsConsole) {
|
||||||
{
|
|
||||||
sender.sendMessage(ChatColor.stripColor(onlineStats.toString()));
|
sender.sendMessage(ChatColor.stripColor(onlineStats.toString()));
|
||||||
sender.sendMessage(ChatColor.stripColor(onlineUsers.toString()));
|
sender.sendMessage(ChatColor.stripColor(onlineUsers.toString()));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
sender.sendMessage(onlineStats.toString());
|
sender.sendMessage(onlineStats.toString());
|
||||||
sender.sendMessage(onlineUsers.toString());
|
sender.sendMessage(onlineUsers.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package me.StevenLawson.TotalFreedomMod.discord.commands;
|
package me.StevenLawson.TotalFreedomMod.discord.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge;
|
import me.StevenLawson.TotalFreedomMod.bridge.EssentialsBridge;
|
||||||
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.discord.command.ExecutableDiscordCommand;
|
import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.manager.VanishManager;
|
||||||
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.bukkit.entity.Player;
|
||||||
|
@ -12,46 +16,57 @@ import org.javacord.api.entity.message.embed.EmbedBuilder;
|
||||||
import org.javacord.api.entity.server.Server;
|
import org.javacord.api.entity.server.Server;
|
||||||
import org.javacord.api.entity.user.User;
|
import org.javacord.api.entity.user.User;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ListCommand extends ExecutableDiscordCommand {
|
public class ListCommand extends ExecutableDiscordCommand {
|
||||||
public ListCommand(String command, String description, String category, List<String> aliases, boolean isAdmin) {
|
|
||||||
super(command, description, category, aliases, isAdmin);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
public ListCommand(String command, String description, String category, List<String> aliases,
|
||||||
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
boolean isAdmin) {
|
||||||
EmbedBuilder builder = new EmbedBuilder()
|
super(command, description, category, aliases, isAdmin);
|
||||||
.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()));
|
|
||||||
|
|
||||||
List<PlayerRank> inGameRanks = new ArrayList<>();
|
@Override
|
||||||
|
public MessageBuilder execute(User user, List<String> args, Server guild) {
|
||||||
|
EmbedBuilder builder = new EmbedBuilder()
|
||||||
|
.setTitle(String.format("Player List - %s",
|
||||||
|
MainConfig.getString(ConfigurationEntry.SERVER_NAME)))
|
||||||
|
.setDescription(
|
||||||
|
String.format("There are %s / %s online players", Bukkit.getOnlinePlayers().size(),
|
||||||
|
VanishManager.getFakeOnlinePlayers()));
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
List<PlayerRank> inGameRanks = new ArrayList<>();
|
||||||
com.earth2me.essentials.User essentialsUser = EssentialsBridge.getEssentialsUser(player.getDisplayName());
|
|
||||||
|
|
||||||
if(essentialsUser != null) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if(essentialsUser.isVanished()) continue;
|
com.earth2me.essentials.User essentialsUser = EssentialsBridge.getEssentialsUser(
|
||||||
|
player.getDisplayName());
|
||||||
|
|
||||||
|
if (essentialsUser != null) {
|
||||||
|
if (essentialsUser.isVanished()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VanishManager.isVanished(player)) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerRank rank = PlayerRank.fromSender(player);
|
PlayerRank rank = PlayerRank.fromSender(player);
|
||||||
|
|
||||||
if(!inGameRanks.contains(rank)) inGameRanks.add(rank);
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new MessageBuilder().addEmbed(builder);
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MessageBuilder().addEmbed(builder);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue