SkillLearnData.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.data.xml.impl;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. import org.w3c.dom.Document;
  25. import org.w3c.dom.Node;
  26. import com.l2jserver.gameserver.model.base.ClassId;
  27. import com.l2jserver.util.data.xml.IXmlReader;
  28. /**
  29. * Holds all skill learn data for all NPCs.
  30. * @author xban1x
  31. */
  32. public final class SkillLearnData implements IXmlReader
  33. {
  34. private final Map<Integer, List<ClassId>> _skillLearn = new HashMap<>();
  35. protected SkillLearnData()
  36. {
  37. load();
  38. }
  39. @Override
  40. public synchronized void load()
  41. {
  42. _skillLearn.clear();
  43. parseDatapackFile("data/skillLearn.xml");
  44. LOGGER.info("{}: Loaded {} Skill Learn data.", getClass().getSimpleName(), _skillLearn.size());
  45. }
  46. @Override
  47. public void parseDocument(Document doc)
  48. {
  49. for (Node node = doc.getFirstChild(); node != null; node = node.getNextSibling())
  50. {
  51. if ("list".equalsIgnoreCase(node.getNodeName()))
  52. {
  53. for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())
  54. {
  55. if ("npc".equalsIgnoreCase(list_node.getNodeName()))
  56. {
  57. final List<ClassId> classIds = new ArrayList<>();
  58. for (Node c = list_node.getFirstChild(); c != null; c = c.getNextSibling())
  59. {
  60. if ("classId".equalsIgnoreCase(c.getNodeName()))
  61. {
  62. classIds.add(ClassId.getClassId(Integer.parseInt(c.getTextContent())));
  63. }
  64. }
  65. _skillLearn.put(parseInteger(list_node.getAttributes(), "id"), classIds);
  66. }
  67. }
  68. }
  69. }
  70. }
  71. /**
  72. * @param npcId
  73. * @return {@link List} of {@link ClassId}'s that this npcId can teach.
  74. */
  75. public List<ClassId> getSkillLearnData(int npcId)
  76. {
  77. return _skillLearn.get(npcId);
  78. }
  79. /**
  80. * Gets the single instance of SkillLearnData.
  81. * @return single instance of SkillLearnData
  82. */
  83. public static SkillLearnData getInstance()
  84. {
  85. return SingletonHolder._instance;
  86. }
  87. private static class SingletonHolder
  88. {
  89. protected static final SkillLearnData _instance = new SkillLearnData();
  90. }
  91. }