SummonItemsData.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 gnu.trove.map.hash.TIntObjectHashMap;
  17. import java.io.File;
  18. import java.util.Scanner;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.model.L2SummonItem;
  22. /**
  23. * @author FBIagent
  24. */
  25. public class SummonItemsData
  26. {
  27. protected static final Logger _log = Logger.getLogger(SummonItemsData.class.getName());
  28. private final TIntObjectHashMap<L2SummonItem> _summonitems = new TIntObjectHashMap<L2SummonItem>();
  29. public static SummonItemsData getInstance()
  30. {
  31. return SingletonHolder._instance;
  32. }
  33. private SummonItemsData()
  34. {
  35. Scanner s;
  36. try
  37. {
  38. s = new Scanner(new File(Config.DATAPACK_ROOT + "/data/summon_items.csv"));
  39. }
  40. catch (Exception e)
  41. {
  42. _log.warning("Summon items data: Can not find '" + Config.DATAPACK_ROOT + "/data/summon_items.csv'");
  43. return;
  44. }
  45. int lineCount = 0;
  46. while (s.hasNextLine())
  47. {
  48. lineCount++;
  49. String line = s.nextLine();
  50. if (line.startsWith("#"))
  51. {
  52. continue;
  53. }
  54. else if (line.isEmpty())
  55. {
  56. continue;
  57. }
  58. String[] lineSplit = line.split(";");
  59. boolean ok = true;
  60. int itemID = 0, npcID = 0;
  61. byte summonType = 0;
  62. int despawn = -1;
  63. try
  64. {
  65. itemID = Integer.parseInt(lineSplit[0]);
  66. npcID = Integer.parseInt(lineSplit[1]);
  67. summonType = Byte.parseByte(lineSplit[2]);
  68. if (summonType == 0)
  69. {
  70. despawn = Integer.parseInt(lineSplit[3]);
  71. }
  72. }
  73. catch (Exception e)
  74. {
  75. _log.warning("Summon items data: Error in line " + lineCount + " -> incomplete/invalid data or wrong seperator!");
  76. _log.warning(" " + line);
  77. ok = false;
  78. }
  79. if (!ok)
  80. {
  81. continue;
  82. }
  83. L2SummonItem summonitem = new L2SummonItem(itemID, npcID, summonType, despawn);
  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.valueCollection())
  98. {
  99. result[i++] = si.getItemId();
  100. }
  101. return result;
  102. }
  103. @SuppressWarnings("synthetic-access")
  104. private static class SingletonHolder
  105. {
  106. protected static final SummonItemsData _instance = new SummonItemsData();
  107. }
  108. }