mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Entity: Address fireticks crashdumps
This will now throw an exception at the source instead of crashing when the entity is saved, which should put the blame on the correct plugin responsible for this. This also includes magic method hacks to preserve backwards compatibility, since the fireTicks field is now protected.
This commit is contained in:
parent
41fd7545e3
commit
4fd3bee360
@ -67,7 +67,7 @@ class Water extends Liquid{
|
||||
|
||||
public function onEntityCollide(Entity $entity) : void{
|
||||
$entity->resetFallDistance();
|
||||
if($entity->fireTicks > 0){
|
||||
if($entity->isOnFire()){
|
||||
$entity->extinguish();
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
/** @var int */
|
||||
public $lastUpdate;
|
||||
/** @var int */
|
||||
public $fireTicks = 0;
|
||||
protected $fireTicks = 0;
|
||||
/** @var CompoundTag */
|
||||
public $namedtag;
|
||||
/** @var bool */
|
||||
@ -1093,8 +1093,8 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
|
||||
public function setOnFire(int $seconds) : void{
|
||||
$ticks = $seconds * 20;
|
||||
if($ticks > $this->fireTicks){
|
||||
$this->fireTicks = $ticks;
|
||||
if($ticks > $this->getFireTicks()){
|
||||
$this->setFireTicks($ticks);
|
||||
}
|
||||
|
||||
$this->setGenericFlag(self::DATA_FLAG_ONFIRE, true);
|
||||
@ -1109,8 +1109,12 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
|
||||
/**
|
||||
* @param int $fireTicks
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setFireTicks(int $fireTicks) : void{
|
||||
if($fireTicks < 0 or $fireTicks > 0x7fff){
|
||||
throw new \InvalidArgumentException("Fire ticks must be in range 0 ... " . 0x7fff . ", got $fireTicks");
|
||||
}
|
||||
$this->fireTicks = $fireTicks;
|
||||
}
|
||||
|
||||
@ -2187,4 +2191,47 @@ abstract class Entity extends Location implements Metadatable, EntityIds{
|
||||
public function __toString(){
|
||||
return (new \ReflectionClass($this))->getShortName() . "(" . $this->getId() . ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: remove this BC hack in 4.0
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \ErrorException
|
||||
*/
|
||||
public function __get($name){
|
||||
if($name === "fireTicks"){
|
||||
return $this->fireTicks;
|
||||
}
|
||||
throw new \ErrorException("Undefined property: " . get_class($this) . "::\$" . $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: remove this BC hack in 4.0
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws \ErrorException
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __set($name, $value){
|
||||
if($name === "fireTicks"){
|
||||
$this->setFireTicks($value);
|
||||
}else{
|
||||
throw new \ErrorException("Undefined property: " . get_class($this) . "::\$" . $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: remove this BC hack in 4.0
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name){
|
||||
return $name === "fireTicks";
|
||||
}
|
||||
}
|
||||
|
@ -319,7 +319,7 @@ abstract class Projectile extends Entity{
|
||||
|
||||
$entityHit->attack($ev);
|
||||
|
||||
if($this->fireTicks > 0){
|
||||
if($this->isOnFire()){
|
||||
$ev = new EntityCombustByEntityEvent($this, $entityHit, 5);
|
||||
$ev->call();
|
||||
if(!$ev->isCancelled()){
|
||||
|
Loading…
x
Reference in New Issue
Block a user