2022-01-27 09:00:50 +00:00
|
|
|
package dev.plex.command.impl;
|
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
import dev.plex.command.PlexCommand;
|
|
|
|
import dev.plex.command.annotation.CommandParameters;
|
|
|
|
import dev.plex.command.annotation.CommandPermissions;
|
2022-03-19 03:33:23 +00:00
|
|
|
import dev.plex.command.annotation.System;
|
2022-01-27 09:00:50 +00:00
|
|
|
import dev.plex.rank.enums.Rank;
|
2022-01-27 21:23:01 +00:00
|
|
|
import java.util.List;
|
2022-01-27 09:00:50 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2022-02-04 04:49:05 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
2022-01-27 09:00:50 +00:00
|
|
|
|
2022-04-07 03:55:01 +00:00
|
|
|
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit")
|
2022-01-30 01:31:10 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
2022-04-01 07:54:22 +00:00
|
|
|
@System(value = "ranks")
|
2022-01-27 09:00:50 +00:00
|
|
|
public class ListCMD extends PlexCommand
|
|
|
|
{
|
|
|
|
@Override
|
2022-02-04 04:49:05 +00:00
|
|
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
2022-01-27 09:00:50 +00:00
|
|
|
{
|
|
|
|
List<Player> players = Lists.newArrayList(Bukkit.getOnlinePlayers());
|
2022-03-18 01:18:35 +00:00
|
|
|
Component list = Component.empty();
|
|
|
|
Component header = Component.text("There " + (players.size() == 1 ? "is" : "are") + " currently").color(NamedTextColor.GRAY)
|
2022-01-27 09:00:50 +00:00
|
|
|
.append(Component.space())
|
|
|
|
.append(Component.text(players.size()).color(NamedTextColor.YELLOW))
|
|
|
|
.append(Component.space())
|
2022-02-04 04:01:30 +00:00
|
|
|
.append(Component.text(players.size() == 1 ? "player" : "players").color(NamedTextColor.GRAY))
|
|
|
|
.append(Component.space())
|
|
|
|
.append(Component.text("online out of").color(NamedTextColor.GRAY))
|
2022-01-27 09:00:50 +00:00
|
|
|
.append(Component.space())
|
|
|
|
.append(Component.text(Bukkit.getMaxPlayers()).color(NamedTextColor.YELLOW))
|
2022-02-04 04:01:30 +00:00
|
|
|
.append(Component.space())
|
2022-03-18 01:18:35 +00:00
|
|
|
.append(Component.text(Bukkit.getMaxPlayers() == 1 ? "player." : "players.").color(NamedTextColor.GRAY));
|
|
|
|
send(sender, header);
|
2022-04-09 05:09:54 +00:00
|
|
|
if (players.size() == 0)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
2022-01-27 09:00:50 +00:00
|
|
|
for (int i = 0; i < players.size(); i++)
|
|
|
|
{
|
|
|
|
Player player = players.get(i);
|
2022-03-18 01:18:35 +00:00
|
|
|
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
2022-01-27 09:00:50 +00:00
|
|
|
if (i != players.size() - 1)
|
|
|
|
{
|
2022-03-18 01:18:35 +00:00
|
|
|
list = list.append(Component.text(",")).append(Component.space());
|
2022-01-27 09:00:50 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-18 01:18:35 +00:00
|
|
|
return list;
|
2022-01-27 09:00:50 +00:00
|
|
|
}
|
|
|
|
}
|