AdminDelete.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 net.sf.l2j.gameserver.handler.admincommandhandlers;
  16. import net.sf.l2j.gameserver.datatables.SpawnTable;
  17. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  18. import net.sf.l2j.gameserver.instancemanager.RaidBossSpawnManager;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Spawn;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  22. import net.sf.l2j.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. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  35. {
  36. if (command.equals("admin_delete"))
  37. handleDelete(activeChar);
  38. return true;
  39. }
  40. public String[] getAdminCommandList()
  41. {
  42. return ADMIN_COMMANDS;
  43. }
  44. // TODO: add possibility to delete any L2Object (except L2PcInstance)
  45. private void handleDelete(L2PcInstance activeChar)
  46. {
  47. L2Object obj = activeChar.getTarget();
  48. if (obj instanceof L2NpcInstance)
  49. {
  50. L2NpcInstance target = (L2NpcInstance) obj;
  51. target.deleteMe();
  52. L2Spawn spawn = target.getSpawn();
  53. if (spawn != null)
  54. {
  55. spawn.stopRespawn();
  56. if (RaidBossSpawnManager.getInstance().isDefined(spawn.getNpcid()))
  57. RaidBossSpawnManager.getInstance().deleteSpawn(spawn, true);
  58. else
  59. SpawnTable.getInstance().deleteSpawn(spawn, true);
  60. }
  61. activeChar.sendMessage("Deleted " + target.getName() + " from " + target.getObjectId() + ".");
  62. }
  63. else
  64. activeChar.sendMessage("Incorrect target.");
  65. }
  66. }