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 = FormatUtil.shortCurrency(money, ess) + ":" + FormatUtil.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 takeMoney(final double value, final CommandSender initiator)
	{
		if (value == 0)
		{
			return;
		}
		setMoney(getMoney() - value);
		sendMessage(_("{0} has been taken from your account.", FormatUtil.displayCurrency(value, ess)));
		if (initiator != null)
		{
			initiator.sendMessage(_("{0} taken from {1} account. New balance: {2}", FormatUtil.displayCurrency(value, ess), this.getPlayer().getDisplayName()));
		}
	}
Exemplo n.º 3
0
	@Override
	protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		final String whois = args[0].toLowerCase(Locale.ENGLISH);
		boolean foundUser = false;
		final Player player = sender instanceof IUser ? ((IUser)sender).getPlayer() : null;
		final IUserMap userMap = ess.getUserMap();
		for (Player onlinePlayer : server.getOnlinePlayers())
		{
			final IUser u = userMap.getUser(onlinePlayer);
			if (player != null && !player.canSee(onlinePlayer))
			{
				continue;
			}
			final Player realPlayer = u.getPlayer();
			final String displayName = FormatUtil.stripFormat(realPlayer.getDisplayName()).toLowerCase(Locale.ENGLISH);
			if (displayName.contains(whois))
			{
				foundUser = true;
				sender.sendMessage(realPlayer.getDisplayName() + " " + _("is") + " " + u.getName());
			}
		}
		if (!foundUser)
		{
			throw new NoSuchFieldException(_("Player not found."));
		}
	}
Exemplo n.º 4
0
	@Override
	public void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
	{
		if (args.length < 1)
		{
			throw new NotEnoughArgumentsException();
		}
		ess.broadcastMessage(null, _("broadcast", FormatUtil.replaceFormat(getFinalArg(args, 0))));
	}
Exemplo n.º 5
0
	@Override
	public void payUser(final IUser reciever, final double value) throws Exception
	{
		if (value == 0)
		{
			return;
		}
		if (canAfford(value))
		{
			setMoney(getMoney() - value);
			reciever.setMoney(reciever.getMoney() + value);
			sendMessage(_("{0} has been sent to {1}", FormatUtil.displayCurrency(value, ess), reciever.getPlayer().getDisplayName()));
			reciever.sendMessage(_("{0} has been received from {1}", FormatUtil.displayCurrency(value, ess), getPlayer().getDisplayName()));
		}
		else
		{
			throw new Exception(_("You do not have sufficient funds."));
		}
	}
Exemplo n.º 6
0
	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, FormatUtil.shortCurrency(money, ess));
		}
	}
	@EventHandler(priority = EventPriority.MONITOR)
	public void onPlayerQuit(final PlayerQuitEvent event)
	{
		final String quitMessage = ess.getSettings().getData().getGeneral().getLeaveMessage();
		if (quitMessage != null)
		{
			final IText itOutput = new KeywordReplacer(new SimpleTextInput(quitMessage), userMap.getUser(event.getPlayer()), ess);
			final SimpleTextPager stPager = new SimpleTextPager(itOutput);
			event.setQuitMessage(FormatUtil.replaceFormat(stPager.getString(0)));
		}
		else
		{
			event.setQuitMessage(null);
		}


		final IUser user = userMap.getUser(event.getPlayer());

		final ISettings settings = ess.getSettings();
		if (settings.getData().getCommands().getGod().isRemoveOnDisconnect() && user.isGodModeEnabled())
		{
			user.setGodModeEnabled(false);
		}
		if (user.isVanished())
		{
			user.toggleVanished();
		}
		if (user.getData().getInventory() != null)
		{
			user.getPlayer().getInventory().setContents(user.getData().getInventory().getBukkitInventory());
			user.getData().setInventory(null);
		}
		user.updateActivity(false);
		//user.getPlayer().dispose();
		if (settings.getData().getGeneral().isPtClearOnQuit())
		{
			user.getData().clearAllPowertools();
			user.queueSave();
			user.sendMessage(_("§6All powertool commands have been cleared."));
		}
	}
Exemplo n.º 8
0
	@Override
	public int compareTo(final IUser t)
	{
		return FormatUtil.stripColor(this.getPlayer().getDisplayName()).compareTo(FormatUtil.stripColor(t.getPlayer().getDisplayName()));
	}
Exemplo n.º 9
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 (FormatUtil.shortCurrency(money, ess).length() * 2 > 15)
				{
					throw new SignException("Line can be too long!");
				}
				sign.setLine(index, FormatUtil.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, FormatUtil.shortCurrency(money, ess) + ":" + FormatUtil.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));
	}