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