TerritoryTable.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.datatables;
  16. import java.util.HashMap;
  17. import java.util.Map;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.gameserver.model.L2Territory;
  20. import com.l2jserver.util.lib.SqlUtils;
  21. /**
  22. * @author Balancer, Mr
  23. */
  24. public class TerritoryTable
  25. {
  26. private static final Logger _log = Logger.getLogger(TerritoryTable.class.getName());
  27. private static final Map<Integer, L2Territory> _territory = new HashMap<>();
  28. /**
  29. * Instantiates a new territory.
  30. */
  31. protected TerritoryTable()
  32. {
  33. load();
  34. }
  35. /**
  36. * Gets the random point.
  37. * @param terr the territory Id?
  38. * @return the random point
  39. */
  40. public int[] getRandomPoint(int terr)
  41. {
  42. return _territory.get(terr).getRandomPoint();
  43. }
  44. /**
  45. * Gets the proc max.
  46. * @param terr the territory Id?
  47. * @return the proc max
  48. */
  49. public int getProcMax(int terr)
  50. {
  51. return _territory.get(terr).getProcMax();
  52. }
  53. /**
  54. * Load the data from database.
  55. */
  56. public void load()
  57. {
  58. _territory.clear();
  59. Integer[][] point = SqlUtils.get2DIntArray(new String[] { "loc_id", "loc_x", "loc_y", "loc_zmin", "loc_zmax", "proc" }, "locations", "loc_id > 0");
  60. for (Integer[] row : point)
  61. {
  62. Integer terr = row[0];
  63. if (terr == null)
  64. {
  65. _log.warning("Null territory!");
  66. continue;
  67. }
  68. if (_territory.get(terr) == null)
  69. {
  70. L2Territory t = new L2Territory(terr);
  71. _territory.put(terr, t);
  72. }
  73. _territory.get(terr).add(row[1], row[2], row[3], row[4], row[5]);
  74. }
  75. }
  76. /**
  77. * Gets the single instance of Territory.
  78. * @return single instance of Territory
  79. */
  80. public static TerritoryTable getInstance()
  81. {
  82. return SingletonHolder._instance;
  83. }
  84. private static class SingletonHolder
  85. {
  86. protected static final TerritoryTable _instance = new TerritoryTable();
  87. }
  88. }