AdminRes.java 5.0 KB

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