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();
}
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();
}
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, ")");
}
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"));
}
}
}
}
}
}
}
}
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();
}
Aggregations