userid = $user->getUID(); if ($database->has("player_stats", ["accountid" => $this->userid])) { $stats = $database->get("player_stats", ["claims", "attacks", "defends", "scans", "distancekm"], ["accountid" => $this->userid]); $this->claims = $stats["claims"]; $this->attacks = $stats["attacks"]; $this->defends = $stats["defends"]; $this->scans = $stats["scans"]; $this->distancekm = $stats["distancekm"]; } } public function getStat(int $stat) { switch ($stat) { case PlayerStats::CLAIMS: return $this->claims; case PlayerStats::ATTACKS: return $this->attacks; case PlayerStats::DEFENDS: return $this->defends; case PlayerStats::SCANS: return $this->scans; case PlayerStats::DISTANCEKM: return $this->distancekm; default: return null; } } public function updateStat(int $stat, $diff) { switch ($stat) { case PlayerStats::CLAIMS: $this->claims += $diff; break; case PlayerStats::ATTACKS: $this->attacks += $diff; break; case PlayerStats::DEFENDS: $this->defends += $diff; break; case PlayerStats::SCANS: $this->scans += $diff; break; case PlayerStats::DISTANCEKM: $this->distancekm += $diff; break; } } public function save() { global $database; if ($database->has("player_stats", ["accountid" => $this->userid])) { $database->update("player_stats", [ "claims" => $this->claims, "attacks" => $this->attacks, "defends" => $this->defends, "scans" => $this->scans, "distancekm" => $this->distancekm ], [ "accountid" => $this->userid ] ); } else { $database->insert("player_stats", [ "accountid" => $this->userid, "claims" => $this->claims, "attacks" => $this->attacks, "defends" => $this->defends, "scans" => $this->scans, "distancekm" => $this->distancekm ] ); } } }