AdminTargetSay.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 com.l2jserver.gameserver.handler.IAdminCommandHandler;
  21. import com.l2jserver.gameserver.model.L2Object;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2StaticObjectInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.clientpackets.Say2;
  27. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  28. /**
  29. * This class handles following admin commands: - targetsay <message> = makes talk a L2Character
  30. * @author nonom
  31. */
  32. public class AdminTargetSay implements IAdminCommandHandler
  33. {
  34. private static final String[] ADMIN_COMMANDS =
  35. {
  36. "admin_targetsay"
  37. };
  38. @Override
  39. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  40. {
  41. if (command.startsWith("admin_targetsay"))
  42. {
  43. try
  44. {
  45. final L2Object obj = activeChar.getTarget();
  46. if ((obj instanceof L2StaticObjectInstance) || !(obj instanceof L2Character))
  47. {
  48. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  49. return false;
  50. }
  51. final String message = command.substring(16);
  52. final L2Character target = (L2Character) obj;
  53. target.broadcastPacket(new CreatureSay(target.getObjectId(), (target.isPlayer() ? Say2.ALL : Say2.NPC_ALL), target.getName(), message));
  54. }
  55. catch (StringIndexOutOfBoundsException e)
  56. {
  57. activeChar.sendMessage("Usage: //targetsay <text>");
  58. return false;
  59. }
  60. }
  61. return true;
  62. }
  63. @Override
  64. public String[] getAdminCommandList()
  65. {
  66. return ADMIN_COMMANDS;
  67. }
  68. }