UITable.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.BufferedReader;
  17. import java.io.File;
  18. import java.io.FileNotFoundException;
  19. import java.io.FileReader;
  20. import java.io.LineNumberReader;
  21. import java.util.ArrayList;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.StringTokenizer;
  26. import java.util.logging.Level;
  27. import java.util.logging.Logger;
  28. import com.l2jserver.Config;
  29. import com.l2jserver.gameserver.model.entity.ActionKey;
  30. /**
  31. * @author mrTJO
  32. */
  33. public class UITable
  34. {
  35. private static final Logger _log = Logger.getLogger(UITable.class.getName());
  36. private Map<Integer, List<ActionKey>> _storedKeys = new HashMap<>();
  37. private Map<Integer, List<Integer>> _storedCategories = new HashMap<>();
  38. public static UITable getInstance()
  39. {
  40. return SingletonHolder._instance;
  41. }
  42. private UITable()
  43. {
  44. parseCatData();
  45. parseKeyData();
  46. _log.info("UITable: Loaded " + _storedCategories.size() + " Categories.");
  47. _log.info("UITable: Loaded " + _storedKeys.size() + " Keys.");
  48. }
  49. private void parseCatData()
  50. {
  51. final File uiData = new File(Config.DATAPACK_ROOT, "data/uicats_en.csv");
  52. try (FileReader fr = new FileReader(uiData);
  53. BufferedReader br = new BufferedReader(fr);
  54. LineNumberReader lnr = new LineNumberReader(br))
  55. {
  56. String line = null;
  57. while ((line = lnr.readLine()) != null)
  58. {
  59. if (line.trim().length() == 0 || line.startsWith("#"))
  60. continue;
  61. StringTokenizer st = new StringTokenizer(line, ";");
  62. int cat = Integer.parseInt(st.nextToken());
  63. int cmd = Integer.parseInt(st.nextToken());
  64. insertCategory(cat, cmd);
  65. }
  66. }
  67. catch (FileNotFoundException e)
  68. {
  69. _log.warning("uicats_en.csv is missing in data folder");
  70. }
  71. catch (Exception e)
  72. {
  73. _log.log(Level.WARNING, "Error while creating UI Default Categories table " + e.getMessage(), e);
  74. }
  75. }
  76. private void parseKeyData()
  77. {
  78. final File uiData = new File(Config.DATAPACK_ROOT, "data/uikeys_en.csv");
  79. try (FileReader fr = new FileReader(uiData);
  80. BufferedReader br = new BufferedReader(fr);
  81. LineNumberReader lnr = new LineNumberReader(br))
  82. {
  83. String line = null;
  84. while ((line = lnr.readLine()) != null)
  85. {
  86. if (line.trim().length() == 0 || line.startsWith("#"))
  87. continue;
  88. StringTokenizer st = new StringTokenizer(line, ";");
  89. int cat = Integer.parseInt(st.nextToken());
  90. int cmd = Integer.parseInt(st.nextToken());
  91. int key = Integer.parseInt(st.nextToken());
  92. int tk1 = Integer.parseInt(st.nextToken());
  93. int tk2 = Integer.parseInt(st.nextToken());
  94. int shw = Integer.parseInt(st.nextToken());
  95. insertKey(cat, cmd, key, tk1, tk2, shw);
  96. }
  97. }
  98. catch (FileNotFoundException e)
  99. {
  100. _log.warning("uikeys_en.csv is missing in data folder");
  101. }
  102. catch (Exception e)
  103. {
  104. _log.log(Level.WARNING, "Error while creating UI Default Keys table " + e.getMessage(), e);
  105. }
  106. }
  107. private void insertCategory(int cat, int cmd)
  108. {
  109. if (_storedCategories.containsKey(cat))
  110. _storedCategories.get(cat).add(cmd);
  111. else
  112. {
  113. List<Integer> tmp = new ArrayList<>();
  114. tmp.add(cmd);
  115. _storedCategories.put(cat, tmp);
  116. }
  117. }
  118. private void insertKey(int cat, int cmdId, int key, int tgKey1, int tgKey2, int show)
  119. {
  120. ActionKey tmk = new ActionKey(cat, cmdId, key, tgKey1, tgKey2, show);
  121. if (_storedKeys.containsKey(cat))
  122. _storedKeys.get(cat).add(tmk);
  123. else
  124. {
  125. List<ActionKey> tmp = new ArrayList<>();
  126. tmp.add(tmk);
  127. _storedKeys.put(cat, tmp);
  128. }
  129. }
  130. public Map<Integer, List<Integer>> getCategories()
  131. {
  132. return _storedCategories;
  133. }
  134. public Map<Integer, List<ActionKey>> getKeys()
  135. {
  136. return _storedKeys;
  137. }
  138. @SuppressWarnings("synthetic-access")
  139. private static class SingletonHolder
  140. {
  141. protected static final UITable _instance = new UITable();
  142. }
  143. }