AdminGmChat.java 3.3 KB

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