use of org.spongepowered.api.service.pagination.PaginationService in project Skree by Skelril.
the class WildernessMetaCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
WildernessWorldWrapper wrapper = service.getEffectWrapper(WildernessWorldWrapper.class).get();
List<Text> result = wrapper.getMetaInformation().stream().sorted(Comparator.comparing(a -> a.getKey().getName())).map(this::createLine).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Meta Info List")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.service.pagination.PaginationService in project Skree by Skelril.
the class MarketVerifyCommand 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();
Task.builder().async().execute(() -> {
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Clause<String, BigDecimal>> profitMargins = new ArrayList<>();
for (IRecipe recipe : CraftingManager.getInstance().getRecipeList()) {
ItemStack output = recipe.getRecipeOutput();
if (output == null) {
continue;
}
Optional<BigDecimal> optResultPrice = service.getPrice(tf(output));
if (!optResultPrice.isPresent()) {
continue;
}
String name = service.getAlias(tf(output)).orElse(output.getItem().getRegistryName().toString());
Collection<ItemStack> items = new ArrayList<>();
if (recipe instanceof ShapedRecipes) {
items.addAll(Lists.newArrayList(((ShapedRecipes) recipe).recipeItems));
} else if (recipe instanceof ShapelessRecipes) {
items.addAll(((ShapelessRecipes) recipe).recipeItems);
} else {
src.sendMessage(Text.of(TextColors.RED, "Unsupported recipe for " + name));
continue;
}
items.removeAll(Collections.singleton(null));
BigDecimal creationCost = BigDecimal.ZERO;
try {
for (ItemStack stack : items) {
creationCost = creationCost.add(service.getPrice(tf(stack)).orElse(BigDecimal.ZERO));
}
} catch (Exception ex) {
src.sendMessage(Text.of(TextColors.RED, "Couldn't complete checks for " + name));
continue;
}
if (creationCost.equals(BigDecimal.ZERO)) {
src.sendMessage(Text.of(TextColors.RED, "No ingredients found on market for " + name));
continue;
}
BigDecimal sellPrice = optResultPrice.get();
sellPrice = sellPrice.multiply(service.getSellFactor(sellPrice));
profitMargins.add(new Clause<>(name, sellPrice.subtract(creationCost)));
}
List<Text> result = profitMargins.stream().sorted((a, b) -> b.getValue().subtract(a.getValue()).intValue()).map(a -> {
boolean profitable = a.getValue().compareTo(BigDecimal.ZERO) >= 0;
return Text.of(profitable ? TextColors.RED : TextColors.GREEN, a.getKey().toUpperCase(), " has a profit margin of ", profitable ? "+" : "", MarketImplUtil.format(a.getValue()));
}).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Profit Margin Report")).padding(Text.of(" ")).sendTo(src);
}).submit(SkreePlugin.inst());
src.sendMessage(Text.of(TextColors.YELLOW, "Verification in progress..."));
return CommandResult.success();
}
use of org.spongepowered.api.service.pagination.PaginationService 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();
}
use of org.spongepowered.api.service.pagination.PaginationService in project Skree by Skelril.
the class RegionListMarkersCommand 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();
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<RegionPoint> points = ref.getPoints();
List<Text> result = ref.getFullPoints().stream().map(a -> Text.of((points.contains(a) ? TextColors.GREEN : TextColors.RED), a.getFloorX(), ", ", a.getFloorY(), ", ", a.getFloorZ())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Markers")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
use of org.spongepowered.api.service.pagination.PaginationService 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