removed useless classes, entities are not in database anymore

This commit is contained in:
GameHerobrine 2024-01-09 05:19:36 +03:00
parent af7293d4d7
commit 1bbe5c7582
14 changed files with 43 additions and 77 deletions

View file

@ -204,22 +204,27 @@ class EntityAPI{
$this->server->api->dhandle("entity.remove", $this->entities[$eid]);
unset($this->entities[$eid]->level->entityList[$eid]);
unset($this->entities[$eid]);
$this->server->query("DELETE FROM entities WHERE EID = " . $eid . ";");
}
}
public function getRadius(Position $center, $radius = 15, $class = false){
$entities = [];
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $center->level->getName() . "' " . ($class !== false ? "AND class = $class " : "") . "AND abs(x - {$center->x}) <= $radius AND abs(y - {$center->y}) <= $radius AND abs(z - {$center->z}) <= $radius;");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->get($e["EID"]);
if($e instanceof Entity){
$entities[$e->eid] = $e;
$minChunkX = ((int)($center->x - $radius)) >> 4;
$minChunkZ = ((int)($center->z - $radius)) >> 4;
$maxChunkX = ((int)($center->x + $radius)) >> 4;
$maxChunkZ = ((int)($center->z - $radius)) >> 4;
$ents = [];
//TODO also index by chunkY?
for($chunkX = $minChunkX; $chunkX <= $maxChunkX; ++$chunkX){
for($chunkZ = $minChunkZ; $chunkZ <= $maxChunkZ; ++$chunkZ){
$ind = "$chunkX $chunkZ";
foreach($center->level->entityListPositioned[$ind] ?? [] as $entid){
if($this->entities[$entid] instanceof Entity && ($class === false || $this->entities[$entid]->class == $class)){
$ents[$entid] = $this->entities[$entid];
}
}
}
}
return $entities;
return $ents;
}
public function heal($eid, $heal, $cause){

View file

@ -32,7 +32,7 @@ class PlayerAPI{
$this->server->api->console->cmdWhitelist("ping");
$this->server->api->console->cmdWhitelist("spawn");
$this->server->api->console->cmdWhitelist("loc");
$this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = " . ENTITY_PLAYER . " AND health < 20;");
//$this->server->preparedSQL->selectPlayersToHeal = $this->server->database->prepare("SELECT EID FROM entities WHERE class = " . ENTITY_PLAYER . " AND health < 20;");
}
public function registerCmd($cmd, $help = ""){
@ -43,7 +43,7 @@ class PlayerAPI{
switch($event){
case "server.regeneration":
if($this->server->difficulty === 0){
$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
//$result = $this->server->preparedSQL->selectPlayersToHeal->execute();
if($result !== false){
while(($player = $result->fetchArray()) !== false){
if(($player = $this->server->api->entity->get($player["EID"])) !== false){
@ -365,6 +365,7 @@ class PlayerAPI{
"z" => $player->level->getSpawn()->z,
]);
}
$player->level->players[$CID] = $player;
$this->server->query("INSERT OR REPLACE INTO players (CID, ip, port, name) VALUES (" . $player->CID . ", '" . $player->ip . "', " . $player->port . ", '" . strtolower($player->username) . "');");
}
}
@ -434,16 +435,8 @@ class PlayerAPI{
public function getAll($level = null){
if($level instanceof Level){
$clients = [];
$l = $this->server->query("SELECT EID FROM entities WHERE level = '" . $level->getName() . "' AND class = '" . ENTITY_PLAYER . "';");
if($l !== false and $l !== true){
while(($e = $l->fetchArray(SQLITE3_ASSOC)) !== false){
$e = $this->getByEID($e["EID"]);
if($e instanceof Player){
$clients[$e->CID] = $e;
}
}
} return $clients;
//safe_var_dump($level->players);
return $level->players;
}
return $this->server->clients;
@ -487,6 +480,7 @@ class PlayerAPI{
}
$this->server->query("DELETE FROM players WHERE name = '" . $player->username . "';");
$this->server->api->entity->remove($player->eid);
unset($player->level->players[$this->CID]);
if($player->entity instanceof Entity){
unset($player->entity->player);
//unset($player->entity);