ChatAll.java 3.6 KB

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