Merged with released L2J-Unity files.

This commit is contained in:
mobiusdev
2016-06-12 01:34:09 +00:00
parent e003e87887
commit 635557f5da
18352 changed files with 3245113 additions and 2892959 deletions

View File

@ -1,160 +1,162 @@
/*
* 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.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Summon;
import com.l2jmobius.gameserver.model.actor.instance.L2CubicInstance;
import com.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
*/
public class AttackStanceTaskManager
{
protected static final Logger _log = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<L2Character, Long> _attackStanceTasks = new ConcurrentHashMap<>();
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FightModeScheduler(), 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
*/
public void addAttackStanceTask(L2Character actor)
{
if (actor == null)
{
return;
}
if (actor.isPlayable())
{
for (L2CubicInstance cubic : actor.getActingPlayer().getCubics().values())
{
if (cubic.getId() != L2CubicInstance.LIFE_CUBIC)
{
cubic.doAction();
}
}
}
_attackStanceTasks.put(actor, System.currentTimeMillis());
}
/**
* Removes the attack stance task.
* @param actor the actor
*/
public void removeAttackStanceTask(L2Character actor)
{
if (actor == null)
{
return;
}
if (actor.isSummon())
{
actor = actor.getActingPlayer();
}
_attackStanceTasks.remove(actor);
}
/**
* Checks for attack stance task.<br>
* @param actor the actor
* @return {@code true} if the character has an attack stance task, {@code false} otherwise
*/
public boolean hasAttackStanceTask(L2Character actor)
{
if (actor == null)
{
return false;
}
if (actor.isSummon())
{
actor = actor.getActingPlayer();
}
return _attackStanceTasks.containsKey(actor);
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
L2Character actor;
for (Entry<L2Character, Long> e : _attackStanceTasks.entrySet())
{
if ((current - e.getValue()) > 15000)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final L2Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
_attackStanceTasks.remove(e.getKey());
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
_log.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager
*/
public static AttackStanceTaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final AttackStanceTaskManager _instance = new AttackStanceTaskManager();
}
}
/*
* 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.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Summon;
import com.l2jmobius.gameserver.network.serverpackets.AutoAttackStop;
/**
* Attack stance task manager.
* @author Luca Baldi, Zoey76
*/
public class AttackStanceTaskManager
{
protected static final Logger _log = Logger.getLogger(AttackStanceTaskManager.class.getName());
protected static final Map<L2Character, Long> _attackStanceTasks = new ConcurrentHashMap<>();
/**
* Instantiates a new attack stance task manager.
*/
protected AttackStanceTaskManager()
{
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new FightModeScheduler(), 0, 1000);
}
/**
* Adds the attack stance task.
* @param actor the actor
*/
public void addAttackStanceTask(L2Character actor)
{
if (actor != null)
{
// if (actor.isPlayable())
// {
// final PlayerInstance player = actor.getActingPlayer();
// for (L2CubicInstance cubic : player.getCubics().values())
// {
// if (cubic.getId() != L2CubicInstance.LIFE_CUBIC)
// {
// cubic.doAction();
// }
// }
// }
_attackStanceTasks.put(actor, System.currentTimeMillis());
}
}
/**
* Removes the attack stance task.
* @param actor the actor
*/
public void removeAttackStanceTask(L2Character actor)
{
if (actor != null)
{
if (actor.isSummon())
{
actor = actor.getActingPlayer();
}
_attackStanceTasks.remove(actor);
}
}
/**
* Checks for attack stance task.<br>
* @param actor the actor
* @return {@code true} if the character has an attack stance task, {@code false} otherwise
*/
public boolean hasAttackStanceTask(L2Character actor)
{
if (actor != null)
{
if (actor.isSummon())
{
actor = actor.getActingPlayer();
}
return _attackStanceTasks.containsKey(actor);
}
return false;
}
protected class FightModeScheduler implements Runnable
{
@Override
public void run()
{
final long current = System.currentTimeMillis();
try
{
final Iterator<Entry<L2Character, Long>> iter = _attackStanceTasks.entrySet().iterator();
Entry<L2Character, Long> e;
L2Character actor;
while (iter.hasNext())
{
e = iter.next();
if ((current - e.getValue()) > 15000)
{
actor = e.getKey();
if (actor != null)
{
actor.broadcastPacket(new AutoAttackStop(actor.getObjectId()));
actor.getAI().setAutoAttacking(false);
if (actor.isPlayer() && actor.hasSummon())
{
final L2Summon pet = actor.getPet();
if (pet != null)
{
pet.broadcastPacket(new AutoAttackStop(pet.getObjectId()));
}
actor.getServitors().values().forEach(s -> s.broadcastPacket(new AutoAttackStop(s.getObjectId())));
}
}
iter.remove();
}
}
}
catch (Exception e)
{
// Unless caught here, players remain in attack positions.
_log.log(Level.WARNING, "Error in FightModeScheduler: " + e.getMessage(), e);
}
}
}
/**
* Gets the single instance of AttackStanceTaskManager.
* @return single instance of AttackStanceTaskManager
*/
public static AttackStanceTaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final AttackStanceTaskManager _instance = new AttackStanceTaskManager();
}
}

