EffectHandler.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.logging.Level;
  18. import java.util.logging.Logger;
  19. import javolution.util.FastMap;
  20. import com.l2jserver.gameserver.model.effects.L2Effect;
  21. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  22. /**
  23. * @author BiggBoss
  24. */
  25. public final class EffectHandler
  26. {
  27. private static final Logger _log = Logger.getLogger(EffectHandler.class.getName());
  28. private final FastMap<Integer, Class<? extends L2Effect>> _handlers;
  29. protected EffectHandler()
  30. {
  31. _handlers = new FastMap<Integer, Class<? extends L2Effect>>();
  32. }
  33. public void registerHandler(String name, Class<? extends L2Effect> func)
  34. {
  35. _handlers.put(name.hashCode(), func);
  36. }
  37. public final Class<? extends L2Effect> getHandler(String name)
  38. {
  39. return _handlers.get(name.hashCode());
  40. }
  41. public int size()
  42. {
  43. return _handlers.size();
  44. }
  45. public void executeScript()
  46. {
  47. try
  48. {
  49. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/EffectMasterHandler.java");
  50. L2ScriptEngineManager.getInstance().executeScript(file);
  51. }
  52. catch (Exception e)
  53. {
  54. _log.log(Level.WARNING, "Problems while running EffectMansterHandler", e);
  55. }
  56. }
  57. private static final class SingletonHolder
  58. {
  59. protected static final EffectHandler _instance = new EffectHandler();
  60. }
  61. public static EffectHandler getInstance()
  62. {
  63. return SingletonHolder._instance;
  64. }
  65. }