AdminHeal.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.Collection;
  17. import java.util.logging.Logger;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2World;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. /**
  26. * This class handles following admin commands:
  27. * - heal = restores HP/MP/CP on target, name or radius
  28. *
  29. * @version $Revision: 1.2.4.5 $ $Date: 2005/04/11 10:06:06 $
  30. * Small typo fix by Zoey76 24/02/2011
  31. */
  32. public class AdminHeal implements IAdminCommandHandler
  33. {
  34. private static Logger _log = Logger.getLogger(AdminRes.class.getName());
  35. private static final String[] ADMIN_COMMANDS =
  36. {
  37. "admin_heal"
  38. };
  39. @Override
  40. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  41. {
  42. if (command.equals("admin_heal"))
  43. handleHeal(activeChar);
  44. else if (command.startsWith("admin_heal"))
  45. {
  46. try
  47. {
  48. String healTarget = command.substring(11);
  49. handleHeal(activeChar, healTarget);
  50. }
  51. catch (StringIndexOutOfBoundsException e)
  52. {
  53. if (Config.DEVELOPER)
  54. _log.warning("Heal error: " + e);
  55. activeChar.sendMessage("Incorrect target/radius specified.");
  56. }
  57. }
  58. return true;
  59. }
  60. @Override
  61. public String[] getAdminCommandList()
  62. {
  63. return ADMIN_COMMANDS;
  64. }
  65. private void handleHeal(L2PcInstance activeChar)
  66. {
  67. handleHeal(activeChar, null);
  68. }
  69. private void handleHeal(L2PcInstance activeChar, String player)
  70. {
  71. L2Object obj = activeChar.getTarget();
  72. if (player != null)
  73. {
  74. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  75. if (plyr != null)
  76. obj = plyr;
  77. else
  78. {
  79. try
  80. {
  81. int radius = Integer.parseInt(player);
  82. Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  83. for (L2Object object : objs)
  84. {
  85. if (object instanceof L2Character)
  86. {
  87. L2Character character = (L2Character) object;
  88. character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
  89. if (object instanceof L2PcInstance)
  90. character.setCurrentCp(character.getMaxCp());
  91. }
  92. }
  93. activeChar.sendMessage("Healed within " + radius + " unit radius.");
  94. return;
  95. }
  96. catch (NumberFormatException nbe)
  97. {
  98. }
  99. }
  100. }
  101. if (obj == null)
  102. obj = activeChar;
  103. if (obj instanceof L2Character)
  104. {
  105. L2Character target = (L2Character) obj;
  106. target.setCurrentHpMp(target.getMaxHp(), target.getMaxMp());
  107. if (target instanceof L2PcInstance)
  108. target.setCurrentCp(target.getMaxCp());
  109. if (Config.DEBUG)
  110. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") healed character " + target.getName());
  111. }
  112. else
  113. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  114. }
  115. }