EffectHandler.java 2.1 KB

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