Made ExplosionPrimeEvent accept setting block breaking settings

This commit is contained in:
Shoghi Cervantes 2014-10-10 22:39:06 +02:00
parent 0dba14074a
commit 0dd46c835c
3 changed files with 37 additions and 2 deletions

View File

@ -126,7 +126,11 @@ class PrimedTNT extends Entity implements Explosive{
$this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4));
if(!$ev->isCancelled()){
(new Explosion($this, $ev->getForce(), $this))->explode();
$explosion = new Explosion($this, $ev->getForce(), $this);
if($ev->isBlockBreaking()){
$explosion->explodeA();
}
$explosion->explodeB();
}
}

View File

@ -31,6 +31,7 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
protected $force;
private $blockBreaking;
/**
* @param Entity $entity
@ -39,6 +40,7 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{
public function __construct(Entity $entity, $force){
$this->entity = $entity;
$this->force = $force;
$this->blockBreaking = true;
}
/**
@ -52,4 +54,18 @@ class ExplosionPrimeEvent extends EntityEvent implements Cancellable{
$this->force = (float) $force;
}
/**
* @return bool
*/
public function isBlockBreaking(){
return $this->blockBreaking;
}
/**
* @param bool $affectsBlocks
*/
public function setBlockBreaking($affectsBlocks){
$this->blockBreaking = (bool) $affectsBlocks;
}
}

View File

@ -64,9 +64,21 @@ class Explosion{
}
/**
* @deprecated
* @return bool
*/
public function explode(){
if($this->explodeA()){
return $this->explodeB();
}
return false;
}
/**
* @return bool
*/
public function explodeA(){
if($this->size < 0.1){
return false;
}
@ -108,6 +120,10 @@ class Explosion{
}
}
return true;
}
public function explodeB(){
$send = [];
$source = $this->source->floor();
$yield = (1 / $this->size) * 100;
@ -204,6 +220,5 @@ class Explosion{
Server::broadcastPacket($this->level->getUsingChunk($source->x >> 4, $source->z >> 4), $pk);
return true;
}
}