Example #1
0
  // TODO: Convert this to use one of the new text classes?
  public static String listKits(final IEssentials ess, final User user) throws Exception {
    try {
      final ConfigurationSection kits = ess.getSettings().getKits();
      final StringBuilder list = new StringBuilder();
      for (String kitItem : kits.getKeys(false)) {
        if (user == null) {
          list.append(" ").append(capitalCase(kitItem));
        } else if (user.isAuthorized("essentials.kits." + kitItem.toLowerCase(Locale.ENGLISH))) {
          String cost = "";
          String name = capitalCase(kitItem);
          BigDecimal costPrice =
              new Trade("kit-" + kitItem.toLowerCase(Locale.ENGLISH), ess).getCommandCost(user);
          if (costPrice.signum() > 0) {
            cost = tl("kitCost", NumberUtil.displayCurrency(costPrice, ess));
          }

          Kit kit = new Kit(kitItem, ess);
          if (kit.getNextUse(user) != 0) {
            name = tl("kitDelay", name);
          }

          list.append(" ").append(name).append(cost);
        }
      }
      return list.toString().trim();
    } catch (Exception ex) {
      throw new Exception(tl("kitError"), ex);
    }
  }
Example #2
0
 @Override
 public void payUser(final User reciever, final BigDecimal value)
     throws ChargeException, MaxMoneyException {
   if (value.signum() == 0) {
     return;
   }
   if (canAfford(value)) {
     setMoney(getMoney().subtract(value));
     reciever.setMoney(reciever.getMoney().add(value));
     sendMessage(
         tl("moneySentTo", NumberUtil.displayCurrency(value, ess), reciever.getDisplayName()));
     reciever.sendMessage(
         tl("moneyRecievedFrom", NumberUtil.displayCurrency(value, ess), getDisplayName()));
   } else {
     throw new ChargeException(tl("notEnoughMoney", NumberUtil.displayCurrency(value, ess)));
   }
 }
Example #3
0
 @Override
 public void giveMoney(final BigDecimal value, final CommandSource initiator)
     throws MaxMoneyException {
   if (value.signum() == 0) {
     return;
   }
   setMoney(getMoney().add(value));
   sendMessage(tl("addedToAccount", NumberUtil.displayCurrency(value, ess)));
   if (initiator != null) {
     initiator.sendMessage(
         tl(
             "addedToOthersAccount",
             NumberUtil.displayCurrency(value, ess),
             this.getDisplayName(),
             NumberUtil.displayCurrency(getMoney(), ess)));
   }
 }
Example #4
0
	private String getHomeName(String search)
	{
		if (NumberUtil.isInt(search))
		{
			try
			{
				search = getHomes().get(Integer.parseInt(search) - 1);
			}
			catch (Exception e)
			{
			}
		}
		return search;
	}
Example #5
0
 @Override
 public void takeMoney(final BigDecimal value, final CommandSource initiator) {
   if (value.signum() == 0) {
     return;
   }
   try {
     setMoney(getMoney().subtract(value));
   } catch (MaxMoneyException ex) {
     ess.getLogger()
         .log(
             Level.WARNING,
             "Invalid call to takeMoney, total balance can't be more than the max-money limit.",
             ex);
   }
   sendMessage(tl("takenFromAccount", NumberUtil.displayCurrency(value, ess)));
   if (initiator != null) {
     initiator.sendMessage(
         tl(
             "takenFromOthersAccount",
             NumberUtil.displayCurrency(value, ess),
             this.getDisplayName(),
             NumberUtil.displayCurrency(getMoney(), ess)));
   }
 }