Exemplo n.º 1
0
 /** {@inheritDoc} */
 @Override
 public void deleteLegionMember(int playerObjId) {
   PreparedStatement statement = DB.prepareStatement(DELETE_LEGIONMEMBER_QUERY);
   try {
     statement.setInt(1, playerObjId);
   } catch (SQLException e) {
     log.error("Some crap, can't set int parameter to PreparedStatement", e);
   }
   DB.executeUpdateAndClose(statement);
 }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public ArrayList<Integer> loadLegionMembers(final int legionId) {
    final ArrayList<Integer> legionMembers = new ArrayList<Integer>();

    boolean success =
        DB.select(
            SELECT_LEGIONMEMBERS_QUERY,
            new ParamReadStH() {

              @Override
              public void setParams(PreparedStatement stmt) throws SQLException {
                stmt.setInt(1, legionId);
              }

              @Override
              public void handleRead(ResultSet resultSet) {
                try {
                  while (resultSet.next()) {
                    int playerObjId = resultSet.getInt("player_id");
                    legionMembers.add(playerObjId);
                  }
                } catch (SQLException sqlE) {
                  log.error(
                      "[DAO: MySQL5LegionMemberDAO] No players in Legion. DELETE Legion Id: "
                          + legionId);
                }
              }
            });

    if (success && legionMembers.size() > 0) {
      return legionMembers;
    }
    return null;
  }
Exemplo n.º 3
0
  @Override
  public void loadItemCooldowns(final Player player) {
    DB.select(
        SELECT_QUERY,
        new ParamReadStH() {

          @Override
          public void setParams(PreparedStatement stmt) throws SQLException {
            stmt.setInt(1, player.getObjectId());
          }

          @Override
          public void handleRead(ResultSet rset) throws SQLException {
            while (rset.next()) {
              int delayId = rset.getInt("delay_id");
              int useDelay = rset.getInt("use_delay");
              long reuseTime = rset.getLong("reuse_time");

              if (reuseTime > System.currentTimeMillis())
                player.addItemCoolDown(delayId, reuseTime, useDelay);
            }
          }
        });
    player.getEffectController().broadCastEffects();
  }
Exemplo n.º 4
0
 /** {@inheritDoc} */
 @Override
 public boolean isIdUsed(final int playerObjId) {
   PreparedStatement s =
       DB.prepareStatement(
           "SELECT count(player_id) as cnt FROM legion_members WHERE ? = legion_members.player_id");
   try {
     s.setInt(1, playerObjId);
     ResultSet rs = s.executeQuery();
     rs.next();
     return rs.getInt("cnt") > 0;
   } catch (SQLException e) {
     log.error("Can't check if name " + playerObjId + ", is used, returning possitive result", e);
     return true;
   } finally {
     DB.close(s);
   }
 }
Exemplo n.º 5
0
  private void deleteItemCooldowns(final Player player) {
    DB.insertUpdate(
        DELETE_QUERY,
        new IUStH() {

          @Override
          public void handleInsertUpdate(PreparedStatement stmt) throws SQLException {
            stmt.setInt(1, player.getObjectId());
            stmt.execute();
          }
        });
  }
Exemplo n.º 6
0
  /** {@inheritDoc} */
  @Override
  public void storeLegionMember(final int playerId, final LegionMember legionMember) {
    DB.insertUpdate(
        UPDATE_LEGIONMEMBER_QUERY,
        new IUStH() {

          @Override
          public void handleInsertUpdate(PreparedStatement stmt) throws SQLException {
            stmt.setString(1, legionMember.getNickname());
            stmt.setString(2, legionMember.getRank().toString());
            stmt.setString(3, legionMember.getSelfIntro());
            stmt.setInt(4, playerId);
            stmt.execute();
          }
        });
  }
Exemplo n.º 7
0
  /** {@inheritDoc} */
  @Override
  public boolean saveNewLegionMember(final LegionMember legionMember) {
    boolean success =
        DB.insertUpdate(
            INSERT_LEGIONMEMBER_QUERY,
            new IUStH() {

              @Override
              public void handleInsertUpdate(PreparedStatement preparedStatement)
                  throws SQLException {
                preparedStatement.setInt(1, legionMember.getLegion().getLegionId());
                preparedStatement.setInt(2, legionMember.getObjectId());
                preparedStatement.setString(3, legionMember.getRank().toString());
                preparedStatement.execute();
              }
            });
    return success;
  }
Exemplo n.º 8
0
  /** {@inheritDoc} */
  @Override
  public LegionMemberEx loadLegionMemberEx(final int playerObjId) {
    final LegionMemberEx legionMemberEx = new LegionMemberEx(playerObjId);

    boolean success =
        DB.select(
            SELECT_LEGIONMEMBEREX_QUERY,
            new ParamReadStH() {

              @Override
              public void setParams(PreparedStatement stmt) throws SQLException {
                stmt.setInt(1, playerObjId);
              }

              @Override
              public void handleRead(ResultSet resultSet) {
                try {
                  resultSet.next();
                  legionMemberEx.setName(resultSet.getString("players.name"));
                  legionMemberEx.setExp(resultSet.getLong("players.exp"));
                  legionMemberEx.setPlayerClass(
                      PlayerClass.valueOf(resultSet.getString("players.player_class")));
                  legionMemberEx.setLastOnline(resultSet.getTimestamp("players.last_online"));
                  legionMemberEx.setWorldId(resultSet.getInt("players.world_id"));

                  int legionId = resultSet.getInt("legion_members.legion_id");
                  legionMemberEx.setRank(
                      LegionRank.valueOf(resultSet.getString("legion_members.rank")));
                  legionMemberEx.setNickname(resultSet.getString("legion_members.nickname"));
                  legionMemberEx.setSelfIntro(resultSet.getString("legion_members.selfintro"));

                  legionMemberEx.setLegion(LegionService.getInstance().getLegion(legionId));
                } catch (SQLException sqlE) {
                  log.debug("[DAO: MySQL5LegionMemberDAO] Player is not in a Legion");
                }
              }
            });

    if (success && legionMemberEx.getLegion() != null) {
      return legionMemberEx;
    }
    return null;
  }
Exemplo n.º 9
0
  /** {@inheritDoc} */
  @Override
  public LegionMember loadLegionMember(final int playerObjId) {
    if (playerObjId == 0) return null;

    final LegionMember legionMember = new LegionMember(playerObjId);

    boolean success =
        DB.select(
            SELECT_LEGIONMEMBER_QUERY,
            new ParamReadStH() {

              @Override
              public void setParams(PreparedStatement stmt) throws SQLException {
                stmt.setInt(1, playerObjId);
              }

              @Override
              public void handleRead(ResultSet resultSet) {
                try {
                  resultSet.next();
                  int legionId = resultSet.getInt("legion_id");
                  legionMember.setRank(LegionRank.valueOf(resultSet.getString("rank")));
                  legionMember.setNickname(resultSet.getString("nickname"));
                  legionMember.setSelfIntro(resultSet.getString("selfintro"));

                  legionMember.setLegion(LegionService.getInstance().getLegion(legionId));
                } catch (SQLException sqlE) {
                  log.debug("[DAO: MySQL5LegionMemberDAO] Player is not in a Legion");
                }
              }
            });

    if (success && legionMember.getLegion() != null) {
      return legionMember;
    }
    return null;
  }