mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-25 12:54:03 +00:00
Added protection for fast movements
This commit is contained in:
parent
14ab386b0f
commit
88a1f83545
@ -753,8 +753,9 @@ class Player{
|
||||
break;
|
||||
}
|
||||
if(($this->entity instanceof Entity) and $data["counter"] > $this->lastMovement){
|
||||
$this->lastMovement = $data["counter"];
|
||||
if($this->server->api->handle("player.move", $this->entity) === false){
|
||||
$this->lastMovement = $data["counter"];
|
||||
$speed = $this->entity->getSpeed();
|
||||
if(($speed > 5 and $this->gamemode !== CREATIVE) or $speed > 12 or $this->server->api->handle("player.move", $this->entity) === false){
|
||||
$this->teleport(new Vector3($this->entity->x, $this->entity->y, $this->entity->z), $this->entity->yaw, $this->entity->pitch);
|
||||
}else{
|
||||
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]);
|
||||
|
@ -72,6 +72,7 @@ class Entity extends stdClass{
|
||||
public $fallY;
|
||||
public $fallStart;
|
||||
private $tickCounter;
|
||||
private $speedMeasure = array(0, 0, 0, 0, 0);
|
||||
private $server;
|
||||
function __construct(PocketMinecraftServer $server, $eid, $class, $type = 0, $data = array()){
|
||||
$this->fallY = false;
|
||||
@ -100,9 +101,9 @@ class Entity extends stdClass{
|
||||
$this->x = isset($this->data["x"]) ? $this->data["x"]:0;
|
||||
$this->y = isset($this->data["y"]) ? $this->data["y"]:0;
|
||||
$this->z = isset($this->data["z"]) ? $this->data["z"]:0;
|
||||
$this->speedX = /*isset($this->data["speedX"]) ? $this->data["speedX"]:*/0;
|
||||
$this->speedY = /*isset($this->data["speedY"]) ? $this->data["speedY"]:*/0;
|
||||
$this->speedZ = /*isset($this->data["speedZ"]) ? $this->data["speedZ"]:*/0;
|
||||
$this->speedX = isset($this->data["speedX"]) ? $this->data["speedX"]:0;
|
||||
$this->speedY = isset($this->data["speedY"]) ? $this->data["speedY"]:0;
|
||||
$this->speedZ = isset($this->data["speedZ"]) ? $this->data["speedZ"]:0;
|
||||
$this->speed = 0;
|
||||
$this->yaw = isset($this->data["yaw"]) ? $this->data["yaw"]:0;
|
||||
$this->pitch = isset($this->data["pitch"]) ? $this->data["pitch"]:0;
|
||||
@ -348,6 +349,10 @@ class Entity extends stdClass{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->calculateVelocity();
|
||||
}
|
||||
}
|
||||
|
||||
if($this->class !== ENTITY_OBJECT and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){
|
||||
@ -357,11 +362,11 @@ class Entity extends stdClass{
|
||||
}else{
|
||||
$this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]);
|
||||
}
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->calculateVelocity();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->calculateVelocity();
|
||||
}
|
||||
$this->updateLast();
|
||||
}
|
||||
}
|
||||
@ -541,6 +546,10 @@ class Entity extends stdClass{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSpeed(){
|
||||
return array_sum($this->speedMeasure) / count($this->speedMeasure);
|
||||
}
|
||||
|
||||
public function calculateVelocity(){
|
||||
$diffTime = microtime(true) - $this->last[5];
|
||||
$origin = new Vector3($this->last[0], $this->last[1], $this->last[2]);
|
||||
@ -552,6 +561,8 @@ class Entity extends stdClass{
|
||||
$this->speedY = $speedY;
|
||||
$this->speedZ = $speedZ;
|
||||
$this->speed = $origin->distance($final) / $diffTime;
|
||||
array_shift($this->speedMeasure);
|
||||
$this->speedMeasure[] = $this->speed;
|
||||
}
|
||||
|
||||
public function updateLast(){
|
||||
|
Loading…
x
Reference in New Issue
Block a user