From 46325a32420940cccb2dfe36bdde34f1929f1847 Mon Sep 17 00:00:00 2001 From: Vincent Date: Wed, 31 Jul 2024 15:26:06 +0100 Subject: [PATCH] fix(command): commands will no longer be sent to a player who doesn't have the appropriate permissions --- src/endstone_core/permissions/permissible_base.cpp | 4 +++- src/endstone_core/player.cpp | 11 ++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/endstone_core/permissions/permissible_base.cpp b/src/endstone_core/permissions/permissible_base.cpp index c13c6defc..b2a88848b 100644 --- a/src/endstone_core/permissions/permissible_base.cpp +++ b/src/endstone_core/permissions/permissible_base.cpp @@ -171,12 +171,14 @@ void PermissibleBase::calculateChildPermissions(const std::unordered_map(parent_, name, attachment, value); plugin_manager.subscribeToPermission(name, parent_); - auto *perm = plugin_manager.getPermission(name); if (perm != nullptr) { calculateChildPermissions(perm->getChildren(), !value, attachment); } diff --git a/src/endstone_core/player.cpp b/src/endstone_core/player.cpp index 0640e866e..c6cccf515 100644 --- a/src/endstone_core/player.cpp +++ b/src/endstone_core/player.cpp @@ -429,14 +429,15 @@ void EndstonePlayer::updateCommands() const AvailableCommandsPacket packet = registry.serializeAvailableCommands(); auto &command_map = server_.getCommandMap(); - for (auto &data : packet.commands) { - auto name = data.name; + for (auto it = packet.commands.begin(); it != packet.commands.end();) { + auto &name = it->name; auto *command = command_map.getCommand(name); - if (command && command->isRegistered() && command->testPermissionSilently(*static_cast(this))) { + if (command && command->isRegistered() && command->testPermissionSilently(*static_cast(this)) && + it->permission_level <= CommandPermissionLevel::GameDirectors) { + ++it; continue; } - data.command_flag |= (CommandFlag::HiddenFromPlayer | CommandFlag::HiddenFromBlock); - data.permission_level = CommandPermissionLevel::Internal; + it = packet.commands.erase(it); } getHandle().sendNetworkPacket(packet);