View File

@ -1,176 +1,181 @@
/*
* 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.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.model.actor.L2Attackable;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
/**
* @author NosBit
*/
public final class DecayTaskManager
{
private final ScheduledExecutorService _decayExecutor = Executors.newSingleThreadScheduledExecutor();
protected final Map<L2Character, ScheduledFuture<?>> _decayTasks = new ConcurrentHashMap<>();
/**
* Adds a decay task for the specified character.<br>
* <br>
* If the decay task already exists it cancels it and re-adds it.
* @param character the character
*/
public void add(L2Character character)
{
if (character == null)
{
return;
}
long delay;
if (character.getTemplate() instanceof L2NpcTemplate)
{
delay = ((L2NpcTemplate) character.getTemplate()).getCorpseTime();
}
else
{
delay = Config.DEFAULT_CORPSE_TIME;
}
if ((character instanceof L2Attackable) && (((L2Attackable) character).isSpoiled() || ((L2Attackable) character).isSeeded()))
{
delay += Config.SPOILED_CORPSE_EXTEND_TIME;
}
add(character, delay, TimeUnit.SECONDS);
}
/**
* Adds a decay task for the specified character.<br>
* <br>
* If the decay task already exists it cancels it and re-adds it.
* @param character the character
* @param delay the delay
* @param timeUnit the time unit of the delay parameter
*/
public void add(L2Character character, long delay, TimeUnit timeUnit)
{
ScheduledFuture<?> decayTask = _decayTasks.put(character, _decayExecutor.schedule(new DecayTask(character), delay, TimeUnit.SECONDS));
if ((decayTask == null) || decayTask.cancel(false))
{
return;
}
decayTask = _decayTasks.remove(character);
if (decayTask != null)
{
decayTask.cancel(false);
}
}
/**
* Cancels the decay task of the specified character.
* @param character the character
*/
public void cancel(L2Character character)
{
final ScheduledFuture<?> decayTask = _decayTasks.remove(character);
if (decayTask != null)
{
decayTask.cancel(false);
}
}
/**
* Gets the remaining time of the specified character's decay task.
* @param character the character
* @return if a decay task exists the remaining time, {@code Long.MAX_VALUE} otherwise
*/
public long getRemainingTime(L2Character character)
{
final ScheduledFuture<?> decayTask = _decayTasks.get(character);
if (decayTask != null)
{
return decayTask.getDelay(TimeUnit.MILLISECONDS);
}
return Long.MAX_VALUE;
}
private class DecayTask implements Runnable
{
private final L2Character _character;
protected DecayTask(L2Character character)
{
_character = character;
}
@Override
public void run()
{
_decayTasks.remove(_character);
_character.onDecay();
}
}
@Override
public String toString()
{
final StringBuilder ret = new StringBuilder();
ret.append("============= DecayTask Manager Report ============");
ret.append(Config.EOL);
ret.append("Tasks count: ");
ret.append(_decayTasks.size());
ret.append(Config.EOL);
ret.append("Tasks dump:");
ret.append(Config.EOL);
for (Entry<L2Character, ScheduledFuture<?>> entry : _decayTasks.entrySet())
{
ret.append("Class/Name: ");
ret.append(entry.getKey().getClass().getSimpleName());
ret.append('/');
ret.append(entry.getKey().getName());
ret.append(" decay timer: ");
ret.append(entry.getValue().getDelay(TimeUnit.MILLISECONDS));
ret.append(Config.EOL);
}
return ret.toString();
}
public static DecayTaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final DecayTaskManager _instance = new DecayTaskManager();
}
}
/*
* 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.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.model.actor.L2Attackable;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.templates.L2NpcTemplate;
/**
* @author NosBit
*/
public final class DecayTaskManager
{
private final ScheduledExecutorService _decayExecutor = Executors.newSingleThreadScheduledExecutor();
protected final Map<L2Character, ScheduledFuture<?>> _decayTasks = new ConcurrentHashMap<>();
/**
* Adds a decay task for the specified character.<br>
* <br>
* If the decay task already exists it cancels it and re-adds it.
* @param character the character
*/
public void add(L2Character character)
{
if (character == null)
{
return;
}
long delay;
if (character.getTemplate() instanceof L2NpcTemplate)
{
delay = ((L2NpcTemplate) character.getTemplate()).getCorpseTime();
}
else
{
delay = Config.DEFAULT_CORPSE_TIME;
}
if (character.isAttackable() && (((L2Attackable) character).isSpoiled() || ((L2Attackable) character).isSeeded()))
{
delay += Config.SPOILED_CORPSE_EXTEND_TIME;
}
add(character, delay, TimeUnit.SECONDS);
}
/**
* Adds a decay task for the specified character.<br>
* <br>
* If the decay task already exists it cancels it and re-adds it.
* @param character the character
* @param delay the delay
* @param timeUnit the time unit of the delay parameter
*/
public void add(L2Character character, long delay, TimeUnit timeUnit)
{
ScheduledFuture<?> decayTask = _decayExecutor.schedule(new DecayTask(character), delay, TimeUnit.SECONDS);
decayTask = _decayTasks.put(character, decayTask);
// if decay task already existed cancel it so we use the new time
if (decayTask != null)
{
if (!decayTask.cancel(false))
{
// old decay task was completed while canceling it remove and cancel the new one
decayTask = _decayTasks.remove(character);
if (decayTask != null)
{
decayTask.cancel(false);
}
}
}
}
/**
* Cancels the decay task of the specified character.
* @param character the character
*/
public void cancel(L2Character character)
{
final ScheduledFuture<?> decayTask = _decayTasks.remove(character);
if (decayTask != null)
{
decayTask.cancel(false);
}
}
/**
* Gets the remaining time of the specified character's decay task.
* @param character the character
* @return if a decay task exists the remaining time, {@code Long.MAX_VALUE} otherwise
*/
public long getRemainingTime(L2Character character)
{
final ScheduledFuture<?> decayTask = _decayTasks.get(character);
if (decayTask != null)
{
return decayTask.getDelay(TimeUnit.MILLISECONDS);
}
return Long.MAX_VALUE;
}
private class DecayTask implements Runnable
{
private final L2Character _character;
protected DecayTask(L2Character character)
{
_character = character;
}
@Override
public void run()
{
_decayTasks.remove(_character);
_character.onDecay();
}
}
@Override
public String toString()
{
final StringBuilder ret = new StringBuilder();
ret.append("============= DecayTask Manager Report ============");
ret.append(Config.EOL);
ret.append("Tasks count: ");
ret.append(_decayTasks.size());
ret.append(Config.EOL);
ret.append("Tasks dump:");
ret.append(Config.EOL);
for (Entry<L2Character, ScheduledFuture<?>> entry : _decayTasks.entrySet())
{
ret.append("Class/Name: ");
ret.append(entry.getKey().getClass().getSimpleName());
ret.append('/');
ret.append(entry.getKey().getName());
ret.append(" decay timer: ");
ret.append(entry.getValue().getDelay(TimeUnit.MILLISECONDS));
ret.append(Config.EOL);
}
return ret.toString();
}
public static DecayTaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final DecayTaskManager _instance = new DecayTaskManager();
}
}

