TargetHandler.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.Map;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import javolution.util.FastMap;
  21. import com.l2jserver.gameserver.model.L2Skill.SkillTargetType;
  22. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  23. /**
  24. * @author UnAfraid
  25. */
  26. public class TargetHandler
  27. {
  28. private static Logger _log = Logger.getLogger(TargetHandler.class.getName());
  29. private final Map<Enum<SkillTargetType>, ISkillTargetTypeHandler> _datatable;
  30. public static TargetHandler getInstance()
  31. {
  32. return SingletonHolder._instance;
  33. }
  34. private TargetHandler()
  35. {
  36. _datatable = new FastMap<Enum<SkillTargetType>, ISkillTargetTypeHandler>();
  37. }
  38. public void registerSkillTargetType(ISkillTargetTypeHandler handler)
  39. {
  40. Enum<SkillTargetType> ids = handler.getTargetType();
  41. if (_datatable.containsKey(ids))
  42. _log.log(Level.FINE, "Target Handler: " + ids.toString() + " is already registered into the map!");
  43. _datatable.put(ids, handler);
  44. }
  45. public ISkillTargetTypeHandler getSkillTarget(Enum<SkillTargetType> skillTargetType)
  46. {
  47. Enum<SkillTargetType> target = skillTargetType;
  48. return _datatable.get(target);
  49. }
  50. public void executeScript()
  51. {
  52. try
  53. {
  54. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/TargetMasterHandler.java");
  55. L2ScriptEngineManager.getInstance().executeScript(file);
  56. }
  57. catch (Exception e)
  58. {
  59. _log.warning("Problems while running TargetMansterHandler");
  60. e.printStackTrace();
  61. }
  62. }
  63. public int size()
  64. {
  65. return _datatable.size();
  66. }
  67. @SuppressWarnings("synthetic-access")
  68. private static class SingletonHolder
  69. {
  70. protected static final TargetHandler _instance = new TargetHandler();
  71. }
  72. }