AdminHeal.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.Collection;
  17. import java.util.logging.Logger;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  20. import net.sf.l2j.gameserver.model.L2Character;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2World;
  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. /**
  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. */
  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. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  40. {
  41. if (command.equals("admin_heal"))
  42. handleRes(activeChar);
  43. else if (command.startsWith("admin_heal"))
  44. {
  45. try
  46. {
  47. String healTarget = command.substring(11);
  48. handleRes(activeChar, healTarget);
  49. }
  50. catch (StringIndexOutOfBoundsException e)
  51. {
  52. if (Config.DEVELOPER)
  53. _log.warning("Heal error: " + e);
  54. activeChar.sendMessage("Incorrect target/radius specified.");
  55. }
  56. }
  57. return true;
  58. }
  59. public String[] getAdminCommandList()
  60. {
  61. return ADMIN_COMMANDS;
  62. }
  63. private void handleRes(L2PcInstance activeChar)
  64. {
  65. handleRes(activeChar, null);
  66. }
  67. private void handleRes(L2PcInstance activeChar, String player)
  68. {
  69. L2Object obj = activeChar.getTarget();
  70. if (player != null)
  71. {
  72. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  73. if (plyr != null)
  74. obj = plyr;
  75. else
  76. {
  77. try
  78. {
  79. int radius = Integer.parseInt(player);
  80. Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  81. //synchronized (activeChar.getKnownList().getKnownObjects())
  82. {
  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. }
  94. activeChar.sendMessage("Healed within " + radius + " unit radius.");
  95. return;
  96. }
  97. catch (NumberFormatException nbe)
  98. {
  99. }
  100. }
  101. }
  102. if (obj == null)
  103. obj = activeChar;
  104. if (obj instanceof L2Character)
  105. {
  106. L2Character target = (L2Character) obj;
  107. target.setCurrentHpMp(target.getMaxHp(), target.getMaxMp());
  108. if (target instanceof L2PcInstance)
  109. target.setCurrentCp(target.getMaxCp());
  110. if (Config.DEBUG)
  111. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") healed character " + target.getName());
  112. }
  113. else
  114. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  115. }
  116. }