ChatAll.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.chathandlers;
  16. import java.util.Collection;
  17. import java.util.StringTokenizer;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.handler.IChatHandler;
  21. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  22. import com.l2jserver.gameserver.handler.VoicedCommandHandler;
  23. import com.l2jserver.gameserver.model.BlockList;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. import com.l2jserver.gameserver.util.Util;
  29. /**
  30. * A chat handler
  31. *
  32. * @author durgus
  33. */
  34. public class ChatAll implements IChatHandler
  35. {
  36. private static final int[] COMMAND_IDS =
  37. {
  38. 0
  39. };
  40. private static Logger _log = Logger.getLogger(ChatAll.class.getName());
  41. /**
  42. * Handle chat type 'all'
  43. * @see com.l2jserver.gameserver.handler.IChatHandler#handleChat(int, com.l2jserver.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  44. */
  45. @Override
  46. public void handleChat(int type, L2PcInstance activeChar, String params, String text)
  47. {
  48. boolean vcd_used = false;
  49. if (text.startsWith("."))
  50. {
  51. StringTokenizer st = new StringTokenizer(text);
  52. IVoicedCommandHandler vch;
  53. String command = "";
  54. if (st.countTokens() > 1)
  55. {
  56. command = st.nextToken().substring(1);
  57. params = text.substring(command.length() + 2);
  58. vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
  59. }
  60. else
  61. {
  62. command = text.substring(1);
  63. if (Config.DEBUG)
  64. _log.info("Command: " + command);
  65. vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
  66. }
  67. if (vch != null)
  68. {
  69. vch.useVoicedCommand(command, activeChar, params);
  70. vcd_used = true;
  71. }
  72. else
  73. {
  74. if (Config.DEBUG)
  75. _log.warning("No handler registered for bypass '" + command + "'");
  76. vcd_used = false;
  77. }
  78. }
  79. if (!vcd_used)
  80. {
  81. if (activeChar.isChatBanned() && Util.contains(Config.BAN_CHAT_CHANNELS, type))
  82. {
  83. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CHATTING_IS_CURRENTLY_PROHIBITED));
  84. return;
  85. }
  86. /**
  87. * Match the character "." literally (Exactly 1 time)
  88. * Match any character that is NOT a . character. Between one and unlimited times as possible, giving back as needed (greedy)
  89. */
  90. if (text.matches("\\.{1}[^\\.]+"))
  91. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_SYNTAX));
  92. else
  93. {
  94. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getAppearance().getVisibleName(), text);
  95. Collection<L2PcInstance> plrs = activeChar.getKnownList().getKnownPlayers().values();
  96. for (L2PcInstance player : plrs)
  97. {
  98. if (player != null && activeChar.isInsideRadius(player, 1250, false, true) && !BlockList.isBlocked(player, activeChar))
  99. player.sendPacket(cs);
  100. }
  101. activeChar.sendPacket(cs);
  102. }
  103. }
  104. }
  105. /**
  106. * Returns the chat types registered to this handler
  107. * @see com.l2jserver.gameserver.handler.IChatHandler#getChatTypeList()
  108. */
  109. @Override
  110. public int[] getChatTypeList()
  111. {
  112. return COMMAND_IDS;
  113. }
  114. }