Guest User

Untitled

a guest
Jul 5th, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.25 KB | None | 0 0
  1. package events.TvT;
  2.  
  3. import java.io.File;
  4. import java.util.Calendar;
  5. import javax.xml.parsers.DocumentBuilderFactory;
  6.  
  7. import l2r.gameserver.utils.GArray;
  8. import org.w3c.dom.Document;
  9. import org.w3c.dom.NamedNodeMap;
  10. import org.w3c.dom.Node;
  11.  
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14.  
  15. public class TvTConfig
  16. {
  17.     private static final Logger _log = LoggerFactory.getLogger(TvTConfig.class);
  18.     public static GArray<Configs> _configs = new GArray<Configs>();
  19.  
  20.     public static void load()
  21.     {
  22.         try
  23.         {
  24.             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  25.             factory.setValidating(false);
  26.             factory.setIgnoringComments(true);
  27.  
  28.             File file = new File("./config/events/TvT.xml");
  29.  
  30.             Calendar _date = Calendar.getInstance();
  31.  
  32.             Document doc = factory.newDocumentBuilder().parse(file);
  33.  
  34.             for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  35.             {
  36.                 if (!"list".equalsIgnoreCase(n.getNodeName()))
  37.                     continue;
  38.                 for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  39.                 {
  40.                     if (!"tvt".equalsIgnoreCase(d.getNodeName()))
  41.                         continue;
  42.                     Configs _config = new Configs();
  43.                     NamedNodeMap attrs = d.getAttributes();
  44.  
  45.                     if(Integer.parseInt(attrs.getNamedItem("day").getNodeValue()) != 0)
  46.                         _date.set(Calendar.DAY_OF_MONTH, Integer.parseInt(attrs.getNamedItem("day").getNodeValue()));
  47.                     _date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(attrs.getNamedItem("hour").getNodeValue()));
  48.                     _date.set(Calendar.MINUTE, Integer.parseInt(attrs.getNamedItem("min").getNodeValue()));
  49.                     _config.START_TIME = (_date.getTimeInMillis() > System.currentTimeMillis() ? _date.getTimeInMillis() / 1000 : _date.getTimeInMillis() / 1000 + 86400);
  50.                     _config.TIME_TO_END_BATTLE = Integer.parseInt(attrs.getNamedItem("TimeToEvent").getNodeValue());
  51.  
  52.                     for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  53.                     {
  54.                         if ("Participants".equalsIgnoreCase(cd.getNodeName()))
  55.                         {
  56.                             attrs = cd.getAttributes();
  57.                             _config.MIN_PARTICIPANTS = Integer.parseInt(attrs.getNamedItem("min").getNodeValue());
  58.                             _config.MAX_PARTICIPANTS = Integer.parseInt(attrs.getNamedItem("max").getNodeValue());
  59.                         }
  60.                         else if ("TimeToRegistration".equalsIgnoreCase(cd.getNodeName()))
  61.                         {
  62.                             attrs = cd.getAttributes();
  63.                             _config.TIME_TO_START_BATTLE = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  64.                         }
  65.                         else if ("AllowKillBonus".equalsIgnoreCase(cd.getNodeName()))
  66.                         {
  67.                             attrs = cd.getAttributes();
  68.                             _config.ALLOW_KILL_BONUS = Boolean.parseBoolean(attrs.getNamedItem("val").getNodeValue());
  69.                         }
  70.                         else if ("AllowHeroSkillAndWeapons".equalsIgnoreCase(cd.getNodeName()))
  71.                         {
  72.                             attrs = cd.getAttributes();
  73.                             _config.ALLOW_HERO_WEAPONS = Boolean.parseBoolean(attrs.getNamedItem("val").getNodeValue());
  74.                         }
  75.                         else if ("KillReward".equalsIgnoreCase(cd.getNodeName()))
  76.                         {
  77.                             attrs = cd.getAttributes();
  78.                             _config.KILL_BONUS_ID = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  79.                             _config.KILL_BONUS_COUNT = Integer.parseInt(attrs.getNamedItem("count").getNodeValue());
  80.                         }
  81.                         else if ("StopAllEffects".equalsIgnoreCase(cd.getNodeName()))
  82.                         {
  83.                             attrs = cd.getAttributes();
  84.                             _config.STOP_ALL_EFFECTS = Boolean.parseBoolean(attrs.getNamedItem("val").getNodeValue());
  85.                         }
  86.                         else if ("AllowTakeItems".equalsIgnoreCase(cd.getNodeName()))
  87.                         {
  88.                             attrs = cd.getAttributes();
  89.                             _config.ALLOW_TAKE_ITEM = Boolean.parseBoolean(attrs.getNamedItem("val").getNodeValue());
  90.                         }
  91.                         else if ("TakeItems".equalsIgnoreCase(cd.getNodeName()))
  92.                         {
  93.                             attrs = cd.getAttributes();
  94.                             _config.TAKE_ITEM_ID = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
  95.                             _config.TAKE_COUNT = Integer.parseInt(attrs.getNamedItem("count").getNodeValue());
  96.                         }
  97.                         else if ("TeamCoords".equalsIgnoreCase(cd.getNodeName()))
  98.                         {
  99.                             attrs = cd.getAttributes();
  100.                             _config.TEAM_NAME.add(attrs.getNamedItem("name").getNodeValue());
  101.                             _config.TEAM_COUNTS += 1;
  102.                         }
  103.                         else if ("Reward".equalsIgnoreCase(cd.getNodeName()))
  104.                         {
  105.                             attrs = cd.getAttributes();
  106.                             _config.ST_REWARD_ITEM_ID = attrs.getNamedItem("id").getNodeValue();
  107.                             _config.ST_REWARD_COUNT = attrs.getNamedItem("count").getNodeValue();
  108.                         }
  109.                         else if ("TeamCoords".equalsIgnoreCase(cd.getNodeName()))
  110.                         {
  111.                             attrs = cd.getAttributes();
  112.                             _config.TEAM_NAME.add(attrs.getNamedItem("name").getNodeValue());
  113.                             _config.TEAM_COUNTS += 1;
  114.                         }
  115.                         else if ("NumberOfRounds".equalsIgnoreCase(cd.getNodeName()))
  116.                         {
  117.                             attrs = cd.getAttributes();
  118.                             _config.NUMBER_OF_ROUNDS = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  119.                         }
  120.                         else if ("ResurrectionTime".equalsIgnoreCase(cd.getNodeName()))
  121.                         {
  122.                             attrs = cd.getAttributes();
  123.                             _config.RESURRECTION_TIME = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  124.                         }
  125.                         else if ("Level".equalsIgnoreCase(cd.getNodeName()))
  126.                         {
  127.                             attrs = cd.getAttributes();
  128.                             _config.MIN_LEVEL = Integer.parseInt(attrs.getNamedItem("min").getNodeValue());
  129.                             _config.MAX_LEVEL = Integer.parseInt(attrs.getNamedItem("max").getNodeValue());
  130.                         }
  131.                         else if ("OpenDoor".equalsIgnoreCase(cd.getNodeName()))
  132.                         {
  133.                             attrs = cd.getAttributes();
  134.                             _config.DOORS.put(Integer.parseInt(attrs.getNamedItem("id").getNodeValue()), Boolean.valueOf(true));
  135.                         }
  136.                         else if ("CloseDoor".equalsIgnoreCase(cd.getNodeName()))
  137.                         {
  138.                             attrs = cd.getAttributes();
  139.                             _config.DOORS.put(Integer.parseInt(attrs.getNamedItem("id").getNodeValue()), Boolean.valueOf(false));
  140.                         }
  141.                         else if ("PauseTime".equalsIgnoreCase(cd.getNodeName()))
  142.                         {
  143.                             attrs = cd.getAttributes();
  144.                             _config.PAUSE_TIME = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  145.                         }
  146.                         else if ("RestrictItems".equalsIgnoreCase(cd.getNodeName()))
  147.                         {
  148.                             attrs = cd.getAttributes();
  149.                             _config.RESTRICT_ITEMS = attrs.getNamedItem("val").getNodeValue();
  150.                         }
  151.                         else if ("ListMageFaiterSupport".equalsIgnoreCase(cd.getNodeName()))
  152.                         {
  153.                             attrs = cd.getAttributes();
  154.                             String[] skills = attrs.getNamedItem("val").getNodeValue().split(",");
  155.                             for (String id : skills)
  156.                                 _config.LIST_MAGE_FAITER_SUPPORT.add(Integer.parseInt(id));
  157.                         }
  158.                         else if ("ListMageMagSupport".equalsIgnoreCase(cd.getNodeName()))
  159.                         {
  160.                             attrs = cd.getAttributes();
  161.                             String[] skills = attrs.getNamedItem("val").getNodeValue().split(",");
  162.                             for (String id : skills)
  163.                                 _config.LIST_MAGE_MAG_SUPPORT.add(Integer.parseInt(id));
  164.                         }
  165.                         else
  166.                         {
  167.                             if (!"RewardForKill".equalsIgnoreCase(cd.getNodeName()))
  168.                                 continue;
  169.                             attrs = cd.getAttributes();
  170.                             _config.REWARD_FOR_KILL = Integer.parseInt(attrs.getNamedItem("val").getNodeValue());
  171.                         }
  172.                     }
  173.  
  174.                     _configs.add(_config);
  175.                 }
  176.             }
  177.  
  178.             _configs.sort();
  179.             _log.info("Loaded " + _configs.size() + " configs for " + TvT.getInstance().getName() + " event.");
  180.         }
  181.         catch (Exception e)
  182.         {
  183.             _log.warn("Error parsing tvt.xml");
  184.         }
  185.     }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment