Fixed AdventureSettings not working

This commit is contained in:
Dylan K. Taylor 2017-08-10 13:01:20 +01:00
parent 0dc8362536
commit 51be88c698
2 changed files with 13 additions and 4 deletions

View File

@ -1330,6 +1330,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$pk->commandPermission = ($this->isOp() ? AdventureSettingsPacket::PERMISSION_OPERATOR : AdventureSettingsPacket::PERMISSION_NORMAL); $pk->commandPermission = ($this->isOp() ? AdventureSettingsPacket::PERMISSION_OPERATOR : AdventureSettingsPacket::PERMISSION_NORMAL);
$pk->playerPermission = ($this->isOp() ? PlayerPermissions::OPERATOR : PlayerPermissions::MEMBER); $pk->playerPermission = ($this->isOp() ? PlayerPermissions::OPERATOR : PlayerPermissions::MEMBER);
$pk->entityUniqueId = $this->getId();
$this->dataPacket($pk); $this->dataPacket($pk);
} }
@ -3085,6 +3086,12 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{ public function handleAdventureSettings(AdventureSettingsPacket $packet) : bool{
if($packet->entityUniqueId !== $this->getId()){
return false; //TODO
}
$handled = false;
$isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING); $isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING);
if($isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){ if($isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"])); $this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]));
@ -3096,6 +3103,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
}else{ }else{
$this->flying = $ev->isFlying(); $this->flying = $ev->isFlying();
} }
$handled = true;
} }
if($packet->getFlag(AdventureSettingsPacket::NO_CLIP) and !$this->allowMovementCheats and !$this->isSpectator()){ if($packet->getFlag(AdventureSettingsPacket::NO_CLIP) and !$this->allowMovementCheats and !$this->isSpectator()){
@ -3105,7 +3114,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
//TODO: check other changes //TODO: check other changes
return true; return $handled;
} }
public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{ public function handleBlockEntityData(BlockEntityDataPacket $packet) : bool{

View File

@ -69,14 +69,14 @@ class AdventureSettingsPacket extends DataPacket{
public $commandPermission = self::PERMISSION_NORMAL; public $commandPermission = self::PERMISSION_NORMAL;
public $flags2 = -1; public $flags2 = -1;
public $playerPermission = PlayerPermissions::MEMBER; public $playerPermission = PlayerPermissions::MEMBER;
public $long1 = 0; public $entityUniqueId; //This is a little-endian long, NOT a var-long. (WTF Mojang)
protected function decodePayload(){ protected function decodePayload(){
$this->flags = $this->getUnsignedVarInt(); $this->flags = $this->getUnsignedVarInt();
$this->commandPermission = $this->getUnsignedVarInt(); $this->commandPermission = $this->getUnsignedVarInt();
$this->flags2 = $this->getUnsignedVarInt(); $this->flags2 = $this->getUnsignedVarInt();
$this->playerPermission = $this->getUnsignedVarInt(); $this->playerPermission = $this->getUnsignedVarInt();
$this->long1 = $this->getLLong(); $this->entityUniqueId = $this->getLLong();
} }
protected function encodePayload(){ protected function encodePayload(){
@ -84,7 +84,7 @@ class AdventureSettingsPacket extends DataPacket{
$this->putUnsignedVarInt($this->commandPermission); $this->putUnsignedVarInt($this->commandPermission);
$this->putUnsignedVarInt($this->flags2); $this->putUnsignedVarInt($this->flags2);
$this->putUnsignedVarInt($this->playerPermission); $this->putUnsignedVarInt($this->playerPermission);
$this->putLLong($this->long1); $this->putLLong($this->entityUniqueId);
} }
public function getFlag(int $flag) : bool{ public function getFlag(int $flag) : bool{