public function loadEntity($entity, $create = true)
 {
     $result = $this->db->query("SELECT * FROM {$this->mtn} WHERE\n\t\t\t\tent_type = '{$this->db->escape_string($entity->getAbsolutePrefix())}' AND\n\t\t\t\tent_name = '{$this->db->escape_string($entity->getName())}';");
     $data = $result->fetch_assoc();
     $result->close();
     if (!is_array($data)) {
         if (!$create) {
             EntityNotCreatedException::throwEx();
         }
         $entity->initDefaultAccounts();
         return;
     }
     $result = $this->db->query("SELECT * FROM {$this->atn} WHERE\n\t\t\t\tent_type = '{$this->db->escape_string($entity->getAbsolutePrefix())}' AND\n\t\t\t\tent_name = '{$this->db->escape_string($entity->getName())}';");
     while (is_array($data = $result->fetch_assoc())) {
         $entity->addAccount($data["name"], $data["amount"], $data["max_containable"], $data["min_amount"]);
     }
     $result->close();
     $result = $this->db->query("SELECT * FROM {$this->ltn} WHERE\n\t\t\t\tent_type = '{$this->db->escape_string($entity->getAbsolutePrefix())}' AND\n\t\t\t\tent_name = '{$this->db->escape_string($entity->getName())}';");
     while (is_array($data = $result->fetch_assoc())) {
         switch ($data["from_type"]) {
             case PlayerEnt::ABSOLUTE_PREFIX:
                 $from = $this->getMain()->getPlayerEnt($data["from_name"])->getAccount($data["from_account"]);
                 break;
             case Service::TYPE:
                 if ($data["from_name"] === Service::NAME) {
                     $from = $this->getMain()->getService()->getService($data["from_account"]);
                     break;
                 }
             default:
                 throw new \RuntimeException("Unsupported creditor type: " . $data["from_type"]);
         }
         $entity->addLoanRaw(new Loan($from, $data["amount"], $entity, $data["due"], $data["increase_per_hour"], $data["name"], $data["creation"], $data["original_amount"], $data["last_interest_update"]));
     }
     $result->close();
 }
 public function loadEntity($entity, $create = true)
 {
     $file = $this->getPath($entity);
     if (!is_file($file)) {
         if (!$create) {
             EntityNotCreatedException::throwEx();
         }
         $entity->initDefaultAccounts();
         return;
     }
     $data = json_decode(file_get_contents($file), true);
     foreach ($data["accounts"] as $account) {
         $entity->addAccount($account["name"], $account["amount"], $account["max containable"], $account["min amount"]);
     }
     foreach ($data["loans"] as $loan) {
         $from = $loan["from"];
         switch ($from["type"]) {
             case PlayerEnt::ABSOLUTE_PREFIX:
                 $from = $this->getMain()->getPlayerEnt($from["name"])->getAccount($from["account"]);
                 break;
             case Service::TYPE:
                 if ($from["name"] === Service::NAME) {
                     $from = $this->getMain()->getService()->getService($from["account"]);
                     break;
                 }
             default:
                 throw new \RuntimeException("Unsupported creditor type: " . $from["type"]);
         }
         $entity->addLoanRaw(new Loan($from, $data["amount"], $entity, $data["due"], $data["increase per hour"], $data["name"], $data["creation"], $data["original amount"], $data["last interest update"]));
     }
 }
 public function loadEntity($entity, $create = true)
 {
     if ($this->existsEntity($entity->getAbsolutePrefix(), $entity->getName())) {
         $result = $this->db->query("SELECT * FROM ent_accounts\n\t\t\t\t\tWHERE ent_type = '{$this->db->escapeString($entity->getAbsolutePrefix())}'\n\t\t\t\t\tAND ent_name = '{$this->db->escapeString($entity->getName())}';");
         while (is_array($data = $result->fetchArray(SQLITE3_ASSOC))) {
             $entity->addAccount($data["name"], $data["amount"], $data["max_containable"], $data["min_amount"]);
         }
         $result = $this->db->query("SELECT * FROM ent_loans\n\t\t\t\t\tWHERE ent_type = '{$this->db->escapeString($entity->getAbsolutePrefix())}'\n\t\t\t\t\tAND ent_name = '{$this->db->escapeString($entity->getName())}';");
         while (is_array($data = $result->fetchArray(SQLITE3_ASSOC))) {
             switch ($type = $data["from_type"]) {
                 case PlayerEnt::ABSOLUTE_PREFIX:
                     $from = $this->getMain()->getPlayerEnt($data["from_name"])->getAccount($data["from_account"]);
                     break;
                 case Service::TYPE:
                     if ($data["from_name"] === Service::NAME) {
                         $from = $this->getMain()->getService()->getService($data["from_account"]);
                         break;
                     }
                 default:
                     throw new \Exception("Unsupported creditor type: {$type}");
             }
             $entity->addLoanRaw(new Loan($from, $data["amount"], $entity, $data["due"], $data["increase_per_hour"], $data["name"], $data["creation"], $data["original_amount"], $data["last_interest_update"]));
         }
     } else {
         if (!$create) {
             EntityNotCreatedException::throwEx();
         }
         $entity->initDefaultAccounts();
     }
 }