VoicedCommandHandler.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.Map;
  17. import java.util.logging.Logger;
  18. import javolution.util.FastMap;
  19. import net.sf.l2j.Config;
  20. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.Banking;
  21. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.Wedding;
  22. import net.sf.l2j.gameserver.handler.voicedcommandhandlers.stats;
  23. /**
  24. * This class ...
  25. *
  26. * @version $Revision: 1.1.4.5 $ $Date: 2005/03/27 15:30:09 $
  27. */
  28. public class VoicedCommandHandler
  29. {
  30. private static Logger _log = Logger.getLogger(ItemHandler.class.getName());
  31. private static VoicedCommandHandler _instance;
  32. private Map<String, IVoicedCommandHandler> _datatable;
  33. public static VoicedCommandHandler getInstance()
  34. {
  35. if (_instance == null)
  36. {
  37. _instance = new VoicedCommandHandler();
  38. }
  39. return _instance;
  40. }
  41. private VoicedCommandHandler()
  42. {
  43. _datatable = new FastMap<String, IVoicedCommandHandler>();
  44. registerVoicedCommandHandler(new stats());
  45. if (Config.L2JMOD_ALLOW_WEDDING)
  46. registerVoicedCommandHandler(new Wedding());
  47. if (Config.BANKING_SYSTEM_ENABLED)
  48. registerVoicedCommandHandler(new Banking());
  49. _log.config("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
  50. }
  51. public void registerVoicedCommandHandler(IVoicedCommandHandler handler)
  52. {
  53. String[] ids = handler.getVoicedCommandList();
  54. for (int i = 0; i < ids.length; i++)
  55. {
  56. if (Config.DEBUG)
  57. _log.fine("Adding handler for command " + ids[i]);
  58. _datatable.put(ids[i], handler);
  59. }
  60. }
  61. public IVoicedCommandHandler getVoicedCommandHandler(String voicedCommand)
  62. {
  63. String command = voicedCommand;
  64. if (voicedCommand.indexOf(" ") != -1)
  65. {
  66. command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
  67. }
  68. if (Config.DEBUG)
  69. _log.fine("getting handler for command: " + command + " -> " + (_datatable.get(command) != null));
  70. return _datatable.get(command);
  71. }
  72. /**
  73. * @return
  74. */
  75. public int size()
  76. {
  77. return _datatable.size();
  78. }
  79. }