EffectHandler.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.handler;
  20. import java.io.File;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import com.l2jserver.gameserver.model.effects.AbstractEffect;
  24. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  25. /**
  26. * @author BiggBoss, UnAfraid
  27. */
  28. public final class EffectHandler implements IHandler<Class<? extends AbstractEffect>, String>
  29. {
  30. private final Map<String, Class<? extends AbstractEffect>> _handlers;
  31. protected EffectHandler()
  32. {
  33. _handlers = new HashMap<>();
  34. }
  35. @Override
  36. public void registerHandler(Class<? extends AbstractEffect> handler)
  37. {
  38. _handlers.put(handler.getSimpleName(), handler);
  39. }
  40. @Override
  41. public synchronized void removeHandler(Class<? extends AbstractEffect> handler)
  42. {
  43. _handlers.remove(handler.getSimpleName());
  44. }
  45. @Override
  46. public Class<? extends AbstractEffect> getHandler(String name)
  47. {
  48. return _handlers.get(name);
  49. }
  50. @Override
  51. public int size()
  52. {
  53. return _handlers.size();
  54. }
  55. public void executeScript()
  56. {
  57. try
  58. {
  59. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/EffectMasterHandler.java");
  60. L2ScriptEngineManager.getInstance().executeScript(file);
  61. }
  62. catch (Exception e)
  63. {
  64. throw new Error("Problems while running EffectMansterHandler", e);
  65. }
  66. }
  67. private static final class SingletonHolder
  68. {
  69. protected static final EffectHandler _instance = new EffectHandler();
  70. }
  71. public static EffectHandler getInstance()
  72. {
  73. return SingletonHolder._instance;
  74. }
  75. }