AdminDelete.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.admincommandhandlers;
  16. import com.l2jserver.gameserver.datatables.SpawnTable;
  17. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  18. import com.l2jserver.gameserver.instancemanager.RaidBossSpawnManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2Spawn;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. /**
  24. * This class handles following admin commands: - delete = deletes target
  25. *
  26. * @version $Revision: 1.2.2.1.2.4 $ $Date: 2005/04/11 10:05:56 $
  27. */
  28. public class AdminDelete implements IAdminCommandHandler
  29. {
  30. private static final String[] ADMIN_COMMANDS =
  31. {
  32. "admin_delete"
  33. };
  34. @Override
  35. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  36. {
  37. if (command.equals("admin_delete"))
  38. handleDelete(activeChar);
  39. return true;
  40. }
  41. @Override
  42. public String[] getAdminCommandList()
  43. {
  44. return ADMIN_COMMANDS;
  45. }
  46. // TODO: add possibility to delete any L2Object (except L2PcInstance)
  47. private void handleDelete(L2PcInstance activeChar)
  48. {
  49. L2Object obj = activeChar.getTarget();
  50. if (obj instanceof L2Npc)
  51. {
  52. L2Npc target = (L2Npc) obj;
  53. target.deleteMe();
  54. L2Spawn spawn = target.getSpawn();
  55. if (spawn != null)
  56. {
  57. spawn.stopRespawn();
  58. if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcid()))
  59. RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
  60. else
  61. SpawnTable.getInstance().deleteSpawn(spawn, true);
  62. }
  63. activeChar.sendMessage("Deleted " + target.getName() + " from " + target.getObjectId() + ".");
  64. }
  65. else
  66. activeChar.sendMessage("Incorrect target.");
  67. }
  68. }