Added ExplosionPrimeEvent

This commit is contained in:
Shoghi Cervantes 2014-10-08 16:45:55 +02:00
parent 64bf293c69
commit 57f7d57c76
2 changed files with 65 additions and 2 deletions

View File

@ -23,6 +23,8 @@ namespace pocketmine\entity;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityRegainHealthEvent;
use pocketmine\event\entity\ExplosionPrimeEvent;
use pocketmine\level\Explosion;
use pocketmine\nbt\tag\Byte;
use pocketmine\nbt\tag\String;
@ -116,12 +118,16 @@ class PrimedTNT extends Entity implements Explosive{
}
public function heal($amount){
public function heal($amount, $source = EntityRegainHealthEvent::CAUSE_MAGIC){
}
public function explode(){
(new Explosion($this, 4, $this))->explode();
$this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4));
if(!$ev->isCancelled()){
(new Explosion($this, $ev->getForce(), $this))->explode();
}
}
public function spawnTo(Player $player){

View File

@ -0,0 +1,57 @@
<?php
/**
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\event\entity;
use pocketmine\block\Block;
use pocketmine\entity\Entity;
use pocketmine\event\Cancellable;
use pocketmine\level\Position;
/**
* Called when a entity decides to explode
*/
class ExplosionPrimeEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
protected $force;
/**
* @param Entity $entity
* @param float $force
*/
public function __construct(Entity $entity, $force){
$this->entity = $entity;
$this->force = $force;
}
/**
* @return float
*/
public function getForce(){
return $this->force;
}
public function setForce($force){
$this->force = (float) $force;
}
}