mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-28 14:19:53 +00:00
Allow setting the flying status for any given player
This commit is contained in:
parent
11e2d23b83
commit
3872a21474
@ -217,6 +217,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
protected $autoJump = true;
|
protected $autoJump = true;
|
||||||
|
|
||||||
|
protected $allowFlight = false;
|
||||||
|
|
||||||
|
|
||||||
private $needACK = [];
|
private $needACK = [];
|
||||||
|
|
||||||
@ -287,6 +289,15 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
return $this->namedtag instanceof Compound;
|
return $this->namedtag instanceof Compound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAllowFlight($value){
|
||||||
|
$this->allowFlight = (bool) $value;
|
||||||
|
$this->sendSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAllowFlight(){
|
||||||
|
return $this->allowFlight;
|
||||||
|
}
|
||||||
|
|
||||||
public function setAutoJump($value){
|
public function setAutoJump($value){
|
||||||
$this->autoJump = $value;
|
$this->autoJump = $value;
|
||||||
$this->sendSettings();
|
$this->sendSettings();
|
||||||
@ -987,6 +998,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$this->inventory->sendHeldItem($this->hasSpawned);
|
$this->inventory->sendHeldItem($this->hasSpawned);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->allowFlight = $this->isCreative();
|
||||||
|
|
||||||
$this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
|
$this->namedtag->playerGameType = new Int("playerGameType", $this->gamemode);
|
||||||
|
|
||||||
$spawnPosition = $this->getSpawn();
|
$spawnPosition = $this->getSpawn();
|
||||||
@ -1034,7 +1047,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
0x00000010 static_time
|
0x00000010 static_time
|
||||||
0x00000020 nametags_visible
|
0x00000020 nametags_visible
|
||||||
0x00000040 auto_jump
|
0x00000040 auto_jump
|
||||||
0x00000080 ?
|
0x00000080 allow_fly
|
||||||
0x00000100 ?
|
0x00000100 ?
|
||||||
0x00000200 ?
|
0x00000200 ?
|
||||||
0x00000400 ?
|
0x00000400 ?
|
||||||
@ -1073,6 +1086,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$flags |= 0x40;
|
$flags |= 0x40;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->allowFlight){
|
||||||
|
$flags |= 0x80;
|
||||||
|
}
|
||||||
|
|
||||||
$pk = new AdventureSettingsPacket();
|
$pk = new AdventureSettingsPacket();
|
||||||
$pk->flags = $flags;
|
$pk->flags = $flags;
|
||||||
$this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY));
|
$this->dataPacket($pk->setChannel(Network::CHANNEL_PRIORITY));
|
||||||
@ -1321,7 +1338,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if($this->onGround){
|
if($this->onGround){
|
||||||
$this->inAirTicks = 0;
|
$this->inAirTicks = 0;
|
||||||
}else{
|
}else{
|
||||||
if($this->inAirTicks > 10 and $this->isSurvival() and !$this->isSleeping() and $this->getDataProperty(self::DATA_NO_AI) === 0){
|
if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and $this->getDataProperty(self::DATA_NO_AI) !== 1){
|
||||||
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - 5));
|
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - 5));
|
||||||
$diff = sqrt(abs($this->speed->y - $expectedVelocity));
|
$diff = sqrt(abs($this->speed->y - $expectedVelocity));
|
||||||
|
|
||||||
@ -1500,6 +1517,10 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$this->gamemode = $this->server->getGamemode();
|
$this->gamemode = $this->server->getGamemode();
|
||||||
$nbt->playerGameType = new Int("playerGameType", $this->gamemode);
|
$nbt->playerGameType = new Int("playerGameType", $this->gamemode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->allowFlight = $this->isCreative();
|
||||||
|
|
||||||
|
|
||||||
if(($level = $this->server->getLevelByName($nbt["Level"])) === null){
|
if(($level = $this->server->getLevelByName($nbt["Level"])) === null){
|
||||||
$this->setLevel($this->server->getDefaultLevel(), true);
|
$this->setLevel($this->server->getDefaultLevel(), true);
|
||||||
$nbt["Level"] = $this->level->getName();
|
$nbt["Level"] = $this->level->getName();
|
||||||
@ -2860,7 +2881,9 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
and $source->getCause() !== EntityDamageEvent::CAUSE_VOID
|
and $source->getCause() !== EntityDamageEvent::CAUSE_VOID
|
||||||
){
|
){
|
||||||
$source->setCancelled();
|
$source->setCancelled();
|
||||||
}
|
}elseif($this->allowFlight and $source->getCause() === EntityDamageEvent::CAUSE_FALL){
|
||||||
|
$source->setCancelled();
|
||||||
|
}
|
||||||
|
|
||||||
parent::attack($damage, $source);
|
parent::attack($damage, $source);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user