AdminKill.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2004-2015 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 java.util.logging.Logger;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.L2World;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. /**
  31. * This class handles following admin commands: - kill = kills target L2Character - kill_monster = kills target non-player - kill <radius> = If radius is specified, then ALL players only in that radius will be killed. - kill_monster <radius> = If radius is specified, then ALL non-players only in
  32. * that radius will be killed.
  33. * @version $Revision: 1.2.4.5 $ $Date: 2007/07/31 10:06:06 $
  34. */
  35. public class AdminKill implements IAdminCommandHandler
  36. {
  37. private static Logger _log = Logger.getLogger(AdminKill.class.getName());
  38. private static final String[] ADMIN_COMMANDS =
  39. {
  40. "admin_kill",
  41. "admin_kill_monster"
  42. };
  43. @Override
  44. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  45. {
  46. if (command.startsWith("admin_kill"))
  47. {
  48. StringTokenizer st = new StringTokenizer(command, " ");
  49. st.nextToken(); // skip command
  50. if (st.hasMoreTokens())
  51. {
  52. String firstParam = st.nextToken();
  53. L2PcInstance plyr = L2World.getInstance().getPlayer(firstParam);
  54. if (plyr != null)
  55. {
  56. if (st.hasMoreTokens())
  57. {
  58. try
  59. {
  60. int radius = Integer.parseInt(st.nextToken());
  61. for (L2Character knownChar : plyr.getKnownList().getKnownCharactersInRadius(radius))
  62. {
  63. if ((knownChar instanceof L2ControllableMobInstance) || (knownChar == activeChar))
  64. {
  65. continue;
  66. }
  67. kill(activeChar, knownChar);
  68. }
  69. activeChar.sendMessage("Killed all characters within a " + radius + " unit radius.");
  70. return true;
  71. }
  72. catch (NumberFormatException e)
  73. {
  74. activeChar.sendMessage("Invalid radius.");
  75. return false;
  76. }
  77. }
  78. kill(activeChar, plyr);
  79. }
  80. else
  81. {
  82. try
  83. {
  84. int radius = Integer.parseInt(firstParam);
  85. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  86. {
  87. if ((knownChar instanceof L2ControllableMobInstance) || (knownChar == activeChar))
  88. {
  89. continue;
  90. }
  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. {
  108. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  109. }
  110. else
  111. {
  112. kill(activeChar, (L2Character) obj);
  113. }
  114. }
  115. }
  116. return true;
  117. }
  118. private void kill(L2PcInstance activeChar, L2Character target)
  119. {
  120. if (target instanceof L2PcInstance)
  121. {
  122. if (!((L2PcInstance) target).isGM())
  123. {
  124. target.stopAllEffects(); // e.g. invincibility effect
  125. }
  126. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
  127. }
  128. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  129. {
  130. target.reduceCurrentHp((target.getMaxHp() * Config.L2JMOD_CHAMPION_HP) + 1, activeChar, null);
  131. }
  132. else
  133. {
  134. boolean targetIsInvul = false;
  135. if (target.isInvul())
  136. {
  137. targetIsInvul = true;
  138. target.setIsInvul(false);
  139. }
  140. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar, null);
  141. if (targetIsInvul)
  142. {
  143. target.setIsInvul(true);
  144. }
  145. }
  146. if (Config.DEBUG)
  147. {
  148. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ")" + " killed character " + target.getObjectId());
  149. }
  150. }
  151. @Override
  152. public String[] getAdminCommandList()
  153. {
  154. return ADMIN_COMMANDS;
  155. }
  156. }