summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-05-19 21:40:56 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-05-19 21:40:56 +0200
commit42c36429d7cd1e6c3f879b6749e18e912deefe0d (patch)
treecd6f9a0ddf88a738596018311702d19d07fc0b5c /src
parentMerge pull request #1010 from mc-server/cactidamage (diff)
downloadcuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.tar
cuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.tar.gz
cuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.tar.bz2
cuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.tar.lz
cuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.tar.xz
cuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.tar.zst
cuberite-42c36429d7cd1e6c3f879b6749e18e912deefe0d.zip
Diffstat (limited to '')
-rw-r--r--src/CompositeChat.cpp22
-rw-r--r--src/CompositeChat.h15
-rw-r--r--src/Entities/Player.cpp8
-rw-r--r--src/Protocol/Protocol17x.cpp29
4 files changed, 70 insertions, 4 deletions
diff --git a/src/CompositeChat.cpp b/src/CompositeChat.cpp
index c70ef1070..d3b7595b7 100644
--- a/src/CompositeChat.cpp
+++ b/src/CompositeChat.cpp
@@ -189,6 +189,15 @@ void cCompositeChat::AddSuggestCommandPart(const AString & a_Text, const AString
+void cCompositeChat::AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style)
+{
+ m_Parts.push_back(new cShowAchievementPart(a_PlayerName, a_Achievement, a_Style));
+}
+
+
+
+
+
void cCompositeChat::ParseText(const AString & a_ParseText)
{
size_t len = a_ParseText.length();
@@ -476,3 +485,16 @@ cCompositeChat::cSuggestCommandPart::cSuggestCommandPart(const AString & a_Text,
+
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// cCompositeChat::cShowAchievementPart:
+
+cCompositeChat::cShowAchievementPart::cShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style) :
+ super(ptShowAchievement, a_Achievement, a_Style),
+ m_PlayerName(a_PlayerName)
+{
+}
+
+
+
+
diff --git a/src/CompositeChat.h b/src/CompositeChat.h
index 5b9c5f612..a0264d864 100644
--- a/src/CompositeChat.h
+++ b/src/CompositeChat.h
@@ -38,6 +38,7 @@ public:
ptUrl,
ptRunCommand,
ptSuggestCommand,
+ ptShowAchievement,
} ;
class cBasePart
@@ -106,6 +107,15 @@ public:
public:
cSuggestCommandPart(const AString & a_Text, const AString & a_Command, const AString & a_Style = "");
} ;
+
+ class cShowAchievementPart :
+ public cBasePart
+ {
+ typedef cBasePart super;
+ public:
+ AString m_PlayerName;
+ cShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
+ } ;
typedef std::vector<cBasePart *> cParts;
@@ -148,6 +158,11 @@ public:
/** Adds a part that suggests a command (enters it into the chat message area, but doesn't send) when clicked.
The default style is underlined yellow text. */
void AddSuggestCommandPart(const AString & a_Text, const AString & a_SuggestedCommand, const AString & a_Style = "u@b");
+
+ /** Adds a part that fully formats a specified achievement using client translatable strings
+ Takes achievement name and player awarded to. Displays as {player} has earned the achievement {achievement_name}.
+ */
+ void AddShowAchievementPart(const AString & a_PlayerName, const AString & a_Achievement, const AString & a_Style = "");
/** Parses text into various parts, adds those.
Recognizes "http:" and "https:" URLs and @color-codes. */
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index c3b763278..3a32bfb2e 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1169,8 +1169,8 @@ unsigned int cPlayer::AwardAchievement(const eStatistic a_Ach)
{
// First time, announce it
cCompositeChat Msg;
- Msg.AddTextPart(m_PlayerName + " has just earned the achievement ");
- Msg.AddTextPart(cStatInfo::GetName(a_Ach)); // TODO 2014-05-12 xdot: Use the proper cCompositeChat part (cAchievement)
+ Msg.SetMessageType(mtSuccess);
+ Msg.AddShowAchievementPart(GetName(), cStatInfo::GetName(a_Ach));
m_World->BroadcastChat(Msg);
// Increment the statistic
@@ -1788,7 +1788,7 @@ bool cPlayer::SaveToDisk()
// Save the player stats.
// We use the default world name (like bukkit) because stats are shared between dimensions/worlds.
- cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), m_PlayerName, &m_Stats);
+ cStatSerializer StatSerializer(cRoot::Get()->GetDefaultWorld()->GetName(), GetName(), &m_Stats);
if (!StatSerializer.Save())
{
LOGERROR("Could not save stats for player %s", m_PlayerName.c_str());
@@ -1963,7 +1963,7 @@ void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos)
BLOCKTYPE Block;
NIBBLETYPE Meta;
- if (!m_World->GetBlockTypeMeta(PosX, PosY, PosZ, Block, Meta))
+ if ((PosY < 0) || (PosY > cChunkDef::Height) || !m_World->GetBlockTypeMeta(PosX, PosY, PosZ, Block, Meta))
{
return;
}
diff --git a/src/Protocol/Protocol17x.cpp b/src/Protocol/Protocol17x.cpp
index 39feee16f..3061d132b 100644
--- a/src/Protocol/Protocol17x.cpp
+++ b/src/Protocol/Protocol17x.cpp
@@ -289,6 +289,35 @@ void cProtocol172::SendChat(const cCompositeChat & a_Message)
AddChatPartStyle(Part, p.m_Style);
break;
}
+
+ case cCompositeChat::ptShowAchievement:
+ {
+ const cCompositeChat::cShowAchievementPart & p = (const cCompositeChat::cShowAchievementPart &)**itr;
+ Part["translate"] = "chat.type.achievement";
+
+ Json::Value Ach;
+ Ach["action"] = "show_achievement";
+ Ach["value"] = p.m_Text;
+
+ Json::Value AchColourAndName;
+ AchColourAndName["color"] = "green";
+ AchColourAndName["translate"] = p.m_Text;
+ AchColourAndName["hoverEvent"] = Ach;
+
+ Json::Value Extra;
+ Extra.append(AchColourAndName);
+
+ Json::Value Name;
+ Name["text"] = p.m_PlayerName;
+
+ Json::Value With;
+ With.append(Name);
+ With.append(Extra);
+
+ Part["with"] = With;
+ AddChatPartStyle(Part, p.m_Style);
+ break;
+ }
}
msg["extra"].append(Part);
} // for itr - Parts[]