SummonItemsData.java 3.0 KB

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