use of org.spongepowered.api.command.CommandException in project Skree by Skelril.
the class RegionListMembersCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = ref.getMembers().stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Members")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
Aggregations