Backport of https://github.com/TrinityCore/TrinityCore/pull/11567