package handlers.admin;
import ru.catssoftware.gameserver.ai.CtrlIntention;
import ru.catssoftware.gameserver.gmaccess.gmController;
import ru.catssoftware.gameserver.gmaccess.gmHandler;
import ru.catssoftware.gameserver.model.L2Object;
import ru.catssoftware.gameserver.model.L2World;
import ru.catssoftware.gameserver.model.actor.instance.L2NpcInstance;
import ru.catssoftware.gameserver.model.actor.instance.L2PcInstance;
public class AdminNpcTeleport extends gmHandler {
private static final String[] COMMANDS = {"teleport_to_npc"};
public static void main(String... args) {
gmController.getInstance().regCommand(new AdminNpcTeleport());
}
@Override
public void runCommand(L2PcInstance admin, String... params) {
String command = params[0];
if (command.startsWith("teleport_to_npc")) {
int npc_id = Integer.parseInt(params[0]);
teleportToNpc(admin, npc_id);
}
}
private void teleportToNpc(L2PcInstance player, int npc_id) {
for (L2Object obj : L2World.getInstance().getAllVisibleObjects()) {
if (obj instanceof L2NpcInstance) {
L2NpcInstance npc = (L2NpcInstance) obj;
if (npc.getNpcId() == npc_id) {
player.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
player.teleToLocation(npc.getX(), npc.getY(), npc.getZ(), true);
}
}
}
}
@Override
public String[] getCommandList() {
return COMMANDS;
}
}