diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-23 01:05:12 +0200 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-23 01:05:12 +0200 |
commit | 49a4613d94d8e500e5bd3c259693fb5ccec4612e (patch) | |
tree | ea2db28bde16c472f02b6a83651df8cf2fe486a9 /source/cRoot.cpp | |
parent | Added a documentation for block and item handlers (diff) | |
download | cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.gz cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.bz2 cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.lz cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.xz cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.zst cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.zip |
Diffstat (limited to 'source/cRoot.cpp')
-rw-r--r-- | source/cRoot.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/source/cRoot.cpp b/source/cRoot.cpp index 5c0c08f7d..4c87210c7 100644 --- a/source/cRoot.cpp +++ b/source/cRoot.cpp @@ -14,6 +14,7 @@ #include "cThread.h" #include "cFileFormatUpdater.h" #include "cRedstone.h" +#include "cPlayer.h" #include "blocks/Block.h" #include "items/Item.h" #include "cChunk.h" @@ -423,6 +424,58 @@ bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback) +bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback) +{ + class cCallback : public cPlayerListCallback + { + unsigned int BestRating; + unsigned int NameLength; + const AString PlayerName; + + cPlayerListCallback & m_Callback; + virtual bool Item (cPlayer * a_pPlayer) + { + unsigned int Rating = RateCompareString (PlayerName, a_pPlayer->GetName()); + if (Rating > 0 && Rating >= BestRating) + { + BestMatch = a_pPlayer; + if( Rating > BestRating ) NumMatches = 0; + BestRating = Rating; + ++NumMatches; + } + if (Rating == NameLength) // Perfect match + { + return false; + } + return true; + } + + public: + cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback) + : m_Callback( a_Callback ) + , BestMatch( NULL ) + , BestRating( 0 ) + , NumMatches( 0 ) + , NameLength( a_PlayerName.length() ) + , PlayerName( a_PlayerName ) + {} + + cPlayer * BestMatch; + unsigned int NumMatches; + } Callback (a_PlayerName, a_Callback); + ForEachPlayer( Callback ); + + if (Callback.NumMatches == 1) + { + return a_Callback.Item (Callback.BestMatch); + } + return false; +} + + + + + void cRoot::LogChunkStats(void) { int SumNumValid = 0; |