ChatAll.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 net.sf.l2j.gameserver.handler.chathandlers;
  16. import java.util.StringTokenizer;
  17. import java.util.logging.Logger;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.handler.IChatHandler;
  20. import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  21. import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.serverpackets.CreatureSay;
  24. /**
  25. * A chat handler
  26. *
  27. * @author durgus
  28. */
  29. public class ChatAll implements IChatHandler
  30. {
  31. private static final int[] COMMAND_IDS = { 0 };
  32. private static Logger _log = Logger.getLogger(ChatAll.class.getName());
  33. /**
  34. * Handle chat type 'all'
  35. * @see net.sf.l2j.gameserver.handler.IChatHandler#handleChat(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  36. */
  37. public void handleChat(int type, L2PcInstance activeChar, String target, String text)
  38. {
  39. if (text.startsWith("."))
  40. {
  41. StringTokenizer st = new StringTokenizer(text);
  42. IVoicedCommandHandler vch;
  43. String command = "";
  44. if (st.countTokens() > 1)
  45. {
  46. command = st.nextToken().substring(1);
  47. target = text.substring(command.length() + 2);
  48. vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
  49. }
  50. else
  51. {
  52. command = text.substring(1);
  53. if (Config.DEBUG) _log.info("Command: "+command);
  54. vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
  55. }
  56. if (vch != null)
  57. {
  58. vch.useVoicedCommand(command, activeChar, target);
  59. }
  60. else
  61. {
  62. if (Config.DEBUG) _log.warning("No handler registered for bypass '"+command+"'");
  63. }
  64. }
  65. else
  66. {
  67. CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getAppearance().getVisibleName(), text);
  68. for (L2PcInstance player : activeChar.getKnownList().getKnownPlayers().values())
  69. {
  70. if (player != null && activeChar.isInsideRadius(player, 1250, false, true))
  71. {
  72. player.sendPacket(cs);
  73. }
  74. }
  75. activeChar.sendPacket(cs);
  76. }
  77. }
  78. /**
  79. * Returns the chat types registered to this handler
  80. * @see net.sf.l2j.gameserver.handler.IChatHandler#getChatTypeList()
  81. */
  82. public int[] getChatTypeList()
  83. {
  84. return COMMAND_IDS;
  85. }
  86. }