EffectHandler.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.io.File;
  17. import java.util.HashMap;
  18. import java.util.Map;
  19. import com.l2jserver.gameserver.model.effects.L2Effect;
  20. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  21. /**
  22. * @author BiggBoss, UnAfraid
  23. */
  24. public final class EffectHandler implements IHandler<Class<? extends L2Effect>, String>
  25. {
  26. private final Map<String, Class<? extends L2Effect>> _handlers;
  27. protected EffectHandler()
  28. {
  29. _handlers = new HashMap<>();
  30. }
  31. @Override
  32. public void registerHandler(Class<? extends L2Effect> handler)
  33. {
  34. _handlers.put(handler.getSimpleName(), handler);
  35. }
  36. @Override
  37. public synchronized void removeHandler(Class<? extends L2Effect> handler)
  38. {
  39. _handlers.remove(handler.getSimpleName());
  40. }
  41. @Override
  42. public final Class<? extends L2Effect> getHandler(String name)
  43. {
  44. return _handlers.get(name);
  45. }
  46. @Override
  47. public int size()
  48. {
  49. return _handlers.size();
  50. }
  51. public void executeScript()
  52. {
  53. try
  54. {
  55. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/EffectMasterHandler.java");
  56. L2ScriptEngineManager.getInstance().executeScript(file);
  57. }
  58. catch (Exception e)
  59. {
  60. throw new Error("Problems while running EffectMansterHandler", e);
  61. }
  62. }
  63. private static final class SingletonHolder
  64. {
  65. protected static final EffectHandler _instance = new EffectHandler();
  66. }
  67. public static EffectHandler getInstance()
  68. {
  69. return SingletonHolder._instance;
  70. }
  71. }