From 312f3774833b9e5b3282f395bbcee63b81a76afc Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 11 Oct 2014 19:01:27 +0200 Subject: [PATCH] Added LeavesDecayEvent --- src/pocketmine/block/Leaves.php | 11 ++++-- src/pocketmine/block/Leaves2.php | 9 +++-- .../event/block/LeavesDecayEvent.php | 34 +++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 src/pocketmine/event/block/LeavesDecayEvent.php diff --git a/src/pocketmine/block/Leaves.php b/src/pocketmine/block/Leaves.php index cf8964990..4dd16ec7f 100644 --- a/src/pocketmine/block/Leaves.php +++ b/src/pocketmine/block/Leaves.php @@ -21,9 +21,11 @@ namespace pocketmine\block; +use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\Player; +use pocketmine\Server; class Leaves extends Transparent{ const OAK = 0; @@ -121,10 +123,13 @@ class Leaves extends Transparent{ $this->meta &= 0x03; $visited = []; $check = 0; - if($this->findLog($this, $visited, 0, $check) === true){ - $this->getLevel()->setBlock($this, $this, false, false, true); + + Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this)); + + if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){ + $this->getLevel()->setBlock($this, $this, false, false); }else{ - $this->getLevel()->setBlock($this, new Air(), false, false, true); + $this->getLevel()->setBlock($this, new Air(), false, false); if(mt_rand(1, 20) === 1){ //Saplings $this->getLevel()->dropItem($this, Item::get($this->id, $this->meta & 0x03, 1)); } diff --git a/src/pocketmine/block/Leaves2.php b/src/pocketmine/block/Leaves2.php index e8e5f64c8..d7bb2fc39 100644 --- a/src/pocketmine/block/Leaves2.php +++ b/src/pocketmine/block/Leaves2.php @@ -21,9 +21,11 @@ namespace pocketmine\block; +use pocketmine\event\block\LeavesDecayEvent; use pocketmine\item\Item; use pocketmine\level\Level; use pocketmine\Player; +use pocketmine\Server; class Leaves2 extends Leaves{ @@ -113,8 +115,11 @@ class Leaves2 extends Leaves{ $this->meta &= 0x03; $visited = []; $check = 0; - if($this->findLog($this, $visited, 0, $check) === true){ - $this->getLevel()->setBlock($this, $this, false, false, true); + + Server::getInstance()->getPluginManager()->callEvent($ev = new LeavesDecayEvent($this)); + + if($ev->isCancelled() or $this->findLog($this, $visited, 0, $check) === true){ + $this->getLevel()->setBlock($this, $this, false, false); }else{ $this->getLevel()->setBlock($this, new Air(), false, false, true); if(mt_rand(1, 20) === 1){ //Saplings diff --git a/src/pocketmine/event/block/LeavesDecayEvent.php b/src/pocketmine/event/block/LeavesDecayEvent.php new file mode 100644 index 000000000..9da0281da --- /dev/null +++ b/src/pocketmine/event/block/LeavesDecayEvent.php @@ -0,0 +1,34 @@ +