Search in sources :

Example 36 with CommandSource

use of org.spongepowered.api.command.CommandSource in project TriggerReactor by wysohn.

the class TriggerReactor method showGlowStones.

@Override
protected void showGlowStones(ICommandSender sender, Set<Entry<SimpleLocation, Trigger>> set) {
    CommandSource source = sender.get();
    if (source instanceof Player) {
        Player player = (Player) source;
        for (Entry<SimpleLocation, Trigger> entry : set) {
            SimpleLocation sloc = entry.getKey();
            player.sendBlockChange(sloc.getX(), sloc.getY(), sloc.getZ(), BlockTypes.GLOWSTONE.getDefaultState());
        }
    }
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Player(org.spongepowered.api.entity.living.player.Player) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) CommandSource(org.spongepowered.api.command.CommandSource)

Example 37 with CommandSource

use of org.spongepowered.api.command.CommandSource in project CatClearLag by Time6628.

the class TilesCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    Optional<World> world = args.getOne(Text.of("world"));
    List<Chunk> chunksToSort = world.isPresent() ? Lists.newArrayList(world.get().getLoadedChunks()) : plugin.getGame().getServer().getWorlds().stream().flatMap(world1 -> Streams.stream(world1.getLoadedChunks())).collect(Collectors.toList());
    TreeMap<Chunk, Integer> sortedChunks = new TreeMap<>((o1, o2) -> Integer.compare(o2.getTileEntities().size(), o1.getTileEntities().size()));
    for (Chunk chunk : chunksToSort) {
        sortedChunks.put(chunk, chunk.getTileEntities().size());
    }
    List<Text> texts = new ArrayList<>();
    sortedChunks.forEach(((chunk, integer) -> texts.add(Text.builder().append(Text.of(chunk.getPosition().getX() + "," + chunk.getPosition().getZ() + " contains " + integer + " tiles.")).onClick(callback(chunk)).build())));
    plugin.getPaginationService().builder().contents((texts)).title(Text.builder().color(TextColors.LIGHT_PURPLE).append(Text.of("Laggy Chunks")).build()).sendTo(src);
    return CommandResult.success();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) CommandSource(org.spongepowered.api.command.CommandSource) Chunk(org.spongepowered.api.world.Chunk) Streams(com.google.common.collect.Streams) GenericArguments(org.spongepowered.api.command.args.GenericArguments) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) TreeMap(java.util.TreeMap) LaggyChunksCommand(me.time6628.clag.sponge.commands.LaggyChunksCommand) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) World(org.spongepowered.api.world.World) Optional(java.util.Optional) CatClearLag(me.time6628.clag.sponge.CatClearLag) TextColors(org.spongepowered.api.text.format.TextColors) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) Chunk(org.spongepowered.api.world.Chunk) TreeMap(java.util.TreeMap)

Example 38 with CommandSource

use of org.spongepowered.api.command.CommandSource in project CatClearLag by Time6628.

the class EntitiesCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) {
    Optional<World> world = args.getOne(Text.of("world"));
    List<Chunk> chunksToSort = world.isPresent() ? Lists.newArrayList(world.get().getLoadedChunks()) : plugin.getGame().getServer().getWorlds().stream().flatMap(world1 -> Streams.stream(world1.getLoadedChunks())).collect(Collectors.toList());
    TreeMap<Chunk, Integer> sortedChunks = new TreeMap<>((o1, o2) -> Integer.compare(o2.getEntities().size(), o1.getEntities().size()));
    for (Chunk chunk : chunksToSort) {
        sortedChunks.put(chunk, chunk.getEntities().size());
    }
    List<Text> texts = new ArrayList<>();
    sortedChunks.forEach(((chunk, integer) -> texts.add(Text.builder().append(Text.of(chunk.getPosition().getX() + "," + chunk.getPosition().getZ() + " in world " + chunk.getWorld().getName() + " contains " + integer + " entities.")).onClick(callback(chunk)).build())));
    plugin.getPaginationService().builder().contents((texts)).title(Text.builder().color(TextColors.LIGHT_PURPLE).append(Text.of("Laggy Chunks")).build()).sendTo(src);
    return CommandResult.success();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) CommandSource(org.spongepowered.api.command.CommandSource) Chunk(org.spongepowered.api.world.Chunk) Streams(com.google.common.collect.Streams) GenericArguments(org.spongepowered.api.command.args.GenericArguments) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) ArrayList(java.util.ArrayList) List(java.util.List) Lists(com.google.common.collect.Lists) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) TreeMap(java.util.TreeMap) LaggyChunksCommand(me.time6628.clag.sponge.commands.LaggyChunksCommand) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) World(org.spongepowered.api.world.World) Optional(java.util.Optional) CatClearLag(me.time6628.clag.sponge.CatClearLag) TextColors(org.spongepowered.api.text.format.TextColors) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) Chunk(org.spongepowered.api.world.Chunk) TreeMap(java.util.TreeMap)

Example 39 with CommandSource

