Chronicle 4 branch.
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.L2Character;
|
||||
import com.l2jmobius.gameserver.model.L2Summon;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
|
||||
|
||||
import javolution.util.FastMap;
|
||||
|
||||
/**
|
||||
* This class ...
|
||||
* @version $Revision: $ $Date: $
|
||||
* @author Luca Baldi
|
||||
*/
|
||||
public class AttackStanceTaskManager
|
||||
{
|
||||
protected static Logger _log = Logger.getLogger(AttackStanceTaskManager.class.getName());
|
||||
|
||||
protected Map<L2Character, Long> _attackStanceTasks = new FastMap<L2Character, Long>().shared();
|
||||
|
||||
public static AttackStanceTaskManager _instance;
|
||||
|
||||
public AttackStanceTaskManager()
|
||||
{
|
||||
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FightModeScheduler(), 0, 1000);
|
||||
}
|
||||
|
||||
public static AttackStanceTaskManager getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new AttackStanceTaskManager();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void addAttackStanceTask(L2Character actor)
|
||||
{
|
||||
if (actor instanceof L2Summon)
|
||||
{
|
||||
final L2Summon summon = (L2Summon) actor;
|
||||
actor = summon.getOwner();
|
||||
}
|
||||
_attackStanceTasks.put(actor, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void removeAttackStanceTask(L2Character actor)
|
||||
{
|
||||
if (actor instanceof L2Summon)
|
||||
{
|
||||
final L2Summon summon = (L2Summon) actor;
|
||||
actor = summon.getOwner();
|
||||
}
|
||||
_attackStanceTasks.remove(actor);
|
||||
}
|
||||
|
||||
public boolean getAttackStanceTask(L2Character actor)
|
||||
{
|
||||
if (actor instanceof L2Summon)
|
||||
{
|
||||
final L2Summon summon = (L2Summon) actor;
|
||||
actor = summon.getOwner();
|
||||
}
|
||||
return _attackStanceTasks.containsKey(actor);
|
||||
}
|
||||
|
||||
private class FightModeScheduler implements Runnable
|
||||
{
|
||||
protected FightModeScheduler()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final Long current = System.currentTimeMillis();
|
||||
try
|
||||
{
|
||||
if (_attackStanceTasks != null)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
for (final L2Character actor : _attackStanceTasks.keySet())
|
||||
{
|
||||
if ((current - _attackStanceTasks.get(actor)) > 15000)
|
||||
{
|
||||
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
|
||||
if ((actor instanceof L2PcInstance) && (((L2PcInstance) actor).getPet() != null))
|
||||
{
|
||||
((L2PcInstance) actor).getPet().broadcastPacket(new AutoAttackStop(((L2PcInstance) actor).getPet().getObjectId()));
|
||||
}
|
||||
actor.getAI().setAutoAttacking(false);
|
||||
_attackStanceTasks.remove(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Throwable e)
|
||||
{
|
||||
// TODO: Find out the reason for exception. Unless caught here, players remain in attack positions.
|
||||
_log.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.L2DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.util.Broadcast;
|
||||
|
||||
import javolution.util.FastList;
|
||||
|
||||
/**
|
||||
* @author nBd
|
||||
*/
|
||||
public class AutoAnnounceTaskManager
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(AutoAnnounceTaskManager.class.getName());
|
||||
|
||||
private static AutoAnnounceTaskManager _instance;
|
||||
protected List<AutoAnnouncement> _announces = new FastList<>();
|
||||
|
||||
public static AutoAnnounceTaskManager getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new AutoAnnounceTaskManager();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public AutoAnnounceTaskManager()
|
||||
{
|
||||
restore();
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
if (!_announces.isEmpty())
|
||||
{
|
||||
for (final AutoAnnouncement a : _announces)
|
||||
{
|
||||
a.stopAnnounce();
|
||||
}
|
||||
|
||||
_announces.clear();
|
||||
}
|
||||
|
||||
java.sql.Connection con = null;
|
||||
@SuppressWarnings("unused")
|
||||
final int count = 0;
|
||||
try
|
||||
{
|
||||
con = L2DatabaseFactory.getInstance().getConnection();
|
||||
final PreparedStatement statement = con.prepareStatement("SELECT id, initial, delay, cycle, memo FROM auto_announcements");
|
||||
final ResultSet data = statement.executeQuery();
|
||||
|
||||
while (data.next())
|
||||
{
|
||||
final int id = data.getInt("id");
|
||||
final long initial = data.getLong("initial");
|
||||
final long delay = data.getLong("delay");
|
||||
final int repeat = data.getInt("cycle");
|
||||
final String memo = data.getString("memo");
|
||||
final String[] text = memo.split("/n");
|
||||
ThreadPoolManager.getInstance().scheduleGeneral(new AutoAnnouncement(id, delay, repeat, text), initial);
|
||||
}
|
||||
data.close();
|
||||
statement.close();
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
_log.log(Level.SEVERE, "AutoAnnouncements: Failed to load announcements data.", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (con != null)
|
||||
{
|
||||
con.close();
|
||||
}
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
_log.log(Level.INFO, "AutoAnnouncements: Loaded " + _announces.size() + " Auto Announcement Data.");
|
||||
}
|
||||
|
||||
private class AutoAnnouncement implements Runnable
|
||||
{
|
||||
private final int _id;
|
||||
private final long _delay;
|
||||
private int _repeat = -1;
|
||||
private final String[] _memo;
|
||||
private boolean _stopped = false;
|
||||
|
||||
public AutoAnnouncement(int id, long delay, int repeat, String[] memo)
|
||||
{
|
||||
_id = id;
|
||||
_delay = delay;
|
||||
_repeat = repeat;
|
||||
_memo = memo;
|
||||
if (!_announces.contains(this))
|
||||
{
|
||||
_announces.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopAnnounce()
|
||||
{
|
||||
_stopped = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
for (final String text : _memo)
|
||||
{
|
||||
announce(text);
|
||||
}
|
||||
|
||||
if (!_stopped && (_repeat > 0))
|
||||
{
|
||||
ThreadPoolManager.getInstance().scheduleGeneral(new AutoAnnouncement(_id, _delay, _repeat--, _memo), _delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void announce(String text)
|
||||
{
|
||||
Broadcast.announceToOnlinePlayers(text);
|
||||
_log.warning("AutoAnnounce: " + text);
|
||||
}
|
||||
}
|
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2RaidBossInstance;
|
||||
|
||||
import javolution.util.FastMap;
|
||||
|
||||
/**
|
||||
* @author la2 Lets drink to code!
|
||||
*/
|
||||
public class DecayTaskManager
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(DecayTaskManager.class.getName());
|
||||
protected Map<L2Character, Long> _decayTasks = new FastMap<L2Character, Long>().shared();
|
||||
|
||||
public static DecayTaskManager _instance;
|
||||
|
||||
public DecayTaskManager()
|
||||
{
|
||||
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new DecayScheduler(), 10000, 5000);
|
||||
}
|
||||
|
||||
public static DecayTaskManager getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new DecayTaskManager();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public void addDecayTask(L2Character actor)
|
||||
{
|
||||
_decayTasks.put(actor, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void addDecayTask(L2Character actor, int interval)
|
||||
{
|
||||
_decayTasks.put(actor, System.currentTimeMillis() + interval);
|
||||
}
|
||||
|
||||
public void cancelDecayTask(L2Character actor)
|
||||
{
|
||||
try
|
||||
{
|
||||
_decayTasks.remove(actor);
|
||||
}
|
||||
catch (final NoSuchElementException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private class DecayScheduler implements Runnable
|
||||
{
|
||||
protected DecayScheduler()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
final Long current = System.currentTimeMillis();
|
||||
int delay;
|
||||
try
|
||||
{
|
||||
if (_decayTasks != null)
|
||||
{
|
||||
for (final L2Character actor : _decayTasks.keySet())
|
||||
{
|
||||
if (actor instanceof L2RaidBossInstance)
|
||||
{
|
||||
delay = 30000;
|
||||
}
|
||||
else
|
||||
{
|
||||
delay = 8500;
|
||||
}
|
||||
if ((current - _decayTasks.get(actor)) > delay)
|
||||
{
|
||||
actor.onDecay();
|
||||
_decayTasks.remove(actor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Throwable e)
|
||||
{
|
||||
// TODO: Find out the reason for exception. Unless caught here, mob decay would stop.
|
||||
_log.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
String ret = "============= DecayTask Manager Report ============\r\n";
|
||||
ret += "Tasks count: " + _decayTasks.size() + "\r\n";
|
||||
ret += "Tasks dump:\r\n";
|
||||
|
||||
final Long current = System.currentTimeMillis();
|
||||
for (final L2Character actor : _decayTasks.keySet())
|
||||
{
|
||||
ret += "Class/Name: " + actor.getClass().getSimpleName() + "/" + actor.getName() + " decay timer: " + (current - _decayTasks.get(actor)) + "\r\n";
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.model.L2Character;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.L2WorldRegion;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2GuardInstance;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PlayableInstance;
|
||||
|
||||
public class KnownListUpdateTaskManager
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(KnownListUpdateTaskManager.class.getName());
|
||||
|
||||
private static KnownListUpdateTaskManager _instance;
|
||||
|
||||
private final static int FULL_UPDATE_TIMER = 100;
|
||||
public static boolean updatePass = true;
|
||||
|
||||
// Do full update every FULL_UPDATE_TIMER * KNOWNLIST_UPDATE_INTERVAL
|
||||
public static int _fullUpdateTimer = FULL_UPDATE_TIMER;
|
||||
|
||||
public KnownListUpdateTaskManager()
|
||||
{
|
||||
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new KnownListUpdate(), 1000, Config.KNOWNLIST_UPDATE_INTERVAL);
|
||||
}
|
||||
|
||||
public static KnownListUpdateTaskManager getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new KnownListUpdateTaskManager();
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
|
||||
private class KnownListUpdate implements Runnable
|
||||
{
|
||||
|
||||
protected KnownListUpdate()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
for (final L2WorldRegion regions[] : L2World.getInstance().getAllWorldRegions())
|
||||
{
|
||||
for (final L2WorldRegion r : regions) // go through all world regions
|
||||
{
|
||||
try
|
||||
{
|
||||
if (r.isActive())
|
||||
{
|
||||
updateRegion(r, (_fullUpdateTimer == FULL_UPDATE_TIMER), updatePass);
|
||||
}
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
updatePass = !updatePass;
|
||||
if (_fullUpdateTimer > 0)
|
||||
{
|
||||
_fullUpdateTimer--;
|
||||
}
|
||||
else
|
||||
{
|
||||
_fullUpdateTimer = FULL_UPDATE_TIMER;
|
||||
}
|
||||
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
_log.warning(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRegion(L2WorldRegion region, boolean fullUpdate, boolean forgetObjects)
|
||||
{
|
||||
for (final L2Object object : region.getVisibleObjects()) // and for all members in region
|
||||
{
|
||||
if ((object == null) || !object.isVisible())
|
||||
{
|
||||
continue; // skip dying objects
|
||||
}
|
||||
|
||||
if (forgetObjects)
|
||||
{
|
||||
object.getKnownList().forgetObjects((Config.GUARD_ATTACK_AGGRO_MOB && (object instanceof L2GuardInstance)) || fullUpdate);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((object instanceof L2PlayableInstance) || (Config.GUARD_ATTACK_AGGRO_MOB && (object instanceof L2GuardInstance)) || fullUpdate)
|
||||
{
|
||||
for (final L2WorldRegion regi : region.getSurroundingRegions()) // offer members of this and surrounding regions
|
||||
{
|
||||
for (final L2Object _object : regi.getVisibleObjects())
|
||||
{
|
||||
if (_object != object)
|
||||
{
|
||||
object.getKnownList().addKnownObject(_object);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (object instanceof L2Character)
|
||||
{
|
||||
for (final L2WorldRegion regi : region.getSurroundingRegions()) // offer members of this and surrounding regions
|
||||
{
|
||||
if (regi.isActive())
|
||||
{
|
||||
for (final L2Object _object : regi.getVisiblePlayable())
|
||||
{
|
||||
if (_object != object)
|
||||
{
|
||||
object.getKnownList().addKnownObject(_object);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public abstract class Task
|
||||
{
|
||||
private static Logger _log = Logger.getLogger(Task.class.getName());
|
||||
|
||||
public void initializate()
|
||||
{
|
||||
if (Config.DEBUG)
|
||||
{
|
||||
_log.info("Task" + getName() + " initialized");
|
||||
}
|
||||
}
|
||||
|
||||
public ScheduledFuture<?> launchSpecial(ExecutedTask instance)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public abstract void onTimeElapsed(ExecutedTask task);
|
||||
|
||||
public void onDestroy()
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,386 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_FIXED_SHEDULED;
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_GLOBAL_TASK;
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_NONE;
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_SHEDULED;
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_SPECIAL;
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_STARTUP;
|
||||
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_TIME;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.L2DatabaseFactory;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskCleanUp;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskJython;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskOlympiadSave;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskRecom;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskRestart;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskSevenSignsUpdate;
|
||||
import com.l2jmobius.gameserver.taskmanager.tasks.TaskShutdown;
|
||||
|
||||
import javolution.util.FastList;
|
||||
import javolution.util.FastMap;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public final class TaskManager
|
||||
{
|
||||
protected static final Logger _log = Logger.getLogger(TaskManager.class.getName());
|
||||
private static TaskManager _instance;
|
||||
|
||||
protected static final String[] SQL_STATEMENTS =
|
||||
{
|
||||
"SELECT id,task,type,last_activation,param1,param2,param3 FROM global_tasks",
|
||||
"UPDATE global_tasks SET last_activation=? WHERE id=?",
|
||||
"SELECT id FROM global_tasks WHERE task=?",
|
||||
"INSERT INTO global_tasks (task,type,last_activation,param1,param2,param3) VALUES(?,?,?,?,?,?)"
|
||||
};
|
||||
|
||||
private final FastMap<Integer, Task> _tasks = new FastMap<>();
|
||||
protected final FastList<ExecutedTask> _currentTasks = new FastList<>();
|
||||
|
||||
public class ExecutedTask implements Runnable
|
||||
{
|
||||
int _id;
|
||||
long _lastActivation;
|
||||
Task _task;
|
||||
TaskTypes _type;
|
||||
String[] _params;
|
||||
ScheduledFuture<?> _scheduled;
|
||||
|
||||
public ExecutedTask(Task task, TaskTypes type, ResultSet rset) throws SQLException
|
||||
{
|
||||
_task = task;
|
||||
_type = type;
|
||||
_id = rset.getInt("id");
|
||||
_lastActivation = rset.getLong("last_activation");
|
||||
_params = new String[]
|
||||
{
|
||||
rset.getString("param1"),
|
||||
rset.getString("param2"),
|
||||
rset.getString("param3")
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
_task.onTimeElapsed(this);
|
||||
|
||||
_lastActivation = System.currentTimeMillis();
|
||||
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[1]))
|
||||
{
|
||||
statement.setLong(1, _lastActivation);
|
||||
statement.setInt(2, _id);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (final SQLException e)
|
||||
{
|
||||
_log.warning("cannot updated the Global Task " + _id + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
if ((_type == TYPE_SHEDULED) || (_type == TYPE_TIME))
|
||||
{
|
||||
stopTask();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object)
|
||||
{
|
||||
return _id == ((ExecutedTask) object)._id;
|
||||
}
|
||||
|
||||
public Task getTask()
|
||||
{
|
||||
return _task;
|
||||
}
|
||||
|
||||
public TaskTypes getType()
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public String[] getParams()
|
||||
{
|
||||
return _params;
|
||||
}
|
||||
|
||||
public long getLastActivation()
|
||||
{
|
||||
return _lastActivation;
|
||||
}
|
||||
|
||||
public void stopTask()
|
||||
{
|
||||
_task.onDestroy();
|
||||
|
||||
if (_scheduled != null)
|
||||
{
|
||||
_scheduled.cancel(true);
|
||||
}
|
||||
|
||||
_currentTasks.remove(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static TaskManager getInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new TaskManager();
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
public TaskManager()
|
||||
{
|
||||
initializate();
|
||||
startAllTasks();
|
||||
}
|
||||
|
||||
private void initializate()
|
||||
{
|
||||
registerTask(new TaskCleanUp());
|
||||
registerTask(new TaskJython());
|
||||
registerTask(new TaskOlympiadSave());
|
||||
registerTask(new TaskRecom());
|
||||
registerTask(new TaskRestart());
|
||||
registerTask(new TaskSevenSignsUpdate());
|
||||
registerTask(new TaskShutdown());
|
||||
}
|
||||
|
||||
public void registerTask(Task task)
|
||||
{
|
||||
final int key = task.getName().hashCode();
|
||||
if (!_tasks.containsKey(key))
|
||||
{
|
||||
_tasks.put(key, task);
|
||||
task.initializate();
|
||||
}
|
||||
}
|
||||
|
||||
private void startAllTasks()
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[0]);
|
||||
ResultSet rset = statement.executeQuery())
|
||||
{
|
||||
while (rset.next())
|
||||
{
|
||||
final Task task = _tasks.get(rset.getString("task").trim().toLowerCase().hashCode());
|
||||
|
||||
if (task == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
final TaskTypes type = TaskTypes.valueOf(rset.getString("type"));
|
||||
|
||||
if (type != TYPE_NONE)
|
||||
{
|
||||
final ExecutedTask current = new ExecutedTask(task, type, rset);
|
||||
if (launchTask(current))
|
||||
{
|
||||
_currentTasks.add(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
_log.severe("error while loading Global Task table " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean launchTask(ExecutedTask task)
|
||||
{
|
||||
final ThreadPoolManager scheduler = ThreadPoolManager.getInstance();
|
||||
final TaskTypes type = task.getType();
|
||||
|
||||
if (type == TYPE_STARTUP)
|
||||
{
|
||||
task.run();
|
||||
return false;
|
||||
}
|
||||
else if (type == TYPE_SHEDULED)
|
||||
{
|
||||
final long delay = Long.valueOf(task.getParams()[0]);
|
||||
task._scheduled = scheduler.scheduleGeneral(task, delay);
|
||||
return true;
|
||||
}
|
||||
else if (type == TYPE_FIXED_SHEDULED)
|
||||
{
|
||||
final long delay = Long.valueOf(task.getParams()[0]);
|
||||
final long interval = Long.valueOf(task.getParams()[1]);
|
||||
|
||||
task._scheduled = scheduler.scheduleGeneralAtFixedRate(task, delay, interval);
|
||||
return true;
|
||||
}
|
||||
else if (type == TYPE_TIME)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Date desired = DateFormat.getInstance().parse(task.getParams()[0]);
|
||||
final long diff = desired.getTime() - System.currentTimeMillis();
|
||||
if (diff >= 0)
|
||||
{
|
||||
task._scheduled = scheduler.scheduleGeneral(task, diff);
|
||||
return true;
|
||||
}
|
||||
_log.info("Task " + task.getId() + " is obsoleted.");
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (type == TYPE_SPECIAL)
|
||||
{
|
||||
final ScheduledFuture<?> result = task.getTask().launchSpecial(task);
|
||||
if (result != null)
|
||||
{
|
||||
task._scheduled = result;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (type == TYPE_GLOBAL_TASK)
|
||||
{
|
||||
final long interval = Long.valueOf(task.getParams()[0]) * 86400000L;
|
||||
final String[] hour = task.getParams()[1].split(":");
|
||||
|
||||
if (hour.length != 3)
|
||||
{
|
||||
_log.warning("Task " + task.getId() + " has incorrect parameters");
|
||||
return false;
|
||||
}
|
||||
|
||||
final Calendar check = Calendar.getInstance();
|
||||
check.setTimeInMillis(task.getLastActivation() + interval);
|
||||
|
||||
final Calendar min = Calendar.getInstance();
|
||||
try
|
||||
{
|
||||
min.set(Calendar.HOUR_OF_DAY, Integer.valueOf(hour[0]));
|
||||
min.set(Calendar.MINUTE, Integer.valueOf(hour[1]));
|
||||
min.set(Calendar.SECOND, Integer.valueOf(hour[2]));
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
_log.warning("Bad parameter on task " + task.getId() + ": " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
long delay = min.getTimeInMillis() - System.currentTimeMillis();
|
||||
|
||||
if (check.after(min) || (delay < 0))
|
||||
{
|
||||
delay += interval;
|
||||
}
|
||||
|
||||
task._scheduled = scheduler.scheduleGeneralAtFixedRate(task, delay, interval);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean addUniqueTask(String task, TaskTypes type, String param1, String param2, String param3)
|
||||
{
|
||||
return addUniqueTask(task, type, param1, param2, param3, 0);
|
||||
}
|
||||
|
||||
public static boolean addUniqueTask(String task, TaskTypes type, String param1, String param2, String param3, long lastActivation)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[2]))
|
||||
{
|
||||
statement.setString(1, task);
|
||||
try (ResultSet rset = statement.executeQuery())
|
||||
{
|
||||
if (!rset.next())
|
||||
{
|
||||
try (PreparedStatement statement2 = con.prepareStatement(SQL_STATEMENTS[3]))
|
||||
{
|
||||
statement2.setString(1, task);
|
||||
statement2.setString(2, type.toString());
|
||||
statement2.setLong(3, lastActivation);
|
||||
statement2.setString(4, param1);
|
||||
statement2.setString(5, param2);
|
||||
statement2.setString(6, param3);
|
||||
statement2.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (final SQLException e)
|
||||
{
|
||||
_log.warning("cannot add the unique task: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean addTask(String task, TaskTypes type, String param1, String param2, String param3)
|
||||
{
|
||||
return addTask(task, type, param1, param2, param3, 0);
|
||||
}
|
||||
|
||||
public static boolean addTask(String task, TaskTypes type, String param1, String param2, String param3, long lastActivation)
|
||||
{
|
||||
try (Connection con = L2DatabaseFactory.getInstance().getConnection();
|
||||
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[3]))
|
||||
{
|
||||
statement.setString(1, task);
|
||||
statement.setString(2, type.toString());
|
||||
statement.setLong(3, lastActivation);
|
||||
statement.setString(4, param1);
|
||||
statement.setString(5, param2);
|
||||
statement.setString(6, param3);
|
||||
statement.execute();
|
||||
}
|
||||
catch (final SQLException e)
|
||||
{
|
||||
_log.warning("cannot add the task: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public enum TaskTypes
|
||||
{
|
||||
TYPE_NONE,
|
||||
TYPE_TIME,
|
||||
TYPE_SHEDULED,
|
||||
TYPE_FIXED_SHEDULED,
|
||||
TYPE_GLOBAL_TASK,
|
||||
TYPE_STARTUP,
|
||||
TYPE_SPECIAL
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
|
||||
/**
|
||||
* @author Tempy
|
||||
*/
|
||||
public final class TaskCleanUp extends Task
|
||||
{
|
||||
public static String NAME = "CleanUp";
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
System.runFinalization();
|
||||
System.gc();
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import org.python.util.PythonInterpreter;
|
||||
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public class TaskJython extends Task
|
||||
{
|
||||
public static final String NAME = "jython";
|
||||
|
||||
private final PythonInterpreter _python = new PythonInterpreter();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.taskmanager.Task#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.taskmanager.Task#onTimeElapsed(com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask)
|
||||
*/
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
_python.cleanup();
|
||||
_python.exec("import sys");
|
||||
_python.execfile("data/scripts/cron/" + task.getParams()[2]);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.Olympiad;
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskTypes;
|
||||
|
||||
/**
|
||||
* Updates all data of Olympiad nobles in db
|
||||
* @author godson
|
||||
*/
|
||||
public class TaskOlympiadSave extends Task
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(TaskOlympiadSave.class.getName());
|
||||
public static final String NAME = "OlympiadSave";
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
try
|
||||
{
|
||||
Olympiad.getInstance().save();
|
||||
_log.info("Olympiad System: Data updated successfully.");
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
_log.warning("Olympiad System: Failed to save Olympiad configuration: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializate()
|
||||
{
|
||||
super.initializate();
|
||||
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "900000", "1800000", "");
|
||||
}
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.model.L2World;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.UserInfo;
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskTypes;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public class TaskRecom extends Task
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(TaskRecom.class.getName());
|
||||
private static final String NAME = "sp_recommendations";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.taskmanager.Task#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.taskmanager.Task#onTimeElapsed(com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask)
|
||||
*/
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
for (final L2PcInstance player : L2World.getInstance().getAllPlayers())
|
||||
{
|
||||
player.restartRecom();
|
||||
player.sendPacket(new UserInfo(player));
|
||||
}
|
||||
_log.config("Recommendation Global Task: launched.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializate()
|
||||
{
|
||||
super.initializate();
|
||||
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "13:00:00", "");
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import com.l2jmobius.gameserver.Shutdown;
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public final class TaskRestart extends Task
|
||||
{
|
||||
public static String NAME = "restart";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.tasks.Task#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.tasks.Task#onTimeElapsed(com.l2jmobius.gameserver.tasks.TaskManager.ExecutedTask)
|
||||
*/
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
final Shutdown handler = new Shutdown(Integer.valueOf(task.getParams()[2]), true);
|
||||
handler.start();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.gameserver.SevenSigns;
|
||||
import com.l2jmobius.gameserver.SevenSignsFestival;
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskTypes;
|
||||
|
||||
/**
|
||||
* Updates all data for the Seven Signs and Festival of Darkness engines, when time is elapsed.
|
||||
* @author Tempy
|
||||
*/
|
||||
public class TaskSevenSignsUpdate extends Task
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(TaskOlympiadSave.class.getName());
|
||||
public static final String NAME = "SevenSignsUpdate";
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
try
|
||||
{
|
||||
SevenSigns.getInstance().saveSevenSignsData(null, true);
|
||||
|
||||
if (!SevenSigns.getInstance().isSealValidationPeriod())
|
||||
{
|
||||
SevenSignsFestival.getInstance().saveFestivalData(false);
|
||||
}
|
||||
|
||||
_log.info("SevenSigns: Data updated successfully.");
|
||||
}
|
||||
catch (final Exception e)
|
||||
{
|
||||
_log.warning("SevenSigns: Failed to save Seven Signs configuration: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializate()
|
||||
{
|
||||
super.initializate();
|
||||
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "1800000", "1800000", "");
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jmobius.gameserver.taskmanager.tasks;
|
||||
|
||||
import com.l2jmobius.gameserver.Shutdown;
|
||||
import com.l2jmobius.gameserver.taskmanager.Task;
|
||||
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
|
||||
|
||||
/**
|
||||
* @author Layane
|
||||
*/
|
||||
public class TaskShutdown extends Task
|
||||
{
|
||||
public static String NAME = "shutdown";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.taskmanager.Task#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.l2jmobius.gameserver.taskmanager.Task#onTimeElapsed(com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask)
|
||||
*/
|
||||
@Override
|
||||
public void onTimeElapsed(ExecutedTask task)
|
||||
{
|
||||
final Shutdown handler = new Shutdown(Integer.valueOf(task.getParams()[2]), false);
|
||||
handler.start();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user