AdminTargetSay.java 2.3 KB

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