View File

@ -1,156 +0,0 @@
/*
* 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.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Playable;
import com.l2jmobius.gameserver.model.actor.instance.L2GuardInstance;
public class KnownListUpdateTaskManager
{
protected static final Logger _log = Logger.getLogger(KnownListUpdateTaskManager.class.getName());
private static final 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 Set<L2WorldRegion> FAILED_REGIONS = ConcurrentHashMap.newKeySet(1);
protected KnownListUpdateTaskManager()
{
ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new KnownListUpdate(), 1000, Config.KNOWNLIST_UPDATE_INTERVAL);
}
private class KnownListUpdate implements Runnable
{
public KnownListUpdate()
{
}
@Override
public void run()
{
try
{
boolean failed;
for (L2WorldRegion regions[] : L2World.getInstance().getWorldRegions())
{
for (L2WorldRegion r : regions) // go through all world regions
{
// avoid stopping update if something went wrong in updateRegion()
try
{
failed = FAILED_REGIONS.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)
{
FAILED_REGIONS.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);
FAILED_REGIONS.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)
{
for (L2Object object : region.getVisibleObjects().values())
{
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);
if (forgetObjects)
{
object.getKnownList().forgetObjects(aggro || fullUpdate);
continue;
}
for (L2WorldRegion regi : region.getSurroundingRegions())
{
if ((object instanceof L2Playable) || (aggro && regi.isActive()) || fullUpdate)
{
for (L2Object obj : regi.getVisibleObjects().values())
{
if (obj != object)
{
object.getKnownList().addKnownObject(obj);
}
}
}
else if ((object instanceof L2Character) && regi.isActive())
{
for (L2Object obj : regi.getVisibleObjects().values())
{
if (obj != object)
{
object.getKnownList().addKnownObject(obj);
}
}
}
}
}
}
public static KnownListUpdateTaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final KnownListUpdateTaskManager _instance = new KnownListUpdateTaskManager();
}
}

View File

@ -1,47 +1,48 @@
/*
* 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.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author Layane
*/
public abstract class Task
{
protected final Logger _log = Logger.getLogger(getClass().getName());
public void initializate()
{
}
public ScheduledFuture<?> launchSpecial(ExecutedTask instance)
{
return null;
}
public abstract String getName();
public abstract void onTimeElapsed(ExecutedTask task);
public void onDestroy()
{
}
}
/*
* 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.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author Layane
*/
public abstract class Task
{
protected final Logger LOGGER = Logger.getLogger(getClass().getName());
public void initializate()
{
}
public ScheduledFuture<?> launchSpecial(ExecutedTask instance)
{
return null;
}
public abstract String getName();
public abstract void onTimeElapsed(ExecutedTask task);
public void onDestroy()
{
}
}

