Exemplo n.º 1
0
	//TODO: Translate these exceptions.
	private void changeAmount(final ISign sign, final int index, final double value, final IEssentials ess) throws SignException
	{

		final String line = sign.getLine(index).trim();
		if (line.isEmpty())
		{
			throw new SignException("Empty line");
		}
		final String[] split = line.split("[ :]+");

		if (split.length == 2)
		{
			final Double money = getMoney(split[0]);
			final Double amount = getDouble(split[1]);
			if (money != null && amount != null)
			{
				final String newline = Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount + value, ess).substring(1);
				if (newline.length() > 15)
				{
					throw new SignException("This sign is full: Line too long!");
				}
				sign.setLine(index, newline);
				return;
			}
		}

		if (split.length == 3)
		{
			if (split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
			{
				final int stackamount = getIntegerPositive(split[0]);
				final int amount = getInteger(split[2]);
				final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
				if (newline.length() > 15)
				{
					throw new SignException("This sign is full: Line too long!");
				}
				sign.setLine(index, newline);
				return;
			}
			else
			{
				final int stackamount = getIntegerPositive(split[0]);
				//TODO: Unused local variable
				final ItemStack item = getItemStack(split[1], stackamount, ess);
				final int amount = getInteger(split[2]);
				final String newline = stackamount + " " + split[1] + ":" + (amount + Math.round(value));
				if (newline.length() > 15)
				{
					throw new SignException("This sign is full: Line too long!");
				}
				sign.setLine(index, newline);
				return;
			}
		}
		throw new SignException(_("invalidSignLine", index + 1));
	}
Exemplo n.º 2
0
	@Override
	public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 2)
		{
			throw new NotEnoughArgumentsException();
		}
		
		final IUser giveTo = getPlayer(args, 0);

		final ItemStack stack = ess.getItemDb().get(args[1], giveTo);

		final String itemname = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace("_", "");
		if (!GivePermissions.getPermission(stack.getType()).isAuthorized(sender))
		{
			throw new Exception(_("cantSpawnItem", itemname));
		}

		if (args.length > 3 && Util.isInt(args[2]) && Util.isInt(args[3]))
		{			
			stack.setAmount(Integer.parseInt(args[2]));
			stack.setDurability(Short.parseShort(args[3]));
		}
		else if (args.length > 2 && Integer.parseInt(args[2]) > 0)
		{
			stack.setAmount(Integer.parseInt(args[2]));
		}		

		if (args.length > 3)
		{
			for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++)
			{
				final String[] split = args[i].split("[:+',;.]", 2);
				if (split.length < 1)
				{
					continue;
				}
				final Enchantment enchantment = Commandenchant.getEnchantment(split[0], sender instanceof Player ? ess.getUser((Player)sender) : null);
				int level;
				if (split.length > 1)
				{
					level = Integer.parseInt(split[1]);
				}
				else
				{
					level = enchantment.getMaxLevel();
				}
				stack.addEnchantment(enchantment, level);
			}
		}

		if (stack.getType() == Material.AIR)
		{
			throw new Exception(_("cantSpawnItem", "Air"));
		}
		
		giveTo.giveItems(stack, false);

		//TODO: TL this.
		final String itemName = stack.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ');
		sender.sendMessage(ChatColor.BLUE + "Giving " + stack.getAmount() + " of " + itemName + " to " + giveTo.getDisplayName() + ".");
		
	}
Exemplo n.º 3
0
	protected final void validateTrade(final ISign sign, final int index, final boolean amountNeeded, final IEssentials ess) throws SignException
	{
		final String line = sign.getLine(index).trim();
		if (line.isEmpty())
		{
			throw new SignException("Empty line");
		}
		final String[] split = line.split("[ :]+");

		if (split.length == 1 && !amountNeeded)
		{
			final Double money = getMoney(split[0]);
			if (money != null)
			{
				if (Util.shortCurrency(money, ess).length() * 2 > 15)
				{
					throw new SignException("Line can be too long!");
				}
				sign.setLine(index, Util.shortCurrency(money, ess) + ":0");
				return;
			}
		}

		if (split.length == 2 && amountNeeded)
		{
			final Double money = getMoney(split[0]);
			Double amount = getDoublePositive(split[1]);
			if (money != null && amount != null)
			{
				amount -= amount % money;
				if (amount < 0.01 || money < 0.01)
				{
					throw new SignException(_("moreThanZero"));
				}
				sign.setLine(index, Util.shortCurrency(money, ess) + ":" + Util.shortCurrency(amount, ess).substring(1));
				return;
			}
		}

		if (split.length == 2 && !amountNeeded)
		{
			final int amount = getIntegerPositive(split[0]);

			if (amount < 1)
			{
				throw new SignException(_("moreThanZero"));
			}
			if (!(split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
				&& getItemStack(split[1], amount, ess).getTypeId() == 0)
			{
				throw new SignException(_("moreThanZero"));
			}
			String newline = amount + " " + split[1] + ":0";
			if ((newline + amount).length() > 15)
			{
				throw new SignException("Line can be too long!");
			}
			sign.setLine(index, newline);
			return;
		}

		if (split.length == 3 && amountNeeded)
		{
			final int stackamount = getIntegerPositive(split[0]);
			int amount = getIntegerPositive(split[2]);
			amount -= amount % stackamount;
			if (amount < 1 || stackamount < 1)
			{
				throw new SignException(_("moreThanZero"));
			}
			if (!(split[1].equalsIgnoreCase("exp") || split[1].equalsIgnoreCase("xp"))
				&& getItemStack(split[1], stackamount, ess).getTypeId() == 0)
			{
				throw new SignException(_("moreThanZero"));
			}
			sign.setLine(index, stackamount + " " + split[1] + ":" + amount);
			return;
		}
		throw new SignException(_("invalidSignLine", index + 1));
	}