@ScriptManifest(author = "Botre", info = "", logo = "", name = "Selection Listener Example", version = 0)
public class SelectionListenerExample extends Script implements SelectionListener<NPC> {
private Sapi sapi;
@Override
public void onStart() throws InterruptedException {
super.onStart();
sapi = new Sapi(this);
sapi.registerMouseAdapter();
sapi.setSelector(Module.NPC);
sapi.getNpcSelector().getSelectionListeners().add(this);
}
@Override
public int onLoop() throws InterruptedException {
//...
return 500;
}
@Override
public void onPaint(Graphics2D g2d) {
super.onPaint(g2d);
for (NPC npc : sapi.getNpcSelector().getSelection()) {
Painter.defaultEntity().paint(g2d, this, npc);
}
}
@Override
public void onExit() throws InterruptedException {
sapi.unregisterMouseAdapter();
super.onExit();
}
@Override
public void onSelection(List<NPC> selection) {
for (NPC npc : selection) {
if(npc != null) {
log("Selected npc with name: " + npc.getName());
if(npc.getActions() == null) continue;
log("This npc has the following actions:");
for (String action : npc.getActions()) {
log("\t" + action);
}
}
}
}
}