Added noclip permission

This commit is contained in:
Dylan K. Taylor 2024-12-01 16:44:32 +00:00
parent a91cef37f6
commit b0bfc30b07
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 15 additions and 11 deletions

View File

@ -100,6 +100,7 @@ final class DefaultPermissionNames{
public const GAME_ITEM_DROP = "pocketmine.game.item.drop"; public const GAME_ITEM_DROP = "pocketmine.game.item.drop";
public const GAME_ITEM_PICKUP = "pocketmine.game.item.pickup"; public const GAME_ITEM_PICKUP = "pocketmine.game.item.pickup";
public const GAME_ITEM_USE = "pocketmine.game.item.use"; public const GAME_ITEM_USE = "pocketmine.game.item.use";
public const GAME_NOCOLLISION = "pocketmine.game.nocollision";
public const GAME_PLAYER_ATTACK = "pocketmine.game.player.attack"; public const GAME_PLAYER_ATTACK = "pocketmine.game.player.attack";
public const GAME_PLAYER_INTERACT = "pocketmine.game.player.interact"; public const GAME_PLAYER_INTERACT = "pocketmine.game.player.interact";
public const GROUP_CONSOLE = "pocketmine.group.console"; public const GROUP_CONSOLE = "pocketmine.group.console";

View File

@ -120,7 +120,7 @@ abstract class DefaultPermissions{
$survivalRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_SURVIVAL)); $survivalRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_SURVIVAL));
$creativeRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_CREATIVE)); $creativeRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_CREATIVE));
$adventureRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_ADVENTURE)); $adventureRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_ADVENTURE));
self::registerPermission(new Permission(Names::GROUP_GAMEMODE_SPECTATOR)); //not currently used, but will be in the future $spectatorRoot = self::registerPermission(new Permission(Names::GROUP_GAMEMODE_SPECTATOR));
self::registerPermission(new Permission(Names::GAME_BLOCK_INTERACT, "Allows the user to interact with blocks"), [$survivalRoot, $creativeRoot, $adventureRoot]); self::registerPermission(new Permission(Names::GAME_BLOCK_INTERACT, "Allows the user to interact with blocks"), [$survivalRoot, $creativeRoot, $adventureRoot]);
self::registerPermission(new Permission(Names::GAME_BLOCK_MINE, "Allows the user to mine blocks"), [$survivalRoot, $creativeRoot, $adventureRoot]); self::registerPermission(new Permission(Names::GAME_BLOCK_MINE, "Allows the user to mine blocks"), [$survivalRoot, $creativeRoot, $adventureRoot]);
@ -141,5 +141,7 @@ abstract class DefaultPermissions{
self::registerPermission(new Permission(Names::GAME_BLOCK_DELETE, "Allows the user to delete any block without delay, including indestructible blocks"), [$creativeRoot]); self::registerPermission(new Permission(Names::GAME_BLOCK_DELETE, "Allows the user to delete any block without delay, including indestructible blocks"), [$creativeRoot]);
self::registerPermission(new Permission(Names::GAME_ITEM_CREATE, "Allows the user to use the creative inventory"), [$creativeRoot]); self::registerPermission(new Permission(Names::GAME_ITEM_CREATE, "Allows the user to use the creative inventory"), [$creativeRoot]);
self::registerPermission(new Permission(Names::GAME_FLIGHT, "Allows the user to toggle flight mode"), [$creativeRoot]); self::registerPermission(new Permission(Names::GAME_FLIGHT, "Allows the user to toggle flight mode"), [$creativeRoot]);
self::registerPermission(new Permission(Names::GAME_NOCOLLISION, "Allows the user to pass through blocks"), [$spectatorRoot]);
} }
} }

View File

@ -275,7 +275,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
//TODO: Abilities //TODO: Abilities
protected bool $autoJump = true; protected bool $autoJump = true;
protected bool $blockCollision = true;
protected bool $flying = false; protected bool $flying = false;
/** @phpstan-var positive-int|null */ /** @phpstan-var positive-int|null */
@ -481,12 +480,13 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* Note: Enabling flight mode in conjunction with this is recommended. A non-flying player will simply fall through * Note: Enabling flight mode in conjunction with this is recommended. A non-flying player will simply fall through
* the ground into the void. * the ground into the void.
* @see Player::setFlying() * @see Player::setFlying()
*
* @deprecated This is now controlled by setting a permission, which allows more fine-tuned control.
* @see DefaultPermissionNames::GAME_NOCOLLISION
*/ */
public function setHasBlockCollision(bool $value) : void{ public function setHasBlockCollision(bool $value) : void{
if($this->blockCollision !== $value){ $this->setBasePermission(DefaultPermissionNames::GAME_NOCOLLISION, !$value);
$this->blockCollision = $value; $this->getNetworkSession()->syncAbilities($this);
$this->getNetworkSession()->syncAbilities($this);
}
} }
/** /**
@ -494,7 +494,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
* If false, the player can move through any block unobstructed. * If false, the player can move through any block unobstructed.
*/ */
public function hasBlockCollision() : bool{ public function hasBlockCollision() : bool{
return $this->blockCollision; return !$this->hasPermission(DefaultPermissionNames::GAME_NOCOLLISION);
} }
public function setFlying(bool $value) : void{ public function setFlying(bool $value) : void{
@ -1127,14 +1127,16 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
$this->gamemode = $gameMode; $this->gamemode = $gameMode;
$this->setBasePermission($this->gamemode->getPermissionGroupName(), true); $this->setBasePermission($this->gamemode->getPermissionGroupName(), true);
//TODO: this preserves old behaviour of gamemode changes overriding setAllowFlight
//we should get rid of this when setAllowFlight is removed //TODO: this preserves old behaviour of gamemode changes overriding setAllowFlight and setHasBlockCollision
//we should get rid of these when the deprecated setters are removed
$this->unsetBasePermission(DefaultPermissionNames::GAME_FLIGHT); $this->unsetBasePermission(DefaultPermissionNames::GAME_FLIGHT);
$this->unsetBasePermission(DefaultPermissionNames::GAME_NOCOLLISION);
$this->hungerManager->setEnabled($this->isSurvival()); $this->hungerManager->setEnabled($this->isSurvival());
if($this->isSpectator()){ if($this->isSpectator()){
$this->setFlying(true); $this->setFlying(true);
$this->setHasBlockCollision(false);
$this->setSilent(); $this->setSilent();
$this->onGround = false; $this->onGround = false;
@ -1145,7 +1147,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
if(!$this->hasPermission(DefaultPermissionNames::GAME_FLIGHT)){ if(!$this->hasPermission(DefaultPermissionNames::GAME_FLIGHT)){
$this->setFlying(false); $this->setFlying(false);
} }
$this->setHasBlockCollision(true);
$this->setSilent(false); $this->setSilent(false);
$this->checkGroundState(0, 0, 0, 0, 0, 0); $this->checkGroundState(0, 0, 0, 0, 0, 0);
} }