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

@ -136,8 +136,8 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
}
protected function checkFuel(Item $fuel){
$this->server->getPluginManager()->callEvent($ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime()));
$ev = new FurnaceBurnEvent($this, $fuel, $fuel->getFuelTime());
$ev->call();
if($ev->isCancelled()){
return;
}
@ -189,7 +189,8 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
if($this->cookTime >= 200){ //10 seconds
$product = ItemFactory::get($smelt->getResult()->getId(), $smelt->getResult()->getDamage(), $product->getCount() + 1);
$this->server->getPluginManager()->callEvent($ev = new FurnaceSmeltEvent($this, $raw, $product));
$ev = new FurnaceSmeltEvent($this, $raw, $product);
$ev->call();
if(!$ev->isCancelled()){
$this->inventory->setResult($ev->getResult());

View File

@ -143,7 +143,7 @@ class Sign extends Spawnable{
$removeFormat = $player->getRemoveFormat();
$ev = new SignChangeEvent($this->getBlock(), $player, array_map(function(string $line) use ($removeFormat){ return TextFormat::clean($line, $removeFormat); }, $lines));
$this->level->getServer()->getPluginManager()->callEvent($ev);
$ev->call();
if(!$ev->isCancelled()){
$this->setText(...$ev->getLines());