AdminTarget.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  17. import net.sf.l2j.gameserver.model.L2World;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  19. /**
  20. * This class handles following admin commands:
  21. * - target name = sets player with respective name as target
  22. *
  23. * @version $Revision: 1.2.4.3 $ $Date: 2005/04/11 10:05:56 $
  24. */
  25. public class AdminTarget implements IAdminCommandHandler
  26. {
  27. private static final String[] ADMIN_COMMANDS =
  28. {
  29. "admin_target"
  30. };
  31. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  32. {
  33. if (command.startsWith("admin_target"))
  34. handleTarget(command, activeChar);
  35. return true;
  36. }
  37. public String[] getAdminCommandList()
  38. {
  39. return ADMIN_COMMANDS;
  40. }
  41. private void handleTarget(String command, L2PcInstance activeChar)
  42. {
  43. try
  44. {
  45. String targetName = command.substring(13);
  46. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  47. if (player != null)
  48. {
  49. player.onAction(activeChar);
  50. }
  51. else
  52. {
  53. activeChar.sendMessage("Player " + targetName + " not found");
  54. }
  55. }
  56. catch (IndexOutOfBoundsException e)
  57. {
  58. activeChar.sendMessage("Please specify correct name.");
  59. }
  60. }
  61. }