2
0

AdminGmChat.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.GmListTable;
  17. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  18. import net.sf.l2j.gameserver.model.L2Object;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  22. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  23. /**
  24. * This class handles following admin commands:
  25. * - gmchat text = sends text to all online GM's
  26. * - gmchat_menu text = same as gmchat, displays the admin panel after chat
  27. *
  28. * @version $Revision: 1.2.4.3 $ $Date: 2005/04/11 10:06:06 $
  29. */
  30. public class AdminGmChat implements IAdminCommandHandler
  31. {
  32. private static final String[] ADMIN_COMMANDS =
  33. {
  34. "admin_gmchat",
  35. "admin_snoop",
  36. "admin_gmchat_menu"
  37. };
  38. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  39. {
  40. if (command.startsWith("admin_gmchat"))
  41. handleGmChat(command, activeChar);
  42. else if (command.startsWith("admin_snoop"))
  43. snoop(command, activeChar);
  44. if (command.startsWith("admin_gmchat_menu"))
  45. AdminHelpPage.showHelpPage(activeChar, "main_menu.htm");
  46. return true;
  47. }
  48. /**
  49. * @param command
  50. * @param activeChar
  51. */
  52. private void snoop(String command, L2PcInstance activeChar)
  53. {
  54. L2Object target = activeChar.getTarget();
  55. if (target == null)
  56. {
  57. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_MUST_SELECT_A_TARGET));
  58. return;
  59. }
  60. if (!(target instanceof L2PcInstance))
  61. {
  62. activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
  63. return;
  64. }
  65. L2PcInstance player = (L2PcInstance) target;
  66. player.addSnooper(activeChar);
  67. activeChar.addSnooped(player);
  68. }
  69. public String[] getAdminCommandList()
  70. {
  71. return ADMIN_COMMANDS;
  72. }
  73. /**
  74. * @param command
  75. * @param activeChar
  76. */
  77. private void handleGmChat(String command, L2PcInstance activeChar)
  78. {
  79. try
  80. {
  81. int offset = 0;
  82. String text;
  83. if (command.contains("menu"))
  84. offset = 17;
  85. else
  86. offset = 13;
  87. text = command.substring(offset);
  88. CreatureSay cs = new CreatureSay(0, 9, activeChar.getName(), text);
  89. GmListTable.broadcastToGMs(cs);
  90. }
  91. catch (StringIndexOutOfBoundsException e)
  92. {
  93. // empty message.. ignore
  94. }
  95. }
  96. }