AdminHeal.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * This class handles following admin commands:
  28. * - heal = restores HP/MP/CP on target, name or radius
  29. *
  30. * @version $Revision: 1.2.4.5 $ $Date: 2005/04/11 10:06:06 $
  31. * Small typo fix by Zoey76 24/02/2011
  32. */
  33. public class AdminHeal implements IAdminCommandHandler
  34. {
  35. private static Logger _log = Logger.getLogger(AdminRes.class.getName());
  36. private static final String[] ADMIN_COMMANDS =
  37. {
  38. "admin_heal"
  39. };
  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. public String[] getAdminCommandList()
  61. {
  62. return ADMIN_COMMANDS;
  63. }
  64. private void handleHeal(L2PcInstance activeChar)
  65. {
  66. handleHeal(activeChar, null);
  67. }
  68. private void handleHeal(L2PcInstance activeChar, String player)
  69. {
  70. L2Object obj = activeChar.getTarget();
  71. if (player != null)
  72. {
  73. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  74. if (plyr != null)
  75. obj = plyr;
  76. else
  77. {
  78. try
  79. {
  80. int radius = Integer.parseInt(player);
  81. Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  82. //synchronized (activeChar.getKnownList().getKnownObjects())
  83. {
  84. for (L2Object object : objs)
  85. {
  86. if (object instanceof L2Character)
  87. {
  88. L2Character character = (L2Character) object;
  89. character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
  90. if (object instanceof L2PcInstance)
  91. character.setCurrentCp(character.getMaxCp());
  92. }
  93. }
  94. }
  95. activeChar.sendMessage("Healed within " + radius + " unit radius.");
  96. return;
  97. }
  98. catch (NumberFormatException nbe)
  99. {
  100. }
  101. }
  102. }
  103. if (obj == null)
  104. obj = activeChar;
  105. if (obj instanceof L2Character)
  106. {
  107. L2Character target = (L2Character) obj;
  108. target.setCurrentHpMp(target.getMaxHp(), target.getMaxMp());
  109. if (target instanceof L2PcInstance)
  110. target.setCurrentCp(target.getMaxCp());
  111. if (Config.DEBUG)
  112. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") healed character " + target.getName());
  113. }
  114. else
  115. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  116. }
  117. }