/** @return float|bool */
 public function Distance($source = false)
 {
     if (gettype($source) != 'object' || get_class($source) != 'Vector2') {
         $source = new Vector2(0, 0);
     }
     if ($this->IsFloat() && $source->IsFloat()) {
         $x = $source->X - $this->X;
         $y = $source->Y - $this->Y;
         $distance = sqrt(($x ^ 2) + ($y ^ 2));
         return $distance;
     } else {
         return false;
     }
 }
 public function entityHurt($data)
 {
     $target = $data['entity'];
     $t = new Vector2($target->x, $target->z);
     $s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
     if ($t->distance($s) <= $this->api->getProperty('spawn-protection')) {
         if (is_numeric($data['cause'])) {
             $e = $this->api->entity->get($data['cause']);
             if ($e !== false and $e->class === ENTITY_PLAYER) {
                 $e->player->sendChat('PvP is not allowed at the spawn');
             }
         }
         return false;
     }
 }
示例#3
0
 /**
  * @param mixed $data
  * @param string $event
  *
  * @return boolean
  */
 public function permissionsCheck($data, $event)
 {
     switch ($event) {
         case "player.flying":
             //OPs can fly around the server.
             if ($this->isOp($data->iusername)) {
                 return true;
             }
             break;
         case "player.block.break":
         case "player.block.place":
             //Spawn protection detection. Allows OPs to place/break blocks in the spawn area.
             if (!$this->isOp($data["player"]->iusername)) {
                 $t = new Vector2($data["target"]->x, $data["target"]->z);
                 $s = new Vector2($this->server->spawn->x, $this->server->spawn->z);
                 if ($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event . ".spawn", $data) !== true) {
                     return false;
                 }
             }
             return;
             break;
         case "console.command":
             //Checks if a command is allowed with the current user permissions.
             if (isset($this->cmdWhitelist[$data["cmd"]])) {
                 return;
             }
             if ($data["issuer"] instanceof Player) {
                 if ($this->server->api->handle("console.check", $data) === true or $this->isOp($data["issuer"]->iusername)) {
                     return;
                 }
             } elseif ($data["issuer"] === "console" or $data["issuer"] === "rcon") {
                 return;
             }
             return false;
             break;
     }
 }
示例#4
0
 public function checkBorder($player)
 {
     $level = $this->getServer()->getLevelByName($player["level"]);
     if ($this->levName != $player["level"]) {
         return false;
     }
     $t = new Vector2($player["x"], $player["z"]);
     $s = new Vector2($this->borderXZ, $this->borderXZ);
     $worlds = [$this->getServer()->getDefaultSpawn()->getLevel()->getName()];
     foreach ($worlds as $key => $value) {
         if (!empty($value[$player["level"]])) {
             $r = $value[$player["level"]];
         }
     }
     if ($t->distance($s) >= $r) {
         return true;
     } else {
         return false;
     }
 }
示例#5
0
 public function calculateVelocity()
 {
     $diffTime = max(0.05, abs(microtime(true) - $this->last[5]));
     $origin = new Vector2($this->last[0], $this->last[2]);
     $final = new Vector2($this->x, $this->z);
     $speedX = ($this->last[0] - $this->x) / $diffTime;
     $speedY = ($this->last[1] - $this->y) / $diffTime;
     $speedZ = ($this->last[2] - $this->z) / $diffTime;
     if ($this->speedX != $speedX or $this->speedY != $speedY or $this->speedZ != $speedZ) {
         $this->speedX = $speedX;
         $this->speedY = $speedY;
         $this->speedZ = $speedZ;
         $this->server->api->handle("entity.motion", $this);
     }
     $this->speed = $origin->distance($final) / $diffTime;
     unset($this->speedMeasure[key($this->speedMeasure)]);
     $this->speedMeasure[] = $this->speed;
 }