/despawn is reworked

This commit is contained in:
GameHerobrine 2023-07-28 03:02:46 +03:00
parent 2d9b37aa9c
commit 177d8b53ab

View file

@ -92,45 +92,54 @@ class EntityAPI{
case "despawn": case "despawn":
$cnt = 0; $cnt = 0;
if(!isset($args[0])){ if(!isset($args[0])){
$output .= "/despawn <all or (mobs,objects,items,fallings)>"; return "/despawn <all|mobs|objects|items|fallings|minecarts>";
break; }
}else{
if($args[0] === "all"){ $despawnclass = 0;
$cnt = 0; $despawntype = 0;
foreach($this->entities as $e){ switch($args[0]){
if(isset($e) && $e != null && !$e->isPlayer()){ //if player, not despawning case "all":
$this->remove($e->eid); foreach($this->entities as $entity){
$cnt++; if($entity instanceof Entity && !$entity->isPlayer()){
$entity->close();
++$cnt;
} }
} }
}else{ break;
$array = explode(",", strtolower($args[0])); case "minecarts":
if(count($array) > 4){ $despawntype = OBJECT_MINECART;
$output .= "Many arguments!"; break;
break; case "mobs":
$despawnclass = ENTITY_MOB;
break;
case "objects":
$despawnclass = ENTITY_OBJECT;
break;
case "items":
$despawnclass = ENTITY_ITEM;
break;
case "fallings":
$despawnclass = ENTITY_FALLING;
break;
}
if($despawnclass){
foreach($this->entities as $entity){
if($entity instanceof Entity && !$entity->isPlayer() && $entity->class === $despawnclass){
$entity->close();
++$cnt;
} }
//terrible code }
$list = ""; }
$temp = ["mobs" => "2", "objects" => "3", "items" => "4", "fallings" => "5"]; if($despawntype){
foreach($array as $value){ foreach($this->entities as $entity){
$list .= $temp[$value]." or "; if($entity instanceof Entity && !$entity->isPlayer() && $entity->type === $despawntype){
} $entity->close();
$despawning = substr($list, 0, -4); ++$cnt;
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";");
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 entities have been despawned!"; return "$cnt entities have been despawned!";
break;
} }
return $output; return $output;
} }