use of org.spongepowered.api.command.CommandSource 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<>();
        CraftingRecipeRegistry recipeRegistry = Sponge.getRegistry().getCraftingRecipeRegistry();
        for (CraftingRecipe recipe : recipeRegistry.getRecipes()) {
            ItemStack output = recipe.getExemplaryResult().createStack();
            Optional<BigDecimal> optResultPrice = service.getPrice(output);
            if (!optResultPrice.isPresent()) {
                continue;
            }
            String name = service.getAlias(output).orElse(output.getType().getId());
            // TODO This has been roughly ported from forge to sponge
            // it may be incorrect, and also could be considerably optimized
            Collection<ItemStack> items = new ArrayList<>();
            if (recipe instanceof ShapedCraftingRecipe) {
                int height = ((ShapedCraftingRecipe) recipe).getHeight();
                int width = ((ShapedCraftingRecipe) recipe).getWidth();
                for (int x = 0; x < width; ++x) {
                    for (int y = 0; y < height; ++y) {
                        getMostExpensiveOption(service, ((ShapedCraftingRecipe) recipe).getIngredient(x, y).displayedItems()).ifPresent(items::add);
                    }
                }
            } else if (recipe instanceof ShapelessCraftingRecipe) {
                ((ShapelessCraftingRecipe) recipe).getIngredientPredicates().forEach(i -> getMostExpensiveOption(service, i.displayedItems()).ifPresent(items::add));
            } 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(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();
}
Also used : java.util(java.util) Vector2i(com.flowpowered.math.vector.Vector2i) BigDecimal(java.math.BigDecimal) QueryOperation(org.spongepowered.api.item.inventory.query.QueryOperation) Lists(com.google.common.collect.Lists) SkreePlugin(com.skelril.skree.SkreePlugin) InventoryColumn(org.spongepowered.api.item.inventory.type.InventoryColumn) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Task(org.spongepowered.api.scheduler.Task) SlotPos(org.spongepowered.api.item.inventory.property.SlotPos) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) Translation(org.spongepowered.api.text.translation.Translation) MarketImplUtil(com.skelril.skree.content.market.MarketImplUtil) CommandResult(org.spongepowered.api.command.CommandResult) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) CraftingGridInventory(org.spongepowered.api.item.inventory.crafting.CraftingGridInventory) MarketService(com.skelril.skree.service.MarketService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) InventoryTransactionResult(org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) World(org.spongepowered.api.world.World) org.spongepowered.api.item.inventory(org.spongepowered.api.item.inventory) org.spongepowered.api.item.recipe.crafting(org.spongepowered.api.item.recipe.crafting) SlotIndex(org.spongepowered.api.item.inventory.property.SlotIndex) InventoryRow(org.spongepowered.api.item.inventory.type.InventoryRow) ItemType(org.spongepowered.api.item.ItemType) Clause(com.skelril.nitro.Clause) BigDecimal(java.math.BigDecimal) CommandException(org.spongepowered.api.command.CommandException) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Clause(com.skelril.nitro.Clause) MarketService(com.skelril.skree.service.MarketService)

Example 40 with CommandSource

use of org.spongepowered.api.command.CommandSource 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();
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) GenericArguments.allOf(org.spongepowered.api.command.args.GenericArguments.allOf) User(org.spongepowered.api.entity.living.player.User) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) RegionService(com.skelril.skree.service.RegionService) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) List(java.util.List) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Region(com.skelril.skree.service.internal.region.Region) Optional(java.util.Optional) GenericArguments.user(org.spongepowered.api.command.args.GenericArguments.user) Player(org.spongepowered.api.entity.living.player.Player) TextColors(org.spongepowered.api.text.format.TextColors) Identifiable(org.spongepowered.api.util.Identifiable) Player(org.spongepowered.api.entity.living.player.Player) User(org.spongepowered.api.entity.living.player.User) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) UUID(java.util.UUID) Identifiable(org.spongepowered.api.util.Identifiable)

Aggregations

CommandSource (org.spongepowered.api.command.CommandSource)93 Text (org.spongepowered.api.text.Text)61 CommandResult (org.spongepowered.api.command.CommandResult)49 List (java.util.List)47 CommandContext (org.spongepowered.api.command.args.CommandContext)45 Collectors (java.util.stream.Collectors)39 Optional (java.util.Optional)37 Sponge (org.spongepowered.api.Sponge)37 Player (org.spongepowered.api.entity.living.player.Player)36 TextColors (org.spongepowered.api.text.format.TextColors)30 CommandElement (org.spongepowered.api.command.args.CommandElement)27 TextActions (org.spongepowered.api.text.action.TextActions)27 GenericArguments (org.spongepowered.api.command.args.GenericArguments)25 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)25 AbstractCommand (io.github.nucleuspowered.nucleus.internal.command.AbstractCommand)24 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)23 RegisterCommand (io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand)23 Util (io.github.nucleuspowered.nucleus.Util)20 Nullable (javax.annotation.Nullable)20 World (org.spongepowered.api.world.World)20