use of com.earth2me.essentials.Trade in project Essentials by EssentialsX.
the class SignSpawnmob method onSignInteract.
@Override
protected boolean onSignInteract(ISign sign, User player, String username, IEssentials ess) throws SignException, ChargeException {
final Trade charge = getTrade(sign, 3, ess);
charge.isAffordableFor(player);
try {
List<String> mobParts = SpawnMob.mobParts(sign.getLine(2));
List<String> mobData = SpawnMob.mobData(sign.getLine(2));
SpawnMob.spawnmob(ess, ess.getServer(), player.getSource(), player, mobParts, mobData, Integer.parseInt(sign.getLine(1)));
} catch (Exception ex) {
throw new SignException(ex.getMessage(), ex);
}
charge.charge(player);
Trade.log("Sign", "Spawnmob", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
return true;
}
use of com.earth2me.essentials.Trade in project Essentials by EssentialsX.
the class Commandtphere method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final User player = getPlayer(server, user, args, 0);
if (!player.isTeleportEnabled()) {
throw new Exception(tl("teleportDisabled", player.getDisplayName()));
}
if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + user.getWorld().getName()));
}
user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND);
throw new NoChargeException();
}
use of com.earth2me.essentials.Trade in project Essentials by EssentialsX.
the class Commandtppos method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (args.length < 3) {
throw new NotEnoughArgumentsException();
}
final double x = args[0].startsWith("~") ? user.getLocation().getX() + (args[0].length() > 1 ? Integer.parseInt(args[0].substring(1)) : 0) : Integer.parseInt(args[0]);
final double y = args[1].startsWith("~") ? user.getLocation().getY() + (args[1].length() > 1 ? Integer.parseInt(args[1].substring(1)) : 0) : Integer.parseInt(args[1]);
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + (args[2].length() > 1 ? Integer.parseInt(args[2].substring(1)) : 0) : Integer.parseInt(args[2]);
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
if (args.length == 4) {
World w = ess.getWorld(args[3]);
if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + w.getName()));
}
loc.setWorld(w);
}
if (args.length > 4) {
loc.setYaw((FloatUtil.parseFloat(args[3]) + 360) % 360);
loc.setPitch(FloatUtil.parseFloat(args[4]));
}
if (args.length > 5) {
World w = ess.getWorld(args[5]);
if (user.getWorld() != w && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + w.getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + w.getName()));
}
loc.setWorld(w);
}
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
throw new NoChargeException();
}
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 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);
}
Aggregations