use of org.spongepowered.api.command.CommandException in project TotalEconomy by Erigitic.
the class JobCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (src instanceof Player) {
Player player = ((Player) src).getPlayer().get();
String jobName = totalEconomy.getTEJobManager().getPlayerJob(player);
player.sendMessage(Text.of(TextColors.GRAY, "Current Job: ", TextColors.GOLD, totalEconomy.getTEJobManager().titleize(jobName)));
player.sendMessage(Text.of(TextColors.GRAY, totalEconomy.getTEJobManager().titleize(jobName), " Level: ", TextColors.GOLD, totalEconomy.getTEJobManager().getJobLevel(jobName, player)));
player.sendMessage(Text.of(TextColors.GRAY, totalEconomy.getTEJobManager().titleize(jobName), " Exp: ", TextColors.GOLD, totalEconomy.getTEJobManager().getJobExp(jobName, player), "/", totalEconomy.getTEJobManager().getExpToLevel(player), " exp\n"));
player.sendMessage(Text.of(TextColors.GRAY, "Available Jobs: ", TextColors.GOLD, totalEconomy.getTEJobManager().getJobList()));
return CommandResult.success();
} else {
throw new CommandException(Text.of("You can't have a job!"));
}
}
use of org.spongepowered.api.command.CommandException in project TotalEconomy by Erigitic.
the class AdminPayCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
String strAmount = (String) args.getOne("amount").get();
User recipient = args.<User>getOne("player").get();
Pattern amountPattern = Pattern.compile("^[+-]?(\\d*\\.)?\\d+$");
Matcher m = amountPattern.matcher(strAmount);
if (m.matches()) {
BigDecimal amount = new BigDecimal((String) args.getOne("amount").get()).setScale(2, BigDecimal.ROUND_DOWN);
TEAccount recipientAccount = (TEAccount) accountManager.getOrCreateAccount(recipient.getUniqueId()).get();
Text amountText = Text.of(defaultCurrency.format(amount).toPlain().replace("-", ""));
TransactionResult transactionResult = recipientAccount.deposit(totalEconomy.getDefaultCurrency(), amount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
if (transactionResult.getResult() == ResultType.SUCCESS) {
if (!strAmount.contains("-")) {
src.sendMessage(Text.of(TextColors.GRAY, "You have sent ", TextColors.GOLD, amountText, TextColors.GRAY, " to ", TextColors.GOLD, recipient.getName(), TextColors.GRAY, "."));
if (recipient.isOnline()) {
recipient.getPlayer().get().sendMessage(Text.of(TextColors.GRAY, "You have received ", TextColors.GOLD, amountText, TextColors.GRAY, " from ", TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
}
} else {
src.sendMessage(Text.of(TextColors.GRAY, "You have removed ", TextColors.GOLD, amountText, TextColors.GRAY, " from ", TextColors.GOLD, recipient.getName(), "'s", TextColors.GRAY, " account."));
if (recipient.isOnline()) {
recipient.getPlayer().get().sendMessage(Text.of(TextColors.GOLD, amountText, TextColors.GRAY, " has been removed from your account by ", TextColors.GOLD, src.getName(), TextColors.GRAY, "."));
}
}
return CommandResult.success();
}
} else {
throw new CommandException(Text.of("Invalid amount! Must be a number!"));
}
return CommandResult.empty();
}
use of org.spongepowered.api.command.CommandException 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.command.CommandException in project Skree by Skelril.
the class RegionAddMemberCommand 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> newMembers = args.<User>getAll("player").stream().map(Identifiable::getUniqueId).filter(a -> !ref.getMembers().contains(a)).collect(Collectors.toList());
ref.addMember(newMembers);
player.sendMessage(Text.of(TextColors.YELLOW, "Added ", newMembers.size(), " players to the region."));
return CommandResult.success();
}
use of org.spongepowered.api.command.CommandException 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();
}
Aggregations