use of org.spongepowered.api.command.args.CommandContext 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.command.args.CommandContext in project Skree by Skelril.
the class RegionRemMemberCommand 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();
if (!ref.getMembers().contains(player.getUniqueId())) {
player.sendMessage(Text.of(TextColors.RED, "You must be a member of the region to modify it!"));
return CommandResult.empty();
}
List<UUID> oldMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> ref.getMembers().contains(a)).collect(Collectors.toList());
ref.remMember(oldMembers);
player.sendMessage(Text.of(TextColors.YELLOW, "Removed ", oldMembers.size(), " players from the region."));
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext in project Skree by Skelril.
the class WorldListCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
List<WorldEffectWrapper> worldEffectWrapperList = service.getEffectWrappers().stream().sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).collect(Collectors.toList());
for (WorldEffectWrapper wrapper : worldEffectWrapperList) {
String worldType = wrapper.getName();
if (!src.hasPermission("skree.world." + worldType.toLowerCase() + ".teleport")) {
continue;
}
src.sendMessage(Text.of(TextColors.GOLD, "Available ", worldType, " worlds (click to teleport):"));
for (World world : wrapper.getWorlds()) {
String worldName = world.getName();
String prettyName = worldName.replaceAll("_", " ");
src.sendMessage(Text.of(TextColors.YELLOW, TextActions.runCommand("/world " + worldName), TextActions.showText(Text.of("Teleport to " + prettyName)), " - ", prettyName));
}
}
return CommandResult.success();
}
use of org.spongepowered.api.command.args.CommandContext 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.command.args.CommandContext in project SpongeCommon by SpongePowered.
the class SpongeCommandFactory method createSpongeChunksCommand.
// Flag children
private static CommandSpec createSpongeChunksCommand() {
return CommandSpec.builder().description(Text.of("Print chunk information, optionally dump")).arguments(optional(seq(literal(Text.of("dump"), "dump"), optional(literal(Text.of("dump-all"), "all"))))).permission("sponge.command.chunks").executor(new ConfigUsingExecutor(true) {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
CommandResult res = super.execute(src, args);
if (args.hasAny("dump")) {
File file = new File(new File(new File("."), "chunk-dumps"), "chunk-info-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(Instant.now()) + "-server.txt");
src.sendMessage(Text.of("Writing chunk info to: ", file));
ChunkSaveHelper.writeChunks(file, args.hasAny("dump-all"));
src.sendMessage(Text.of("Chunk info complete"));
}
return res;
}
@Override
protected Text processGlobal(SpongeConfig<GlobalConfig> config, CommandSource source, CommandContext args) throws CommandException {
for (World world : SpongeImpl.getGame().getServer().getWorlds()) {
source.sendMessage(Text.of("World ", Text.of(TextStyles.BOLD, world.getName()), getChunksInfo(((WorldServer) world))));
}
return Text.of("Printed chunk info for all worlds ");
}
@Override
protected Text processDimension(SpongeConfig<DimensionConfig> config, DimensionType dim, CommandSource source, CommandContext args) throws CommandException {
SpongeImpl.getGame().getServer().getWorlds().stream().filter(world -> world.getDimension().getType().equals(dim)).forEach(world -> source.sendMessage(Text.of("World ", Text.of(TextStyles.BOLD, world.getName()), getChunksInfo(((WorldServer) world)))));
return Text.of("Printed chunk info for all worlds in dimension ", dim.getName());
}
@Override
protected Text processWorld(SpongeConfig<WorldConfig> config, World world, CommandSource source, CommandContext args) throws CommandException {
return getChunksInfo((WorldServer) world);
}
protected Text key(Object text) {
return Text.of(TextColors.GOLD, text);
}
protected Text value(Object text) {
return Text.of(TextColors.GRAY, text);
}
protected Text getChunksInfo(WorldServer worldserver) {
return Text.of(NEWLINE_TEXT, key("DimensionId: "), value(WorldManager.getDimensionId(worldserver)), NEWLINE_TEXT, key("Loaded chunks: "), value(worldserver.getChunkProvider().getLoadedChunkCount()), NEWLINE_TEXT, key("Active chunks: "), value(worldserver.getChunkProvider().getLoadedChunks().size()), NEWLINE_TEXT, key("Entities: "), value(worldserver.loadedEntityList.size()), NEWLINE_TEXT, key("Tile Entities: "), value(worldserver.loadedTileEntityList.size()), NEWLINE_TEXT, key("Removed Entities:"), value(worldserver.unloadedEntityList.size()), NEWLINE_TEXT, key("Removed Tile Entities: "), value(worldserver.tileEntitiesToBeRemoved), NEWLINE_TEXT);
}
}).build();
}
Aggregations