2
0

SkillHandler.java 1.8 KB

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