ChatHandler.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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;
  16. import java.util.logging.Logger;
  17. import javolution.util.FastMap;
  18. import net.sf.l2j.Config;
  19. import net.sf.l2j.gameserver.handler.chathandlers.ChatAll;
  20. import net.sf.l2j.gameserver.handler.chathandlers.ChatAlliance;
  21. import net.sf.l2j.gameserver.handler.chathandlers.ChatClan;
  22. import net.sf.l2j.gameserver.handler.chathandlers.ChatHeroVoice;
  23. import net.sf.l2j.gameserver.handler.chathandlers.ChatParty;
  24. import net.sf.l2j.gameserver.handler.chathandlers.ChatPartyRoomAll;
  25. import net.sf.l2j.gameserver.handler.chathandlers.ChatPartyRoomCommander;
  26. import net.sf.l2j.gameserver.handler.chathandlers.ChatPetition;
  27. import net.sf.l2j.gameserver.handler.chathandlers.ChatShout;
  28. import net.sf.l2j.gameserver.handler.chathandlers.ChatTell;
  29. import net.sf.l2j.gameserver.handler.chathandlers.ChatTrade;
  30. /**
  31. * This class handles all chat handlers
  32. *
  33. * @author durgus
  34. */
  35. public class ChatHandler
  36. {
  37. private static Logger _log = Logger.getLogger(ChatHandler.class.getName());
  38. private static ChatHandler _instance;
  39. private FastMap<Integer, IChatHandler> _datatable;
  40. public static ChatHandler getInstance()
  41. {
  42. if (_instance == null)
  43. {
  44. _instance = new ChatHandler();
  45. }
  46. return _instance;
  47. }
  48. /**
  49. * Singleton constructor
  50. */
  51. private ChatHandler()
  52. {
  53. _datatable = new FastMap<Integer, IChatHandler>();
  54. registerChatHandler(new ChatAll());
  55. registerChatHandler(new ChatAlliance());
  56. registerChatHandler(new ChatClan());
  57. registerChatHandler(new ChatHeroVoice());
  58. registerChatHandler(new ChatParty());
  59. registerChatHandler(new ChatPartyRoomAll());
  60. registerChatHandler(new ChatPartyRoomCommander());
  61. registerChatHandler(new ChatPetition());
  62. registerChatHandler(new ChatShout());
  63. registerChatHandler(new ChatTell());
  64. registerChatHandler(new ChatTrade());
  65. _log.config("ChatHandler: Loaded " + _datatable.size() + " handlers.");
  66. }
  67. /**
  68. * Register a new chat handler
  69. * @param handler
  70. */
  71. public void registerChatHandler(IChatHandler handler)
  72. {
  73. int[] ids = handler.getChatTypeList();
  74. for (int i = 0; i < ids.length; i++)
  75. {
  76. if (Config.DEBUG)
  77. _log.fine("Adding handler for chat type " + ids[i]);
  78. _datatable.put(ids[i], handler);
  79. }
  80. }
  81. /**
  82. * Get the chat handler for the given chat type
  83. * @param chatType
  84. * @return
  85. */
  86. public IChatHandler getChatHandler(int chatType)
  87. {
  88. return _datatable.get(chatType);
  89. }
  90. /**
  91. * Returns the size
  92. * @return
  93. */
  94. public int size()
  95. {
  96. return _datatable.size();
  97. }
  98. }