Territory.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 com.l2jserver.gameserver;
  24. import java.util.Map;
  25. import java.util.logging.Logger;
  26. import javolution.util.FastMap;
  27. import com.l2jserver.gameserver.model.L2Territory;
  28. import com.l2jserver.util.lib.SqlUtils;
  29. public class Territory
  30. {
  31. private static Logger _log = Logger.getLogger(TradeController.class.getName());
  32. private static Map<Integer, L2Territory> _territory;
  33. public static Territory getInstance()
  34. {
  35. return SingletonHolder._instance;
  36. }
  37. private Territory()
  38. {
  39. // load all data at server start
  40. reload_data();
  41. }
  42. public int[] getRandomPoint(int terr)
  43. {
  44. return _territory.get(terr).getRandomPoint();
  45. }
  46. public int getProcMax(int terr)
  47. {
  48. return _territory.get(terr).getProcMax();
  49. }
  50. public void reload_data()
  51. {
  52. _territory = new FastMap<Integer, L2Territory>();
  53. Integer[][] point = SqlUtils.get2DIntArray(new String[] { "loc_id", "loc_x", "loc_y", "loc_zmin", "loc_zmax", "proc" }, "locations", "loc_id > 0");
  54. for (Integer[] row : point)
  55. {
  56. // _log.info("row = "+row[0]);
  57. Integer terr = row[0];
  58. if (terr == null)
  59. {
  60. _log.warning("Null territory!");
  61. continue;
  62. }
  63. if (_territory.get(terr) == null)
  64. {
  65. L2Territory t = new L2Territory(terr);
  66. _territory.put(terr, t);
  67. }
  68. _territory.get(terr).add(row[1], row[2], row[3], row[4], row[5]);
  69. }
  70. }
  71. @SuppressWarnings("synthetic-access")
  72. private static class SingletonHolder
  73. {
  74. protected static final Territory _instance = new Territory();
  75. }
  76. }