use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Economy method setMoney.
public static void setMoney(String name, BigDecimal balance) throws UserDoesNotExistException, NoLoanPermittedException {
User user = getUserByName(name);
if (user == null) {
throw new UserDoesNotExistException(name);
}
if (balance.compareTo(ess.getSettings().getMinMoney()) < 0) {
throw new NoLoanPermittedException();
}
if (balance.signum() < 0 && !user.isAuthorized("essentials.eco.loan")) {
throw new NoLoanPermittedException();
}
try {
user.setMoney(balance);
} catch (MaxMoneyException ex) {
//TODO: Update API to show max balance errors
}
Trade.log("API", "Set", "API", name, new Trade(balance, ess), null, null, null, ess);
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Economy method substract.
public static void substract(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException {
BigDecimal result = getMoneyExact(name).subtract(amount, MATH_CONTEXT);
setMoney(name, result);
Trade.log("API", "Subtract", "API", name, new Trade(amount, ess), null, null, null, ess);
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandspawn method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) {
final User otherUser = getPlayer(server, user, args, 0);
respawn(user.getSource(), user, otherUser, charge);
if (!otherUser.equals(user)) {
otherUser.sendMessage(tl("teleportAtoB", user.getDisplayName(), "spawn"));
}
} else {
respawn(user.getSource(), user, user, charge);
}
throw new NoChargeException();
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandpay method updatePlayer.
@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User player, final String[] args) throws ChargeException {
User user = ess.getUser(sender.getPlayer());
try {
if (!player.isAcceptingPay()) {
sender.sendMessage(tl("notAcceptingPay", player.getDisplayName()));
return;
}
if (user.isPromptingPayConfirm() && !amount.equals(user.getConfirmingPayments().get(player))) {
// Used to reset confirmations and inform to confirm when a new pay command has been inserted.
if (!informToConfirm) {
// User hasnt been asked to confirm payment to this player, reset all confirmed payments and ask to confirm again.
// Clear previous confirmations to ensure that a new confirmation message is brought up.
user.getConfirmingPayments().clear();
this.informToConfirm = true;
}
user.getConfirmingPayments().put(player, amount);
return;
}
user.payUser(player, amount);
user.getConfirmingPayments().remove(player);
Trade.log("Command", "Pay", "Player", user.getName(), new Trade(amount, ess), player.getName(), new Trade(amount, ess), user.getLocation(), ess);
} catch (MaxMoneyException ex) {
sender.sendMessage(tl("maxMoney"));
try {
user.setMoney(user.getMoney().add(amount));
} catch (MaxMoneyException ignored) {
// this should never happen
}
} catch (Exception e) {
sender.sendMessage(e.getMessage());
}
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandsell method sellItem.
private BigDecimal sellItem(User user, ItemStack is, String[] args, boolean isBulkSell) throws Exception {
int amount = ess.getWorth().getAmount(ess, user, is, args, isBulkSell);
BigDecimal worth = ess.getWorth().getPrice(is);
if (worth == null) {
throw new Exception(tl("itemCannotBeSold"));
}
if (amount <= 0) {
if (!isBulkSell) {
user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(BigDecimal.ZERO, ess), BigDecimal.ZERO, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)));
}
return BigDecimal.ZERO;
}
BigDecimal result = worth.multiply(BigDecimal.valueOf(amount));
//TODO: Prices for Enchantments
final ItemStack ris = is.clone();
ris.setAmount(amount);
if (!user.getBase().getInventory().containsAtLeast(ris, amount)) {
// This should never happen.
throw new IllegalStateException("Trying to remove more items than are available.");
}
user.getBase().getInventory().removeItem(ris);
user.getBase().updateInventory();
Trade.log("Command", "Sell", "Item", user.getName(), new Trade(ris, ess), user.getName(), new Trade(result, ess), user.getLocation(), ess);
user.giveMoney(result);
user.sendMessage(tl("itemSold", NumberUtil.displayCurrency(result, ess), amount, is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(worth, ess)));
logger.log(Level.INFO, tl("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)));
return result;
}
Aggregations