Esempio n. 1
0
	@Override
	protected boolean onSignBreak(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException
	{
		if ((sign.getLine(3).length() > 3 && sign.getLine(3).substring(2).equalsIgnoreCase(username))
			|| SignsPermissions.TRADE_OVERRIDE.isAuthorized(player))
		{
			try
			{
				final Trade stored1 = getTrade(sign, 1, true, false, ess);
				final Trade stored2 = getTrade(sign, 2, true, false, ess);
				stored1.pay(player);
				stored2.pay(player);
				Trade.log("Sign", "Trade", "Break", username, stored2, username, stored1, sign.getBlock().getLocation(), ess);
			}
			catch (SignException e)
			{
				if (SignsPermissions.TRADE_OVERRIDE.isAuthorized(player))
				{
					return true;
				}
				throw e;
			}
			return true;
		}
		else
		{
			return false;
		}
	}
Esempio n. 2
0
	@Override
	protected boolean onSignCreate(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
	{
		validateTrade(sign, 1, false, ess);
		validateTrade(sign, 2, true, ess);
		final Trade charge = getTrade(sign, 2, true, true, ess);
		charge.isAffordableFor(player);
		sign.setLine(3, "§8" + username);
		charge.charge(player);
		Trade.log("Sign", "Trade", "Create", username, charge, username, null, sign.getBlock().getLocation(), ess);
		return true;
	}
Esempio n. 3
0
	protected final void addAmount(final ISign sign, final int index, final Trade trade, final IEssentials ess) throws SignException
	{
		final Double money = trade.getMoney();
		if (money != null)
		{
			changeAmount(sign, index, money, ess);
		}
		final ItemStack item = trade.getItemStack();
		if (item != null)
		{
			changeAmount(sign, index, item.getAmount(), ess);
		}
		final Integer exp = trade.getExperience();
		if (exp != null)
		{
			changeAmount(sign, index, exp.intValue(), ess);
		}
	}
Esempio n. 4
0
	@Override
	protected boolean onSignInteract(final ISign sign, final IUser player, final String username, final IEssentials ess) throws SignException, ChargeException
	{
		if (sign.getLine(3).substring(2).equalsIgnoreCase(username))
		{
			final Trade store = rechargeSign(sign, ess, player);
			Trade stored = null;
			try
			{
				stored = getTrade(sign, 1, true, true, ess);
				subtractAmount(sign, 1, stored, ess);
				stored.pay(player);
			}
			catch (SignException e)
			{
				if (store == null)
				{
					throw new SignException(_("tradeSignEmptyOwner"), e);
				}
			}
			Trade.log("Sign", "Trade", "OwnerInteract", username, store, username, stored, sign.getBlock().getLocation(), ess);
		}
		else
		{
			final Trade charge = getTrade(sign, 1, false, false, ess);
			final Trade trade = getTrade(sign, 2, false, true, ess);
			charge.isAffordableFor(player);
			addAmount(sign, 1, charge, ess);
			subtractAmount(sign, 2, trade, ess);
			if (!trade.pay(player, false))
			{
				subtractAmount(sign, 1, charge, ess);
				addAmount(sign, 2, trade, ess);
				throw new ChargeException("Full inventory");
			}
			charge.charge(player);
			Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, sign.getBlock().getLocation(), ess);
		}
		sign.updateSign();
		return true;
	}
Esempio n. 5
0
	private Trade rechargeSign(final ISign sign, final IEssentials ess, final IUser player) throws SignException, ChargeException
	{
		final Trade trade = getTrade(sign, 2, false, false, ess);
		if (trade.getItemStack() != null && player.getItemInHand() != null
			&& trade.getItemStack().getTypeId() == player.getItemInHand().getTypeId()
			&& trade.getItemStack().getDurability() == player.getItemInHand().getDurability()
			&& trade.getItemStack().getEnchantments().equals(player.getItemInHand().getEnchantments()))
		{
			int amount = player.getItemInHand().getAmount();
			amount -= amount % trade.getItemStack().getAmount();
			if (amount > 0)
			{
				final ItemStack stack = player.getItemInHand().clone();
				stack.setAmount(amount);
				final Trade store = new Trade(stack, ess);
				addAmount(sign, 2, store, ess);
				store.charge(player);
				return store;
			}
		}
		return null;
	}