SkillHandler.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (C) 2004-2014 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. import com.l2jserver.gameserver.model.skills.L2SkillType;
  23. /**
  24. * @author UnAfraid
  25. */
  26. public class SkillHandler implements IHandler<ISkillHandler, L2SkillType>
  27. {
  28. private final Map<Integer, ISkillHandler> _datatable;
  29. protected SkillHandler()
  30. {
  31. _datatable = new HashMap<>();
  32. }
  33. @Override
  34. public void registerHandler(ISkillHandler handler)
  35. {
  36. L2SkillType[] types = handler.getSkillIds();
  37. for (L2SkillType t : types)
  38. {
  39. _datatable.put(t.ordinal(), handler);
  40. }
  41. }
  42. @Override
  43. public synchronized void removeHandler(ISkillHandler handler)
  44. {
  45. L2SkillType[] types = handler.getSkillIds();
  46. for (L2SkillType t : types)
  47. {
  48. _datatable.remove(t.ordinal());
  49. }
  50. }
  51. @Override
  52. public ISkillHandler getHandler(L2SkillType skillType)
  53. {
  54. return _datatable.get(skillType.ordinal());
  55. }
  56. @Override
  57. public int size()
  58. {
  59. return _datatable.size();
  60. }
  61. public static SkillHandler getInstance()
  62. {
  63. return SingletonHolder._instance;
  64. }
  65. private static class SingletonHolder
  66. {
  67. protected static final SkillHandler _instance = new SkillHandler();
  68. }
  69. }