BypassHandler.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.handler;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. /**
  23. * @author nBd, UnAfraid
  24. */
  25. public class BypassHandler implements IHandler<IBypassHandler, String>
  26. {
  27. private final Map<String, IBypassHandler> _datatable;
  28. protected BypassHandler()
  29. {
  30. _datatable = new HashMap<>();
  31. }
  32. @Override
  33. public void registerHandler(IBypassHandler handler)
  34. {
  35. for (String element : handler.getBypassList())
  36. {
  37. _datatable.put(element.toLowerCase(), handler);
  38. }
  39. }
  40. @Override
  41. public synchronized void removeHandler(IBypassHandler handler)
  42. {
  43. for (String element : handler.getBypassList())
  44. {
  45. _datatable.remove(element.toLowerCase());
  46. }
  47. }
  48. @Override
  49. public IBypassHandler getHandler(String command)
  50. {
  51. if (command.contains(" "))
  52. {
  53. command = command.substring(0, command.indexOf(" "));
  54. }
  55. return _datatable.get(command.toLowerCase());
  56. }
  57. @Override
  58. public int size()
  59. {
  60. return _datatable.size();
  61. }
  62. public static BypassHandler getInstance()
  63. {
  64. return SingletonHolder._instance;
  65. }
  66. private static class SingletonHolder
  67. {
  68. protected static final BypassHandler _instance = new BypassHandler();
  69. }
  70. }