diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua index 955978670..89e9955a9 100644 --- a/Server/Plugins/APIDump/APIDesc.lua +++ b/Server/Plugins/APIDump/APIDesc.lua @@ -12292,7 +12292,7 @@ end Type = "cTeam", }, }, - Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error.", + Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error. For example if the team already exists.", }, RemoveObjective = { diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 88b3f6113..3f75d62d2 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -377,11 +377,15 @@ cTeam * cScoreboard::RegisterTeam( const AString & a_Prefix, const AString & a_Suffix ) { - cTeam Team(a_Name, a_DisplayName, a_Prefix, a_Suffix); + auto [TeamIterator, TeamExists] = m_Teams.try_emplace(a_Name, a_Name, a_DisplayName, a_Prefix, a_Suffix); - std::pair Status = m_Teams.insert(cNamedTeam(a_Name, Team)); + if (!TeamExists && GetTeam(a_Name)) + { + LOGWARNING("Tried to register a team that already exists: %s", a_Name.c_str()); + return nullptr; + } - return Status.second ? &Status.first->second : nullptr; + return &TeamIterator->second; }