AdminHeal.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.L2PcInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  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. */
  31. public class AdminHeal implements IAdminCommandHandler {
  32. private static Logger _log = Logger.getLogger(AdminRes.class.getName());
  33. private static final String[] ADMIN_COMMANDS = { "admin_heal" };
  34. public boolean useAdminCommand(String command, L2PcInstance activeChar) {
  35. if (command.equals("admin_heal")) handleRes(activeChar);
  36. else if (command.startsWith("admin_heal"))
  37. {
  38. try
  39. {
  40. String healTarget = command.substring(11);
  41. handleRes(activeChar, healTarget);
  42. }
  43. catch (StringIndexOutOfBoundsException e)
  44. {
  45. if (Config.DEVELOPER)
  46. _log.warning("Heal error: "+e);
  47. activeChar.sendMessage("Incorrect target/radius specified.");
  48. }
  49. }
  50. return true;
  51. }
  52. public String[] getAdminCommandList() {
  53. return ADMIN_COMMANDS;
  54. }
  55. private void handleRes(L2PcInstance activeChar)
  56. {
  57. handleRes(activeChar, null);
  58. }
  59. private void handleRes(L2PcInstance activeChar, String player) {
  60. L2Object obj = activeChar.getTarget();
  61. if (player != null)
  62. {
  63. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  64. if (plyr != null)
  65. obj = plyr;
  66. else
  67. {
  68. try
  69. {
  70. int radius = Integer.parseInt(player);
  71. for (L2Object object : activeChar.getKnownList().getKnownObjects().values())
  72. {
  73. if (object instanceof L2Character)
  74. {
  75. L2Character character = (L2Character) object;
  76. character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
  77. if ( object instanceof L2PcInstance ) character.setCurrentCp(character.getMaxCp());
  78. }
  79. }
  80. activeChar.sendMessage("Healed within " + radius + " unit radius.");
  81. return;
  82. }
  83. catch (NumberFormatException nbe) {}
  84. }
  85. }
  86. if (obj == null)
  87. obj = activeChar;
  88. if (obj instanceof L2Character)
  89. {
  90. L2Character target = (L2Character)obj;
  91. target.setCurrentHpMp(target.getMaxHp(), target.getMaxMp());
  92. if ( target instanceof L2PcInstance )
  93. target.setCurrentCp(target.getMaxCp());
  94. if (Config.DEBUG)
  95. _log.fine("GM: "+activeChar.getName()+"("+activeChar.getObjectId()+") healed character "+target.getName());
  96. }
  97. else
  98. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  99. }
  100. }