mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-20 16:00:20 +00:00
Added API method Entity->isClosed() and made Entity->closed protected
This commit is contained in:
parent
20aa519f3a
commit
eebc52e00b
@ -817,7 +817,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
|
||||
if($this->spawned){
|
||||
foreach($this->level->getChunkEntities($x, $z) as $entity){
|
||||
if($entity !== $this and !$entity->closed and $entity->isAlive()){
|
||||
if($entity !== $this and !$entity->isClosed() and $entity->isAlive()){
|
||||
$entity->spawnTo($this);
|
||||
}
|
||||
}
|
||||
@ -896,7 +896,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
||||
foreach($this->usedChunks as $index => $c){
|
||||
Level::getXZ($index, $chunkX, $chunkZ);
|
||||
foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){
|
||||
if($entity !== $this and !$entity->closed and $entity->isAlive()){
|
||||
if($entity !== $this and !$entity->isClosed() and $entity->isAlive()){
|
||||
$entity->spawnTo($this);
|
||||
}
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
protected $server;
|
||||
|
||||
/** @var bool */
|
||||
public $closed = false;
|
||||
protected $closed = false;
|
||||
|
||||
/** @var TimingsHandler */
|
||||
protected $timings;
|
||||
@ -1826,6 +1826,19 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the entity has been "closed".
|
||||
* @return bool
|
||||
*/
|
||||
public function isClosed() : bool{
|
||||
return $this->closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the entity and frees attached references.
|
||||
*
|
||||
* WARNING: Entities are unusable after this has been executed!
|
||||
*/
|
||||
public function close(){
|
||||
if(!$this->closed){
|
||||
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
|
||||
|
@ -722,7 +722,7 @@ class Level implements ChunkManager, Metadatable{
|
||||
//Update entities that need update
|
||||
Timings::$tickEntityTimer->startTiming();
|
||||
foreach($this->updateEntities as $id => $entity){
|
||||
if($entity->closed or !$entity->onUpdate($currentTick)){
|
||||
if($entity->isClosed() or !$entity->onUpdate($currentTick)){
|
||||
unset($this->updateEntities[$id]);
|
||||
}
|
||||
}
|
||||
|
@ -611,7 +611,7 @@ class Chunk{
|
||||
* @param Entity $entity
|
||||
*/
|
||||
public function addEntity(Entity $entity){
|
||||
if($entity->closed){
|
||||
if($entity->isClosed()){
|
||||
throw new \InvalidArgumentException("Attempted to add a garbage closed Entity to a chunk");
|
||||
}
|
||||
$this->entities[$entity->getId()] = $entity;
|
||||
|
@ -71,7 +71,7 @@ class Anvil extends McRegion{
|
||||
$entities = [];
|
||||
|
||||
foreach($chunk->getEntities() as $entity){
|
||||
if(!($entity instanceof Player) and !$entity->closed){
|
||||
if(!($entity instanceof Player) and !$entity->isClosed()){
|
||||
$entity->saveNBT();
|
||||
$entities[] = $entity->namedtag;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ class McRegion extends BaseLevelProvider{
|
||||
$entities = [];
|
||||
|
||||
foreach($chunk->getEntities() as $entity){
|
||||
if(!($entity instanceof Player) and !$entity->closed){
|
||||
if(!($entity instanceof Player) and !$entity->isClosed()){
|
||||
$entity->saveNBT();
|
||||
$entities[] = $entity->namedtag;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class PMAnvil extends Anvil{
|
||||
$entities = [];
|
||||
|
||||
foreach($chunk->getEntities() as $entity){
|
||||
if(!($entity instanceof Player) and !$entity->closed){
|
||||
if(!($entity instanceof Player) and !$entity->isClosed()){
|
||||
$entity->saveNBT();
|
||||
$entities[] = $entity->namedtag;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user