View File

@ -1,398 +1,380 @@
/*
* 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_NONE;
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_SHEDULED;
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.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskBirthday;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskClanLeaderApply;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskCleanUp;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskDailySkillReuseClean;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskDailyWorldChatPointReset;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskGlobalVariablesSave;
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.TaskScript;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskShutdown;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskVitalityReset;
/**
* @author Layane
*/
public final class TaskManager
{
protected static final Logger _log = Logger.getLogger(TaskManager.class.getName());
private final Map<Integer, Task> _tasks = new ConcurrentHashMap<>();
protected final List<ExecutedTask> _currentTasks = new CopyOnWriteArrayList<>();
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(?,?,?,?,?,?)"
};
protected TaskManager()
{
initializate();
startAllTasks();
_log.log(Level.INFO, getClass().getSimpleName() + ": Loaded: " + _tasks.size() + " Tasks");
}
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();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[1]))
{
statement.setLong(1, lastActivation);
statement.setInt(2, id);
statement.executeUpdate();
}
catch (SQLException e)
{
_log.log(Level.WARNING, getClass().getSimpleName() + ": Cannot updated the Global Task " + id + ": " + e.getMessage(), e);
}
if ((type == TYPE_SHEDULED) || (type == TYPE_TIME))
{
stopTask();
}
}
@Override
public boolean equals(Object object)
{
return (this == object) || ((object instanceof ExecutedTask) && (id == ((ExecutedTask) object).id));
}
@Override
public int hashCode()
{
return 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);
}
}
private void initializate()
{
registerTask(new TaskBirthday());
registerTask(new TaskClanLeaderApply());
registerTask(new TaskCleanUp());
registerTask(new TaskDailySkillReuseClean());
registerTask(new TaskDailyWorldChatPointReset());
registerTask(new TaskGlobalVariablesSave());
registerTask(new TaskOlympiadSave());
registerTask(new TaskRecom());
registerTask(new TaskRestart());
registerTask(new TaskScript());
registerTask(new TaskShutdown());
registerTask(new TaskVitalityReset());
}
public void registerTask(Task task)
{
_tasks.computeIfAbsent(task.getName().hashCode(), k ->
{
task.initializate();
return task;
});
}
private void startAllTasks()
{
try (Connection con = DatabaseFactory.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 (Exception e)
{
_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error while loading Global Task table: " + e.getMessage(), 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
{
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(getClass().getSimpleName() + ": Task " + task.getId() + " is obsoleted.");
}
catch (Exception e)
{
}
break;
}
case TYPE_SPECIAL:
{
final 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;
final String[] hour = task.getParams()[1].split(":");
if (hour.length != 3)
{
_log.warning(getClass().getSimpleName() + ": 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.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, getClass().getSimpleName() + ": 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)
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps1 = con.prepareStatement(SQL_STATEMENTS[2]))
{
ps1.setString(1, task);
try (ResultSet rs = ps1.executeQuery())
{
if (!rs.next())
{
try (PreparedStatement ps2 = con.prepareStatement(SQL_STATEMENTS[3]))
{
ps2.setString(1, task);
ps2.setString(2, type.toString());
ps2.setLong(3, lastActivation);
ps2.setString(4, param1);
ps2.setString(5, param2);
ps2.setString(6, param3);
ps2.execute();
}
}
}
return true;
}
catch (SQLException e)
{
_log.log(Level.WARNING, TaskManager.class.getSimpleName() + ": Cannot add the unique task: " + e.getMessage(), 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)
{
try (Connection con = DatabaseFactory.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();
return true;
}
catch (SQLException e)
{
_log.log(Level.WARNING, TaskManager.class.getSimpleName() + ": Cannot add the task: " + e.getMessage(), e);
}
return false;
}
public static TaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final TaskManager _instance = new TaskManager();
}
}
/*
* 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_NONE;
import static com.l2jmobius.gameserver.taskmanager.TaskTypes.TYPE_SHEDULED;
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.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ScheduledFuture;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.ThreadPoolManager;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskBirthday;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskCleanUp;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskRestart;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskScript;
import com.l2jmobius.gameserver.taskmanager.tasks.TaskShutdown;
/**
* @author Layane
*/
public final class TaskManager
{
protected static final Logger LOGGER = Logger.getLogger(TaskManager.class.getName());
private final Map<Integer, Task> _tasks = new ConcurrentHashMap<>();
protected final List<ExecutedTask> _currentTasks = new CopyOnWriteArrayList<>();
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(?,?,?,?,?,?)"
};
protected TaskManager()
{
initializate();
startAllTasks();
LOGGER.info(getClass().getSimpleName() + ": Loaded: " + _tasks.size() + " Tasks.");
}
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();
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(SQL_STATEMENTS[1]))
{
statement.setLong(1, lastActivation);
statement.setInt(2, id);
statement.executeUpdate();
}
catch (SQLException e)
{
LOGGER.warning("Cannot updated the Global Task " + id + ": " + e);
}
if ((type == TYPE_SHEDULED) || (type == TYPE_TIME))
{
stopTask();
}
}
@Override
public boolean equals(Object object)
{
if (this == object)
{
return true;
}
if (!(object instanceof ExecutedTask))
{
return false;
}
return id == ((ExecutedTask) object).id;
}
@Override
public int hashCode()
{
return 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);
}
}
private void initializate()
{
registerTask(new TaskBirthday());
registerTask(new TaskCleanUp());
registerTask(new TaskRestart());
registerTask(new TaskScript());
registerTask(new TaskShutdown());
}
public void registerTask(Task task)
{
final int key = task.getName().hashCode();
_tasks.computeIfAbsent(key, k ->
{
task.initializate();
return task;
});
}
private void startAllTasks()
{
try (Connection con = DatabaseFactory.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 (Exception e)
{
LOGGER.log(Level.SEVERE, "Error while loading Global Task table: ", 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
{
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;
}
LOGGER.info("Task " + task.getId() + " is obsoleted.");
}
catch (Exception e)
{
}
break;
case TYPE_SPECIAL:
final 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;
final String[] hour = task.getParams()[1].split(":");
if (hour.length != 3)
{
LOGGER.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.parseInt(hour[0]));
min.set(Calendar.MINUTE, Integer.parseInt(hour[1]));
min.set(Calendar.SECOND, Integer.parseInt(hour[2]));
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Bad parameter on task " + task.getId() + ": ", 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)
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps1 = con.prepareStatement(SQL_STATEMENTS[2]))
{
ps1.setString(1, task);
try (ResultSet rs = ps1.executeQuery())
{
if (!rs.next())
{
try (PreparedStatement ps2 = con.prepareStatement(SQL_STATEMENTS[3]))
{
ps2.setString(1, task);
ps2.setString(2, type.toString());
ps2.setLong(3, lastActivation);
ps2.setString(4, param1);
ps2.setString(5, param2);
ps2.setString(6, param3);
ps2.execute();
}
}
}
return true;
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, "Cannot add the unique task: ", 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)
{
try (Connection con = DatabaseFactory.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();
return true;
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, "Cannot add the task: ", e);
}
return false;
}
public static TaskManager getInstance()
{
return SingletonHolder._instance;
}
private static class SingletonHolder
{
protected static final TaskManager _instance = new TaskManager();
}
}

