Search in sources :

Example 1 with Text

use of org.spongepowered.api.text.Text 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();
}
Also used : java.util(java.util) ItemStack(net.minecraft.item.ItemStack) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) SkreePlugin(com.skelril.skree.SkreePlugin) 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) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) TextColors(org.spongepowered.api.text.format.TextColors) ForgeTransformer.tf(com.skelril.nitro.transformer.ForgeTransformer.tf) MarketImplUtil(com.skelril.skree.content.market.MarketImplUtil) CommandResult(org.spongepowered.api.command.CommandResult) IRecipe(net.minecraft.item.crafting.IRecipe) CommandSource(org.spongepowered.api.command.CommandSource) Sponge(org.spongepowered.api.Sponge) MarketService(com.skelril.skree.service.MarketService) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) CraftingManager(net.minecraft.item.crafting.CraftingManager) Clause(com.skelril.nitro.Clause) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) BigDecimal(java.math.BigDecimal) CommandException(org.spongepowered.api.command.CommandException) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Clause(com.skelril.nitro.Clause) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes) MarketService(com.skelril.skree.service.MarketService)

Example 2 with Text

use of org.spongepowered.api.text.Text 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();
}
Also used : WorldService(com.skelril.skree.service.WorldService) CommandResult(org.spongepowered.api.command.CommandResult) CommandSource(org.spongepowered.api.command.CommandSource) DecimalFormat(java.text.DecimalFormat) Sponge(org.spongepowered.api.Sponge) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Collectors(java.util.stream.Collectors) 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) Map(java.util.Map) Player(org.spongepowered.api.entity.living.player.Player) Comparator(java.util.Comparator) TextColors(org.spongepowered.api.text.format.TextColors) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) WorldService(com.skelril.skree.service.WorldService)

Example 3 with Text

use of org.spongepowered.api.text.Text in project Skree by Skelril.

the class MarketListCommand method createLine.

private Text createLine(ItemDescriptor entry, MarketService service) {
    String buy = format(entry.getCurrentValue());
    String sell = format(entry.getCurrentValue().multiply(service.getSellFactor(entry.getCurrentValue())));
    Text buyText = Text.of(TextColors.WHITE, buy);
    Text sellText = Text.of(TextColors.WHITE, sell);
    return Text.of(TextActions.runCommand("/market lookup " + entry.getName()), TextActions.showText(Text.of("Show detailed item information")), TextColors.BLUE, entry.getName().toUpperCase(), TextColors.GRAY, " x", format(new BigDecimal(entry.getStock())), TextColors.YELLOW, " (Quick Price: ", buyText, " - ", sellText, ")");
}
Also used : Text(org.spongepowered.api.text.Text) BigDecimal(java.math.BigDecimal)

Example 4 with Text

use of org.spongepowered.api.text.Text in project TotalEconomy by Erigitic.

the class TEJobManager method onSignInteract.

/**
     * Called when a player clicks a sign. If the clicked sign is a "Job Changing" sign then the player's job will
     * be changed on click.
     *
     * @param event InteractBlockEvent
     */
@Listener
public void onSignInteract(InteractBlockEvent event) {
    if (event.getCause().first(Player.class).isPresent()) {
        Player player = event.getCause().first(Player.class).get();
        if (event.getTargetBlock().getLocation().isPresent()) {
            Optional<TileEntity> tileEntityOpt = event.getTargetBlock().getLocation().get().getTileEntity();
            if (tileEntityOpt.isPresent()) {
                TileEntity tileEntity = tileEntityOpt.get();
                if (tileEntity instanceof Sign) {
                    Sign sign = (Sign) tileEntity;
                    Optional<SignData> data = sign.getOrCreate(SignData.class);
                    if (data.isPresent()) {
                        SignData signData = data.get();
                        Text lineOneText = signData.lines().get(0);
                        Text lineTwoText = signData.lines().get(1);
                        String lineOne = lineOneText.toPlain();
                        String lineTwo = lineTwoText.toPlain().toLowerCase();
                        if (lineOne.equals("[TEJobs]")) {
                            if (jobExists(lineTwo)) {
                                if (setJob(player, lineTwo)) {
                                    player.sendMessage(Text.of(TextColors.GRAY, "Job changed to: ", TextColors.GOLD, lineTwo));
                                } else {
                                    player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to set job. Contact your administrator."));
                                }
                            } else {
                                player.sendMessage(Text.of(TextColors.RED, "[TE] Sorry, this job does not exist"));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Player(org.spongepowered.api.entity.living.player.Player) SignData(org.spongepowered.api.data.manipulator.mutable.tileentity.SignData) Sign(org.spongepowered.api.block.tileentity.Sign) Text(org.spongepowered.api.text.Text) Listener(org.spongepowered.api.event.Listener)

Example 5 with Text

use of org.spongepowered.api.text.Text in project HuskyCrates-Sponge by codeHusky.

the class VirtualCrate method getCrateItem.

/***
     * Retrieve the crate chest.
     * @since 0.10.2
     * @param quantity the quantity of chests you want.
     * @return the ItemStack with the chest.
     */
public ItemStack getCrateItem(int quantity) {
    ItemStack stacky = ItemStack.builder().itemType(crateBlockItemType).quantity(quantity).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName)).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A placeable ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, " crate."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    stacky.offer(Keys.ITEM_LORE, itemLore);
    return ItemStack.builder().fromContainer(stacky.toContainer().set(DataQuery.of("UnsafeData", "crateID"), id)).build();
}
Also used : ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

Text (org.spongepowered.api.text.Text)285 Player (org.spongepowered.api.entity.living.player.Player)75 List (java.util.List)56 Optional (java.util.Optional)45 Collectors (java.util.stream.Collectors)44 CommandResult (org.spongepowered.api.command.CommandResult)44 CommandSource (org.spongepowered.api.command.CommandSource)44 Sponge (org.spongepowered.api.Sponge)43 ArrayList (java.util.ArrayList)38 TextColors (org.spongepowered.api.text.format.TextColors)37 ItemStack (org.spongepowered.api.item.inventory.ItemStack)36 CommandContext (org.spongepowered.api.command.args.CommandContext)35 Map (java.util.Map)32 Listener (org.spongepowered.api.event.Listener)32 Util (io.github.nucleuspowered.nucleus.Util)29 CommandException (org.spongepowered.api.command.CommandException)29 User (org.spongepowered.api.entity.living.player.User)28 TextActions (org.spongepowered.api.text.action.TextActions)26 NonnullByDefault (org.spongepowered.api.util.annotation.NonnullByDefault)25 Permissions (io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions)24