Migrate a bunch of PluginManager->callEvent() usages to Event->call

This has the triple bonus effect of a) making a lot of code easier to read, b) reducing Server::getInstance() usages, and c) removing a whole bunch of Server dependencies.

The network and block namespaces are untouched by this commit due to potential for merge conflicts. These should be dealt with separately on master.
This commit is contained in:
Dylan K. Taylor
2018-10-05 17:27:29 +01:00
parent 6efef3bbc7
commit 1dd6591ac1
27 changed files with 138 additions and 99 deletions

View File

@ -134,7 +134,8 @@ class CraftingTransaction extends InventoryTransaction{
}
protected function callExecuteEvent() : bool{
$this->source->getServer()->getPluginManager()->callEvent($ev = new CraftItemEvent($this, $this->recipe, $this->repetitions, $this->inputs, $this->outputs));
$ev = new CraftItemEvent($this, $this->recipe, $this->repetitions, $this->inputs, $this->outputs);
$ev->call();
return !$ev->isCancelled();
}

View File

@ -29,7 +29,6 @@ use pocketmine\inventory\transaction\action\InventoryAction;
use pocketmine\inventory\transaction\action\SlotChangeAction;
use pocketmine\item\Item;
use pocketmine\Player;
use pocketmine\Server;
/**
* This InventoryTransaction only allows doing Transaction between one / two inventories
@ -250,7 +249,8 @@ class InventoryTransaction{
}
protected function callExecuteEvent() : bool{
Server::getInstance()->getPluginManager()->callEvent($ev = new InventoryTransactionEvent($this));
$ev = new InventoryTransactionEvent($this);
$ev->call();
return !$ev->isCancelled();
}

View File

@ -42,7 +42,8 @@ class DropItemAction extends InventoryAction{
}
public function onPreExecute(Player $source) : bool{
$source->getServer()->getPluginManager()->callEvent($ev = new PlayerDropItemEvent($source, $this->targetItem));
$ev = new PlayerDropItemEvent($source, $this->targetItem);
$ev->call();
if($ev->isCancelled()){
return false;
}