TransformationManager.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.instancemanager;
  16. import java.util.Collection;
  17. import java.util.Map;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.gameserver.model.L2Transformation;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import javolution.util.FastMap;
  22. /**
  23. *
  24. * @author KenM
  25. */
  26. public class TransformationManager
  27. {
  28. private static final Logger _log = Logger.getLogger(TransformationManager.class.getName());
  29. public static TransformationManager getInstance()
  30. {
  31. return SingletonHolder._instance;
  32. }
  33. private Map<Integer, L2Transformation> _transformations;
  34. private TransformationManager()
  35. {
  36. _transformations = new FastMap<Integer, L2Transformation>();
  37. }
  38. public void report()
  39. {
  40. _log.info("Loaded: " + this.getAllTransformations().size() + " transformations.");
  41. }
  42. public boolean transformPlayer(int id, L2PcInstance player)
  43. {
  44. L2Transformation template = this.getTransformationById(id);
  45. if (template != null)
  46. {
  47. L2Transformation trans = template.createTransformationForPlayer(player);
  48. trans.start();
  49. return true;
  50. }
  51. else
  52. {
  53. return false;
  54. }
  55. }
  56. public L2Transformation getTransformationById(int id)
  57. {
  58. return _transformations.get(id);
  59. }
  60. public L2Transformation registerTransformation(L2Transformation transformation)
  61. {
  62. return _transformations.put(transformation.getId(), transformation);
  63. }
  64. public Collection<L2Transformation> getAllTransformations()
  65. {
  66. return _transformations.values();
  67. }
  68. @SuppressWarnings("synthetic-access")
  69. private static class SingletonHolder
  70. {
  71. protected static final TransformationManager _instance = new TransformationManager();
  72. }
  73. }