AdminRes.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.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 = {"admin_res", "admin_res_monster"};
  37. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  38. {
  39. if (command.startsWith("admin_res "))
  40. handleRes(activeChar, command.split(" ")[1]);
  41. else if (command.equals("admin_res"))
  42. handleRes(activeChar);
  43. else if (command.startsWith("admin_res_monster "))
  44. handleNonPlayerRes(activeChar, command.split(" ")[1]);
  45. else if (command.equals("admin_res_monster"))
  46. handleNonPlayerRes(activeChar);
  47. return true;
  48. }
  49. public String[] getAdminCommandList()
  50. {
  51. return ADMIN_COMMANDS;
  52. }
  53. private void handleRes(L2PcInstance activeChar)
  54. {
  55. handleRes(activeChar, null);
  56. }
  57. private void handleRes(L2PcInstance activeChar, String resParam)
  58. {
  59. L2Object obj = activeChar.getTarget();
  60. if (resParam != null)
  61. {
  62. // Check if a player name was specified as a param.
  63. L2PcInstance plyr = L2World.getInstance().getPlayer(resParam);
  64. if (plyr != null)
  65. {
  66. obj = plyr;
  67. }
  68. else
  69. {
  70. // Otherwise, check if the param was a radius.
  71. try
  72. {
  73. int radius = Integer.parseInt(resParam);
  74. for (L2PcInstance knownPlayer : activeChar.getKnownList().getKnownPlayersInRadius(radius))
  75. doResurrect(knownPlayer);
  76. activeChar.sendMessage("Resurrected all players within a " + radius + " unit radius.");
  77. return;
  78. }
  79. catch (NumberFormatException e) {
  80. activeChar.sendMessage("Enter a valid player name or radius.");
  81. return;
  82. }
  83. }
  84. }
  85. if (obj == null)
  86. obj = activeChar;
  87. if (obj instanceof L2ControllableMobInstance)
  88. {
  89. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  90. return;
  91. }
  92. doResurrect((L2Character)obj);
  93. if (Config.DEBUG)
  94. _log.fine("GM: "+activeChar.getName()+"("+activeChar.getObjectId()+") resurrected character "+ obj.getObjectId());
  95. }
  96. private void handleNonPlayerRes(L2PcInstance activeChar)
  97. {
  98. handleNonPlayerRes(activeChar, "");
  99. }
  100. private void handleNonPlayerRes(L2PcInstance activeChar, String radiusStr)
  101. {
  102. L2Object obj = activeChar.getTarget();
  103. try {
  104. int radius = 0;
  105. if (!radiusStr.equals(""))
  106. {
  107. radius = Integer.parseInt(radiusStr);
  108. for (L2Character knownChar : activeChar.getKnownList().getKnownCharactersInRadius(radius))
  109. if (!(knownChar instanceof L2PcInstance)
  110. && !(knownChar instanceof L2ControllableMobInstance))
  111. doResurrect(knownChar);
  112. activeChar.sendMessage("Resurrected all non-players within a " + radius + " unit radius.");
  113. }
  114. }
  115. catch (NumberFormatException e) {
  116. activeChar.sendMessage("Enter a valid radius.");
  117. return;
  118. }
  119. if (obj instanceof L2PcInstance || obj instanceof L2ControllableMobInstance)
  120. {
  121. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  122. return;
  123. }
  124. doResurrect((L2Character)obj);
  125. }
  126. private void doResurrect(L2Character targetChar)
  127. {
  128. if(!targetChar.isDead()) return;
  129. // If the target is a player, then restore the XP lost on death.
  130. if (targetChar instanceof L2PcInstance)
  131. ((L2PcInstance)targetChar).restoreExp(100.0);
  132. // If the target is an NPC, then abort it's auto decay and respawn.
  133. else
  134. DecayTaskManager.getInstance().cancelDecayTask(targetChar);
  135. targetChar.doRevive();
  136. }
  137. }