package LGMods;
import l2.gameserver.model.Creature;
import l2.gameserver.model.Player;
import l2.gameserver.model.instances.NpcInstance;
import l2.gameserver.listener.actor.OnAttackListener;
import l2.gameserver.model.actor.listener.CharListenerList;
import l2.gameserver.scripts.ScriptFile;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* PURPOSE: Capture interaction with NPCs using the Attack Listener (test purpose).
* USAGE: Since dialog click (FirstTalk) is not working on this revision,
* we use the attack click to validate that logging works correctly.
* DATE: 01/18/2026 10:30
*/
public class SentinelNpcInteractionTest implements ScriptFile {
/**
* Listener responsible for capturing attacks against NPCs
*/
private static class NpcTestListeners implements OnAttackListener {
@Override
public void onAttack(Creature attacker, Creature target) {
// Check if the attacker is a player and the target is an NPC
if (attacker == null || !attacker.isPlayer() || target == null || !target.isNpc()) {
return;
}
Player player = attacker.getPlayer();
NpcInstance npc = (NpcInstance) target;
String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
// Formatted log output
String log = String.format(
"[%s] Player [%s] clicked and interacted with the NPC [%s ID: %d]",
time,
player.getName(),
npc.getName(),
npc.getNpcId()
);
// Print to console
System.out.println("[LOG-test] " + log);
}
}
@Override
public void onLoad() {
// Register the listener globally
NpcTestListeners listeners = new NpcTestListeners();
CharListenerList.addGlobal(listeners);
System.out.println("[test] Test Log Module successfully loaded!");
}
@Override
public void onReload() {
// Not used
}
@Override
public void onShutdown() {
// Not used
}
}