View File

@ -1,31 +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
}
/*
* 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
}

View File

@ -1,89 +1,145 @@
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.TimeUnit;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.instancemanager.MailManager;
import com.l2jmobius.gameserver.model.entity.Message;
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;
/**
* Birthday Gift task.
* @author Zoey76
*/
public class TaskBirthday extends Task
{
private static final String NAME = "birthday";
/** Get all players that have had a birthday since last check. */
private static final String SELECT_PENDING_BIRTHDAY_GIFTS = "SELECT charId, char_name, createDate, (YEAR(NOW()) - YEAR(createDate)) AS age FROM characters WHERE (YEAR(NOW()) - YEAR(createDate) > 0) AND ((DATE_ADD(createDate, INTERVAL (YEAR(NOW()) - YEAR(createDate)) YEAR)) BETWEEN FROM_UNIXTIME(?) AND NOW())";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
_log.info("BirthdayManager: " + giveBirthdayGifts(task.getLastActivation()) + " gifts sent.");
}
private int giveBirthdayGifts(long lastActivation)
{
int birthdayGiftCount = 0;
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement(SELECT_PENDING_BIRTHDAY_GIFTS))
{
ps.setLong(1, TimeUnit.SECONDS.convert(lastActivation, TimeUnit.MILLISECONDS));
try (ResultSet rs = ps.executeQuery())
{
while (rs.next())
{
final String text = Config.ALT_BIRTHDAY_MAIL_TEXT.replaceAll("$c1", rs.getString("char_name")).replaceAll("$s1", Integer.toString(rs.getInt("age")));
final Message msg = new Message(rs.getInt("charId"), Config.ALT_BIRTHDAY_MAIL_SUBJECT, text, MailType.BIRTHDAY);
msg.createAttachments().addItem("Birthday", Config.ALT_BIRTHDAY_GIFT, 1, null, null);
MailManager.getInstance().sendMessage(msg);
birthdayGiftCount++;
}
}
}
catch (SQLException e)
{
_log.warning("Error checking birthdays: " + e.getMessage());
}
return birthdayGiftCount;
}
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
}
}
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Level;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.data.sql.impl.CharNameTable;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.instancemanager.MailManager;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
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;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Nyaran
*/
public class TaskBirthday extends Task
{
private static final String NAME = "birthday";
private static final String QUERY = "SELECT charId, createDate FROM characters WHERE createDate LIKE ?";
private static final Calendar _today = Calendar.getInstance();
private int _count = 0;
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
final Calendar lastExecDate = Calendar.getInstance();
final long lastActivation = task.getLastActivation();
if (lastActivation > 0)
{
lastExecDate.setTimeInMillis(lastActivation);
}
final String rangeDate = "[" + Util.getDateString(lastExecDate.getTime()) + "] - [" + Util.getDateString(_today.getTime()) + "]";
for (; !_today.before(lastExecDate); lastExecDate.add(Calendar.DATE, 1))
{
checkBirthday(lastExecDate.get(Calendar.YEAR), lastExecDate.get(Calendar.MONTH), lastExecDate.get(Calendar.DATE));
}
LOGGER.info("BirthdayManager: " + _count + " gifts sent. " + rangeDate);
}
private void checkBirthday(int year, int month, int day)
{
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement(QUERY))
{
statement.setString(1, "%-" + getNum(month + 1) + "-" + getNum(day));
try (ResultSet rset = statement.executeQuery())
{
while (rset.next())
{
final int playerId = rset.getInt("charId");
final Calendar createDate = Calendar.getInstance();
createDate.setTime(rset.getDate("createDate"));
final int age = year - createDate.get(Calendar.YEAR);
if (age <= 0)
{
continue;
}
String text = Config.ALT_BIRTHDAY_MAIL_TEXT;
if (text.contains("$c1"))
{
text = text.replace("$c1", CharNameTable.getInstance().getNameById(playerId));
}
if (text.contains("$s1"))
{
text = text.replace("$s1", String.valueOf(age));
}
final Message msg = new Message(playerId, Config.ALT_BIRTHDAY_MAIL_SUBJECT, text, MailType.BIRTHDAY);
final Mail attachments = msg.createAttachments();
attachments.addItem("Birthday", Config.ALT_BIRTHDAY_GIFT, 1, null, null);
MailManager.getInstance().sendMessage(msg);
_count++;
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, "Error checking birthdays. ", e);
}
// If character birthday is 29-Feb and year isn't leap, send gift on 28-feb
final GregorianCalendar calendar = new GregorianCalendar();
if ((month == Calendar.FEBRUARY) && (day == 28) && !calendar.isLeapYear(_today.get(Calendar.YEAR)))
{
checkBirthday(year, Calendar.FEBRUARY, 29);
}
}
/**
* @param num the number to format.
* @return the formatted number starting with a 0 if it is lower or equal than 10.
*/
private String getNum(int num)
{
return (num <= 9) ? "0" + num : String.valueOf(num);
}
@Override
public void initializate()
{
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
}
}

