mirror of
https://github.com/TheDeus-Group/TFM-4.3-Reloaded.git
synced 2024-12-22 22:34:58 +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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import me.StevenLawson.TotalFreedomMod.admin.AdminList;
|
||||
import me.StevenLawson.TotalFreedomMod.manager.VanishManager;
|
||||
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
||||
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -9,11 +12,9 @@ import org.bukkit.command.Command;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@CommandPermissions(level = AdminLevel.ALL, source = SourceType.BOTH)
|
||||
public class Command_list extends FreedomCommand {
|
||||
|
||||
private enum ListFilter {
|
||||
ALL,
|
||||
ADMINS,
|
||||
|
@ -21,59 +22,58 @@ public class Command_list extends FreedomCommand {
|
|||
}
|
||||
|
||||
@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) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Utilities.isFromHostConsole(sender.getName())) {
|
||||
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());
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
final ListFilter listFilter;
|
||||
if (args.length == 1)
|
||||
{
|
||||
if ("-a".equals(args[0]))
|
||||
{
|
||||
if (args.length == 1) {
|
||||
if ("-a".equals(args[0])) {
|
||||
listFilter = ListFilter.ADMINS;
|
||||
}
|
||||
else if ("-i".equals(args[0]))
|
||||
{
|
||||
} else if ("-i".equals(args[0])) {
|
||||
listFilter = ListFilter.IMPOSTORS;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
listFilter = ListFilter.ALL;
|
||||
}
|
||||
|
||||
final StringBuilder onlineStats = 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(" out of a maximum ").append(ChatColor.RED).append(server.getMaxPlayers());
|
||||
onlineStats.append(ChatColor.BLUE).append("There are ").append(ChatColor.RED)
|
||||
.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.");
|
||||
|
||||
final List<String> names = new ArrayList<String>();
|
||||
for (Player player : server.getOnlinePlayers())
|
||||
{
|
||||
if (listFilter == ListFilter.ADMINS && !AdminList.isSuperAdmin(player))
|
||||
{
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
if (VanishManager.isVanished(player))
|
||||
continue;
|
||||
|
||||
if (listFilter == ListFilter.ADMINS && !AdminList.isSuperAdmin(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (listFilter == ListFilter.IMPOSTORS && !AdminList.isAdminImpostor(player))
|
||||
{
|
||||
if (listFilter == ListFilter.IMPOSTORS && !AdminList.isAdminImpostor(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -84,13 +84,10 @@ public class Command_list extends FreedomCommand {
|
|||
onlineUsers.append(listFilter == ListFilter.ADMINS ? "admins: " : "players: ");
|
||||
onlineUsers.append(StringUtils.join(names, ChatColor.WHITE + ", "));
|
||||
|
||||
if (senderIsConsole)
|
||||
{
|
||||
if (senderIsConsole) {
|
||||
sender.sendMessage(ChatColor.stripColor(onlineStats.toString()));
|
||||
sender.sendMessage(ChatColor.stripColor(onlineUsers.toString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sender.sendMessage(onlineStats.toString());
|
||||
sender.sendMessage(onlineUsers.toString());
|
||||
}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
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.config.ConfigurationEntry;
|
||||
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
|
||||
import me.StevenLawson.TotalFreedomMod.discord.command.ExecutableDiscordCommand;
|
||||
import me.StevenLawson.TotalFreedomMod.manager.VanishManager;
|
||||
import me.StevenLawson.TotalFreedomMod.player.PlayerRank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -12,33 +16,43 @@ import org.javacord.api.entity.message.embed.EmbedBuilder;
|
|||
import org.javacord.api.entity.server.Server;
|
||||
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 ListCommand(String command, String description, String category, List<String> aliases, boolean isAdmin) {
|
||||
|
||||
public ListCommand(String command, String description, String category, List<String> aliases,
|
||||
boolean isAdmin) {
|
||||
super(command, description, category, aliases, isAdmin);
|
||||
}
|
||||
|
||||
@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(), Bukkit.getMaxPlayers()));
|
||||
.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()));
|
||||
|
||||
List<PlayerRank> inGameRanks = new ArrayList<>();
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
com.earth2me.essentials.User essentialsUser = EssentialsBridge.getEssentialsUser(player.getDisplayName());
|
||||
com.earth2me.essentials.User essentialsUser = EssentialsBridge.getEssentialsUser(
|
||||
player.getDisplayName());
|
||||
|
||||
if(essentialsUser != null) {
|
||||
if(essentialsUser.isVanished()) continue;
|
||||
if (essentialsUser != null) {
|
||||
if (essentialsUser.isVanished()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (VanishManager.isVanished(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PlayerRank rank = PlayerRank.fromSender(player);
|
||||
|
||||
if(!inGameRanks.contains(rank)) inGameRanks.add(rank);
|
||||
if (!inGameRanks.contains(rank)) {
|
||||
inGameRanks.add(rank);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(inGameRanks);
|
||||
|
@ -47,8 +61,9 @@ public class ListCommand extends ExecutableDiscordCommand {
|
|||
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));
|
||||
if (inGame.size() > 0) {
|
||||
builder.addField(String.format("%s (%s)", inGameRank.getPlural(), inGame.size()),
|
||||
String.join(", ", inGame));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue