PHP code example of nglam2911 / libasyneco

1. Go to this page and download the library: Download nglam2911/libasyneco library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nglam2911 / libasyneco example snippets


//use NgLam2911\libasyneco\providers\EcoProvider;
//use NgLam2911\libasyneco\libasyneco;
//protected EcoProvider $provider
//onEnable() or onLoad()

try{
  $this->provider = libasyneco::init("*your provider*"); //"economyapi" or "bedrockeconomy"
}catch(InvalidProviderException){
  //Invalid Provider
}catch(DependencyMissingException){
  //Mising libasyneco's dependency
}

/** @var Player $player */
try{
  $money = yield from $this->provider->myMoney($player);
}catch(EcoException){
  //Error
}

/** @var Player $player */
/** @var float|int $amount */
try{
  yield from $this->provider->addMoney($player, $amount);
}catch(EcoException){
  //Error
}