Precautionary cancel NPC quest timers on decay.

This commit is contained in:
MobiusDevelopment
2020-03-31 11:13:30 +00:00
parent 39d35b111f
commit 4ed01c5fba
34 changed files with 765 additions and 0 deletions

View File

@ -16,6 +16,7 @@
*/
package org.l2jmobius.gameserver.model.actor;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
@ -77,6 +78,7 @@ import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.items.Weapon;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.model.olympiad.Olympiad;
import org.l2jmobius.gameserver.model.quest.QuestTimer;
import org.l2jmobius.gameserver.model.skills.Skill;
import org.l2jmobius.gameserver.model.spawns.NpcSpawnTemplate;
import org.l2jmobius.gameserver.model.stats.Formulas;
@ -156,6 +158,8 @@ public class Npc extends Creature
/** Contains information about local tax payments. */
private TaxZone _taxZone = null;
private final List<QuestTimer> _questTimers = new ArrayList<>();
/**
* Constructor of NpcInstance (use Creature constructor).<br>
* <br>
@ -1136,6 +1140,9 @@ public class Npc extends Creature
instance.removeNpc(this);
}
// Stop quest timers
stopQuestTimers();
// Clear script value
_scriptValue = 0;
}
@ -1854,4 +1861,32 @@ public class Npc extends Creature
{
return _raidStatus;
}
public void addQuestTimer(QuestTimer questTimer)
{
synchronized (_questTimers)
{
_questTimers.add(questTimer);
}
}
public void removeQuestTimer(QuestTimer questTimer)
{
synchronized (_questTimers)
{
_questTimers.remove(questTimer);
}
}
public void stopQuestTimers()
{
synchronized (_questTimers)
{
for (QuestTimer timer : _questTimers)
{
timer.cancel();
}
_questTimers.clear();
}
}
}

View File

@ -48,6 +48,11 @@ public class QuestTimer
_scheduler = ThreadPool.schedule(new ScheduleTimerTask(), time); // Prepare auto end task
}
if (npc != null)
{
npc.addQuestTimer(this);
}
if (player != null)
{
player.addQuestTimer(this);
@ -62,6 +67,11 @@ public class QuestTimer
_scheduler = null;
}
if (_npc != null)
{
_npc.removeQuestTimer(this);
}
if (_player != null)
{
_player.removeQuestTimer(this);