2
0

ChatAll.java 3.1 KB

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