AdminGmChat.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.datatables.AdminTable;
  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. /**
  25. * This class handles following admin commands:
  26. * - gmchat text = sends text to all online GM's
  27. * - gmchat_menu text = same as gmchat, displays the admin panel after chat
  28. *
  29. * @version $Revision: 1.2.4.3 $ $Date: 2005/04/11 10:06:06 $
  30. */
  31. public class AdminGmChat implements IAdminCommandHandler
  32. {
  33. private static final String[] ADMIN_COMMANDS =
  34. {
  35. "admin_gmchat",
  36. "admin_snoop",
  37. "admin_gmchat_menu"
  38. };
  39. @Override
  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(SystemMessageId.SELECT_TARGET);
  66. return;
  67. }
  68. if (!(target instanceof L2PcInstance))
  69. {
  70. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  71. return;
  72. }
  73. L2PcInstance player = (L2PcInstance) target;
  74. player.addSnooper(activeChar);
  75. activeChar.addSnooped(player);
  76. }
  77. @Override
  78. public String[] getAdminCommandList()
  79. {
  80. return ADMIN_COMMANDS;
  81. }
  82. /**
  83. * @param command
  84. * @param activeChar
  85. */
  86. private void handleGmChat(String command, L2PcInstance activeChar)
  87. {
  88. try
  89. {
  90. int offset = 0;
  91. String text;
  92. if (command.startsWith("admin_gmchat_menu"))
  93. offset = 18;
  94. else
  95. offset = 13;
  96. text = command.substring(offset);
  97. CreatureSay cs = new CreatureSay(0, Say2.ALLIANCE, activeChar.getName(), text);
  98. AdminTable.getInstance().broadcastToGMs(cs);
  99. }
  100. catch (StringIndexOutOfBoundsException e)
  101. {
  102. // Who cares?
  103. }
  104. }
  105. }