ChatAll.java 3.7 KB

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