Territory.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. /*
  16. coded by Balancer
  17. ported to L2JRU by Mr
  18. balancer@balancer.ru
  19. http://balancer.ru
  20. version 0.1.1, 2005-06-07
  21. version 0.1, 2005-03-16
  22. */
  23. package net.sf.l2j.gameserver;
  24. import java.util.Map;
  25. import java.util.logging.Logger;
  26. import javolution.util.FastMap;
  27. import net.sf.l2j.gameserver.lib.SqlUtils;
  28. import net.sf.l2j.gameserver.model.L2Territory;
  29. public class Territory
  30. {
  31. private static Logger _log = Logger.getLogger(TradeController.class.getName());
  32. private static final Territory _instance = new Territory();
  33. private static Map<Integer,L2Territory> _territory;
  34. public static Territory getInstance()
  35. {
  36. return _instance;
  37. }
  38. private Territory()
  39. {
  40. // load all data at server start
  41. reload_data();
  42. }
  43. public int[] getRandomPoint(int terr)
  44. {
  45. return _territory.get(terr).getRandomPoint();
  46. }
  47. public int getProcMax(int terr)
  48. {
  49. return _territory.get(terr).getProcMax();
  50. }
  51. public void reload_data()
  52. {
  53. _territory = new FastMap<Integer,L2Territory>();
  54. Integer[][] point = SqlUtils.get2DIntArray(new String[]{"loc_id","loc_x","loc_y","loc_zmin","loc_zmax","proc"}, "locations", "loc_id > 0");
  55. for(Integer[] row : point)
  56. {
  57. // _log.info("row = "+row[0]);
  58. Integer terr = row[0];
  59. if(terr == null)
  60. {
  61. _log.warning("Null territory!");
  62. continue;
  63. }
  64. if(_territory.get(terr) == null)
  65. {
  66. L2Territory t = new L2Territory(terr);
  67. _territory.put(terr, t);
  68. }
  69. _territory.get(terr).add(row[1],row[2],row[3],row[4],row[5]);
  70. }
  71. }
  72. }