Exemplo n.º 1
0
 @Override
 public boolean isOldName(final String name) {
   PreparedStatement s =
       DB.prepareStatement(
           "SELECT count(player_id) as cnt FROM old_names WHERE ? = old_names.old_name");
   try {
     s.setString(1, name);
     ResultSet rs = s.executeQuery();
     rs.next();
     return rs.getInt("cnt") > 0;
   } catch (SQLException e) {
     log.error("Can't check if name " + name + ", is used, returning possitive result", e);
     return true;
   } finally {
     DB.close(s);
   }
 }
 @Override
 public void unpunishPlayer(final Player player) {
   DB.insertUpdate(
       DELETE_QUERY,
       new IUStH() {
         @Override
         public void handleInsertUpdate(PreparedStatement ps) throws SQLException {
           ps.setInt(1, player.getObjectId());
           ps.execute();
         }
       });
 }
 @Override
 public void punishPlayer(final Player player, final int mode) {
   DB.insertUpdate(
       REPLACE_QUERY,
       new IUStH() {
         @Override
         public void handleInsertUpdate(PreparedStatement ps) throws SQLException {
           ps.setInt(1, player.getObjectId());
           ps.setInt(2, mode);
           ps.setLong(3, player.getPrisonTimer());
           ps.execute();
         }
       });
 }
 @Override
 public void storePlayerPunishments(final Player player) {
   DB.insertUpdate(
       UPDATE_QUERY,
       new IUStH() {
         @Override
         public void handleInsertUpdate(PreparedStatement ps) throws SQLException {
           ps.setInt(1, player.isInPrison() ? 1 : 0);
           ps.setLong(2, player.getPrisonTimer());
           ps.setInt(3, player.getObjectId());
           ps.execute();
         }
       });
 }
Exemplo n.º 5
0
  @Override
  public void insertNames(final int id, final String oldname, final String newname) {
    DB.insertUpdate(
        INSERT_QUERY,
        new IUStH() {

          @Override
          public void handleInsertUpdate(PreparedStatement stmt) throws SQLException {
            stmt.setInt(1, id);
            stmt.setString(2, oldname);
            stmt.setString(3, newname);
            stmt.execute();
          }
        });
  }
  @Override
  public void loadPlayerPunishments(final Player player) {
    DB.select(
        SELECT_QUERY,
        new ParamReadStH() {
          @Override
          public void setParams(PreparedStatement ps) throws SQLException {
            ps.setInt(1, player.getObjectId());
          }

          @Override
          public void handleRead(ResultSet rs) throws SQLException {
            while (rs.next()) {
              player.setPrisonTimer(rs.getLong("punishment_timer"));

              if (player.isInPrison()) player.setPrisonTimer(rs.getLong("punishment_timer"));
              else player.setPrisonTimer(0);
            }
          }
        });
  }
  @Override
  public TitleList loadTitleList(final int playerId) {
    final TitleList tl = new TitleList();

    DB.select(
        LOAD_QUERY,
        new ParamReadStH() {

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

          @Override
          public void handleRead(ResultSet rset) throws SQLException {
            while (rset.next()) {
              int id = rset.getInt("title_id");
              int remaining = rset.getInt("remaining");
              tl.addEntry(id, remaining);
            }
          }
        });
    return tl;
  }
Exemplo n.º 8
0
  /*
   *  (non-Javadoc)
   * @see com.aionemu.gameserver.utils.chathandlers.admincommands.AdminCommand#executeCommand(com.aionemu.gameserver.gameobjects.Player, java.lang.String[])
   */
  @Override
  public void executeCommand(Player admin, String... params) {
    if (params == null) {
      PacketSendUtility.sendMessage(admin, "syntax //add itemID");
      return;
    }

    int parameter = 0;
    try {
      parameter = Integer.parseInt(params[0]);
    } catch (NumberFormatException e) {
      PacketSendUtility.sendMessage(admin, "Param needs to be a number.");

      return;
    }
    int activePlayer = admin.getObjectId();
    try {
      try {
        PreparedStatement ps =
            DB.prepareStatement("SELECT id FROM item_list WHERE `id`=" + parameter);
        ResultSet rs = ps.executeQuery();
        rs.last();
        parameter = rs.getInt("id");
      } catch (Exception e) {
        parameter = 0;
      }

      if (parameter != 0) {
        Inventory itemsDbOfPlayerCount = new Inventory(); // wrong
        itemsDbOfPlayerCount.getInventoryFromDb(activePlayer);
        int totalItemsCount = itemsDbOfPlayerCount.getItemsCount();

        Inventory equipedItems = new Inventory();
        equipedItems.getEquipedItemsFromDb(activePlayer);
        int totalEquipedItemsCount = equipedItems.getEquipedItemsCount();

        int cubes = 1;
        int cubesize = 27;
        int allowItemsCount = cubesize * cubes - 1;

        if (totalItemsCount <= allowItemsCount) {
          Inventory items = new Inventory();
          items.putItemToDb(activePlayer, parameter, 1);
          items.getLastUniqueIdFromDb();
          int newItemUniqueId = items.getnewItemUniqueIdValue();

          PacketSendUtility.sendPacket(
              admin, new SM_INVENTORY_INFO(newItemUniqueId, parameter, 1, 1, 8));
          PacketSendUtility.sendMessage(admin, "Added Item.");
        } else {
          PacketSendUtility.sendMessage(admin, "Inventory is Full.");
        }
      } else {
        PacketSendUtility.sendMessage(admin, "Invalid Item.");
      }

    } catch (Exception e) {
      PacketSendUtility.sendMessage(admin, "There was an error in the Code.");

      return;
    }
  }