SummonItemsData.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /**
  16. *
  17. * @author FBIagent
  18. *
  19. */
  20. package net.sf.l2j.gameserver.datatables;
  21. import java.io.File;
  22. import java.util.Scanner;
  23. import java.util.logging.Logger;
  24. import javolution.util.FastMap;
  25. import net.sf.l2j.Config;
  26. import net.sf.l2j.gameserver.model.L2SummonItem;
  27. public class SummonItemsData
  28. {
  29. protected static final Logger _log = Logger.getLogger(SummonItemsData.class.getName());
  30. private FastMap<Integer, L2SummonItem> _summonitems;
  31. private static SummonItemsData _instance;
  32. public static SummonItemsData getInstance()
  33. {
  34. if (_instance == null)
  35. _instance = new SummonItemsData();
  36. return _instance;
  37. }
  38. public SummonItemsData()
  39. {
  40. _summonitems = new FastMap<Integer, L2SummonItem>();
  41. Scanner s;
  42. try
  43. {
  44. s = new Scanner(new File(Config.DATAPACK_ROOT + "/data/summon_items.csv"));
  45. }
  46. catch (Exception e)
  47. {
  48. _log.warning("Summon items data: Can not find '" + Config.DATAPACK_ROOT + "/data/summon_items.csv'");
  49. return;
  50. }
  51. int lineCount = 0,
  52. commentLinesCount = 0;
  53. while (s.hasNextLine())
  54. {
  55. lineCount++;
  56. String line = s.nextLine();
  57. if (line.startsWith("#"))
  58. {
  59. commentLinesCount++;
  60. continue;
  61. }
  62. else if (line.equals(""))
  63. continue;
  64. String[] lineSplit = line.split(";");
  65. boolean ok = true;
  66. int itemID = 0,
  67. npcID = 0;
  68. byte summonType = 0;
  69. try
  70. {
  71. itemID = Integer.parseInt(lineSplit[0]);
  72. npcID = Integer.parseInt(lineSplit[1]);
  73. summonType = Byte.parseByte(lineSplit[2]);
  74. }
  75. catch (Exception e)
  76. {
  77. _log.warning("Summon items data: Error in line " + lineCount + " -> incomplete/invalid data or wrong seperator!");
  78. _log.warning(" " + line);
  79. ok = false;
  80. }
  81. if (!ok)
  82. continue;
  83. L2SummonItem summonitem = new L2SummonItem(itemID, npcID, summonType);
  84. _summonitems.put(itemID, summonitem);
  85. }
  86. _log.info("Summon items data: Loaded " + _summonitems.size() + " summon items.");
  87. }
  88. public L2SummonItem getSummonItem(int itemId)
  89. {
  90. return _summonitems.get(itemId);
  91. }
  92. public int[] itemIDs()
  93. {
  94. int size = _summonitems.size();
  95. int[] result = new int[size];
  96. int i = 0;
  97. for (L2SummonItem si : _summonitems.values())
  98. {
  99. result[i] = si.getItemId();
  100. i++;
  101. }
  102. return result;
  103. }
  104. }