2
0

ActionHandler.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.Map;
  17. import javolution.util.FastMap;
  18. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  19. public class ActionHandler
  20. {
  21. private Map<InstanceType, IActionHandler> _actions;
  22. private Map<InstanceType, IActionHandler> _actionsShift;
  23. public static ActionHandler getInstance()
  24. {
  25. return SingletonHolder._instance;
  26. }
  27. private ActionHandler()
  28. {
  29. _actions = new FastMap<InstanceType, IActionHandler>();
  30. _actionsShift = new FastMap<InstanceType, IActionHandler>();
  31. }
  32. public void registerActionHandler(IActionHandler handler)
  33. {
  34. _actions.put(handler.getInstanceType(), handler);
  35. }
  36. public void registerActionShiftHandler(IActionHandler handler)
  37. {
  38. _actionsShift.put(handler.getInstanceType(), handler);
  39. }
  40. public IActionHandler getActionHandler(InstanceType iType)
  41. {
  42. IActionHandler result = null;
  43. for (InstanceType t = iType; t != null; t = t.getParent())
  44. {
  45. result = _actions.get(t);
  46. if (result != null)
  47. break;
  48. }
  49. return result;
  50. }
  51. public IActionHandler getActionShiftHandler(InstanceType iType)
  52. {
  53. IActionHandler result = null;
  54. for (InstanceType t = iType; t != null; t = t.getParent())
  55. {
  56. result = _actionsShift.get(t);
  57. if (result != null)
  58. break;
  59. }
  60. return result;
  61. }
  62. public int size()
  63. {
  64. return _actions.size();
  65. }
  66. public int sizeShift()
  67. {
  68. return _actionsShift.size();
  69. }
  70. @SuppressWarnings("synthetic-access")
  71. private static class SingletonHolder
  72. {
  73. protected static final ActionHandler _instance = new ActionHandler();
  74. }
  75. }