actual freya branch

This commit is contained in:
2026-09-12 15:41:31 +00:00
parent 8049e0a882
commit 68c1cd27d4
3510 changed files with 336689 additions and 302906 deletions
@@ -0,0 +1,144 @@
/*
* $HeadURL: $
*
* $Author: $ $Date: $ $Revision: $
*
*
* 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.l2jserver.gameserver.taskmanager;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javolution.util.FastMap;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Summon;
import com.l2jserver.gameserver.model.actor.instance.L2CubicInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.AutoAttackStop;
/**
* This class ...
* @version $Revision: $ $Date: $
* @author Luca Baldi
*/
public class AttackStanceTaskManager
{
protected static final Logger _log = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected Map<L2Character, Long> _attackStanceTasks = new FastMap<L2Character, Long>().shared();
private AttackStanceTaskManager()
{
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FightModeScheduler(), 0, 1000);
}
public static AttackStanceTaskManager getInstance()
{
return SingletonHolder._instance;
}
public void addAttackStanceTask(L2Character actor)
{
if (actor instanceof L2Summon)
{
L2Summon summon = (L2Summon) actor;
actor = summon.getOwner();
}
if (actor instanceof L2PcInstance)
{
L2PcInstance player = (L2PcInstance) actor;
for (L2CubicInstance cubic : player.getCubics().values())
{
if (cubic.getId() != L2CubicInstance.LIFE_CUBIC)
{
cubic.doAction();
}
}
}
_attackStanceTasks.put(actor, System.currentTimeMillis());
}
public void removeAttackStanceTask(L2Character actor)
{
if (actor instanceof L2Summon)
{
L2Summon summon = (L2Summon) actor;
actor = summon.getOwner();
}
_attackStanceTasks.remove(actor);
}
public boolean getAttackStanceTask(L2Character actor)
{
if (actor instanceof L2Summon)
{
L2Summon summon = (L2Summon) actor;
actor = summon.getOwner();
}
return _attackStanceTasks.containsKey(actor);
}
private class FightModeScheduler implements Runnable
{
protected FightModeScheduler()
{
// Do nothing
}
@Override
public void run()
{
Long current = System.currentTimeMillis();
try
{
if (_attackStanceTasks != null)
{
synchronized (this)
{
for (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 (Exception e)
{
// TODO: Find out the reason for exception. Unless caught here,
// players remain in attack positions.
_log.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final AttackStanceTaskManager _instance = new AttackStanceTaskManager();
}
}
@@ -0,0 +1,224 @@
/*
* 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.l2jserver.gameserver.taskmanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javolution.util.FastList;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.util.Broadcast;
/**
* @author nBd
*/
public class AutoAnnounceTaskManager
{
protected static final Logger _log = Logger.getLogger(AutoAnnounceTaskManager.class.getName());
protected List<AutoAnnouncement> _announces = new FastList<>();
private int _nextId = 1;
public static AutoAnnounceTaskManager getInstance()
{
return SingletonHolder._instance;
}
private AutoAnnounceTaskManager()
{
restore();
}
public List<AutoAnnouncement> getAutoAnnouncements()
{
return _announces;
}
public void restore()
{
if (!_announces.isEmpty())
{
for (AutoAnnouncement a : _announces)
{
a.stopAnnounce();
}
_announces.clear();
}
Connection conn = null;
int count = 0;
try
{
conn = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = conn.prepareStatement("SELECT id, initial, delay, cycle, memo FROM auto_announcements");
ResultSet data = statement.executeQuery();
while (data.next())
{
int id = data.getInt("id");
long initial = data.getLong("initial");
long delay = data.getLong("delay");
int repeat = data.getInt("cycle");
String memo = data.getString("memo");
String[] text = memo.split("/n");
ThreadPoolManager.getInstance().scheduleGeneral(new AutoAnnouncement(id, delay, repeat, text), initial);
count++;
if (_nextId <= id)
{
_nextId = id + 1;
}
}
data.close();
statement.close();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "AutoAnnoucements: Failed to load announcements data.", e);
}
finally
{
L2DatabaseFactory.close(conn);
}
_log.log(Level.INFO, "AutoAnnoucements: Loaded " + count + " Auto Annoucement Data.");
}
public void addAutoAnnounce(long initial, long delay, int repeat, String memo)
{
Connection conn = null;
try
{
conn = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = conn.prepareStatement("INSERT INTO auto_announcements (id, initial, delay, cycle, memo) VALUES (?,?,?,?,?)");
statement.setInt(1, _nextId);
statement.setLong(2, initial);
statement.setLong(3, delay);
statement.setInt(4, repeat);
statement.setString(5, memo);
statement.execute();
statement.close();
String[] text = memo.split("/n");
ThreadPoolManager.getInstance().scheduleGeneral(new AutoAnnouncement(_nextId++, delay, repeat, text), initial);
}
catch (Exception e)
{
_log.log(Level.SEVERE, "AutoAnnoucements: Failed to add announcements data.", e);
}
finally
{
L2DatabaseFactory.close(conn);
}
}
public void deleteAutoAnnounce(int index)
{
Connection conn = null;
try
{
AutoAnnouncement a = _announces.get(index);
a.stopAnnounce();
conn = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = conn.prepareStatement("DELETE FROM auto_announcements WHERE id = ?");
statement.setInt(1, a._id);
statement.execute();
statement.close();
_announces.remove(index);
}
catch (Exception e)
{
_log.log(Level.SEVERE, "AutoAnnoucements: Failed to delete announcements data.", e);
}
finally
{
L2DatabaseFactory.close(conn);
}
}
public class AutoAnnouncement implements Runnable
{
protected 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 String[] getMemo()
{
return _memo;
}
public void stopAnnounce()
{
_stopped = true;
}
@Override
public void run()
{
if (!_stopped && (_repeat != 0))
{
for (String text : _memo)
{
announce(text);
}
if (_repeat > 0)
{
_repeat--;
}
ThreadPoolManager.getInstance().scheduleGeneral(this, _delay);
}
else
{
stopAnnounce();
}
}
}
public void announce(String text)
{
Broadcast.announceToOnlinePlayers(text);
_log.info("AutoAnnounce: " + text);
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final AutoAnnounceTaskManager _instance = new AutoAnnounceTaskManager();
}
}
@@ -0,0 +1,154 @@
/*
* 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.l2jserver.gameserver.taskmanager;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javolution.util.FastMap;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.L2Attackable;
import com.l2jserver.gameserver.model.actor.L2Character;
/**
* @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 final int RAID_BOSS_DECAY_TIME = 30000;
public static final int ATTACKABLE_DECAY_TIME = 8500;
private DecayTaskManager()
{
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new DecayScheduler(), 10000, 5000);
}
public static DecayTaskManager getInstance()
{
return SingletonHolder._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 (NoSuchElementException e)
{
}
}
private class DecayScheduler implements Runnable
{
protected DecayScheduler()
{
// Do nothing
}
@Override
public void run()
{
long current = System.currentTimeMillis();
int delay;
try
{
Iterator<Entry<L2Character, Long>> it = _decayTasks.entrySet().iterator();
while (it.hasNext())
{
Entry<L2Character, Long> e = it.next();
L2Character actor = e.getKey();
Long next = e.getValue();
if (next == null)
{
continue;
}
if (actor.isRaid() && !actor.isRaidMinion())
{
delay = RAID_BOSS_DECAY_TIME;
}
else if ((actor instanceof L2Attackable) && (((L2Attackable) actor).isSpoil() || ((L2Attackable) actor).isSeeded()))
{
delay = ATTACKABLE_DECAY_TIME * 2;
}
else
{
delay = ATTACKABLE_DECAY_TIME;
}
if ((current - next) > delay)
{
actor.onDecay();
it.remove();
}
}
}
catch (Exception e)
{
// TODO: Find out the reason for exception. Unless caught here,
// mob decay would stop.
_log.log(Level.WARNING, "Error in DecayScheduler: " + e.getMessage(), e);
}
}
}
@Override
public String toString()
{
String ret = "============= DecayTask Manager Report ============\r\n";
ret += "Tasks count: " + _decayTasks.size() + "\r\n";
ret += "Tasks dump:\r\n";
Long current = System.currentTimeMillis();
for (L2Character actor : _decayTasks.keySet())
{
ret += "Class/Name: " + actor.getClass().getSimpleName() + "/" + actor.getName() + " decay timer: " + (current - _decayTasks.get(actor)) + "\r\n";
}
return ret;
}
/**
* <u><b><font color="FF0000">Read only</font></b></u>
*/
public Map<L2Character, Long> getTasks()
{
return _decayTasks;
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final DecayTaskManager _instance = new DecayTaskManager();
}
}
@@ -0,0 +1,175 @@
/*
* 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.l2jserver.gameserver.taskmanager;
import java.util.Collection;
import java.util.logging.Level;
import java.util.logging.Logger;
import javolution.util.FastSet;
import com.l2jserver.Config;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.L2WorldRegion;
import com.l2jserver.gameserver.model.actor.L2Attackable;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Playable;
import com.l2jserver.gameserver.model.actor.instance.L2GuardInstance;
public class KnownListUpdateTaskManager
{
protected static final Logger _log = Logger.getLogger(KnownListUpdateTaskManager.class.getName());
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;
protected static final FastSet<L2WorldRegion> _failedRegions = new FastSet<>(1);
private KnownListUpdateTaskManager()
{
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new KnownListUpdate(), 1000, Config.KNOWNLIST_UPDATE_INTERVAL);
}
public static KnownListUpdateTaskManager getInstance()
{
return SingletonHolder._instance;
}
private class KnownListUpdate implements Runnable
{
public KnownListUpdate()
{
}
@Override
public void run()
{
try
{
boolean failed;
for (L2WorldRegion regions[] : L2World.getInstance().getAllWorldRegions())
{
for (L2WorldRegion r : regions) // go through all world regions
{
// avoid stopping update if something went wrong in updateRegion()
try
{
failed = _failedRegions.contains(r); // failed on last pass
if (r.isActive()) // and check only if the region is active
{
updateRegion(r, ((_fullUpdateTimer == FULL_UPDATE_TIMER) || failed), updatePass);
}
if (failed)
{
_failedRegions.remove(r); // if all ok, remove
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "KnownListUpdateTaskManager: updateRegion(" + _fullUpdateTimer + "," + updatePass + ") failed for region " + r.getName() + ". Full update scheduled. " + e.getMessage(), e);
_failedRegions.add(r);
}
}
}
updatePass = !updatePass;
if (_fullUpdateTimer > 0)
{
_fullUpdateTimer--;
}
else
{
_fullUpdateTimer = FULL_UPDATE_TIMER;
}
}
catch (Exception e)
{
_log.log(Level.WARNING, "", e);
}
}
}
public void updateRegion(L2WorldRegion region, boolean fullUpdate, boolean forgetObjects)
{
// synchronized (syncObject)
{
Collection<L2Object> vObj = region.getVisibleObjects().values();
// synchronized (region.getVisibleObjects())
{
for (L2Object object : vObj) // and for all members in region
{
if ((object == null) || !object.isVisible())
{
continue; // skip dying objects
}
// Some mobs need faster knownlist update
final boolean aggro = (Config.GUARD_ATTACK_AGGRO_MOB && (object instanceof L2GuardInstance)) || ((object instanceof L2Attackable) && (((L2Attackable) object).getEnemyClan() != null));
if (forgetObjects)
{
object.getKnownList().forgetObjects(aggro || fullUpdate);
continue;
}
for (L2WorldRegion regi : region.getSurroundingRegions())
{
if ((object instanceof L2Playable) || (aggro && regi.isActive()) || fullUpdate)
{
Collection<L2Object> inrObj = regi.getVisibleObjects().values();
// synchronized (regi.getVisibleObjects())
{
for (L2Object _object : inrObj)
{
if (_object != object)
{
object.getKnownList().addKnownObject(_object);
}
}
}
}
else if (object instanceof L2Character)
{
if (regi.isActive())
{
Collection<L2Playable> inrPls = regi.getVisiblePlayable().values();
// synchronized (regi.getVisiblePlayable())
{
for (L2Object _object : inrPls)
{
if (_object != object)
{
object.getKnownList().addKnownObject(_object);
}
}
}
}
}
}
}
}
}
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final KnownListUpdateTaskManager _instance = new KnownListUpdateTaskManager();
}
}
@@ -0,0 +1,50 @@
/*
* 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.l2jserver.gameserver.taskmanager;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Logger;
import com.l2jserver.Config;
import com.l2jserver.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() + " inializate");
}
}
public ScheduledFuture<?> launchSpecial(ExecutedTask instance)
{
return null;
}
public abstract String getName();
public abstract void onTimeElapsed(ExecutedTask task);
public void onDestroy()
{
}
}
@@ -0,0 +1,440 @@
/*
* 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.l2jserver.gameserver.taskmanager;
import static com.l2jserver.gameserver.taskmanager.TaskTypes.TYPE_NONE;
import static com.l2jserver.gameserver.taskmanager.TaskTypes.TYPE_SHEDULED;
import static com.l2jserver.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.Level;
import java.util.logging.Logger;
import javolution.util.FastList;
import javolution.util.FastMap;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.taskmanager.tasks.TaskCleanUp;
import com.l2jserver.gameserver.taskmanager.tasks.TaskDailyQuestClean;
import com.l2jserver.gameserver.taskmanager.tasks.TaskGlobalVariablesSave;
import com.l2jserver.gameserver.taskmanager.tasks.TaskJython;
import com.l2jserver.gameserver.taskmanager.tasks.TaskOlympiadSave;
import com.l2jserver.gameserver.taskmanager.tasks.TaskRaidPointsReset;
import com.l2jserver.gameserver.taskmanager.tasks.TaskRecom;
import com.l2jserver.gameserver.taskmanager.tasks.TaskRestart;
import com.l2jserver.gameserver.taskmanager.tasks.TaskScript;
import com.l2jserver.gameserver.taskmanager.tasks.TaskSevenSignsUpdate;
import com.l2jserver.gameserver.taskmanager.tasks.TaskShutdown;
/**
* @author Layane
*/
public final class TaskManager
{
protected static final Logger _log = Logger.getLogger(TaskManager.class.getName());
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 ptask, TaskTypes ptype, ResultSet rset) throws SQLException
{
task = ptask;
type = ptype;
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();
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[1]);
statement.setLong(1, lastActivation);
statement.setInt(2, id);
statement.executeUpdate();
statement.close();
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Cannot updated the Global Task " + id + ": " + e.getMessage(), e);
}
finally
{
L2DatabaseFactory.close(con);
}
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()
{
return SingletonHolder._instance;
}
private TaskManager()
{
initializate();
startAllTasks();
}
private void initializate()
{
registerTask(new TaskCleanUp());
registerTask(new TaskScript());
registerTask(new TaskJython());
registerTask(new TaskGlobalVariablesSave());
registerTask(new TaskOlympiadSave());
registerTask(new TaskRaidPointsReset());
registerTask(new TaskRecom());
registerTask(new TaskRestart());
registerTask(new TaskSevenSignsUpdate());
registerTask(new TaskShutdown());
registerTask(new TaskDailyQuestClean());
}
public void registerTask(Task task)
{
int key = task.getName().hashCode();
if (!_tasks.containsKey(key))
{
_tasks.put(key, task);
task.initializate();
}
}
private void startAllTasks()
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[0]);
ResultSet rset = statement.executeQuery();
while (rset.next())
{
Task task = _tasks.get(rset.getString("task").trim().toLowerCase().hashCode());
if (task == null)
{
continue;
}
TaskTypes type = TaskTypes.valueOf(rset.getString("type"));
if (type != TYPE_NONE)
{
ExecutedTask current = new ExecutedTask(task, type, rset);
if (launchTask(current))
{
_currentTasks.add(current);
}
}
}
rset.close();
statement.close();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Error while loading Global Task table: " + e.getMessage(), e);
}
finally
{
try
{
L2DatabaseFactory.close(con);
}
catch (Exception e)
{
}
}
}
private boolean launchTask(ExecutedTask task)
{
final ThreadPoolManager scheduler = ThreadPoolManager.getInstance();
final TaskTypes type = task.getType();
long delay, interval;
switch (type)
{
case TYPE_STARTUP:
task.run();
return false;
case TYPE_SHEDULED:
delay = Long.valueOf(task.getParams()[0]);
task.scheduled = scheduler.scheduleGeneral(task, delay);
return true;
case TYPE_FIXED_SHEDULED:
delay = Long.valueOf(task.getParams()[0]);
interval = Long.valueOf(task.getParams()[1]);
task.scheduled = scheduler.scheduleGeneralAtFixedRate(task, delay, interval);
return true;
case TYPE_TIME:
try
{
Date desired = DateFormat.getInstance().parse(task.getParams()[0]);
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 (Exception e)
{
}
break;
case TYPE_SPECIAL:
ScheduledFuture<?> result = task.getTask().launchSpecial(task);
if (result != null)
{
task.scheduled = result;
return true;
}
break;
case TYPE_GLOBAL_TASK:
interval = Long.valueOf(task.getParams()[0]) * 86400000L;
String[] hour = task.getParams()[1].split(":");
if (hour.length != 3)
{
_log.warning("Task " + task.getId() + " has incorrect parameters");
return false;
}
Calendar check = Calendar.getInstance();
check.setTimeInMillis(task.getLastActivation() + interval);
Calendar min = Calendar.getInstance();
try
{
min.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour[0]));
min.set(Calendar.MINUTE, Integer.parseInt(hour[1]));
min.set(Calendar.SECOND, Integer.parseInt(hour[2]));
}
catch (Exception e)
{
_log.log(Level.WARNING, "Bad parameter on task " + task.getId() + ": " + e.getMessage(), e);
return false;
}
delay = min.getTimeInMillis() - System.currentTimeMillis();
if (check.after(min) || (delay < 0))
{
delay += interval;
}
task.scheduled = scheduler.scheduleGeneralAtFixedRate(task, delay, interval);
return true;
default:
return false;
}
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)
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[2]);
statement.setString(1, task);
ResultSet rset = statement.executeQuery();
if (!rset.next())
{
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();
}
rset.close();
statement.close();
return true;
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Cannot add the unique task: " + e.getMessage(), e);
}
finally
{
try
{
L2DatabaseFactory.close(con);
}
catch (Exception e)
{
}
}
return false;
}
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)
{
Connection con = null;
try
{
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();
statement.close();
return true;
}
catch (SQLException e)
{
_log.log(Level.WARNING, "Cannot add the task: " + e.getMessage(), e);
}
finally
{
try
{
L2DatabaseFactory.close(con);
}
catch (Exception e)
{
}
}
return false;
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final TaskManager _instance = new TaskManager();
}
}
@@ -0,0 +1,29 @@
/*
* 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.l2jserver.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,45 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author Tempy
*/
public final class TaskCleanUp extends Task
{
public static final String NAME = "clean_up";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
System.runFinalization();
System.gc();
}
}
@@ -0,0 +1,93 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
import com.l2jserver.gameserver.taskmanager.TaskTypes;
/**
** @author Gnacik
*/
public class TaskDailyQuestClean extends Task
{
private static final Logger _log = Logger.getLogger(TaskDailyQuestClean.class.getName());
private static final String NAME = "daily_quest_clean";
private static final String[] _daily_names =
{
"463_IMustBeaGenius",
"464_Oath",
"458_PerfectForm",
"461_RumbleInTheBase"
};
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
for (String name : _daily_names)
{
PreparedStatement statement = con.prepareStatement("DELETE FROM character_quests WHERE name=? AND var='<state>' AND value='Completed';");
statement.setString(1, name);
statement.execute();
statement.close();
}
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Could not reset daily quests: " + e);
}
finally
{
L2DatabaseFactory.close(con);
}
_log.config("Daily quests cleared");
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#initializate()
*/
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
}
}
@@ -0,0 +1,61 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.util.logging.Logger;
import com.l2jserver.gameserver.instancemanager.GlobalVariablesManager;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
import com.l2jserver.gameserver.taskmanager.TaskTypes;
/**
* @author Gigiikun
*/
public class TaskGlobalVariablesSave extends Task
{
private static final Logger _log = Logger.getLogger(TaskGlobalVariablesSave.class.getName());
public static final String NAME = "global_varibales_save";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
GlobalVariablesManager.getInstance().saveVars();
_log.info("GlobalVariablesManager: Data updated successfully.");
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#initializate()
*/
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "500000", "1800000", "");
}
}
@@ -0,0 +1,50 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import org.python.util.PythonInterpreter;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author Layane
*/
public class TaskJython extends Task
{
public static final String NAME = "jython";
private final PythonInterpreter _python = new PythonInterpreter();
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.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,65 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.util.logging.Logger;
import com.l2jserver.gameserver.model.olympiad.Olympiad;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
import com.l2jserver.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 = "olympiad_save";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
if (Olympiad.getInstance().inCompPeriod())
{
Olympiad.getInstance().saveOlympiadStatus();
_log.info("Olympiad System: Data updated.");
}
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#initializate()
*/
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "900000", "1800000", "");
}
}
@@ -0,0 +1,116 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.util.Calendar;
import java.util.Map;
import java.util.logging.Logger;
import com.l2jserver.Config;
import com.l2jserver.gameserver.datatables.ClanTable;
import com.l2jserver.gameserver.instancemanager.RaidBossPointsManager;
import com.l2jserver.gameserver.model.L2Clan;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
import com.l2jserver.gameserver.taskmanager.TaskTypes;
public class TaskRaidPointsReset extends Task
{
private static final Logger _log = Logger.getLogger(TaskRaidPointsReset.class.getName());
public static final String NAME = "raid_points_reset";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
Calendar cal = Calendar.getInstance();
if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY)
{
// reward clan reputation points
Map<Integer, Integer> rankList = RaidBossPointsManager.getInstance().getRankList();
for (L2Clan c : ClanTable.getInstance().getClans())
{
for (Map.Entry<Integer, Integer> entry : rankList.entrySet())
{
if ((entry.getValue() <= 100) && c.isMember(entry.getKey()))
{
int reputation = 0;
switch (entry.getValue())
{
case 1:
reputation = Config.RAID_RANKING_1ST;
break;
case 2:
reputation = Config.RAID_RANKING_2ND;
break;
case 3:
reputation = Config.RAID_RANKING_3RD;
break;
case 4:
reputation = Config.RAID_RANKING_4TH;
break;
case 5:
reputation = Config.RAID_RANKING_5TH;
break;
case 6:
reputation = Config.RAID_RANKING_6TH;
break;
case 7:
reputation = Config.RAID_RANKING_7TH;
break;
case 8:
reputation = Config.RAID_RANKING_8TH;
break;
case 9:
reputation = Config.RAID_RANKING_9TH;
break;
case 10:
reputation = Config.RAID_RANKING_10TH;
break;
default:
if (entry.getValue() <= 50)
{
reputation = Config.RAID_RANKING_UP_TO_50TH;
}
else
{
reputation = Config.RAID_RANKING_UP_TO_100TH;
}
break;
}
c.addReputationScore(reputation, true);
}
}
}
RaidBossPointsManager.getInstance().cleanUp();
_log.info("Raid Points Reset Global Task: launched.");
}
}
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "00:10:00", "");
}
}
@@ -0,0 +1,88 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
import com.l2jserver.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 = "recommendations";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=0 WHERE rec_have <= 20");
statement.setInt(1, 0); // Rec left = 0
statement.setInt(2, 3600000); // Timer = 1 hour
statement.execute();
statement = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=GREATEST(rec_have-20,0) WHERE rec_have > 20");
statement.setInt(1, 0); // Rec left = 0
statement.setInt(2, 3600000); // Timer = 1 hour
statement.execute();
statement.close();
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Could not reset Recommendations System: " + e);
}
finally
{
L2DatabaseFactory.close(con);
}
_log.config("Recommendations System reseted");
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#initializate()
*/
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
}
}
@@ -0,0 +1,47 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import com.l2jserver.gameserver.Shutdown;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author Layane
*/
public final class TaskRestart extends Task
{
public static final String NAME = "restart";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
Shutdown handler = new Shutdown(Integer.parseInt(task.getParams()[2]), true);
handler.start();
}
}
@@ -0,0 +1,71 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.io.File;
import java.util.logging.Logger;
import javax.script.ScriptException;
import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author janiii
*/
public class TaskScript extends Task
{
private static final Logger _log = Logger.getLogger(TaskScript.class.getName());
public static final String NAME = "script";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "cron/" + task.getParams()[2]);
if (file.isFile())
{
try
{
L2ScriptEngineManager.getInstance().executeScript(file);
}
catch (ScriptException e)
{
_log.warning("Failed loading: " + task.getParams()[2]);
L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
}
catch (Exception e)
{
_log.warning("Failed loading: " + task.getParams()[2]);
}
}
else
{
_log.warning("File Not Found: " + task.getParams()[2]);
}
}
}
@@ -0,0 +1,77 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jserver.gameserver.SevenSigns;
import com.l2jserver.gameserver.SevenSignsFestival;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
import com.l2jserver.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(TaskSevenSignsUpdate.class.getName());
public static final String NAME = "seven_signs_update";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
try
{
SevenSigns.getInstance().saveSevenSignsStatus();
if (!SevenSigns.getInstance().isSealValidationPeriod())
{
SevenSignsFestival.getInstance().saveFestivalData(false);
}
_log.info("SevenSigns: Data updated successfully.");
}
catch (Exception e)
{
_log.log(Level.WARNING, "SevenSigns: Failed to save Seven Signs configuration: " + e.getMessage(), e);
}
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#initializate()
*/
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "1800000", "1800000", "");
}
}
@@ -0,0 +1,47 @@
/*
* 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.l2jserver.gameserver.taskmanager.tasks;
import com.l2jserver.gameserver.Shutdown;
import com.l2jserver.gameserver.taskmanager.Task;
import com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author Layane
*/
public class TaskShutdown extends Task
{
public static final String NAME = "shutdown";
/**
* @see com.l2jserver.gameserver.taskmanager.Task#getName()
*/
@Override
public String getName()
{
return NAME;
}
/**
* @see com.l2jserver.gameserver.taskmanager.Task#onTimeElapsed(com.l2jserver.gameserver.taskmanager.TaskManager.ExecutedTask)
*/
@Override
public void onTimeElapsed(ExecutedTask task)
{
Shutdown handler = new Shutdown(Integer.parseInt(task.getParams()[2]), false);
handler.start();
}
}