From 133f398a423504862e1d1a6de77212fcfc98d47c Mon Sep 17 00:00:00 2001 From: ArkQuark <74979909+ArkQuark@users.noreply.github.com> Date: Sun, 5 Jun 2022 01:53:41 +0300 Subject: [PATCH] Despawn command into core --- src/API/EntityAPI.php | 58 +++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 67437ce3..e4a83231 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -82,6 +82,7 @@ class EntityAPI{ $this->server->schedule(25, array($this, "updateEntities"), array(), true); $this->server->api->console->register("summon", "", array($this, "commandHandler")); $this->server->api->console->register("spawnmob", "", array($this, "commandHandler")); + $this->server->api->console->register("despawn", "", array($this, "CommandHandler")); } public function commandHandler($cmd, $args, $issuer, $alias){ @@ -163,30 +164,45 @@ class EntityAPI{ $output .= $amount." ".$baby.$this->mobName[$type].$plural." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; break; - } - elseif(strtolower($args[1]) == 'baby'){//summon [baby] - if($type > 13){ - $output .= "Baby can be only animals!"; + } + elseif(strtolower($args[1]) == 'baby'){//summon [baby] + if($type > 13){ + $output .= "Baby can be only animals!"; + break; + } + else{ + $spawnX = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP); + $spawnY = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP); + $spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP); + $spawnLevel = $issuer->entity->level; + + $entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array( + "x" => $spawnX, + "y" => $spawnY, + "z" => $spawnZ, + "Health" => $this->hp[$type], + "isBaby" => 1, + )); + $this->spawnToAll($entityit, $level); + $output .= "Baby ".$this->mobName[$type]." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; + break; + } break; } - else{ - $spawnX = round($issuer->entity->x, 1, PHP_ROUND_HALF_UP); - $spawnY = round($issuer->entity->y, 1, PHP_ROUND_HALF_UP); - $spawnZ = round($issuer->entity->z, 1, PHP_ROUND_HALF_UP); - $spawnLevel = $issuer->entity->level; - - $entityit = $this->add($spawnLevel, ENTITY_MOB, $type, array( - "x" => $spawnX, - "y" => $spawnY, - "z" => $spawnZ, - "Health" => $this->hp[$type], - "isBaby" => 1, - )); - $this->spawnToAll($entityit, $level); - $output .= "Baby ".$this->mobName[$type]." spawned in ".$spawnX.", ".$spawnY.", ".$spawnZ."."; - break; + case 'despawn': + $cnt = 0; + $l = $this->server->query("SELECT EID FROM entities WHERE class = ".ENTITY_MOB.";"); + if ($l !== false and $l !== true){ + while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ + $e = $this->get($e["EID"]); + if ($e instanceof Entity){ + $this->remove($e->eid); + $cnt++; + } + } } - } + $output .= $cnt." mobs has been despawned!"; + break; } return $output; }