AdminHeal.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.Collection;
  21. import java.util.logging.Logger;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  24. import com.l2jserver.gameserver.model.L2Object;
  25. import com.l2jserver.gameserver.model.L2World;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. /**
  30. * This class handles following admin commands: - heal = restores HP/MP/CP on target, name or radius
  31. * @version $Revision: 1.2.4.5 $ $Date: 2005/04/11 10:06:06 $ 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. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.equals("admin_heal"))
  44. {
  45. handleHeal(activeChar);
  46. }
  47. else if (command.startsWith("admin_heal"))
  48. {
  49. try
  50. {
  51. String healTarget = command.substring(11);
  52. handleHeal(activeChar, healTarget);
  53. }
  54. catch (StringIndexOutOfBoundsException e)
  55. {
  56. if (Config.DEVELOPER)
  57. {
  58. _log.warning("Heal error: " + e);
  59. }
  60. activeChar.sendMessage("Incorrect target/radius specified.");
  61. }
  62. }
  63. return true;
  64. }
  65. @Override
  66. public String[] getAdminCommandList()
  67. {
  68. return ADMIN_COMMANDS;
  69. }
  70. private void handleHeal(L2PcInstance activeChar)
  71. {
  72. handleHeal(activeChar, null);
  73. }
  74. private void handleHeal(L2PcInstance activeChar, String player)
  75. {
  76. L2Object obj = activeChar.getTarget();
  77. if (player != null)
  78. {
  79. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  80. if (plyr != null)
  81. {
  82. obj = plyr;
  83. }
  84. else
  85. {
  86. try
  87. {
  88. int radius = Integer.parseInt(player);
  89. Collection<L2Object> objs = activeChar.getKnownList().getKnownObjects().values();
  90. for (L2Object object : objs)
  91. {
  92. if (object instanceof L2Character)
  93. {
  94. L2Character character = (L2Character) object;
  95. character.setCurrentHpMp(character.getMaxHp(), character.getMaxMp());
  96. if (object instanceof L2PcInstance)
  97. {
  98. character.setCurrentCp(character.getMaxCp());
  99. }
  100. }
  101. }
  102. activeChar.sendMessage("Healed within " + radius + " unit radius.");
  103. return;
  104. }
  105. catch (NumberFormatException nbe)
  106. {
  107. }
  108. }
  109. }
  110. if (obj == null)
  111. {
  112. obj = activeChar;
  113. }
  114. if (obj instanceof L2Character)
  115. {
  116. L2Character target = (L2Character) obj;
  117. target.setCurrentHpMp(target.getMaxHp(), target.getMaxMp());
  118. if (target instanceof L2PcInstance)
  119. {
  120. target.setCurrentCp(target.getMaxCp());
  121. }
  122. if (Config.DEBUG)
  123. {
  124. _log.fine("GM: " + activeChar.getName() + "(" + activeChar.getObjectId() + ") healed character " + target.getName());
  125. }
  126. }
  127. else
  128. {
  129. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  130. }
  131. }
  132. }