View File

@ -1,72 +0,0 @@
/*
* 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.Calendar;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
import com.l2jmobius.gameserver.model.L2Clan;
import com.l2jmobius.gameserver.model.L2ClanMember;
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 UnAfraid
*/
public class TaskClanLeaderApply extends Task
{
private static final String NAME = "clanleaderapply";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) != Config.ALT_CLAN_LEADER_DATE_CHANGE)
{
return;
}
for (L2Clan clan : ClanTable.getInstance().getClans())
{
if (clan.getNewLeaderId() != 0)
{
final L2ClanMember member = clan.getClanMember(clan.getNewLeaderId());
if (member == null)
{
continue;
}
clan.setNewLeader(member);
}
}
_log.info(getClass().getSimpleName() + ": launched.");
}
@Override
public void initializate()
{
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", Config.ALT_CLAN_LEADER_HOUR_CHANGE, "");
}
}

View File

@ -1,41 +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 final String NAME = "clean_up";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
System.runFinalization();
System.gc();
}
}
/*
* 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 final String NAME = "clean_up";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
System.runFinalization();
System.gc();
}
}

View File

@ -1,71 +0,0 @@
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import com.l2jmobius.commons.database.DatabaseFactory;
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;
public class TaskDailySkillReuseClean extends Task
{
private static final String NAME = "daily_skill_clean";
private static final int[] _daily_skills =
{
2510,
22180
};
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
for (int skill_id : _daily_skills)
{
try (PreparedStatement ps = con.prepareStatement("DELETE FROM character_skills_save WHERE skill_id=?;"))
{
ps.setInt(1, skill_id);
ps.execute();
}
}
}
catch (Exception e)
{
_log.severe(getClass().getSimpleName() + ": Could not reset daily skill reuse: " + e);
}
_log.info("Daily skill reuse cleaned.");
}
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
}
}

View File

@ -1,74 +0,0 @@
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.ExWorldChatCnt;
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;
public class TaskDailyWorldChatPointReset extends Task
{
private static final String NAME = "daily_world_chat_reset";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
// Update data for offline players.
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("UPDATE character_variables SET val = ? WHERE var = ?"))
{
ps.setInt(1, Config.WORLD_CHAT_POINTS_PER_DAY);
ps.setString(2, L2PcInstance.WORLD_CHAT_VARIABLE_NAME);
ps.executeUpdate();
}
catch (Exception e)
{
_log.severe(getClass().getSimpleName() + ": Could not reset daily world chat points: " + e);
}
// Update data for online players.
L2World.getInstance().getPlayers().stream().forEach(player ->
{
player.setWorldChatPoints(Config.WORLD_CHAT_POINTS_PER_DAY);
player.sendPacket(new ExWorldChatCnt(player));
player.getVariables().storeMe();
});
_log.info("Daily world chat points has been resetted.");
}
@Override
public void initializate()
{
TaskManager.addUniqueTask(getName(), TaskTypes.TYPE_GLOBAL_TASK, "1", Config.WORLD_CHAT_RESET_TIME, "");
}
}

View File

@ -1,50 +0,0 @@
/*
* 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.instancemanager.GlobalVariablesManager;
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 Gigiikun
*/
public class TaskGlobalVariablesSave extends Task
{
public static final String NAME = "global_varibales_save";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
GlobalVariablesManager.getInstance().storeMe();
}
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "500000", "1800000", "");
}
}

