public static ArrayList<String> getMissionLogs(Town town) {
    Connection context = null;
    ResultSet rs = null;
    PreparedStatement ps = null;

    try {
      ArrayList<String> out = new ArrayList<String>();
      try {
        context = SQL.getGameConnection();
        ps =
            context.prepareStatement(
                "SELECT * FROM " + SQL.tb_prefix + TABLE_NAME + " WHERE `town_id` = ?");
        ps.setInt(1, town.getId());
        rs = ps.executeQuery();

        SimpleDateFormat sdf = new SimpleDateFormat("M/dd h:mm:ss a z");
        while (rs.next()) {
          Date date = new Date(rs.getLong("time"));
          Town target = CivGlobal.getTownFromId(rs.getInt("target_id"));
          if (target == null) {
            continue;
          }

          String playerName = rs.getString("playerName");
          playerName = CivGlobal.getResidentViaUUID(UUID.fromString(playerName)).getName();

          String str =
              sdf.format(date)
                  + " - "
                  + rs.getString("playerName")
                  + ":"
                  + target.getName()
                  + ":"
                  + rs.getString("missionName")
                  + " -- "
                  + rs.getString("result");
          out.add(str);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      }

      return out;
    } finally {
      SQL.close(rs, ps, context);
    }
  }
예제 #2
0
  @Override
  public void load(ResultSet rs)
      throws SQLException, InvalidNameException, InvalidObjectException, CivException {
    this.setId(rs.getInt("id"));
    this.configRandomEvent = CivSettings.randomEvents.get(rs.getString("config_id"));
    if (this.configRandomEvent == null) {
      /* Delete the random event. */
      this.delete();
      throw new CivException("Couldn't find random event config id:" + rs.getString("config_id"));
    }

    this.town = CivGlobal.getTownFromId(rs.getInt("town_id"));
    if (this.town == null) {
      this.delete();
      throw new CivException(
          "Couldn't find town id:" + rs.getInt("town_id") + " while loading random event.");
    }

    this.startDate = new Date(rs.getLong("start_date"));
    this.active = rs.getBoolean("active");

    loadComponentVars(rs.getString("component_vars"));
    loadSavedMessages(rs.getString("saved_messages"));

    /* Re-run the on start to re-enable any listeners. */
    /* Loop through all components for onStart() */
    buildComponents();
    for (RandomEventComponent comp : this.actions.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.requirements.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.success.values()) {
      comp.onStart();
    }
    for (RandomEventComponent comp : this.failure.values()) {
      comp.onStart();
    }

    RandomEventSweeper.register(this);
  }