2
0

SummonItemsData.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.io.File;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. import java.util.Scanner;
  24. import java.util.logging.Logger;
  25. import com.l2jserver.Config;
  26. import com.l2jserver.gameserver.model.L2SummonItem;
  27. /**
  28. * @author FBIagent
  29. */
  30. public class SummonItemsData
  31. {
  32. private static final Logger _log = Logger.getLogger(SummonItemsData.class.getName());
  33. private static final Map<Integer, L2SummonItem> _summonitems = new HashMap<>();
  34. protected SummonItemsData()
  35. {
  36. try (Scanner s = new Scanner(new File(Config.DATAPACK_ROOT, "data/summon_items.csv")))
  37. {
  38. int lineCount = 0;
  39. while (s.hasNextLine())
  40. {
  41. lineCount++;
  42. String line = s.nextLine();
  43. if (line.isEmpty() || (line.charAt(0) == '#'))
  44. {
  45. continue;
  46. }
  47. String[] lineSplit = line.split(";");
  48. int itemID = 0, npcID = 0;
  49. byte summonType = 0;
  50. int despawn = -1;
  51. try
  52. {
  53. itemID = Integer.parseInt(lineSplit[0]);
  54. npcID = Integer.parseInt(lineSplit[1]);
  55. summonType = Byte.parseByte(lineSplit[2]);
  56. if (summonType == 0)
  57. {
  58. despawn = Integer.parseInt(lineSplit[3]);
  59. }
  60. }
  61. catch (Exception e)
  62. {
  63. _log.warning(getClass().getSimpleName() + ": Error in line " + lineCount + " -> incomplete/invalid data or wrong seperator!");
  64. _log.warning(" " + line);
  65. continue;
  66. }
  67. _summonitems.put(itemID, new L2SummonItem(itemID, npcID, summonType, despawn));
  68. }
  69. _log.info(getClass().getSimpleName() + ": Loaded " + _summonitems.size() + " summon items.");
  70. }
  71. catch (Exception e)
  72. {
  73. _log.warning(getClass().getSimpleName() + ": Can not find '" + Config.DATAPACK_ROOT + "/data/summon_items.csv'");
  74. return;
  75. }
  76. }
  77. public L2SummonItem getSummonItem(int itemId)
  78. {
  79. return _summonitems.get(itemId);
  80. }
  81. public int[] itemIDs()
  82. {
  83. int size = _summonitems.size();
  84. int[] result = new int[size];
  85. int i = 0;
  86. for (L2SummonItem si : _summonitems.values())
  87. {
  88. result[i++] = si.getItemId();
  89. }
  90. return result;
  91. }
  92. public static SummonItemsData getInstance()
  93. {
  94. return SingletonHolder._instance;
  95. }
  96. private static class SingletonHolder
  97. {
  98. protected static final SummonItemsData _instance = new SummonItemsData();
  99. }
  100. }