Skip to content

Commit

Permalink
Add /vanished command
Browse files Browse the repository at this point in the history
Signed-off-by: zzuf <[email protected]>
  • Loading branch information
zzufx committed Feb 10, 2024
1 parent fcd6285 commit 4a16155
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/main/java/dev/pgm/community/commands/VanishedCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package dev.pgm.community.commands;

import static net.kyori.adventure.text.Component.text;

import dev.pgm.community.CommunityCommand;
import dev.pgm.community.CommunityPermissions;
import dev.pgm.community.utils.CommandAudience;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import tc.oc.pgm.api.integration.Integration;
import tc.oc.pgm.lib.cloud.commandframework.annotations.CommandDescription;
import tc.oc.pgm.lib.cloud.commandframework.annotations.CommandMethod;
import tc.oc.pgm.lib.cloud.commandframework.annotations.CommandPermission;
import tc.oc.pgm.util.named.NameStyle;
import tc.oc.pgm.util.player.PlayerComponent;
import tc.oc.pgm.util.text.TextFormatter;

public class VanishedCommand extends CommunityCommand {
@CommandMethod("vanished")
@CommandDescription("View a list of online vanished players")
@CommandPermission(CommunityPermissions.VIEW_VANISHED)
public void viewVanished(CommandAudience viewer) {
List<Component> vanishedNames =
Bukkit.getOnlinePlayers().stream()
.filter(Integration::isVanished)
.map(player -> PlayerComponent.player(player, NameStyle.VERBOSE))
.collect(Collectors.toList());

if (vanishedNames.isEmpty()) {
viewer.sendWarning(text("No online players are vanished!"));
return;
}

Component count =
text()
.append(text("Vanished", NamedTextColor.DARK_AQUA))
.append(text(": "))
.append(text(vanishedNames.size()))
.build();
Component nameList = TextFormatter.list(vanishedNames, NamedTextColor.GRAY);

viewer.sendMessage(count);
viewer.sendMessage(nameList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import dev.pgm.community.commands.ServerInfoCommand;
import dev.pgm.community.commands.StaffCommand;
import dev.pgm.community.commands.SudoCommand;
import dev.pgm.community.commands.VanishedCommand;
import dev.pgm.community.commands.injectors.CommandAudienceProvider;
import dev.pgm.community.commands.player.TargetPlayer;
import dev.pgm.community.commands.providers.GameModeParser;
Expand Down Expand Up @@ -171,6 +172,7 @@ protected void registerCommands() {
register(new ServerInfoCommand());
register(new StaffCommand());
register(new SudoCommand());
register(new VanishedCommand());

// Community plugin command
register(new CommunityPluginCommand());
Expand Down

0 comments on commit 4a16155

Please sign in to comment.