Added EntityCombustEvent and childs

This commit is contained in:
Shoghi Cervantes 2014-10-08 15:51:27 +02:00
parent dd140ce018
commit b0c314526d
6 changed files with 166 additions and 3 deletions

View File

@ -21,6 +21,7 @@
namespace pocketmine\block;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\item\Item;
use pocketmine\entity\Entity;
use pocketmine\level\Level;
@ -41,12 +42,17 @@ class Fire extends Flowable{
}
public function onEntityCollide(Entity $entity){
$entity->setOnFire(8);
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_FIRE, 1);
Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$entity->attack($ev->getFinalDamage(), $ev);
}
$ev = new EntityCombustByBlockEvent($this, $entity, 8);
Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration());
}
}
public function getDrops(Item $item){

View File

@ -21,6 +21,7 @@
namespace pocketmine\block;
use pocketmine\event\entity\EntityCombustByBlockEvent;
use pocketmine\item\Item;
use pocketmine\entity\Entity;
use pocketmine\level\Level;
@ -41,12 +42,17 @@ class Lava extends Liquid{
public function onEntityCollide(Entity $entity){
$entity->fallDistance *= 0.5;
$entity->setOnFire(15);
$ev = new EntityDamageEvent($entity, EntityDamageEvent::CAUSE_LAVA, 4);
Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$entity->attack($ev->getFinalDamage(), $ev);
}
$ev = new EntityCombustByBlockEvent($this, $entity, 15);
Server::getInstance()->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$entity->setOnFire($ev->getDuration());
}
}
public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){

View File

@ -22,6 +22,7 @@
namespace pocketmine\entity;
use pocketmine\event\entity\EntityCombustByEntityEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\level\format\FullChunk;
@ -127,7 +128,11 @@ class Arrow extends Projectile{
if(!$ev->isCancelled()){
$movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev);
if($this->fireTicks > 0){
$movingObjectPosition->entityHit->setOnFire(5);
$ev = new EntityCombustByEntityEvent($this, $movingObjectPosition->entityHit, 5);
$this->server->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$movingObjectPosition->entityHit->setOnFire($ev->getDuration());
}
}
$this->kill();
}

View File

@ -0,0 +1,49 @@
<?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;
class EntityCombustByBlockEvent extends EntityCombustEvent{
public static $handlerList = null;
protected $combuster;
/**
* @param Block $combuster
* @param Entity $combustee
* @param int $duration
*/
public function __construct(Block $combuster, Entity $combustee, $duration){
parent::__construct($combustee, $duration);
$this->combuster = $combuster;
}
/**
* @return Block
*/
public function getCombuster(){
return $this->combuster;
}
}

View File

@ -0,0 +1,48 @@
<?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\entity\Entity;
class EntityCombustByEntityEvent extends EntityCombustEvent{
public static $handlerList = null;
protected $combuster;
/**
* @param Entity $combuster
* @param Entity $combustee
* @param int $duration
*/
public function __construct(Entity $combuster, Entity $combustee, $duration){
parent::__construct($combustee, $duration);
$this->combuster = $combuster;
}
/**
* @return Entity
*/
public function getCombuster(){
return $this->combuster;
}
}

View File

@ -0,0 +1,49 @@
<?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\entity\Entity;
use pocketmine\event\Cancellable;
class EntityCombustEvent extends EntityEvent implements Cancellable{
public static $handlerList = null;
protected $duration;
/**
* @param Entity $combustee
* @param int $duration
*/
public function __construct(Entity $combustee, $duration){
$this->entity = $combustee;
$this->duration = $duration;
}
public function getDuration(){
return $this->duration;
}
public function setDuration($duration){
$this->duration = (int) $duration;
}
}