Advertisement
Sarada-L2

IconTable para IXmlReader

Jun 11th, 2021
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. diff --git a/java/net/sf/l2j/gameserver/GameServer.java b/java/net/sf/l2j/gameserver/GameServer.java
  2. index fd6397d..23c0401 100644
  3. --- a/java/net/sf/l2j/gameserver/GameServer.java
  4. +++ b/java/net/sf/l2j/gameserver/GameServer.java
  5. @@ -39,6 +39,7 @@
  6. import net.sf.l2j.gameserver.data.manager.LotteryManager;
  7. import net.sf.l2j.gameserver.data.manager.PartyMatchRoomManager;
  8. import net.sf.l2j.gameserver.data.manager.PetitionManager;
  9. import net.sf.l2j.gameserver.data.manager.RaidBossManager;
  10. import net.sf.l2j.gameserver.data.manager.RaidPointManager;
  11. import net.sf.l2j.gameserver.data.manager.SevenSignsManager;
  12. @@ -57,6 +58,7 @@
  13. import net.sf.l2j.gameserver.data.xml.FishData;
  14. import net.sf.l2j.gameserver.data.xml.HennaData;
  15. import net.sf.l2j.gameserver.data.xml.HerbDropData;
  16. +import net.sf.l2j.gameserver.data.xml.IconTable;
  17. import net.sf.l2j.gameserver.data.xml.InstantTeleportData;
  18. import net.sf.l2j.gameserver.data.xml.ItemData;
  19. import net.sf.l2j.gameserver.data.xml.MapRegionData;
  20. @@ -209,6 +211,8 @@
  21. RandomAnimationTaskManager.getInstance();
  22. ShadowItemTaskManager.getInstance();
  23. WaterTaskManager.getInstance();
  24. + IconTable.getInstance();
  25.  
  26. StringUtil.printSection("Auto Spawns");
  27. AutoSpawnTable.getInstance();
  28.  
  29. \ No newline at end of file
  30. diff --git a/java/net/sf/l2j/gameserver/data/xml/IconTable.java b/java/net/sf/l2j/gameserver/data/xml/IconTable.java
  31. new file mode 100644
  32. index 0000000..131cdf8
  33. --- /dev/null
  34. +++ b/java/net/sf/l2j/gameserver/data/xml/IconTable.java
  35. @@ -0,0 +1,100 @@
  36. +/*
  37. + * This program is free software: you can redistribute it and/or modify it under
  38. + * the terms of the GNU General Public License as published by the Free Software
  39. + * Foundation, either version 3 of the License, or (at your option) any later
  40. + * version.
  41. + *
  42. + * This program is distributed in the hope that it will be useful, but WITHOUT
  43. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  44. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  45. + * details.
  46. + *
  47. + * You should have received a copy of the GNU General Public License along with
  48. + * this program. If not, see <http://www.gnu.org/licenses/>.
  49. + */
  50. +package net.sf.l2j.gameserver.data.xml;
  51. +
  52. +import java.nio.file.Path;
  53. +import java.util.Map;
  54. +import java.util.concurrent.ConcurrentHashMap;
  55. +import java.util.logging.Level;
  56. +import java.util.logging.Logger;
  57. +
  58. +import net.sf.l2j.commons.data.xml.IXmlReader;
  59. +
  60. +import org.w3c.dom.Document;
  61. +import org.w3c.dom.NamedNodeMap;
  62. +import org.w3c.dom.Node;
  63. +
  64. +/**
  65. + *
  66. + * @author Sarada
  67. + *
  68. + */
  69. +public class IconTable implements IXmlReader
  70. +{
  71. + private static final Logger _log = Logger.getLogger(IconTable.class.getName());
  72. +
  73. + private static Map<Integer, String> _icons = new ConcurrentHashMap<>();
  74. +
  75. + public static final IconTable getInstance()
  76. + {
  77. + return SingletonHolder._instance;
  78. + }
  79. +
  80. + public IconTable()
  81. + {
  82. + load();
  83. + }
  84. + @Override
  85. + public void load()
  86. + {
  87. + parseFile("./data/xml/icons.xml");
  88. + LOGGER.info("Loaded " + _icons.size() + " icons.");
  89. + }
  90. + @Override
  91. + public void parseDocument(Document doc, Path path)
  92. + {
  93. + try
  94. + {
  95. + Node n = doc.getFirstChild();
  96. + for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  97. + {
  98. + if (d.getNodeName().equalsIgnoreCase("icon"))
  99. + {
  100. + NamedNodeMap attrs = d.getAttributes();
  101. +
  102. + int itemId = Integer.valueOf(attrs.getNamedItem("itemId").getNodeValue());
  103. + String iconName = attrs.getNamedItem("iconName").getNodeValue();
  104. +
  105. + if (itemId == 0 && itemId < 0)
  106. + {
  107. + _log.log(Level.WARNING, "Icon Table: itemId=\"" + itemId + "\" is not item ID, Ignoring it!");
  108. + continue;
  109. + }
  110. + _icons.put(itemId, iconName);
  111. + }
  112. + }
  113. + }
  114. + catch (Exception e)
  115. + {
  116. + _log.log(Level.WARNING, "Icon Table: Error loading from database: " + e.getMessage(), e);
  117. + }
  118. +
  119. + _log.info("Icon Table: Loaded " + _icons.size() + " icons.");
  120. + }
  121. +
  122. + public static String getIcon(int id)
  123. + {
  124. + if (_icons.get(id) == null)
  125. + return "icon.NOIMAGE";
  126. +
  127. + return _icons.get(id);
  128. + }
  129. +
  130. + private static class SingletonHolder
  131. + {
  132. + protected static final IconTable _instance = new IconTable();
  133. + }
  134. +
  135. +}
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement