Exemple #1
1
	public static void checkTime(final User user, final String kitName, final Map<String, Object> els) throws NoChargeException
	{
		final double delay = els.containsKey("delay") ? ((Number)els.get("delay")).doubleValue() : 0L;
		final Calendar c = new GregorianCalendar();
		c.add(Calendar.SECOND, -(int)delay);
		c.add(Calendar.MILLISECOND, -(int)((delay * 1000.0) % 1000.0));

		final long mintime = c.getTimeInMillis();

		final Long lastTime = user.getKitTimestamp(kitName);
		if (lastTime == null || lastTime < mintime)
		{
			final Calendar now = new GregorianCalendar();
			user.setKitTimestamp(kitName, now.getTimeInMillis());
		}
		else
		{
			final Calendar future = new GregorianCalendar();
			future.setTimeInMillis(lastTime);
			future.add(Calendar.SECOND, (int)delay);
			future.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
			user.sendMessage(_("kitTimed", Util.formatDateDiff(future.getTimeInMillis())));
			throw new NoChargeException();
		}
	}
 public void setTime(final User user) throws Exception {
   final Calendar time = new GregorianCalendar();
   user.setKitTimestamp(kitName, time.getTimeInMillis());
 }