diff options
author | andrew <xdotftw@gmail.com> | 2014-01-21 18:43:13 +0100 |
---|---|---|
committer | andrew <xdotftw@gmail.com> | 2014-01-21 18:43:13 +0100 |
commit | fa4750f015f1fed0937ba9fe80fc183c27d9e929 (patch) | |
tree | eddd2dbe01ff851750359164074d8aaa8306929e /src/Scoreboard.cpp | |
parent | Scoreboard protocol support (diff) | |
download | cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.tar cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.tar.gz cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.tar.bz2 cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.tar.lz cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.tar.xz cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.tar.zst cuberite-fa4750f015f1fed0937ba9fe80fc183c27d9e929.zip |
Diffstat (limited to 'src/Scoreboard.cpp')
-rw-r--r-- | src/Scoreboard.cpp | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index 7fa1eab99..e6812d3d7 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -7,6 +7,7 @@ #include "Scoreboard.h" #include "World.h" +#include "ClientHandle.h" @@ -178,6 +179,20 @@ void cObjective::SetDisplayName(const AString & a_Name) +void cObjective::SendTo(cClientHandle & a_Client) +{ + a_Client.SendScoreboardObjective(m_Name, m_DisplayName, 0); + + for (cScoreMap::const_iterator it = m_Scores.begin(); it != m_Scores.end(); ++it) + { + a_Client.SendScoreUpdate(m_Name, it->first, it->second, 0); + } +} + + + + + cTeam::cTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix) : m_AllowsFriendlyFire(true) @@ -397,11 +412,19 @@ void cScoreboard::SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot) cObjective * Objective = GetObjective(a_Objective); - m_Display[a_Slot] = Objective; + SetDisplay(Objective, a_Slot); +} + + + + + +void cScoreboard::SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot) +{ + m_Display[a_Slot] = a_Objective; ASSERT(m_World != NULL); - m_World->BroadcastDisplayObjective(Objective ? a_Objective : "", a_Slot); - + m_World->BroadcastDisplayObjective(a_Objective ? a_Objective->GetName() : "", a_Slot); } @@ -440,6 +463,31 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb +void cScoreboard::SendTo(cClientHandle & a_Client) +{ + cCSLock Lock(m_CSObjectives); + + for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it) + { + it->second.SendTo(a_Client); + } + + for (int i = 0; i < (int) E_DISPLAY_SLOT_COUNT; ++i) + { + // Avoid race conditions + cObjective * Objective = m_Display[i]; + + if (Objective) + { + a_Client.SendDisplayObjective(Objective->GetName(), (eDisplaySlot) i); + } + } +} + + + + + unsigned int cScoreboard::GetNumObjectives(void) const { return m_Objectives.size(); |