@Override
 public void unpunishPlayer(final Player player) {
   Connection con = null;
   try {
     con = DatabaseFactory.getConnection();
     PreparedStatement ps = con.prepareStatement(DELETE_QUERY);
     ps.setInt(1, player.getObjectId());
     ps.execute();
   } catch (Exception e) {
     log.error(e);
   } finally {
     DatabaseFactory.close(con);
   }
 }
 @Override
 public void punishPlayer(final Player player, final int mode) {
   Connection con = null;
   try {
     con = DatabaseFactory.getConnection();
     PreparedStatement ps = con.prepareStatement(REPLACE_QUERY);
     ps.setInt(1, player.getObjectId());
     ps.setInt(2, mode);
     ps.setLong(3, player.getPrisonTimer());
     ps.execute();
   } catch (Exception e) {
     log.error(e);
   } finally {
     DatabaseFactory.close(con);
   }
 }
 @Override
 public void storePlayerPunishments(final Player player) {
   Connection con = null;
   try {
     con = DatabaseFactory.getConnection();
     PreparedStatement ps = con.prepareStatement(UPDATE_QUERY);
     ps.setInt(1, player.isInPrison() ? 1 : 0);
     ps.setLong(2, player.getPrisonTimer());
     ps.setInt(3, player.getObjectId());
     ps.execute();
   } catch (Exception e) {
     log.error(e);
   } finally {
     DatabaseFactory.close(con);
   }
 }
  @Override
  public void loadPlayerPunishments(final Player player) {
    Connection con = null;
    try {
      con = DatabaseFactory.getConnection();
      PreparedStatement stmt = con.prepareStatement(SELECT_QUERY);
      stmt.setInt(1, player.getObjectId());
      ResultSet rs = stmt.executeQuery();
      while (rs.next()) {
        player.setPrisonTimer(rs.getLong("punishment_timer"));

        if (player.isInPrison()) player.setPrisonTimer(rs.getLong("punishment_timer"));
        else player.setPrisonTimer(0);
      }
    } catch (Exception e) {
      log.error(e);
    } finally {
      DatabaseFactory.close(con);
    }
  }
Exemple #5
0
  @Override
  public void storeItemCooldowns(Player player) {
    deleteItemCooldowns(player);
    Map<Integer, ItemCooldown> itemCoolDowns = player.getItemCoolDowns();

    if (itemCoolDowns == null) return;

    Map<Integer, ItemCooldown> map = Maps.filterValues(itemCoolDowns, itemCooldownPredicate);
    final Iterator<Map.Entry<Integer, ItemCooldown>> iterator = map.entrySet().iterator();
    if (!iterator.hasNext()) {
      return;
    }

    Connection con = null;
    PreparedStatement st = null;
    try {
      con = DatabaseFactory.getConnection();
      con.setAutoCommit(false);
      st = con.prepareStatement(INSERT_QUERY);

      while (iterator.hasNext()) {
        Map.Entry<Integer, ItemCooldown> entry = iterator.next();
        st.setInt(1, player.getObjectId());
        st.setInt(2, entry.getKey());
        st.setInt(3, entry.getValue().getUseDelay());
        st.setLong(4, entry.getValue().getReuseTime());
        st.addBatch();
      }

      st.executeBatch();
      con.commit();
    } catch (SQLException e) {
      log.error("Error while storing item cooldows for player " + player.getObjectId(), e);
    } finally {
      DatabaseFactory.close(st, con);
    }
  }