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 Commandspawner method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length < 1 || args[0].length() < 2) {
throw new NotEnoughArgumentsException(tl("mobsAvailable", StringUtil.joinList(Mob.getMobList())));
}
final Location target = LocationUtil.getTarget(user.getBase());
if (target == null || target.getBlock().getType() != Material.MOB_SPAWNER) {
throw new Exception(tl("mobSpawnTarget"));
}
String name = args[0];
int delay = 0;
Mob mob = null;
mob = Mob.fromName(name);
if (mob == null) {
throw new Exception(tl("invalidMob"));
}
if (ess.getSettings().getProtectPreventSpawn(mob.getType().toString().toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("disabledToSpawnMob"));
}
if (!user.isAuthorized("essentials.spawner." + mob.name.toLowerCase(Locale.ENGLISH))) {
throw new Exception(tl("noPermToSpawnMob"));
}
if (args.length > 1) {
if (NumberUtil.isInt(args[1])) {
delay = Integer.parseInt(args[1]);
}
}
final Trade charge = new Trade("spawner-" + mob.name.toLowerCase(Locale.ENGLISH), ess);
charge.isAffordableFor(user);
try {
CreatureSpawner spawner = (CreatureSpawner) target.getBlock().getState();
spawner.setSpawnedType(mob.getType());
spawner.setDelay(delay);
spawner.update();
} catch (Throwable ex) {
throw new Exception(tl("mobSpawnError"), ex);
}
charge.charge(user);
user.sendMessage(tl("setSpawner", mob.name));
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandrepair method repairHand.
public void repairHand(User user) throws Exception {
final ItemStack item = user.getBase().getItemInHand();
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
throw new Exception(tl("repairInvalidType"));
}
if (!item.getEnchantments().isEmpty() && !ess.getSettings().getRepairEnchanted() && !user.isAuthorized("essentials.repair.enchanted")) {
throw new Exception(tl("repairEnchanted"));
}
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
charge.isAffordableFor(user);
repairItem(item);
charge.charge(user);
user.getBase().updateInventory();
user.sendMessage(tl("repair", itemName.replace('_', ' ')));
}
Aggregations