When i use entity->getId() it returns entity count in the server My anti-lag: PHP: public function onspawnentity(EntitySpawnEvent $e) { $entity = $e->getEntity(); if(!in_array($entity->getId(), [63,64,-1,1])) { $entity->kill(); $this->getLogger()->info($entity->getId()); } }
Am i supposed to use this? Is there any short way? (Because i don't want this code to kill my slappers and i know i can use Slapper's entity type but is there any other short way?) PHP: $entity instanceof Player
$entity->getId() doesn't return entity count on the server. It returns unique id for the entity in int. That id is got by increasing one int (Entity::$entityCount) so it may be similar to entity count, however, if you despawn some entity, it's irrelevant to call it entity count. Btw, what this code is supposed to do and where is the problem with it?
I want to kill every mob without Players, Items and other plugin's custom entities. Problem is entity->getId not returns the id of the entity (thanks for replying)
For network id you can use $entity::NETWORK_ID, but using check $entity instanceof ... is better as network ids are kinda deprecated
PHP: if(!($entity instanceof Player) && !($entity instanceof pocketmine\entity\ItemEntity) && !($entity instanceof jojoe77777\slapper\entities\SlapperEntity)) { $entity->kill(); $this->getLogger()->info($entity->getId()); } I used that but it didnt work. It still kills items and slappers. But not kills me. (I am gonna try network id)
NETWORK_ID doesnt work. I tried on armor stand and in armor stand's code there is not property named NETWORK_ID.
Armor stands are not implemented yet. You can find it's network id here. If there is no property named NETWORK_ID then you have implemented armor stand entity wrong.
This code works for me PHP: foreach ($this->level->getEntities() as $entity) { if ($entity instanceof ItemEntity) { $entity->flagForDespawn(); } }