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