From 57082c8148f5b40c968146b614540771fbbb8aef Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 1 Dec 2024 15:49:19 +0000 Subject: [PATCH] Added instabreak permission --- src/network/mcpe/NetworkSession.php | 2 +- src/permission/DefaultPermissionNames.php | 3 ++- src/permission/DefaultPermissions.php | 3 ++- src/player/Player.php | 2 +- src/world/World.php | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/network/mcpe/NetworkSession.php b/src/network/mcpe/NetworkSession.php index 5ade880f3..c93ee50b1 100644 --- a/src/network/mcpe/NetworkSession.php +++ b/src/network/mcpe/NetworkSession.php @@ -1045,7 +1045,7 @@ class NetworkSession{ AbilitiesLayer::ABILITY_INFINITE_RESOURCES => !$for->hasFiniteResources(), AbilitiesLayer::ABILITY_LIGHTNING => false, AbilitiesLayer::ABILITY_BUILD => $for->hasPermission(DefaultPermissionNames::GAME_BLOCK_PLACE), - AbilitiesLayer::ABILITY_MINE => $for->hasPermission(DefaultPermissionNames::GAME_BLOCK_BREAK), + AbilitiesLayer::ABILITY_MINE => $for->hasPermission(DefaultPermissionNames::GAME_BLOCK_MINE), AbilitiesLayer::ABILITY_DOORS_AND_SWITCHES => $for->hasPermission(DefaultPermissionNames::GAME_BLOCK_INTERACT), AbilitiesLayer::ABILITY_OPEN_CONTAINERS => $for->hasPermission(DefaultPermissionNames::GAME_BLOCK_INTERACT) || $for->hasPermission(DefaultPermissionNames::GAME_ENTITY_INTERACT), //not perfect, but this is a pain to implement right now AbilitiesLayer::ABILITY_ATTACK_PLAYERS => $for->hasPermission(DefaultPermissionNames::GAME_PLAYER_ATTACK), diff --git a/src/permission/DefaultPermissionNames.php b/src/permission/DefaultPermissionNames.php index adfd4c1f0..c7204047e 100644 --- a/src/permission/DefaultPermissionNames.php +++ b/src/permission/DefaultPermissionNames.php @@ -86,8 +86,9 @@ final class DefaultPermissionNames{ public const COMMAND_WHITELIST_REMOVE = "pocketmine.command.whitelist.remove"; public const COMMAND_XP_OTHER = "pocketmine.command.xp.other"; public const COMMAND_XP_SELF = "pocketmine.command.xp.self"; - public const GAME_BLOCK_BREAK = "pocketmine.game.block.break"; + public const GAME_BLOCK_DELETE = "pocketmine.game.block.delete"; public const GAME_BLOCK_INTERACT = "pocketmine.game.block.interact"; + public const GAME_BLOCK_MINE = "pocketmine.game.block.mine"; public const GAME_BLOCK_PLACE = "pocketmine.game.block.place"; public const GAME_CHAT = "pocketmine.game.chat"; public const GAME_ENTITY_ATTACK = "pocketmine.game.entity.attack"; diff --git a/src/permission/DefaultPermissions.php b/src/permission/DefaultPermissions.php index d6c7b5633..bd66cb5fb 100644 --- a/src/permission/DefaultPermissions.php +++ b/src/permission/DefaultPermissions.php @@ -122,8 +122,8 @@ abstract class DefaultPermissions{ $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 - self::registerPermission(new Permission(Names::GAME_BLOCK_BREAK, "Allows the user to break 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_PLACE, "Allows the user to place blocks"), [$survivalRoot, $creativeRoot, $adventureRoot]); self::registerPermission(new Permission(Names::GAME_ENTITY_ATTACK, "Allows the user to attack entities"), [$survivalRoot, $creativeRoot, $adventureRoot]); self::registerPermission(new Permission(Names::GAME_ENTITY_INTERACT, "Allows the user to interact with entities"), [$survivalRoot, $creativeRoot, $adventureRoot]); @@ -133,6 +133,7 @@ abstract class DefaultPermissions{ self::registerPermission(new Permission(Names::GAME_PLAYER_ATTACK, "Allows the user to attack other players"), [$survivalRoot, $creativeRoot, $adventureRoot]); self::registerPermission(new Permission(Names::GAME_PLAYER_INTERACT, "Allows the user to interact with other players"), [$survivalRoot, $creativeRoot, $adventureRoot]); + 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_FLIGHT, "Allows the user to toggle flight mode"), [$creativeRoot]); } diff --git a/src/player/Player.php b/src/player/Player.php index 6ef2c4641..d5ad1744c 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1800,7 +1800,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ return true; } - if(!$this->isCreative() && !$target->getBreakInfo()->breaksInstantly()){ + if(!$this->hasPermission(DefaultPermissionNames::GAME_BLOCK_DELETE) && !$target->getBreakInfo()->breaksInstantly()){ $this->blockBreakHandler = new SurvivalBlockBreakHandler($this, $pos, $target, $face, 16); } diff --git a/src/world/World.php b/src/world/World.php index 60a0e01e1..788d78974 100644 --- a/src/world/World.php +++ b/src/world/World.php @@ -2065,9 +2065,9 @@ class World implements ChunkManager{ } if($player !== null){ - $ev = new BlockBreakEvent($player, $target, $item, $player->isCreative(), $drops, $xpDrop); + $ev = new BlockBreakEvent($player, $target, $item, $player->hasPermission(DefaultPermissionNames::GAME_BLOCK_DELETE), $drops, $xpDrop); - if($target instanceof Air || ($player->isSurvival() && !$target->getBreakInfo()->isBreakable()) || !$player->hasPermission(DefaultPermissionNames::GAME_BLOCK_BREAK)){ + if($target instanceof Air || (!$player->hasPermission(DefaultPermissionNames::GAME_BLOCK_DELETE) && !$target->getBreakInfo()->isBreakable()) || !$player->hasPermission(DefaultPermissionNames::GAME_BLOCK_MINE)){ $ev->cancel(); }