use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandback method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
if (user.getLastLocation() == null) {
throw new Exception(tl("noLocationFound"));
}
if (user.getWorld() != user.getLastLocation().getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getLastLocation().getWorld().getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + user.getLastLocation().getWorld().getName()));
}
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().back(charge);
throw new NoChargeException();
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class SignKit method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException {
final String kitName = sign.getLine(1).toLowerCase(Locale.ENGLISH).trim();
final String group = sign.getLine(2).trim();
if ((!group.isEmpty() && ("ยง2Everyone".equals(group) || player.inGroup(group))) || (group.isEmpty() && (player.isAuthorized("essentials.kits." + kitName)))) {
final Trade charge = getTrade(sign, 3, ess);
charge.isAffordableFor(player);
try {
final Kit kit = new Kit(kitName, ess);
kit.checkDelay(player);
kit.setTime(player);
kit.expandItems(player);
charge.charge(player);
Trade.log("Sign", "Kit", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess);
} catch (NoChargeException ex) {
return false;
} catch (Exception ex) {
throw new SignException(ex.getMessage(), ex);
}
return true;
} else {
if (group.isEmpty()) {
throw new SignException(tl("noKitPermission", "essentials.kits." + kitName));
} else {
throw new SignException(tl("noKitGroup", group));
}
}
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class SignProtection method checkIfSignsAreBroken.
private void checkIfSignsAreBroken(final Block block, final User player, final String username, final IEssentials ess) throws MaxMoneyException {
final Map<Location, SignProtectionState> signs = getConnectedSigns(block, player, username, false);
for (Map.Entry<Location, SignProtectionState> entry : signs.entrySet()) {
if (entry.getValue() != SignProtectionState.NOSIGN) {
final Block sign = entry.getKey().getBlock();
if (!hasAdjacentBlock(sign, block)) {
block.setType(Material.AIR);
final Trade trade = new Trade(new ItemStack(Material.SIGN, 1), ess);
trade.pay(player, OverflowType.DROP);
}
}
}
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class Commandworld method run.
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
World world;
if (args.length < 1) {
World nether = null;
final List<World> worlds = server.getWorlds();
for (World world2 : worlds) {
if (world2.getEnvironment() == World.Environment.NETHER) {
nether = world2;
break;
}
}
if (nether == null) {
return;
}
world = user.getWorld() == nether ? worlds.get(0) : nether;
} else {
world = ess.getWorld(getFinalArg(args, 0));
if (world == null) {
user.sendMessage(tl("invalidWorld"));
user.sendMessage(tl("possibleWorlds", server.getWorlds().size() - 1));
user.sendMessage(tl("typeWorldName"));
throw new NoChargeException();
}
}
if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
throw new Exception(tl("noPerm", "essentials.worlds." + world.getName()));
}
double factor;
if (user.getWorld().getEnvironment() == World.Environment.NETHER && world.getEnvironment() == World.Environment.NORMAL) {
factor = 8.0;
} else if (user.getWorld().getEnvironment() == World.Environment.NORMAL && world.getEnvironment() == World.Environment.NETHER) {
factor = 1.0 / 8.0;
} else {
factor = 1.0;
}
final Location loc = user.getLocation();
final Location target = new Location(world, loc.getBlockX() * factor + .5, loc.getBlockY(), loc.getBlockZ() * factor + .5);
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);
user.getTeleport().teleport(target, charge, TeleportCause.COMMAND);
throw new NoChargeException();
}
use of com.earth2me.essentials.Trade in project Essentials by drtshock.
the class SignSell method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException, MaxMoneyException {
Trade charge = getTrade(sign, 1, 2, player, ess);
Trade money = getTrade(sign, 3, ess);
// Check if the player is trying to sell in bulk.
if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
ItemStack heldItem = player.getItemInHand();
if (charge.getItemStack().isSimilar(heldItem)) {
int initialItemAmount = charge.getItemStack().getAmount();
int newItemAmount = heldItem.getAmount();
ItemStack item = charge.getItemStack();
item.setAmount(newItemAmount);
charge = new Trade(item, ess);
BigDecimal chargeAmount = money.getMoney();
BigDecimal pricePerSingleItem = chargeAmount.divide(new BigDecimal(initialItemAmount));
pricePerSingleItem = pricePerSingleItem.multiply(new BigDecimal(newItemAmount));
money = new Trade(pricePerSingleItem, ess);
}
}
charge.isAffordableFor(player);
money.pay(player, OverflowType.DROP);
charge.charge(player);
Trade.log("Sign", "Sell", "Interact", username, charge, username, money, sign.getBlock().getLocation(), ess);
return true;
}
Aggregations