FishingRodsData.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.datatables;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import org.w3c.dom.Document;
  19. import org.w3c.dom.NamedNodeMap;
  20. import org.w3c.dom.Node;
  21. import com.l2jserver.gameserver.engines.DocumentParser;
  22. import com.l2jserver.gameserver.model.StatsSet;
  23. import com.l2jserver.gameserver.model.fishing.L2FishingRod;
  24. /**
  25. * This class holds the Fishing Rods information.
  26. * @author nonom
  27. */
  28. public final class FishingRodsData extends DocumentParser
  29. {
  30. private static final Map<Integer, L2FishingRod> _fishingRods = new HashMap<>();
  31. protected FishingRodsData()
  32. {
  33. _fishingRods.clear();
  34. parseDatapackFile("data/stats/items/fishing/fishingRods.xml");
  35. _log.info(getClass().getSimpleName() + ": Loaded " + _fishingRods.size() + " Fishing Rods.");
  36. }
  37. @Override
  38. protected void parseDocument(Document doc)
  39. {
  40. NamedNodeMap attrs;
  41. Node att;
  42. L2FishingRod fishingRod;
  43. StatsSet set;
  44. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  45. {
  46. if ("list".equalsIgnoreCase(n.getNodeName()))
  47. {
  48. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  49. {
  50. if ("fishingRod".equalsIgnoreCase(d.getNodeName()))
  51. {
  52. attrs = d.getAttributes();
  53. set = new StatsSet();
  54. for (int i = 0; i < attrs.getLength(); i++)
  55. {
  56. att = attrs.item(i);
  57. set.set(att.getNodeName(), att.getNodeValue());
  58. }
  59. fishingRod = new L2FishingRod(set);
  60. _fishingRods.put(fishingRod.getFishingRodItemId(), fishingRod);
  61. }
  62. }
  63. }
  64. }
  65. }
  66. /**
  67. * @param itemId
  68. * @return A fishing Rod by Item Id
  69. */
  70. public L2FishingRod getFishingRod(int itemId)
  71. {
  72. return _fishingRods.get(itemId);
  73. }
  74. public static FishingRodsData getInstance()
  75. {
  76. return SingletonHolder._instance;
  77. }
  78. private static class SingletonHolder
  79. {
  80. protected static final FishingRodsData _instance = new FishingRodsData();
  81. }
  82. }