summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/CommandBlockEntity.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-01-23 23:46:51 +0100
committermadmaxoft <github@xoft.cz>2014-01-23 23:46:51 +0100
commit98976de0710e60cc9d11c85cf398b0ec565399c5 (patch)
treeeaae19ce64cfc644a9b5836f6fea4c6e7f9ebd2f /src/BlockEntities/CommandBlockEntity.cpp
parentFixed a warning in ScoreboardSerializer. (diff)
parentMerge pull request #580 from xdot/master (diff)
downloadcuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.tar
cuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.tar.gz
cuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.tar.bz2
cuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.tar.lz
cuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.tar.xz
cuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.tar.zst
cuberite-98976de0710e60cc9d11c85cf398b0ec565399c5.zip
Diffstat (limited to 'src/BlockEntities/CommandBlockEntity.cpp')
-rw-r--r--src/BlockEntities/CommandBlockEntity.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp
index 7e9015d33..0bc6ca359 100644
--- a/src/BlockEntities/CommandBlockEntity.cpp
+++ b/src/BlockEntities/CommandBlockEntity.cpp
@@ -151,9 +151,13 @@ void cCommandBlockEntity::SendTo(cClientHandle & a_Client)
bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value)
{
- m_Command = a_Value.get("Command", "").asString();
+ m_PosX = a_Value.get("x", 0).asInt();
+ m_PosY = a_Value.get("y", 0).asInt();
+ m_PosZ = a_Value.get("z", 0).asInt();
- m_LastOutput = a_Value.get("LastOutput", "").asString();
+ m_Command = a_Value.get("Command", "").asString();
+ m_LastOutput = a_Value.get("LastOutput", "").asString();
+ m_Result = a_Value.get("SuccessCount", 0).asInt();
return true;
}
@@ -164,9 +168,13 @@ bool cCommandBlockEntity::LoadFromJson(const Json::Value & a_Value)
void cCommandBlockEntity::SaveToJson(Json::Value & a_Value)
{
- a_Value["Command"] = m_Command;
+ a_Value["x"] = m_PosX;
+ a_Value["y"] = m_PosY;
+ a_Value["z"] = m_PosZ;
- a_Value["LastOutput"] = m_LastOutput;
+ a_Value["Command"] = m_Command;
+ a_Value["LastOutput"] = m_LastOutput;
+ a_Value["SuccessCount"] = m_Result;
}
@@ -175,18 +183,24 @@ void cCommandBlockEntity::SaveToJson(Json::Value & a_Value)
void cCommandBlockEntity::Execute()
{
+ if (m_World != NULL)
+ {
+ if (!m_World->AreCommandBlocksEnabled())
+ {
+ return;
+ }
+ }
+
class CommandBlockOutCb :
public cCommandOutputCallback
{
- cCommandBlockEntity* m_CmdBlock;
+ cCommandBlockEntity * m_CmdBlock;
public:
- CommandBlockOutCb(cCommandBlockEntity* a_CmdBlock) : m_CmdBlock(a_CmdBlock) {}
+ CommandBlockOutCb(cCommandBlockEntity * a_CmdBlock) : m_CmdBlock(a_CmdBlock) {}
virtual void Out(const AString & a_Text)
{
- ASSERT(m_CmdBlock != NULL);
-
// Overwrite field
m_CmdBlock->SetLastOutput(a_Text);
}
@@ -194,7 +208,7 @@ void cCommandBlockEntity::Execute()
LOGD("cCommandBlockEntity: Executing command %s", m_Command.c_str());
- cServer* Server = cRoot::Get()->GetServer();
+ cServer * Server = cRoot::Get()->GetServer();
Server->ExecuteConsoleCommand(m_Command, CmdBlockOutCb);