AdminRes.java 5.0 KB

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