FishingRodsData.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. load();
  34. }
  35. @Override
  36. public void load()
  37. {
  38. _fishingRods.clear();
  39. parseDatapackFile("data/stats/items/fishing/fishingRods.xml");
  40. _log.info(getClass().getSimpleName() + ": Loaded " + _fishingRods.size() + " Fishing Rods.");
  41. }
  42. @Override
  43. protected void parseDocument(Document doc)
  44. {
  45. NamedNodeMap attrs;
  46. Node att;
  47. L2FishingRod fishingRod;
  48. StatsSet set;
  49. for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  50. {
  51. if ("list".equalsIgnoreCase(n.getNodeName()))
  52. {
  53. for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  54. {
  55. if ("fishingRod".equalsIgnoreCase(d.getNodeName()))
  56. {
  57. attrs = d.getAttributes();
  58. set = new StatsSet();
  59. for (int i = 0; i < attrs.getLength(); i++)
  60. {
  61. att = attrs.item(i);
  62. set.set(att.getNodeName(), att.getNodeValue());
  63. }
  64. fishingRod = new L2FishingRod(set);
  65. _fishingRods.put(fishingRod.getFishingRodItemId(), fishingRod);
  66. }
  67. }
  68. }
  69. }
  70. }
  71. /**
  72. * @param itemId
  73. * @return A fishing Rod by Item Id
  74. */
  75. public L2FishingRod getFishingRod(int itemId)
  76. {
  77. return _fishingRods.get(itemId);
  78. }
  79. public static FishingRodsData getInstance()
  80. {
  81. return SingletonHolder._instance;
  82. }
  83. private static class SingletonHolder
  84. {
  85. protected static final FishingRodsData _instance = new FishingRodsData();
  86. }
  87. }