AdminKill.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 java.util.StringTokenizer;
  17. import java.util.logging.Logger;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  20. import net.sf.l2j.gameserver.model.L2Character;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2World;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2ControllableMobInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.network.SystemMessageId;
  26. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  27. /**
  28. * This class handles following admin commands:
  29. * - kill = kills target L2Character
  30. * - kill_monster = kills target non-player
  31. *
  32. * - kill <radius> = If radius is specified, then ALL players only in that radius will be killed.
  33. * - kill_monster <radius> = If radius is specified, then ALL non-players only in that radius will be killed.
  34. *
  35. * @version $Revision: 1.2.4.5 $ $Date: 2007/07/31 10:06:06 $
  36. */
  37. public class AdminKill implements IAdminCommandHandler
  38. {
  39. private static Logger _log = Logger.getLogger(AdminKill.class.getName());
  40. private static final String[] ADMIN_COMMANDS =
  41. {
  42. "admin_kill",
  43. "admin_kill_monster"
  44. };
  45. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  46. {
  47. if (command.startsWith("admin_kill"))
  48. {
  49. StringTokenizer st = new StringTokenizer(command, " ");
  50. st.nextToken(); // skip command
  51. if (st.hasMoreTokens())
  52. {
  53. String firstParam = st.nextToken();
  54. L2PcInstance plyr = L2World.getInstance().getPlayer(firstParam);
  55. if (plyr != null)
  56. {
  57. if (st.hasMoreTokens())
  58. {
  59. try
  60. {
  61. int radius = Integer.parseInt(st.nextToken());
  62. for (L2Character knownChar : plyr.getKnownList().getKnownCharactersInRadius(radius))
  63. {
  64. if (knownChar instanceof L2ControllableMobInstance || knownChar == activeChar)
  65. continue;
  66. kill(activeChar, knownChar);
  67. }
  68. activeChar.sendMessage("Killed all characters within a " + radius + " unit radius.");
  69. return true;
  70. }
  71. catch (NumberFormatException e)
  72. {
  73. activeChar.sendMessage("Invalid radius.");
  74. return false;
  75. }
  76. }
  77. else
  78. {
  79. kill(activeChar, plyr);
  80. }
  81. }
  82. else
  83. {
  84. try
  85. {
  86. int radius = Integer.parseInt(firstParam);
  87. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  88. {
  89. if (knownChar instanceof L2ControllableMobInstance || knownChar == activeChar)
  90. continue;
  91. kill(activeChar, knownChar);
  92. }
  93. activeChar.sendMessage("Killed all characters within a " + radius + " unit radius.");
  94. return true;
  95. }
  96. catch (NumberFormatException e)
  97. {
  98. activeChar.sendMessage("Usage: //kill <player_name | radius>");
  99. return false;
  100. }
  101. }
  102. }
  103. else
  104. {
  105. L2Object obj = activeChar.getTarget();
  106. if (obj instanceof L2ControllableMobInstance || !(obj instanceof L2Character))
  107. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  108. else
  109. kill(activeChar, (L2Character) obj);
  110. }
  111. }
  112. return true;
  113. }
  114. private void kill(L2PcInstance activeChar, L2Character target)
  115. {
  116. if (target instanceof L2PcInstance)
  117. {
  118. if (!((L2PcInstance) target).isGM())
  119. target.stopAllEffects(); // e.g. invincibility effect
  120. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar);
  121. }
  122. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  123. target.reduceCurrentHp(target.getMaxHp() * Config.L2JMOD_CHAMPION_HP + 1, activeChar);
  124. else
  125. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar);
  126. if (Config.DEBUG)
  127. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ")" + " killed character " + target.getObjectId());
  128. }
  129. public String[] getAdminCommandList()
  130. {
  131. return ADMIN_COMMANDS;
  132. }
  133. }