1
0

Merge remote-tracking branch 'xdot/master'

* xdot/master:
  Command block fixes 2
This commit is contained in:
Mattes D 2014-01-23 14:06:05 +01:00
commit 0526ed327c
6 changed files with 104 additions and 40 deletions

View File

@ -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_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["Command"] = m_Command;
a_Value["LastOutput"] = m_LastOutput;
a_Value["SuccessCount"] = m_Result;
}
@ -175,6 +183,14 @@ void cCommandBlockEntity::SaveToJson(Json::Value & a_Value)
void cCommandBlockEntity::Execute()
{
if (m_World)
{
if (!m_World->AreCommandBlocksEnabled())
{
return;
}
}
class CommandBlockOutCb :
public cCommandOutputCallback
{
@ -185,8 +201,6 @@ void cCommandBlockEntity::Execute()
virtual void Out(const AString & a_Text)
{
ASSERT(m_CmdBlock != NULL);
// Overwrite field
m_CmdBlock->SetLastOutput(a_Text);
}

View File

@ -610,26 +610,19 @@ void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a
}
}
class cUpdateCommandBlock :
public cCommandBlockCallback
{
AString m_Command;
public:
cUpdateCommandBlock(const AString & a_Command) : m_Command(a_Command) {}
virtual bool Item(cCommandBlockEntity * a_CommandBlock) override
{
a_CommandBlock->SetCommand(m_Command);
return false;
}
} CmdBlockCB (Command);
cWorld * World = m_Player->GetWorld();
World->DoWithCommandBlockAt(BlockX, BlockY, BlockZ, CmdBlockCB);
if (World->AreCommandBlocksEnabled())
{
World->SetCommandBlockCommand(BlockX, BlockY, BlockZ, Command);
SendChat(Printf("%s[INFO]%s Successfully set command block command", cChatColor::Green.c_str(), cChatColor::White.c_str()));
}
else
{
SendChat(Printf("%s[INFO]%s Command blocks are not enabled on this server", cChatColor::Green.c_str(), cChatColor::White.c_str()));
}
}

View File

@ -22,6 +22,8 @@
#include "Entities/Player.h"
#include "Entities/TNTEntity.h"
#include "BlockEntities/CommandBlockEntity.h"
// Simulators:
#include "Simulator/SimulatorManager.h"
#include "Simulator/FloodyFluidSimulator.h"
@ -540,6 +542,7 @@ void cWorld::Start(void)
m_bEnabledPVP = IniFile.GetValueSetB("PVP", "Enabled", true);
m_IsDeepSnowEnabled = IniFile.GetValueSetB("Physics", "DeepSnow", false);
m_ShouldLavaSpawnFire = IniFile.GetValueSetB("Physics", "ShouldLavaSpawnFire", true);
m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false);
m_GameMode = (eGameMode)IniFile.GetValueSetI("GameMode", "GameMode", m_GameMode);
@ -2611,6 +2614,28 @@ bool cWorld::UpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, const AString
bool cWorld::SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command)
{
class cUpdateCommandBlock : public cCommandBlockCallback
{
AString m_Command;
public:
cUpdateCommandBlock(const AString & a_Command) : m_Command(a_Command) {}
virtual bool Item(cCommandBlockEntity * a_CommandBlock) override
{
a_CommandBlock->SetCommand(m_Command);
return false;
}
} CmdBlockCB (a_Command);
return DoWithCommandBlockAt(a_BlockX, a_BlockY, a_BlockZ, CmdBlockCB);
}
void cWorld::ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay)
{
m_ChunkMap->ChunksStay(a_Chunks, a_Stay);

View File

@ -296,6 +296,9 @@ public:
/** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as SetSignLines() */
bool UpdateSign(int a_X, int a_Y, int a_Z, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp
/** Sets the command block command. Returns true if command changed. */
bool SetCommandBlockCommand(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Command); // tolua_export
/** Marks (a_Stay == true) or unmarks (a_Stay == false) chunks as non-unloadable. To be used only by cChunkStay! */
void ChunksStay(const cChunkCoordsList & a_Chunks, bool a_Stay = true);
@ -512,6 +515,10 @@ public:
/// Returns the associated scoreboard instance
cScoreboard & GetScoreBoard(void) { return m_Scoreboard; }
bool AreCommandBlocksEnabled(void) const { return m_bCommandBlocksEnabled; }
void SetCommandBlocksEnabled(bool a_Flag) { m_bCommandBlocksEnabled = a_Flag; }
// tolua_end
inline static void AbsoluteToRelative( int & a_X, int & a_Y, int & a_Z, int & a_ChunkX, int & a_ChunkY, int & a_ChunkZ )
@ -775,6 +782,8 @@ private:
bool m_IsSaplingBonemealable;
bool m_IsSugarcaneBonemealable;
bool m_bCommandBlocksEnabled;
cCriticalSection m_CSFastSetBlock;
sSetBlockList m_FastSetBlockQueue;

View File

@ -666,6 +666,7 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity)
case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break;
case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break;
case E_BLOCK_COMMAND_BLOCK: AddCommandBlockEntity((cCommandBlockEntity *) a_Entity); break;
default:
{
ASSERT(!"Unhandled block entity saved into Anvil");

View File

@ -10,6 +10,7 @@
#include "json/json.h"
#include "../StringCompression.h"
#include "../BlockEntities/ChestEntity.h"
#include "../BlockEntities/CommandBlockEntity.h"
#include "../BlockEntities/DispenserEntity.h"
#include "../BlockEntities/FurnaceEntity.h"
#include "../BlockEntities/JukeboxEntity.h"
@ -79,6 +80,7 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity)
case E_BLOCK_WALLSIGN: SaveInto = "Signs"; break;
case E_BLOCK_NOTE_BLOCK: SaveInto = "Notes"; break;
case E_BLOCK_JUKEBOX: SaveInto = "Jukeboxes"; break;
case E_BLOCK_COMMAND_BLOCK: SaveInto = "CommandBlocks"; break;
default:
{
@ -383,6 +385,26 @@ void cWSSCompact::LoadEntitiesFromJson(Json::Value & a_Value, cEntityList & a_En
}
} // for itr - AllJukeboxes[]
}
// Load command blocks
Json::Value AllCommandBlocks = a_Value.get("CommandBlocks", Json::nullValue);
if( !AllCommandBlocks.empty() )
{
for( Json::Value::iterator itr = AllCommandBlocks.begin(); itr != AllCommandBlocks.end(); ++itr )
{
Json::Value & CommandBlock = *itr;
cCommandBlockEntity * CommandBlockEntity = new cCommandBlockEntity(0, 0, 0, a_World);
if ( !CommandBlockEntity->LoadFromJson( CommandBlock ) )
{
LOGERROR("ERROR READING COMMAND BLOCK FROM JSON!" );
delete CommandBlockEntity;
}
else
{
a_BlockEntities.push_back( CommandBlockEntity );
}
} // for itr - AllCommandBlocks[]
}
}