mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 12:31:59 +01:00
whoall command use ListDisplay.
This commit is contained in:
parent
6b7089eec0
commit
0f23deeca1
@ -18,7 +18,6 @@ import co.aikar.commands.annotation.Subcommand;
|
||||
import co.aikar.commands.annotation.Syntax;
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ColorAlternator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.ContentFilter;
|
||||
import com.onarandombox.MultiverseCore.commandTools.display.inline.ListDisplay;
|
||||
@ -39,7 +38,6 @@ public class WhoCommand extends MultiverseCommand {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
//TODO ACF: Possibly do paging.
|
||||
@Subcommand("whoall")
|
||||
@CommandPermission("multiverse.core.list.who.all")
|
||||
@Syntax("[filter]")
|
||||
@ -54,11 +52,27 @@ public class WhoCommand extends MultiverseCommand {
|
||||
|
||||
sender.sendMessage(String.format("%s--- Worlds and their players --- %s%s/%s",
|
||||
ChatColor.GOLD, ChatColor.AQUA, visiblePlayers.size(), this.plugin.getServer().getMaxPlayers()));
|
||||
if (filter.hasFilter()) {
|
||||
sender.sendMessage(String.format("[ %s ]", filter.getFormattedString()));
|
||||
}
|
||||
|
||||
ListDisplay display = new ListDisplay().withSender(sender)
|
||||
.withFilter(filter)
|
||||
.withEmptyMessage(String.format("%sNo players found.", ChatColor.GRAY));
|
||||
|
||||
this.plugin.getMVWorldManager().getMVWorlds().stream()
|
||||
.filter(world -> player == null || this.plugin.getMVPerms().canEnterWorld(player, world))
|
||||
.forEach(world -> sender.sendMessage(String.format("%s%s - %s",
|
||||
world.getColoredWorldString(), ChatColor.WHITE, buildPlayerString(world, filter, visiblePlayers))));
|
||||
.forEach(world -> showPLayersInWorld(world, display, visiblePlayers));
|
||||
}
|
||||
|
||||
private void showPLayersInWorld(@NotNull MultiverseWorld world,
|
||||
@NotNull ListDisplay display,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
display.withCreator(buildPlayerList(world, visiblePlayers))
|
||||
.withPrefix(String.format("%s%s - ", world.getColoredWorldString(), ChatColor.WHITE))
|
||||
.build()
|
||||
.run();
|
||||
}
|
||||
|
||||
@Subcommand("who")
|
||||
@ -78,9 +92,11 @@ public class WhoCommand extends MultiverseCommand {
|
||||
@Description("Filter the player names.")
|
||||
@NotNull ContentFilter filter) {
|
||||
|
||||
Set<Player> visiblePlayers = getVisiblePlayers(player);
|
||||
|
||||
new ListDisplay().withSender(sender)
|
||||
.withHeader(String.format("%s===[ Players in %s%s ]===", ChatColor.AQUA, world.getColoredWorldString(), ChatColor.AQUA))
|
||||
.withCreator(buildPlayerList(world, player))
|
||||
.withCreator(buildPlayerList(world, visiblePlayers))
|
||||
.withFilter(filter)
|
||||
.withEmptyMessage(String.format("%sNo players found.", ChatColor.GRAY))
|
||||
.build()
|
||||
@ -89,15 +105,12 @@ public class WhoCommand extends MultiverseCommand {
|
||||
|
||||
@NotNull
|
||||
private ContentCreator<List<String>> buildPlayerList(@NotNull MultiverseWorld world,
|
||||
@Nullable Player player) {
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
return () -> {
|
||||
Set<Player> visiblePlayers = getVisiblePlayers(player);
|
||||
return world.getCBWorld().getPlayers().stream()
|
||||
.filter(visiblePlayers::contains)
|
||||
.map(Player::getDisplayName)
|
||||
.collect(Collectors.toList());
|
||||
};
|
||||
return () -> world.getCBWorld().getPlayers().stream()
|
||||
.filter(visiblePlayers::contains)
|
||||
.map(Player::getDisplayName)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -106,20 +119,4 @@ public class WhoCommand extends MultiverseCommand {
|
||||
.filter(targetPLayer -> player == null || player.canSee(targetPLayer))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String buildPlayerString(@NotNull MultiverseWorld world,
|
||||
@NotNull ContentFilter filter,
|
||||
@NotNull Set<Player> visiblePlayers) {
|
||||
|
||||
String playersInWorld = world.getCBWorld().getPlayers().stream()
|
||||
.filter(visiblePlayers::contains)
|
||||
.filter(p -> filter.checkMatch(p.getDisplayName()))
|
||||
.map(Player::getDisplayName)
|
||||
.collect(Collectors.joining(", "));
|
||||
|
||||
return (playersInWorld.isEmpty())
|
||||
? String.format("%sNo players found.", ChatColor.GRAY)
|
||||
: playersInWorld;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user