@Override public void storeHouseObjectCooldowns(final Player player) { deleteHouseObjectCoolDowns(player); Map<Integer, Long> houseObjectCoolDowns = player.getHouseObjectCooldownList().getHouseObjectCooldowns(); if (houseObjectCoolDowns == null) return; for (Map.Entry<Integer, Long> entry : houseObjectCoolDowns.entrySet()) { final int templateId = entry.getKey(); final long reuseTime = entry.getValue(); if (reuseTime < System.currentTimeMillis()) continue; Connection con = null; try { con = DatabaseFactory.getConnection(); PreparedStatement stmt = con.prepareStatement(INSERT_QUERY); stmt.setInt(1, player.getObjectId()); stmt.setInt(2, templateId); stmt.setLong(3, reuseTime); stmt.execute(); } catch (SQLException e) { log.error("storeHouseObjectCoolDowns", e); } finally { DatabaseFactory.close(con); } } }
@Override public void loadHouseObjectCooldowns(final Player player) { Connection con = null; FastMap<Integer, Long> houseObjectCoolDowns = new FastMap<Integer, Long>(); try { con = DatabaseFactory.getConnection(); PreparedStatement stmt = con.prepareStatement(SELECT_QUERY); stmt.setInt(1, player.getObjectId()); ResultSet rset = stmt.executeQuery(); while (rset.next()) { int objectId = rset.getInt("object_id"); long reuseTime = rset.getLong("reuse_time"); int delay = (int) ((reuseTime - System.currentTimeMillis()) / 1000); if (delay > 0) { houseObjectCoolDowns.put(objectId, reuseTime); } } player.getHouseObjectCooldownList().setHouseObjectCooldowns(houseObjectCoolDowns); rset.close(); stmt.close(); } catch (SQLException e) { log.error("LoadHouseObjectCooldowns", e); } finally { DatabaseFactory.close(con); } }