summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorandrew <xdotftw@gmail.com>2014-03-01 11:06:19 +0100
committerandrew <xdotftw@gmail.com>2014-03-01 11:08:40 +0100
commit5c449452871340eeae9df8f34c5e145fda991d92 (patch)
treee55eed91cb7616386dd1fe2c04b4904a0ff5099b
parentForgotten changes to cChunkInterface. (diff)
downloadcuberite-5c449452871340eeae9df8f34c5e145fda991d92.tar
cuberite-5c449452871340eeae9df8f34c5e145fda991d92.tar.gz
cuberite-5c449452871340eeae9df8f34c5e145fda991d92.tar.bz2
cuberite-5c449452871340eeae9df8f34c5e145fda991d92.tar.lz
cuberite-5c449452871340eeae9df8f34c5e145fda991d92.tar.xz
cuberite-5c449452871340eeae9df8f34c5e145fda991d92.tar.zst
cuberite-5c449452871340eeae9df8f34c5e145fda991d92.zip
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua90
-rw-r--r--src/Bindings/AllToLua.pkg1
-rw-r--r--src/Entities/Player.cpp21
-rw-r--r--src/Scoreboard.cpp30
-rw-r--r--src/Scoreboard.h67
5 files changed, 160 insertions, 49 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index c6221f30d..c2dd6ba99 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -1115,6 +1115,42 @@ local Item5 = cItem(E_ITEM_DIAMOND_CHESTPLATE, 1, 0, "thorns=1;unbreaking=3");
},
}, -- cItem
+ cObjective =
+ {
+ Desc = [[
+ This class represents a single scoreboard objective.
+ ]],
+ Functions =
+ {
+ AddScore = { Params = "string, number", Return = "Score", Notes = "Adds a value to the score of the specified player and returns the new value." },
+ GetDisplayName = { Params = "", Return = "string", Notes = "Returns the display name of the objective. This name will be shown to the connected players." },
+ GetName = { Params = "", Return = "string", Notes = "Returns the internal name of the objective." },
+ GetScore = { Params = "string", Return = "Score", Notes = "Returns the score of the specified player." },
+ GetType = { Params = "", Return = "eType", Notes = "Returns the type of the objective. (i.e what is being tracked)" },
+ Reset = { Params = "", Return = "", Notes = "Resets the scores of the tracked players." },
+ ResetScore = { Params = "string", Return = "", Notes = "Reset the score of the specified player." },
+ SetDisplayName = { Params = "string", Return = "", Notes = "Sets the display name of the objective." },
+ SetScore = { Params = "string, Score", Return = "", Notes = "Sets the score of the specified player." },
+ SubScore = { Params = "string, number", Return = "Score", Notes = "Subtracts a value from the score of the specified player and returns the new value." },
+ },
+ Constants =
+ {
+ E_TYPE_ACHIEVEMENT = { Notes = "" },
+ E_TYPE_DEATH_COUNT = { Notes = "" },
+ E_TYPE_DUMMY = { Notes = "" },
+ E_TYPE_HEALTH = { Notes = "" },
+ E_TYPE_PLAYER_KILL_COUNT = { Notes = "" },
+ E_TYPE_STAT = { Notes = "" },
+ E_TYPE_STAT_BLOCK_MINE = { Notes = "" },
+ E_TYPE_STAT_ENTITY_KILL = { Notes = "" },
+ E_TYPE_STAT_ENTITY_KILLED_BY = { Notes = "" },
+ E_TYPE_STAT_ITEM_BREAK = { Notes = "" },
+ E_TYPE_STAT_ITEM_CRAFT = { Notes = "" },
+ E_TYPE_STAT_ITEM_USE = { Notes = "" },
+ E_TYPE_TOTAL_KILL_COUNT = { Notes = "" },
+ },
+ }, -- cObjective
+
cPainting =
{
Desc = "This class represents a painting in the world. These paintings are special and different from Vanilla in that they can be critical-hit.",
@@ -1821,6 +1857,34 @@ end
},
}, -- cRoot
+ cScoreboard =
+ {
+ Desc = [[
+ This class manages the objectives and teams of a single world.
+ ]],
+ Functions =
+ {
+ AddPlayerScore = { Params = "Name, Type, Value", Return = "", Notes = "Adds a value to all player scores of the specified objective type." },
+ GetNumObjectives = { Params = "", Return = "number", Notes = "Returns the nuber of registered objectives." },
+ GetNumTeams = { Params = "", Return = "number", Notes = "Returns the number of registered teams." },
+ GetObjective = { Params = "string", Return = "{{cObjective}}", Notes = "Returns the objective with the specified name." },
+ GetObjectiveIn = { Params = "DisplaySlot", Return = "{{cObjective}}", Notes = "Returns the objective in the specified display slot. Can be nil." },
+ GetTeam = { Params = "string", Return = "{{cTeam}}", Notes = "Returns the team with the specified name." },
+ RegisterObjective = { Params = "Name, DisplayName, Type", Return = "{{cObjective}}", Notes = "Registers a new scoreboard objective. Returns the {{cObjective}} instance, nil on error." },
+ RegisterTeam = { Params = "Name, DisplayName, Prefix, Suffix", Return = "{{cTeam}}", Notes = "Registers a new team. Returns the {{cTeam}} instance, nil on error." },
+ RemoveObjective = { Params = "string", Return = "bool", Notes = "Removes the objective with the specified name. Returns true if operation was successful." },
+ RemoveTeam = { Params = "string", Return = "bool", Notes = "Removes the team with the specified name. Returns true if operation was successful." },
+ SetDisplay = { Params = "Name, DisplaySlot", Return = "", Notes = "Updates the currently displayed objective." },
+ },
+ Constants =
+ {
+ E_DISPLAY_SLOT_COUNT = { Notes = "" },
+ E_DISPLAY_SLOT_LIST = { Notes = "" },
+ E_DISPLAY_SLOT_NAME = { Notes = "" },
+ E_DISPLAY_SLOT_SIDEBAR = { Notes = "" },
+ },
+ }, -- cScoreboard
+
cServer =
{
Desc = [[
@@ -1841,6 +1905,32 @@ end
},
}, -- cServer
+ cTeam =
+ {
+ Desc = [[
+ This class manages a single player team.
+ ]],
+ Functions =
+ {
+ AddPlayer = { Params = "string", Returns = "bool", Notes = "Adds a player to this team. Returns true if the operation was successful." },
+ AllowsFriendlyFire = { Params = "", Return = "bool", Notes = "Returns whether team friendly fire is allowed." },
+ CanSeeFriendlyInvisible = { Params = "", Return = "bool", Notes = "Returns whether players can see invisible teammates." },
+ HasPlayer = { Params = "string", Returns = "bool", Notes = "Returns whether the specified player is a member of this team." },
+ GetDisplayName = { Params = "", Return = "string", Notes = "Returns the display name of the team." },
+ GetName = { Params = "", Return = "string", Notes = "Returns the internal name of the team." },
+ GetNumPlayers = { Params = "", Return = "number", Notes = "Returns the number of registered players." },
+ GetPrefix = { Params = "", Return = "string", Notes = "Returns the prefix prepended to the names of the members of this team." },
+ RemovePlayer = { Params = "string", Returns = "bool", Notes = "Removes the player with the specified name from this team. Returns true if the operation was successful." },
+ Reset = { Params = "", Returns = "", Notes = "Removes all players from this team." },
+ GetSuffix = { Params = "", Return = "string", Notes = "Returns the suffix appended to the names of the members of this team." },
+ SetCanSeeFriendlyInvisible = { Params = "bool", Return = "", Notes = "Set whether players can see invisible teammates." },
+ SetDisplayName = { Params = "string", Return = "", Notes = "Sets the display name of this team. (i.e. what will be shown to the players)" },
+ SetFriendlyFire = { Params = "bool", Return = "", Notes = "Sets whether team friendly fire is allowed." },
+ SetPrefix = { Params = "string", Return = "", Notes = "Sets the prefix prepended to the names of the members of this team." },
+ SetSuffix = { Params = "string", Return = "", Notes = "Sets the suffix appended to the names of the members of this team." },
+ },
+ }, -- cTeam
+
cTNTEntity =
{
Desc = "This class manages a TNT entity.",
diff --git a/src/Bindings/AllToLua.pkg b/src/Bindings/AllToLua.pkg
index 6537437cd..1a2140771 100644
--- a/src/Bindings/AllToLua.pkg
+++ b/src/Bindings/AllToLua.pkg
@@ -75,6 +75,7 @@ $cfile "../Mobs/Monster.h"
$cfile "../CompositeChat.h"
$cfile "../Map.h"
$cfile "../MapManager.h"
+$cfile "../Scoreboard.h"
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index f419ee09c..416bda2ec 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -858,6 +858,8 @@ void cPlayer::KilledBy(cEntity * a_Killer)
else if (a_Killer->IsPlayer())
{
GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), ((cPlayer *)a_Killer)->GetName().c_str()));
+
+ m_World->GetScoreBoard().AddPlayerScore(((cPlayer *)a_Killer)->GetName(), cObjective::E_TYPE_PLAYER_KILL_COUNT, 1);
}
else
{
@@ -867,24 +869,7 @@ void cPlayer::KilledBy(cEntity * a_Killer)
GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str()));
}
- class cIncrementCounterCB
- : public cObjectiveCallback
- {
- AString m_Name;
- public:
- cIncrementCounterCB(const AString & a_Name) : m_Name(a_Name) {}
-
- virtual bool Item(cObjective * a_Objective) override
- {
- a_Objective->AddScore(m_Name, 1);
- return true;
- }
- } IncrementCounter (GetName());
-
- cScoreboard & Scoreboard = m_World->GetScoreBoard();
-
- // Update scoreboard objectives
- Scoreboard.ForEachObjectiveWith(cObjective::E_TYPE_DEATH_COUNT, IncrementCounter);
+ m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::E_TYPE_DEATH_COUNT, 1);
}
diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp
index 61ecac5b7..1c5a22eff 100644
--- a/src/Scoreboard.cpp
+++ b/src/Scoreboard.cpp
@@ -246,6 +246,17 @@ void cTeam::Reset(void)
+void cTeam::SetDisplayName(const AString & a_Name)
+{
+ m_DisplayName = a_Name;
+
+ // TODO 2014-03-01 xdot: Update clients
+}
+
+
+
+
+
unsigned int cTeam::GetNumPlayers(void) const
{
return m_Players.size();
@@ -306,6 +317,8 @@ bool cScoreboard::RemoveObjective(const AString & a_Name)
ASSERT(m_World != NULL);
m_World->BroadcastScoreboardObjective(it->second.GetName(), it->second.GetDisplayName(), 1);
+ // TODO 2014-03-01 xdot: Remove objective from display slot
+
return true;
}
@@ -465,6 +478,23 @@ void cScoreboard::ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallb
+void cScoreboard::AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value)
+{
+ cCSLock Lock(m_CSObjectives);
+
+ for (cObjectiveMap::iterator it = m_Objectives.begin(); it != m_Objectives.end(); ++it)
+ {
+ if (it->second.GetType() == a_Type)
+ {
+ it->second.AddScore(a_Name, a_Value);
+ }
+ }
+}
+
+
+
+
+
void cScoreboard::SendTo(cClientHandle & a_Client)
{
cCSLock Lock(m_CSObjectives);
diff --git a/src/Scoreboard.h b/src/Scoreboard.h
index f64ba2bce..f9a8665da 100644
--- a/src/Scoreboard.h
+++ b/src/Scoreboard.h
@@ -67,29 +67,29 @@ public:
const AString & GetName(void) const { return m_Name; }
const AString & GetDisplayName(void) const { return m_DisplayName; }
- /// Resets the objective
+ /** Resets the objective */
void Reset(void);
- /// Returns the score of the specified player
+ /** Returns the score of the specified player */
Score GetScore(const AString & a_Name) const;
- /// Sets the score of the specified player
+ /** Sets the score of the specified player */
void SetScore(const AString & a_Name, Score a_Score);
- /// Resets the score of the specified player
+ /** Resets the score of the specified player */
void ResetScore(const AString & a_Name);
- /// Adds a_Delta and returns the new score
+ /** Adds a_Delta and returns the new score */
Score AddScore(const AString & a_Name, Score a_Delta);
- /// Subtracts a_Delta and returns the new score
+ /** Subtracts a_Delta and returns the new score */
Score SubScore(const AString & a_Name, Score a_Delta);
void SetDisplayName(const AString & a_Name);
// tolua_end
- /// Send this objective to the specified client
+ /** Send this objective to the specified client */
void SendTo(cClientHandle & a_Client);
private:
@@ -109,7 +109,8 @@ private:
friend class cScoreboardSerializer;
-};
+
+}; // tolua_export
@@ -127,21 +128,21 @@ public:
const AString & a_Prefix, const AString & a_Suffix
);
- /// Adds a new player to the team
+ // tolua_begin
+
+ /** Adds a new player to the team */
bool AddPlayer(const AString & a_Name);
- /// Removes a player from the team
+ /** Removes a player from the team */
bool RemovePlayer(const AString & a_Name);
- /// Returns whether the specified player is in this team
+ /** Returns whether the specified player is in this team */
bool HasPlayer(const AString & a_Name) const;
- /// Removes all registered players
+ /** Removes all registered players */
void Reset(void);
- // tolua_begin
-
- /// Returns the number of registered players
+ /** Returns the number of registered players */
unsigned int GetNumPlayers(void) const;
bool AllowsFriendlyFire(void) const { return m_AllowsFriendlyFire; }
@@ -180,7 +181,8 @@ private:
friend class cScoreboardSerializer;
-};
+
+}; // tolua_export
@@ -209,44 +211,46 @@ public:
// tolua_begin
- /// Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision
+ /** Registers a new scoreboard objective, returns the cObjective instance, NULL on name collision */
cObjective * RegisterObjective(const AString & a_Name, const AString & a_DisplayName, cObjective::eType a_Type);
- /// Removes a registered objective, returns true if operation was successful
+ /** Removes a registered objective, returns true if operation was successful */
bool RemoveObjective(const AString & a_Name);
- /// Retrieves the objective with the specified name, NULL if not found
+ /** Retrieves the objective with the specified name, NULL if not found */
cObjective * GetObjective(const AString & a_Name);
- /// Registers a new team, returns the cTeam instance, NULL on name collision
+ /** Registers a new team, returns the cTeam instance, NULL on name collision */
cTeam * RegisterTeam(const AString & a_Name, const AString & a_DisplayName, const AString & a_Prefix, const AString & a_Suffix);
- /// Removes a registered team, returns true if operation was successful
+ /** Removes a registered team, returns true if operation was successful */
bool RemoveTeam(const AString & a_Name);
- /// Retrieves the team with the specified name, NULL if not found
+ /** Retrieves the team with the specified name, NULL if not found */
cTeam * GetTeam(const AString & a_Name);
- cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn)
-
void SetDisplay(const AString & a_Objective, eDisplaySlot a_Slot);
- void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot);
-
cObjective * GetObjectiveIn(eDisplaySlot a_Slot);
- /// Execute callback for each objective with the specified type
- void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
-
unsigned int GetNumObjectives(void) const;
unsigned int GetNumTeams(void) const;
+ void AddPlayerScore(const AString & a_Name, cObjective::eType a_Type, cObjective::Score a_Value = 1);
+
// tolua_end
- /// Send this scoreboard to the specified client
+ /** Send this scoreboard to the specified client */
void SendTo(cClientHandle & a_Client);
+ cTeam * QueryPlayerTeam(const AString & a_Name); // WARNING: O(n logn)
+
+ /** Execute callback for each objective with the specified type */
+ void ForEachObjectiveWith(cObjective::eType a_Type, cObjectiveCallback& a_Callback);
+
+ void SetDisplay(cObjective * a_Objective, eDisplaySlot a_Slot);
+
private:
@@ -269,7 +273,8 @@ private:
friend class cScoreboardSerializer;
-} ;
+
+}; // tolua_export