View File

@ -1,55 +0,0 @@
/*
* 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.model.olympiad.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
{
public static final String NAME = "olympiad_save";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
if (Olympiad.getInstance().inCompPeriod())
{
Olympiad.getInstance().saveOlympiadStatus();
_log.info("Olympiad System: Data updated.");
}
}
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_FIXED_SHEDULED, "900000", "1800000", "");
}
}

View File

@ -1,73 +0,0 @@
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import com.l2jmobius.commons.database.DatabaseFactory;
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 String NAME = "recommendations";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
try (Connection con = DatabaseFactory.getInstance().getConnection())
{
try (PreparedStatement ps = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=0 WHERE rec_have <= 20"))
{
ps.setInt(1, 0); // Rec left = 0
ps.setInt(2, 3600000); // Timer = 1 hour
ps.execute();
}
try (PreparedStatement ps = con.prepareStatement("UPDATE character_reco_bonus SET rec_left=?, time_left=?, rec_have=GREATEST(rec_have-20,0) WHERE rec_have > 20"))
{
ps.setInt(1, 0); // Rec left = 0
ps.setInt(2, 3600000); // Timer = 1 hour
ps.execute();
}
}
catch (Exception e)
{
_log.severe(getClass().getSimpleName() + ": Could not reset Recommendations System: " + e);
}
_log.info("Recommendations System reseted");
}
@Override
public void initializate()
{
super.initializate();
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", "06:30:00", "");
}
}

View File

@ -1,42 +1,42 @@
/*
* 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 final String NAME = "restart";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
final Shutdown handler = new Shutdown(Integer.parseInt(task.getParams()[2]), true);
handler.start();
}
}
/*
* 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 final String NAME = "restart";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
final Shutdown handler = new Shutdown(Integer.parseInt(task.getParams()[2]), true);
handler.start();
}
}

View File

@ -1,65 +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 java.io.File;
import javax.script.ScriptException;
import com.l2jmobius.gameserver.scripting.L2ScriptEngineManager;
import com.l2jmobius.gameserver.taskmanager.Task;
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author janiii
*/
public class TaskScript extends Task
{
public static final String NAME = "script";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
final 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]);
}
}
}
/*
* 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.nio.file.Paths;
import java.util.logging.Level;
import com.l2jmobius.gameserver.scripting.ScriptEngineManager;
import com.l2jmobius.gameserver.taskmanager.Task;
import com.l2jmobius.gameserver.taskmanager.TaskManager.ExecutedTask;
/**
* @author janiii
*/
public class TaskScript extends Task
{
public static final String NAME = "script";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
try
{
ScriptEngineManager.getInstance().executeScript(Paths.get("cron", task.getParams()[2]));
}
catch (Exception e)
{
LOGGER.log(Level.WARNING, "Script execution failed!", e);
}
}
}

