/*
* Copyright (C) 2004-2015 L2J DataPack
*
* This file is part of L2J DataPack.
*
* L2J DataPack is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* L2J DataPack is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package handlers.admincommandhandlers;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.l2jserver.Config;
import com.l2jserver.gameserver.SevenSigns;
import com.l2jserver.gameserver.data.xml.impl.AdminData;
import com.l2jserver.gameserver.data.xml.impl.NpcData;
import com.l2jserver.gameserver.datatables.SpawnTable;
import com.l2jserver.gameserver.handler.IAdminCommandHandler;
import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager;
import com.l2jserver.gameserver.instancemanager.InstanceManager;
import com.l2jserver.gameserver.instancemanager.QuestManager;
import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
import com.l2jserver.gameserver.model.AutoSpawnHandler;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2Spawn;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
import com.l2jserver.gameserver.model.entity.Instance;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
import com.l2jserver.gameserver.util.Broadcast;
import com.l2jserver.util.StringUtil;
/**
* This class handles following admin commands: - show_spawns = shows menu - spawn_index lvl = shows menu for monsters with respective level - spawn_monster id = spawns monster id on target
* @version $Revision: 1.2.2.5.2.5 $ $Date: 2005/04/11 10:06:06 $
*/
public class AdminSpawn implements IAdminCommandHandler
{
private static final Logger _log = Logger.getLogger(AdminSpawn.class.getName());
private static final String[] ADMIN_COMMANDS =
{
"admin_show_spawns",
"admin_spawn",
"admin_spawn_monster",
"admin_spawn_index",
"admin_unspawnall",
"admin_respawnall",
"admin_spawn_reload",
"admin_npc_index",
"admin_spawn_once",
"admin_show_npcs",
"admin_spawnnight",
"admin_spawnday",
"admin_instance_spawns",
"admin_list_spawns",
"admin_list_positions",
"admin_spawn_debug_menu",
"admin_spawn_debug_print",
"admin_spawn_debug_print_menu"
};
@Override
public boolean useAdminCommand(String command, L2PcInstance activeChar)
{
if (command.equals("admin_show_spawns"))
{
AdminHtml.showAdminHtml(activeChar, "spawns.htm");
}
else if (command.equalsIgnoreCase("admin_spawn_debug_menu"))
{
AdminHtml.showAdminHtml(activeChar, "spawns_debug.htm");
}
else if (command.startsWith("admin_spawn_debug_print"))
{
StringTokenizer st = new StringTokenizer(command, " ");
L2Object target = activeChar.getTarget();
if (target instanceof L2Npc)
{
try
{
st.nextToken();
int type = Integer.parseInt(st.nextToken());
printSpawn((L2Npc) target, type);
if (command.contains("_menu"))
{
AdminHtml.showAdminHtml(activeChar, "spawns_debug.htm");
}
}
catch (Exception e)
{
}
}
else
{
activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
}
}
else if (command.startsWith("admin_spawn_index"))
{
StringTokenizer st = new StringTokenizer(command, " ");
try
{
st.nextToken();
int level = Integer.parseInt(st.nextToken());
int from = 0;
try
{
from = Integer.parseInt(st.nextToken());
}
catch (NoSuchElementException nsee)
{
}
showMonsters(activeChar, level, from);
}
catch (Exception e)
{
AdminHtml.showAdminHtml(activeChar, "spawns.htm");
}
}
else if (command.equals("admin_show_npcs"))
{
AdminHtml.showAdminHtml(activeChar, "npcs.htm");
}
else if (command.startsWith("admin_npc_index"))
{
StringTokenizer st = new StringTokenizer(command, " ");
try
{
st.nextToken();
String letter = st.nextToken();
int from = 0;
try
{
from = Integer.parseInt(st.nextToken());
}
catch (NoSuchElementException nsee)
{
}
showNpcs(activeChar, letter, from);
}
catch (Exception e)
{
AdminHtml.showAdminHtml(activeChar, "npcs.htm");
}
}
else if (command.startsWith("admin_instance_spawns"))
{
StringTokenizer st = new StringTokenizer(command, " ");
try
{
st.nextToken();
int instance = Integer.parseInt(st.nextToken());
if (instance >= 300000)
{
final StringBuilder html = StringUtil.startAppend(500 + 1000, "
", "Spawns for " + String.valueOf(instance) + "", "
", "
NpcName
Action
");
int counter = 0;
int skiped = 0;
Instance inst = InstanceManager.getInstance().getInstance(instance);
if (inst != null)
{
for (L2Npc npc : inst.getNpcs())
{
if (!npc.isDead())
{
// Only 50 because of client html limitation
if (counter < 50)
{
StringUtil.append(html, "