use of com.skelril.skree.service.internal.market.ItemDescriptor in project Skree by Skelril.
the class MarketListCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
return CommandResult.empty();
}
MarketService service = optService.get();
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
Optional<String> optFilter = args.getOne("name");
String filter = optFilter.isPresent() ? optFilter.get() : "";
if (!filter.matches(MarketService.VALID_ALIAS_REGEX)) {
src.sendMessage(Text.of(TextColors.RED, "Invalid filter supplied."));
return CommandResult.empty();
}
List<ItemDescriptor> prices = filter.isEmpty() ? service.getPrices() : service.getPrices(filter + "%");
if (prices.isEmpty()) {
src.sendMessage(Text.of(TextColors.YELLOW, "No items matched."));
return CommandResult.success();
}
List<Text> result = prices.stream().filter(a -> filter.isEmpty() || a.getName().startsWith(filter)).sorted(Comparator.comparing(ItemDescriptor::getCurrentValue)).map(a -> createLine(a, service)).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Item List")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
Aggregations