View File

@ -1,42 +1,42 @@
/*
* 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 final String NAME = "shutdown";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
final Shutdown handler = new Shutdown(Integer.parseInt(task.getParams()[2]), false);
handler.start();
}
}
/*
* 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 final String NAME = "shutdown";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
final Shutdown handler = new Shutdown(Integer.parseInt(task.getParams()[2]), false);
handler.start();
}
}

View File

@ -1,78 +0,0 @@
/*
* 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.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Calendar;
import java.util.logging.Level;
import com.l2jmobius.Config;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.actor.stat.PcStat;
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 UnAfraid
*/
public class TaskVitalityReset extends Task
{
private static final String NAME = "vitalityreset";
@Override
public String getName()
{
return NAME;
}
@Override
public void onTimeElapsed(ExecutedTask task)
{
if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) != Config.ALT_VITALITY_DATE_RESET)
{
return;
}
for (L2PcInstance player : L2World.getInstance().getPlayers())
{
player.setVitalityPoints(PcStat.MAX_VITALITY_POINTS, false);
}
try (Connection con = DatabaseFactory.getInstance().getConnection();
PreparedStatement st = con.prepareStatement("DELETE FROM account_gsdata WHERE var = ?"))
{
st.setString(1, PcStat.VITALITY_VARIABLE);
st.execute();
}
catch (Exception e)
{
_log.log(Level.WARNING, "", e);
}
_log.info(getClass().getSimpleName() + ": launched.");
}
@Override
public void initializate()
{
TaskManager.addUniqueTask(NAME, TaskTypes.TYPE_GLOBAL_TASK, "1", Config.ALT_VITALITY_HOUR_RESET, "");
}
}