AdminRes.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2World;
  21. import com.l2jserver.gameserver.model.actor.L2Character;
  22. import com.l2jserver.gameserver.model.actor.instance.L2ControllableMobInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.taskmanager.DecayTaskManager;
  26. /**
  27. * This class handles following admin commands:
  28. * - res = resurrects target L2Character
  29. *
  30. * @version $Revision: 1.2.4.5 $ $Date: 2005/04/11 10:06:06 $
  31. */
  32. public class AdminRes implements IAdminCommandHandler
  33. {
  34. private static Logger _log = Logger.getLogger(AdminRes.class.getName());
  35. private static final String[] ADMIN_COMMANDS =
  36. {
  37. "admin_res",
  38. "admin_res_monster"
  39. };
  40. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.startsWith("admin_res "))
  44. handleRes(activeChar, command.split(" ")[1]);
  45. else if (command.equals("admin_res"))
  46. handleRes(activeChar);
  47. else if (command.startsWith("admin_res_monster "))
  48. handleNonPlayerRes(activeChar, command.split(" ")[1]);
  49. else if (command.equals("admin_res_monster"))
  50. handleNonPlayerRes(activeChar);
  51. return true;
  52. }
  53. @Override
  54. public String[] getAdminCommandList()
  55. {
  56. return ADMIN_COMMANDS;
  57. }
  58. private void handleRes(L2PcInstance activeChar)
  59. {
  60. handleRes(activeChar, null);
  61. }
  62. private void handleRes(L2PcInstance activeChar, String resParam)
  63. {
  64. L2Object obj = activeChar.getTarget();
  65. if (resParam != null)
  66. {
  67. // Check if a player name was specified as a param.
  68. L2PcInstance plyr = L2World.getInstance().getPlayer(resParam);
  69. if (plyr != null)
  70. {
  71. obj = plyr;
  72. }
  73. else
  74. {
  75. // Otherwise, check if the param was a radius.
  76. try
  77. {
  78. int radius = Integer.parseInt(resParam);
  79. for (L2PcInstance knownPlayer : activeChar.getKnownList().getKnownPlayersInRadius(radius))
  80. doResurrect(knownPlayer);
  81. activeChar.sendMessage("Resurrected all players within a " + radius + " unit radius.");
  82. return;
  83. }
  84. catch (NumberFormatException e)
  85. {
  86. activeChar.sendMessage("Enter a valid player name or radius.");
  87. return;
  88. }
  89. }
  90. }
  91. if (obj == null)
  92. obj = activeChar;
  93. if (obj instanceof L2ControllableMobInstance)
  94. {
  95. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  96. return;
  97. }
  98. doResurrect((L2Character) obj);
  99. if (Config.DEBUG)
  100. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") resurrected character " + obj.getObjectId());
  101. }
  102. private void handleNonPlayerRes(L2PcInstance activeChar)
  103. {
  104. handleNonPlayerRes(activeChar, "");
  105. }
  106. private void handleNonPlayerRes(L2PcInstance activeChar, String radiusStr)
  107. {
  108. L2Object obj = activeChar.getTarget();
  109. try
  110. {
  111. int radius = 0;
  112. if (!radiusStr.isEmpty())
  113. {
  114. radius = Integer.parseInt(radiusStr);
  115. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  116. if (!(knownChar instanceof L2PcInstance) && !(knownChar instanceof L2ControllableMobInstance))
  117. doResurrect(knownChar);
  118. activeChar.sendMessage("Resurrected all non-players within a " + radius + " unit radius.");
  119. }
  120. }
  121. catch (NumberFormatException e)
  122. {
  123. activeChar.sendMessage("Enter a valid radius.");
  124. return;
  125. }
  126. if (obj instanceof L2PcInstance || obj instanceof L2ControllableMobInstance)
  127. {
  128. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  129. return;
  130. }
  131. doResurrect((L2Character) obj);
  132. }
  133. private void doResurrect(L2Character targetChar)
  134. {
  135. if (!targetChar.isDead())
  136. return;
  137. // If the target is a player, then restore the XP lost on death.
  138. if (targetChar instanceof L2PcInstance)
  139. ((L2PcInstance) targetChar).restoreExp(100.0);
  140. // If the target is an NPC, then abort it's auto decay and respawn.
  141. else
  142. DecayTaskManager.getInstance().cancelDecayTask(targetChar);
  143. targetChar.doRevive();
  144. }
  145. }