AdminScan.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.StringTokenizer;
  21. import com.l2jserver.gameserver.datatables.SpawnTable;
  22. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  23. import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.L2Spawn;
  26. import com.l2jserver.gameserver.model.L2World;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  31. /**
  32. * @author NosBit
  33. */
  34. public class AdminScan implements IAdminCommandHandler
  35. {
  36. private static final String[] ADMIN_COMMANDS =
  37. {
  38. "admin_scan",
  39. "admin_deleteNpcByObjectId"
  40. };
  41. private static final int DEFAULT_RADIUS = 500;
  42. @Override
  43. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  44. {
  45. final StringTokenizer st = new StringTokenizer(command, " ");
  46. final String actualCommand = st.nextToken();
  47. switch (actualCommand.toLowerCase())
  48. {
  49. case "admin_scan":
  50. {
  51. int radius = DEFAULT_RADIUS;
  52. if (st.hasMoreElements())
  53. {
  54. try
  55. {
  56. radius = Integer.parseInt(st.nextToken());
  57. }
  58. catch (NumberFormatException e)
  59. {
  60. activeChar.sendMessage("Usage: //scan [radius]");
  61. return false;
  62. }
  63. }
  64. sendNpcList(activeChar, radius);
  65. break;
  66. }
  67. case "admin_deletenpcbyobjectid":
  68. {
  69. if (!st.hasMoreElements())
  70. {
  71. activeChar.sendMessage("Usage: //deletenpcbyobjectid <object_id>");
  72. return false;
  73. }
  74. try
  75. {
  76. int objectId = Integer.parseInt(st.nextToken());
  77. final L2Object target = L2World.getInstance().findObject(objectId);
  78. final L2Npc npc = target instanceof L2Npc ? (L2Npc) target : null;
  79. if (npc == null)
  80. {
  81. activeChar.sendMessage("NPC does not exist or object_id does not belong to an NPC");
  82. return false;
  83. }
  84. npc.deleteMe();
  85. final L2Spawn spawn = npc.getSpawn();
  86. if (spawn != null)
  87. {
  88. spawn.stopRespawn();
  89. if (RaidBossSpawnManager.getInstance().isDefined(spawn.getId()))
  90. {
  91. RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
  92. }
  93. else
  94. {
  95. SpawnTable.getInstance().deleteSpawn(spawn, true);
  96. }
  97. }
  98. activeChar.sendMessage(npc.getName() + " have been deleted.");
  99. }
  100. catch (NumberFormatException e)
  101. {
  102. activeChar.sendMessage("object_id must be a number.");
  103. return false;
  104. }
  105. sendNpcList(activeChar, DEFAULT_RADIUS);
  106. break;
  107. }
  108. }
  109. return true;
  110. }
  111. private void sendNpcList(L2PcInstance activeChar, int radius)
  112. {
  113. final NpcHtmlMessage html = new NpcHtmlMessage();
  114. html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/scan.htm");
  115. final StringBuilder sb = new StringBuilder();
  116. for (L2Character character : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  117. {
  118. if (character instanceof L2Npc)
  119. {
  120. sb.append("<tr>");
  121. sb.append("<td width=\"54\">" + character.getId() + "</td>");
  122. sb.append("<td width=\"54\">" + character.getName() + "</td>");
  123. sb.append("<td width=\"54\">" + Math.round(activeChar.calculateDistance(character, false, false)) + "</td>");
  124. sb.append("<td width=\"54\"><a action=\"bypass -h admin_deleteNpcByObjectId " + character.getObjectId() + "\"><font color=\"LEVEL\">Delete</font></a></td>");
  125. sb.append("<td width=\"54\"><a action=\"bypass -h admin_move_to " + character.getX() + " " + character.getY() + " " + character.getZ() + "\"><font color=\"LEVEL\">Go to</font></a></td>");
  126. sb.append("</tr>");
  127. }
  128. }
  129. html.replace("%data%", sb.toString());
  130. activeChar.sendPacket(html);
  131. }
  132. @Override
  133. public String[] getAdminCommandList()
  134. {
  135. return ADMIN_COMMANDS;
  136. }
  137. }