use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class SignWarp method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
final String warpName = sign.getLine(1);
final String group = sign.getLine(2);
if ((!group.isEmpty() && ("ยง2Everyone".equals(group) || player.inGroup(group))) || (group.isEmpty() && (!ess.getSettings().getPerWarpPermission() || player.isAuthorized("essentials.warps." + warpName)))) {
final Trade charge = getTrade(sign, 3, ess);
try {
player.getTeleport().warp(player, warpName, charge, TeleportCause.PLUGIN);
Trade.log("Sign", "Warp", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
} catch (Exception ex) {
throw new SignException(ex.getMessage(), ex);
}
return true;
}
return false;
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandcondense method condenseStack.
private boolean condenseStack(final User user, final ItemStack stack, final boolean validateReverse) throws ChargeException, MaxMoneyException {
final SimpleRecipe condenseType = getCondenseType(stack);
if (condenseType != null) {
final ItemStack input = condenseType.getInput();
final ItemStack result = condenseType.getResult();
if (validateReverse) {
boolean pass = false;
for (Recipe revRecipe : ess.getServer().getRecipesFor(input)) {
if (getStackOnRecipeMatch(revRecipe, result) != null) {
pass = true;
break;
}
}
if (!pass) {
return false;
}
}
int amount = 0;
for (final ItemStack contents : user.getBase().getInventory().getContents()) {
if (contents != null && contents.isSimilar(stack)) {
amount += contents.getAmount();
}
}
int output = ((amount / input.getAmount()) * result.getAmount());
amount -= amount % input.getAmount();
if (amount > 0) {
input.setAmount(amount);
result.setAmount(output);
final Trade remove = new Trade(input, ess);
final Trade add = new Trade(result, ess);
remove.charge(user);
add.pay(user, OverflowType.DROP);
return true;
}
}
return false;
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Economy method resetBalance.
/**
* Resets the balance of a user to the starting balance
*
* @param name Name of the user
*
* @throws UserDoesNotExistException If a user by that name does not exists
* @throws NoLoanPermittedException If the user is not allowed to have a negative balance
*/
public static void resetBalance(String name) throws UserDoesNotExistException, NoLoanPermittedException {
if (ess == null) {
throw new RuntimeException(noCallBeforeLoad);
}
setMoney(name, ess.getSettings().getStartingBalance());
Trade.log("API", "Reset", "API", name, new Trade(BigDecimal.ZERO, ess), null, null, null, ess);
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Economy method multiply.
public static void multiply(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException {
BigDecimal result = getMoneyExact(name).multiply(amount, MATH_CONTEXT);
setMoney(name, result);
Trade.log("API", "Multiply", "API", name, new Trade(amount, ess), null, null, null, ess);
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Economy method add.
public static void add(String name, BigDecimal amount) throws UserDoesNotExistException, NoLoanPermittedException, ArithmeticException {
BigDecimal result = getMoneyExact(name).add(amount, MATH_CONTEXT);
setMoney(name, result);
Trade.log("API", "Add", "API", name, new Trade(amount, ess), null, null, null, ess);
}
Aggregations