FishingRodsData.java 2.8 KB

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