despawn from nc 0.8

This commit is contained in:
GameHerobrine 2023-12-12 13:05:12 +03:00
parent 721700380f
commit 0fb08b3a1c

View file

@ -100,45 +100,53 @@ 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;
//terrible code break;
$list = ""; case "objects":
$temp = ["mobs" => "2", "objects" => "3", "items" => "4", "fallings" => "5"]; $despawnclass = ENTITY_OBJECT;
foreach($array as $value){ break;
$list .= $temp[$value]." or "; case "items":
} $despawnclass = ENTITY_ITEM;
$despawning = substr($list, 0, -4); break;
$l = $this->server->query("SELECT EID FROM entities WHERE class = ".$despawning.";"); case "fallings":
if($l !== false and $l !== true){ $despawnclass = ENTITY_FALLING;
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){ break;
$e = $this->get($e["EID"]); }
if($e instanceof Entity){ if($despawnclass){
$this->remove($e->eid); foreach($this->entities as $entity){
$cnt++; if($entity instanceof Entity && !$entity->isPlayer() && $entity->class === $despawnclass){
} $entity->close();
} ++$cnt;
} }
} }
} }
if($despawntype){
$output = "$cnt entities have been despawned!"; foreach($this->entities as $entity){
break; if($entity instanceof Entity && !$entity->isPlayer() && $entity->type === $despawntype){
$entity->close();
++$cnt;
}
}
}
return "$cnt entities have been despawned!";
} }
return $output; return $output;
} }