I've fixed it myself.
Apart of issues with NPC references in Frintezza.java itself, there is race condition within org.l2jmobius.gameserver.model.quest.QuestTimer.java. I guess other places with single shot timers are affected as well.
Updated QuestTimer.java
package org.l2jmobius.gameserver.model.quest;
import java.util.Objects;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.l2jmobius.commons.threads.ThreadPool;
import org.l2jmobius.gameserver.model.actor.Npc;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.events.AbstractScript;
public class QuestTimer
{
public static final Logger LOGGER = Logger.getLogger(AbstractScript.class.getName());
protected final String _name;
protected final Quest _quest;
protected Npc _npc;
protected Player _player;
protected final boolean _isRepeating;
protected final AtomicReference<ScheduledFuture<?>> _scheduler = new AtomicReference<>();
protected volatile boolean _isActive;
public QuestTimer(Quest quest, String name, long time, Npc npc, Player player, boolean repeating)
{
_quest = quest;
_name = name;
_npc = npc;
_player = player;
_isRepeating = repeating;
_isActive = true;
if (repeating)
{
_scheduler.set(ThreadPool.scheduleAtFixedRate(new ScheduleTimerTask(), time, time)); // Prepare auto end task
}
else
{
_scheduler.set(ThreadPool.schedule(new ScheduleTimerTask(), time)); // Prepare auto end task
}
if (npc != null)
{
npc.addQuestTimer(this);
}
if (player != null)
{
player.addQuestTimer(this);
}
}
public void cancel()
{
cancelTask();
if (_npc != null)
{
_npc.removeQuestTimer(this);
}
if (_player != null)
{
_player.removeQuestTimer(this);
}
// Nullify references to avoid memory leaks
_npc = null;
_player = null;
}
public void cancelTask()
{
ScheduledFuture<?> scheduler = _scheduler.getAndSet(null); // Atomically get and nullify
if ((scheduler != null) && !scheduler.isDone() && !scheduler.isCancelled())
{
scheduler.cancel(false);
}
_quest.removeQuestTimer(this); // Ensure timer is removed before nullifying scheduler
}
/**
* public method to compare if this timer matches with the key attributes passed.
* @param quest : Quest instance to which the timer is attached
* @param name : Name of the timer
* @param npc : Npc instance attached to the desired timer (null if no npc attached)
* @param player : Player instance attached to the desired timer (null if no player attached)
* @return boolean
*/
public boolean equals(Quest quest, String name, Npc npc, Player player)
{
return (_quest == quest) && (Objects.equals(_name, name)) && // Handles null safety
(_npc == npc) && (_player == player);
}
public boolean isActive()
{
ScheduledFuture<?> scheduler = _scheduler.get(); // Get the current reference safely
return (scheduler != null) && !scheduler.isCancelled() && !scheduler.isDone() && _isActive;
}
public boolean isRepeating()
{
return _isRepeating;
}
public Quest getQuest()
{
return _quest;
}
public Npc getNpc()
{
return _npc;
}
public Player getPlayer()
{
return _player;
}
[member=79]override[/member]
public String toString()
{
return _name;
}
public class ScheduleTimerTask implements Runnable
{
[member=79]override[/member]
public void run()
{
ScheduledFuture<?> scheduler = _scheduler.get();
if (scheduler == null)
{
LOGGER.log(Level.WARNING, "Scheduler is NULL");
return;
}
if (!_isRepeating)
{
_isActive = false;
}
_quest.notifyEvent(_name, _npc, _player);
if (!_isRepeating)
{
cancel();
}
}
}
}
Plus changes to Quest.java :: getQuestTimer due to changes in QuestTimer
for (QuestTimer timer : timers)
{
if ((timer != null) && timer.equals(this, name, npc, player) && timer.isActive())
{
return timer;
}
}