AdminGmChat.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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.data.xml.impl.AdminData;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.L2Object;
  23. import com.l2jserver.gameserver.model.L2World;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  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: - gmchat text = sends text to all online GM's - gmchat_menu text = same as gmchat, displays the admin panel after chat
  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. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. if (command.startsWith("admin_gmchat"))
  44. {
  45. handleGmChat(command, activeChar);
  46. }
  47. else if (command.startsWith("admin_snoop"))
  48. {
  49. snoop(command, activeChar);
  50. }
  51. if (command.startsWith("admin_gmchat_menu"))
  52. {
  53. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  54. }
  55. return true;
  56. }
  57. /**
  58. * @param command
  59. * @param activeChar
  60. */
  61. private void snoop(String command, L2PcInstance activeChar)
  62. {
  63. L2Object target = null;
  64. if (command.length() > 12)
  65. {
  66. target = L2World.getInstance().getPlayer(command.substring(12));
  67. }
  68. if (target == null)
  69. {
  70. target = activeChar.getTarget();
  71. }
  72. if (target == null)
  73. {
  74. activeChar.sendPacket(SystemMessageId.SELECT_TARGET);
  75. return;
  76. }
  77. if (!(target instanceof L2PcInstance))
  78. {
  79. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  80. return;
  81. }
  82. L2PcInstance player = (L2PcInstance) target;
  83. player.addSnooper(activeChar);
  84. activeChar.addSnooped(player);
  85. }
  86. @Override
  87. public String[] getAdminCommandList()
  88. {
  89. return ADMIN_COMMANDS;
  90. }
  91. /**
  92. * @param command
  93. * @param activeChar
  94. */
  95. private void handleGmChat(String command, L2PcInstance activeChar)
  96. {
  97. try
  98. {
  99. int offset = 0;
  100. String text;
  101. if (command.startsWith("admin_gmchat_menu"))
  102. {
  103. offset = 18;
  104. }
  105. else
  106. {
  107. offset = 13;
  108. }
  109. text = command.substring(offset);
  110. CreatureSay cs = new CreatureSay(0, Say2.ALLIANCE, activeChar.getName(), text);
  111. AdminData.getInstance().broadcastToGMs(cs);
  112. }
  113. catch (StringIndexOutOfBoundsException e)
  114. {
  115. // Who cares?
  116. }
  117. }
  118. }