AdminKill.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 java.util.StringTokenizer;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2World;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. /**
  27. * This class handles following admin commands:
  28. * - kill = kills target L2Character
  29. * - kill_monster = kills target non-player
  30. *
  31. * - kill <radius> = If radius is specified, then ALL players only in that radius will be killed.
  32. * - kill_monster <radius> = If radius is specified, then ALL non-players only in that radius will be killed.
  33. *
  34. * @version $Revision: 1.2.4.5 $ $Date: 2007/07/31 10:06:06 $
  35. */
  36. public class AdminKill implements IAdminCommandHandler
  37. {
  38. private static Logger _log = Logger.getLogger(AdminKill.class.getName());
  39. private static final String[] ADMIN_COMMANDS =
  40. {
  41. "admin_kill",
  42. "admin_kill_monster"
  43. };
  44. @Override
  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. kill(activeChar, plyr);
  78. }
  79. else
  80. {
  81. try
  82. {
  83. int radius = Integer.parseInt(firstParam);
  84. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  85. {
  86. if (knownChar instanceof L2ControllableMobInstance || knownChar == activeChar)
  87. continue;
  88. kill(activeChar, knownChar);
  89. }
  90. activeChar.sendMessage("Killed all characters within a " + radius + " unit radius.");
  91. return true;
  92. }
  93. catch (NumberFormatException e)
  94. {
  95. activeChar.sendMessage("Usage: //kill <player_name | radius>");
  96. return false;
  97. }
  98. }
  99. }
  100. else
  101. {
  102. L2Object obj = activeChar.getTarget();
  103. if (obj instanceof L2ControllableMobInstance || !(obj instanceof L2Character))
  104. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  105. else
  106. kill(activeChar, (L2Character) obj);
  107. }
  108. }
  109. return true;
  110. }
  111. private void kill(L2PcInstance activeChar, L2Character target)
  112. {
  113. if (target instanceof L2PcInstance)
  114. {
  115. if (!((L2PcInstance) target).isGM())
  116. target.stopAllEffects(); // e.g. invincibility effect
  117. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
  118. }
  119. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  120. target.reduceCurrentHp(target.getMaxHp() * Config.L2JMOD_CHAMPION_HP + 1, activeChar, null);
  121. else
  122. {
  123. boolean targetIsInvul = false;
  124. if (target.isInvul())
  125. {
  126. targetIsInvul = true;
  127. target.setIsInvul(false);
  128. }
  129. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar, null);
  130. if (targetIsInvul)
  131. {
  132. target.setIsInvul(true);
  133. }
  134. }
  135. if (Config.DEBUG)
  136. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ")" + " killed character " + target.getObjectId());
  137. }
  138. @Override
  139. public String[] getAdminCommandList()
  140. {
  141. return ADMIN_COMMANDS;
  142. }
  143. }