TerritoryTable.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2004-2013 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.datatables;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.gameserver.model.L2Territory;
  24. import com.l2jserver.util.lib.SqlUtils;
  25. /**
  26. * @author Balancer, Mr
  27. */
  28. public class TerritoryTable
  29. {
  30. private static final Logger _log = Logger.getLogger(TerritoryTable.class.getName());
  31. private static final Map<Integer, L2Territory> _territory = new HashMap<>();
  32. /**
  33. * Instantiates a new territory.
  34. */
  35. protected TerritoryTable()
  36. {
  37. load();
  38. }
  39. /**
  40. * Gets the random point.
  41. * @param terr the territory Id?
  42. * @return the random point
  43. */
  44. public int[] getRandomPoint(int terr)
  45. {
  46. return _territory.get(terr).getRandomPoint();
  47. }
  48. /**
  49. * Gets the proc max.
  50. * @param terr the territory Id?
  51. * @return the proc max
  52. */
  53. public int getProcMax(int terr)
  54. {
  55. return _territory.get(terr).getProcMax();
  56. }
  57. /**
  58. * Load the data from database.
  59. */
  60. public void load()
  61. {
  62. _territory.clear();
  63. Integer[][] point = SqlUtils.get2DIntArray(new String[]
  64. {
  65. "loc_id",
  66. "loc_x",
  67. "loc_y",
  68. "loc_zmin",
  69. "loc_zmax",
  70. "proc"
  71. }, "locations", "loc_id > 0");
  72. for (Integer[] row : point)
  73. {
  74. Integer terr = row[0];
  75. if (terr == null)
  76. {
  77. _log.warning(getClass().getSimpleName() + ": Null territory!");
  78. continue;
  79. }
  80. if (_territory.get(terr) == null)
  81. {
  82. L2Territory t = new L2Territory(terr);
  83. _territory.put(terr, t);
  84. }
  85. _territory.get(terr).add(row[1], row[2], row[3], row[4], row[5]);
  86. }
  87. }
  88. /**
  89. * Gets the single instance of Territory.
  90. * @return single instance of Territory
  91. */
  92. public static TerritoryTable getInstance()
  93. {
  94. return SingletonHolder._instance;
  95. }
  96. private static class SingletonHolder
  97. {
  98. protected static final TerritoryTable _instance = new TerritoryTable();
  99. }
  100. }