Example #1
0
  private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired) {
    for (ItemStack item : items) {
      if (item == null) {
        continue;
      }
      final String itemName = item.getType().toString().toLowerCase();
      final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);
      try {
        charge.isAffordableFor(user);
      } catch (ChargeException ex) {
        user.sendMessage(ex.getMessage());
        continue;
      }

      try {
        repairItem(item);
      } catch (Exception e) {
        continue;
      }
      try {
        charge.charge(user);
      } catch (ChargeException ex) {
        user.sendMessage(ex.getMessage());
      }
      repaired.add(itemName.replace('_', ' '));
    }
  }
Example #2
0
	@Override
	protected 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);
		user.sendMessage(_("backUsageMsg"));
		user.getTeleport().back(charge);
	}
 protected final void validateTrade(
     final ISign sign,
     final int amountIndex,
     final int itemIndex,
     final User player,
     final IEssentials ess)
     throws SignException {
   final Trade trade = getTrade(sign, amountIndex, itemIndex, player, ess);
   final ItemStack item = trade.getItemStack();
   sign.setLine(amountIndex, Integer.toString(item.getAmount()));
   sign.setLine(itemIndex, sign.getLine(itemIndex).trim());
 }
 protected final void validateTrade(final ISign sign, final int index, final IEssentials ess)
     throws SignException {
   final String line = sign.getLine(index).trim();
   if (line.isEmpty()) {
     return;
   }
   final Trade trade = getTrade(sign, index, 0, ess);
   final Double money = trade.getMoney();
   if (money != null) {
     sign.setLine(index, Util.formatCurrency(money, ess));
   }
 }
  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;
  }
Example #6
0
  @Override
  public void run(
      final Server server, final User user, final String commandLabel, final String[] args)
      throws Exception {
    if (args.length < 1) {
      throw new NotEnoughArgumentsException();
    }

    if (args[0].equalsIgnoreCase("hand")) {
      final ItemStack item = user.getItemInHand();
      if (item == null) {
        throw new Exception(Util.i18n("repairInvalidType"));
      }
      final String itemName = item.getType().toString().toLowerCase();
      final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), ess);

      charge.isAffordableFor(user);

      repairItem(item);

      charge.charge(user);

      user.sendMessage(Util.format("repair", itemName.replace('_', ' ')));
    } else if (args[0].equalsIgnoreCase("all")) {
      final List<String> repaired = new ArrayList<String>();
      repairItems(user.getInventory().getContents(), user, repaired);

      repairItems(user.getInventory().getArmorContents(), user, repaired);

      if (repaired.isEmpty()) {
        throw new Exception(Util.format("repairNone"));
      } else {
        user.sendMessage(Util.format("repair", Util.joinList(repaired)));
      }

    } else {
      throw new NotEnoughArgumentsException();
    }
  }
Example #7
0
	@Override
	public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
	{
		switch (args.length)
		{
		case 0:
			throw new NotEnoughArgumentsException();

		case 1:
			final User player = getPlayer(server, args, 0);
			if (!player.isTeleportEnabled())
			{
				throw new Exception(_("teleportDisabled", player.getDisplayName()));
			}
			if (user.getWorld() != player.getWorld() && ess.getSettings().getIsWorldTeleportPermissions()
				&& !user.isAuthorized("essentials.world." + player.getWorld().getName()))
			{
				throw new Exception(_("noPerm", "essentials.world." + player.getWorld().getName()));
			}
			user.sendMessage(_("teleporting"));
			final Trade charge = new Trade(this.getName(), ess);
			charge.isAffordableFor(user);
			user.getTeleport().teleport(player, charge, TeleportCause.COMMAND);
			throw new NoChargeException();

		default:
			if (!user.isAuthorized("essentials.tp.others"))
			{
				throw new Exception(_("noPerm", "essentials.tp.others"));
			}
			user.sendMessage(_("teleporting"));
			final User target = getPlayer(server, args, 0);
			final User toPlayer = getPlayer(server, args, 1);
			target.getTeleport().now(toPlayer, false, TeleportCause.COMMAND);
			target.sendMessage(_("teleportAtoB", user.getDisplayName(), toPlayer.getDisplayName()));
			break;
		}
	}