Skip to content

TradeManager Guides

Wenox edited this page Oct 25, 2025 · 1 revision

TradeManager

Overview

The TradeManager class is a static manager responsible for handling trade requests between players in the Skyblock plugin. It allows players to send trade requests to other players, which automatically expire after 60 seconds if not accepted. The class uses an in-memory array to store active trade requests and integrates with the plugin's scheduler for expiration handling.

Methods

addTradeRequest(Player $player, string $victimName): void

Adds a trade request from the specified player to the victim player.

  • Parameters:
    • $player (Player): The player sending the trade request.
    • $victimName (string): The name of the player to whom the trade request is being sent.
  • Behavior:
    • Prevents self-trade requests and duplicate requests.
    • Stores the request in the internal $trades array.
    • Schedules an automatic removal of the request after 60 seconds (1200 ticks).
    • Notifies the victim if the request expires without acceptance.

hasTradeRequest(Player $player, string $victimName): bool

Checks if a trade request exists from the specified player to the victim.

  • Parameters:
    • $player (Player): The player who sent the trade request.
    • $victimName (string): The name of the player to whom the request was sent.
  • Returns: true if the request exists, false otherwise.

getTradeRequests(Player $player): array

Retrieves all active trade requests sent by the specified player.

  • Parameters:
    • $player (Player): The player whose trade requests to retrieve.
  • Returns: An array of victim names (strings) representing active trade requests.

removeTradeRequest(Player $player, string $victimName): void

Removes a specific trade request from the specified player to the victim.

  • Parameters:
    • $player (Player): The player who sent the trade request.
    • $victimName (string): The name of the player to whom the request was sent.
  • Behavior: Removes the request from the internal $trades array if it exists.

Usage Examples

Sending a Trade Request

use Biswajit\Core\Managers\TradeManager;
use Biswajit\Core\Player;

// Assuming $player is a Player instance and $victimName is a string
TradeManager::addTradeRequest($player, $victimName);

Checking for a Trade Request

if (TradeManager::hasTradeRequest($player, $victimName)) {
    // Handle existing request
}

Retrieving All Trade Requests for a Player

$requests = TradeManager::getTradeRequests($player);
foreach ($requests as $victim) {
    // Process each request
}

Removing a Trade Request

TradeManager::removeTradeRequest($player, $victimName);

Clone this wiki locally