VoicedCommandHandler.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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) _log.fine("Adding handler for command "+ids[i]);
  57. _datatable.put(ids[i], handler);
  58. }
  59. }
  60. public IVoicedCommandHandler getVoicedCommandHandler(String voicedCommand)
  61. {
  62. String command = voicedCommand;
  63. if (voicedCommand.indexOf(" ") != -1) {
  64. command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
  65. }
  66. if (Config.DEBUG)
  67. _log.fine("getting handler for command: "+command+
  68. " -> "+(_datatable.get(command) != null));
  69. return _datatable.get(command);
  70. }
  71. /**
  72. * @return
  73. */
  74. public int size()
  75. {
  76. return _datatable.size();
  77. }
  78. }