Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot fix for EconomyAPI #428

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed API
  • Loading branch information
Frago9876543210 committed Dec 16, 2018
commit 9d2fd53b940b44d47ca5914324e864d1cfb14bed
15 changes: 7 additions & 8 deletions EconomyAPI/src/onebone/economyapi/EconomyAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\utils\Config;
use pocketmine\utils\Internet;
use pocketmine\utils\Utils;
use pocketmine\utils\TextFormat;

use onebone\economyapi\provider\Provider;
Expand Down Expand Up @@ -143,7 +142,7 @@ public function createAccount($player, $defaultMoney = false, bool $force = fals
if(!$this->provider->accountExists($player)){
$defaultMoney = ($defaultMoney === false) ? $this->getConfig()->get("default-money") : $defaultMoney;

$this->getServer()->getPluginManager()->callEvent($ev = new CreateAccountEvent($this, $player, $defaultMoney, "none"));
($ev = new CreateAccountEvent($this, $player, $defaultMoney, "none"))->call();
if(!$ev->isCancelled() or $force === true){
$this->provider->createAccount($player, $ev->getDefaultMoney());
}
Expand Down Expand Up @@ -192,10 +191,10 @@ public function setMoney($player, $amount, bool $force = false, string $issuer =
return self::RET_INVALID;
}

$this->getServer()->getPluginManager()->callEvent($ev = new SetMoneyEvent($this, $player, $amount, $issuer));
($ev = new SetMoneyEvent($this, $player, $amount, $issuer))->call();
if(!$ev->isCancelled() or $force === true){
$this->provider->setMoney($player, $amount);
$this->getServer()->getPluginManager()->callEvent(new MoneyChangedEvent($this, $player, $amount, $issuer));
(new MoneyChangedEvent($this, $player, $amount, $issuer))->call();
return self::RET_SUCCESS;
}
return self::RET_CANCELLED;
Expand Down Expand Up @@ -225,10 +224,10 @@ public function addMoney($player, $amount, bool $force = false, $issuer = "none"
return self::RET_INVALID;
}

$this->getServer()->getPluginManager()->callEvent($ev = new AddMoneyEvent($this, $player, $amount, $issuer));
($ev = new AddMoneyEvent($this, $player, $amount, $issuer))->call();
if(!$ev->isCancelled() or $force === true){
$this->provider->addMoney($player, $amount);
$this->getServer()->getPluginManager()->callEvent(new MoneyChangedEvent($this, $player, $amount + $money, $issuer));
(new MoneyChangedEvent($this, $player, $amount + $money, $issuer))->call();
return self::RET_SUCCESS;
}
return self::RET_CANCELLED;
Expand Down Expand Up @@ -258,10 +257,10 @@ public function reduceMoney($player, $amount, bool $force = false, $issuer = "no
return self::RET_INVALID;
}

$this->getServer()->getPluginManager()->callEvent($ev = new ReduceMoneyEvent($this, $player, $amount, $issuer));
($ev = new ReduceMoneyEvent($this, $player, $amount, $issuer))->call();
if(!$ev->isCancelled() or $force === true){
$this->provider->reduceMoney($player, $amount);
$this->getServer()->getPluginManager()->callEvent(new MoneyChangedEvent($this, $player, $money - $amount, $issuer));
(new MoneyChangedEvent($this, $player, $money - $amount, $issuer))->call();
return self::RET_SUCCESS;
}
return self::RET_CANCELLED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function execute(CommandSender $sender, string $label, array $params): bo
}

$task = new SortTask($sender->getName(), $this->plugin->getAllMoney(), $this->plugin->getConfig()->get("add-op-at-rank"), $page, $ops, $banned);
$server->getScheduler()->scheduleAsyncTask($task);
$server->getAsyncPool()->submitTask($task);

return true;
}
Expand Down
5 changes: 3 additions & 2 deletions EconomyAPI/src/onebone/economyapi/task/SortTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(string $sender, array $moneyData, bool $addOp, int $
$this->banList = $banList;
}

public function onRun(){
public function onRun() : void{
$this->topList = serialize((array)$this->getTopList());
}

Expand Down Expand Up @@ -81,7 +81,8 @@ private function getTopList(){
return $ret;
}

public function onCompletion(Server $server){
public function onCompletion() : void{
$server = Server::getInstance();
if($this->sender === "CONSOLE" or ($player = $server->getPlayerExact($this->sender)) instanceof Player){ // TODO: Rcon
$plugin = EconomyAPI::getInstance();

Expand Down