BypassHandler.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 com.l2jserver.gameserver.handler;
  16. import gnu.trove.map.hash.TIntObjectHashMap;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.Config;
  20. /**
  21. *
  22. * @author nBd
  23. *
  24. */
  25. public class BypassHandler
  26. {
  27. private static Logger _log = Logger.getLogger(BypassHandler.class.getName());
  28. private final TIntObjectHashMap<IBypassHandler> _datatable;
  29. public static BypassHandler getInstance()
  30. {
  31. return SingletonHolder._instance;
  32. }
  33. protected BypassHandler()
  34. {
  35. _datatable = new TIntObjectHashMap<IBypassHandler>();
  36. }
  37. public void registerHandler(IBypassHandler handler)
  38. {
  39. for (String element : handler.getBypassList())
  40. {
  41. if (Config.DEBUG)
  42. _log.log(Level.FINE, "Adding handler for command " + element);
  43. _datatable.put(element.toLowerCase().hashCode(), handler);
  44. }
  45. }
  46. public IBypassHandler getHandler(String BypassCommand)
  47. {
  48. String command = BypassCommand;
  49. if (BypassCommand.indexOf(" ") != -1)
  50. {
  51. command = BypassCommand.substring(0, BypassCommand.indexOf(" "));
  52. }
  53. if (Config.DEBUG)
  54. _log.log(Level.FINE, "getting handler for command: " + command + " -> " + (_datatable.get(command.hashCode()) != null));
  55. return _datatable.get(command.toLowerCase().hashCode());
  56. }
  57. public int size()
  58. {
  59. return _datatable.size();
  60. }
  61. private static class SingletonHolder
  62. {
  63. protected static final BypassHandler _instance = new BypassHandler();
  64. }
  65. }