123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package com.l2jserver.gameserver.datatables;
- import gnu.trove.map.hash.TIntObjectHashMap;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import com.l2jserver.Config;
- import com.l2jserver.L2DatabaseFactory;
- import com.l2jserver.gameserver.model.L2TeleportLocation;
- /**
- * This class ...
- *
- * @version $Revision: 1.3.2.2.2.3 $ $Date: 2005/03/27 15:29:18 $
- */
- public class TeleportLocationTable
- {
- private static Logger _log = Logger.getLogger(TeleportLocationTable.class.getName());
-
- private TIntObjectHashMap<L2TeleportLocation> _teleports;
-
- public static TeleportLocationTable getInstance()
- {
- return SingletonHolder._instance;
- }
-
- protected TeleportLocationTable()
- {
- reloadAll();
- }
-
- public void reloadAll()
- {
- _teleports = new TIntObjectHashMap<>();
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- Statement s = con.createStatement();
- ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM teleport"))
- {
- L2TeleportLocation teleport;
- while (rs.next())
- {
- teleport = new L2TeleportLocation();
-
- teleport.setTeleId(rs.getInt("id"));
- teleport.setLocX(rs.getInt("loc_x"));
- teleport.setLocY(rs.getInt("loc_y"));
- teleport.setLocZ(rs.getInt("loc_z"));
- teleport.setPrice(rs.getInt("price"));
- teleport.setIsForNoble(rs.getInt("fornoble") == 1);
- teleport.setItemId(rs.getInt("itemId"));
-
- _teleports.put(teleport.getTeleId(), teleport);
- }
- _log.info("TeleportLocationTable: Loaded " + _teleports.size() + " Teleport Location Templates.");
- }
- catch (Exception e)
- {
- _log.log(Level.SEVERE, "Error loading Teleport Table.", e);
- }
-
- if (Config.CUSTOM_TELEPORT_TABLE)
- {
- int _cTeleCount = _teleports.size();
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- Statement s = con.createStatement();
- ResultSet rs = s.executeQuery("SELECT id, loc_x, loc_y, loc_z, price, fornoble, itemId FROM custom_teleport"))
- {
- L2TeleportLocation teleport;
- while (rs.next())
- {
- teleport = new L2TeleportLocation();
- teleport.setTeleId(rs.getInt("id"));
- teleport.setLocX(rs.getInt("loc_x"));
- teleport.setLocY(rs.getInt("loc_y"));
- teleport.setLocZ(rs.getInt("loc_z"));
- teleport.setPrice(rs.getInt("price"));
- teleport.setIsForNoble(rs.getInt("fornoble") == 1);
- teleport.setItemId(rs.getInt("itemId"));
-
- _teleports.put(teleport.getTeleId(), teleport);
- }
- _cTeleCount = _teleports.size() - _cTeleCount;
- if (_cTeleCount > 0)
- {
- _log.info("TeleportLocationTable: Loaded " + _cTeleCount + " Custom Teleport Location Templates.");
- }
- }
- catch (Exception e)
- {
- _log.log(Level.WARNING, "Error while creating custom teleport table " + e.getMessage(), e);
- }
- }
- }
-
- /**
- * @param id
- * @return
- */
- public L2TeleportLocation getTemplate(int id)
- {
- return _teleports.get(id);
- }
-
- private static class SingletonHolder
- {
- protected static final TeleportLocationTable _instance = new TeleportLocationTable();
- }
- }
|