All pastes #708310 Raw Edit

Ahmed

public java v1 · immutable
#708310 ·published 2007-09-23 19:14 UTC
rendered paste body
/* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */package net.sf.l2j.gameserver.model.entity;import net.sf.l2j.Config;import net.sf.l2j.gameserver.Announcements;/** This class is the TvTTask which is called upon by the L2J Oneo Event Manager. <br> * This class runs the TvT Engine by FBIagent. * * @author  Ahmed */public class TvTTask implements Runnable{	public void run()	{		for (;;)		{			if (Config.TVT_EVENT_ENABLED)			{			waiter(Config.TIME_BETWEEN_EVENTS * 60); // Waits the delay before starting the event (in minutes)			TvTEvent.init();			Announcements.getInstance().announceToAll("TvT Event registration opened for " + Config.TVT_EVENT_PARTICIPATION_TIME +  " minutes.");			waiter(Config.TVT_EVENT_PARTICIPATION_TIME * 60); // in config given as minutes			Announcements.getInstance().announceToAll("TvT Event Participation period has ended.");			TvTEvent.sysMsgToAllParticipants("TvT Event participants will be teleported in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + "seconds.");			waiter(Config.TVT_EVENT_RUNNING_TIME * 60); // in config given as minutes			Announcements.getInstance().announceToAll(TvTEvent.calculateRewards());			TvTEvent.sysMsgToAllParticipants("TvT Event participants will be teleported back to registration area in " + Config.TVT_EVENT_START_LEAVE_TELEPORT_DELAY + " seconds.");			TvTEvent.stopFight();			}			else				if (!Config.TVT_EVENT_ENABLED)				{					return;				}		}	}	/**	 * This method waits for a period time delay<br><br>	 *	 * @param interval<br>	 */	void waiter(int seconds)	{		while (seconds > 1)		{			seconds--; // here because we don't want to see two time announce at the same time			if (TvTEvent.isParticipating() || TvTEvent.isStarted())			{				switch (seconds)				{				case 3600: // 1 hour left					if (TvTEvent.isParticipating())					{						Announcements.getInstance().announceToAll("TvT Event registration opened for: " + seconds / 60 / 60 + "hour(s)!");					} else						if (TvTEvent.isStarted())					{						TvTEvent.sysMsgToAllParticipants("TvT Event will finish in " + seconds / 60 / 60 + "hour(s)!");					}					break;				case 1800: // 30 minutes left				case 900: // 15 minutes left				case 600: //  10 minutes left				case 300: // 5 minutes left				case 240: // 4 minutes left				case 180: // 3 minutes left				case 120: // 2 minutes left				case 60: // 1 minute left					if (TvTEvent.isParticipating())					{						Announcements.getInstance().announceToAll("TvT Event registration opened for: " + seconds / 60 + "minute(s)!");					} else						if (TvTEvent.isStarted())					{						TvTEvent.sysMsgToAllParticipants("TvT Event will finish in " + seconds / 60 + "minute(s)!");					}					break;				case 30: // 30 seconds left				case 15: // 15 seconds left				case 10: // 10 seconds left				case 5: // 5 seconds left				case 4: // 4 seconds left				case 3: // 3 seconds left				case 2: // 2 seconds left				case 1: // 1 seconds left					if (TvTEvent.isParticipating())					{						Announcements.getInstance().announceToAll("TvT Event registration opened for: " + seconds + " second(s)!");					} else						if (TvTEvent.isStarted())					{						TvTEvent.sysMsgToAllParticipants("TvT Event will finish in " + seconds + " second(s)!");					}					break;				}			}			long oneSecWaitStart = System.currentTimeMillis();			// only the try catch with Thread.sleep(1000) give bad count-down on high wait times			while (oneSecWaitStart + 1000L > System.currentTimeMillis())			{				try				{					Thread.sleep(1);				}				catch (InterruptedException ie)				{}			}		}	}}