AdminKill.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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.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 = {"admin_kill", "admin_kill_monster"};
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.startsWith("admin_kill"))
  44. {
  45. StringTokenizer st = new StringTokenizer(command, " ");
  46. st.nextToken(); // skip command
  47. if (st.hasMoreTokens())
  48. {
  49. String firstParam = st.nextToken();
  50. L2PcInstance plyr = L2World.getInstance().getPlayer(firstParam);
  51. if (plyr != null)
  52. {
  53. if (st.hasMoreTokens())
  54. {
  55. try
  56. {
  57. int radius = Integer.parseInt(st.nextToken());
  58. for (L2Character knownChar : plyr.getKnownList().getKnownCharactersInRadius(radius))
  59. {
  60. if (knownChar instanceof L2ControllableMobInstance || knownChar == activeChar)
  61. continue;
  62. kill(activeChar, knownChar);
  63. }
  64. activeChar.sendMessage("Killed all characters within a " + radius + " unit radius.");
  65. return true;
  66. }
  67. catch (NumberFormatException e) {
  68. activeChar.sendMessage("Invalid radius.");
  69. return false;
  70. }
  71. } else
  72. {
  73. kill(activeChar, plyr);
  74. }
  75. }
  76. else
  77. {
  78. try
  79. {
  80. int radius = Integer.parseInt(firstParam);
  81. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  82. {
  83. if (knownChar instanceof L2ControllableMobInstance || knownChar == activeChar)
  84. continue;
  85. kill(activeChar, knownChar);
  86. }
  87. activeChar.sendMessage("Killed all characters within a " + radius + " unit radius.");
  88. return true;
  89. }
  90. catch (NumberFormatException e) {
  91. activeChar.sendMessage("Usage: //kill <player_name | radius>");
  92. return false;
  93. }
  94. }
  95. }
  96. else
  97. {
  98. L2Object obj = activeChar.getTarget();
  99. if (obj instanceof L2ControllableMobInstance || !(obj instanceof L2Character))
  100. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  101. else
  102. kill(activeChar, (L2Character)obj);
  103. }
  104. }
  105. return true;
  106. }
  107. private void kill(L2PcInstance activeChar, L2Character target)
  108. {
  109. if (target instanceof L2PcInstance)
  110. {
  111. if(!((L2PcInstance)target).isGM())
  112. target.stopAllEffects(); // e.g. invincibility effect
  113. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar);
  114. }
  115. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  116. target.reduceCurrentHp(target.getMaxHp()*Config.L2JMOD_CHAMPION_HP + 1, activeChar);
  117. else
  118. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar);
  119. if (Config.DEBUG)
  120. _log.fine("GM: "+activeChar.getName()+"("+activeChar.getObjectId()+")"+
  121. " killed character "+target.getObjectId());
  122. }
  123. public String[] getAdminCommandList()
  124. {
  125. return ADMIN_COMMANDS;
  126. }
  127. }