diff options
author | Mattes D <github@xoft.cz> | 2014-01-23 14:06:05 +0100 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2014-01-23 14:06:05 +0100 |
commit | 0526ed327c9679919486e49f36ba4d051390a73e (patch) | |
tree | 7a75ff77e167214dd3dc63c31df4fc41ad8d6530 /src | |
parent | Authenticator: Reduced logging levels. (diff) | |
parent | Command block fixes 2 (diff) | |
download | cuberite-0526ed327c9679919486e49f36ba4d051390a73e.tar cuberite-0526ed327c9679919486e49f36ba4d051390a73e.tar.gz cuberite-0526ed327c9679919486e49f36ba4d051390a73e.tar.bz2 cuberite-0526ed327c9679919486e49f36ba4d051390a73e.tar.lz cuberite-0526ed327c9679919486e49f36ba4d051390a73e.tar.xz cuberite-0526ed327c9679919486e49f36ba4d051390a73e.tar.zst cuberite-0526ed327c9679919486e49f36ba4d051390a73e.zip |
Diffstat (limited to '')
-rw-r--r-- | src/BlockEntities/CommandBlockEntity.cpp | 26 | ||||
-rw-r--r-- | src/ClientHandle.cpp | 25 | ||||
-rw-r--r-- | src/World.cpp | 27 | ||||
-rw-r--r-- | src/World.h | 9 | ||||
-rw-r--r-- | src/WorldStorage/NBTChunkSerializer.cpp | 19 | ||||
-rw-r--r-- | src/WorldStorage/WSSCompact.cpp | 38 |
6 files changed, 104 insertions, 40 deletions
diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 7e9015d33..db8eb1436 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,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); } diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 0a2d3c1be..ed04edac0 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -610,25 +610,18 @@ 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())); + 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())); + } } diff --git a/src/World.cpp b/src/World.cpp index 49d42f08e..453a22c2d 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -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" @@ -523,7 +525,7 @@ void cWorld::Start(void) } m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema); - m_StorageCompressionFactor = IniFile.GetValueSetI ("Storage", "CompressionFactor", m_StorageCompressionFactor); + m_StorageCompressionFactor = IniFile.GetValueSetI("Storage", "CompressionFactor", m_StorageCompressionFactor); m_MaxCactusHeight = IniFile.GetValueSetI("Plants", "MaxCactusHeight", 3); m_MaxSugarcaneHeight = IniFile.GetValueSetI("Plants", "MaxSugarcaneHeight", 3); m_IsCactusBonemealable = IniFile.GetValueSetB("Plants", "IsCactusBonemealable", false); @@ -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); diff --git a/src/World.h b/src/World.h index 2d6baa99f..61c7604df 100644 --- a/src/World.h +++ b/src/World.h @@ -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); @@ -511,6 +514,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 @@ -774,6 +781,8 @@ private: bool m_IsPumpkinBonemealable; bool m_IsSaplingBonemealable; bool m_IsSugarcaneBonemealable; + + bool m_bCommandBlocksEnabled; cCriticalSection m_CSFastSetBlock; sSetBlockList m_FastSetBlockQueue; diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index c84128022..e46a28caa 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -652,20 +652,21 @@ void cNBTChunkSerializer::BlockEntity(cBlockEntity * a_Entity) m_Writer.BeginList("TileEntities", TAG_Compound); } m_IsTagOpen = true; - + // Add tile-entity into NBT: switch (a_Entity->GetBlockType()) { - case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break; - case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break; - case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break; - case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; - case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; + case E_BLOCK_CHEST: AddChestEntity ((cChestEntity *) a_Entity); break; + case E_BLOCK_DISPENSER: AddDispenserEntity ((cDispenserEntity *) a_Entity); break; + case E_BLOCK_DROPPER: AddDropperEntity ((cDropperEntity *) a_Entity); break; + case E_BLOCK_FURNACE: AddFurnaceEntity ((cFurnaceEntity *) a_Entity); break; + case E_BLOCK_HOPPER: AddHopperEntity ((cHopperEntity *) a_Entity); break; case E_BLOCK_SIGN_POST: - case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; - case E_BLOCK_NOTE_BLOCK: AddNoteEntity ((cNoteEntity *) a_Entity); break; - case E_BLOCK_JUKEBOX: AddJukeboxEntity ((cJukeboxEntity *) a_Entity); break; + case E_BLOCK_WALLSIGN: AddSignEntity ((cSignEntity *) a_Entity); break; + 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"); diff --git a/src/WorldStorage/WSSCompact.cpp b/src/WorldStorage/WSSCompact.cpp index ea17a8ec1..d020b73cc 100644 --- a/src/WorldStorage/WSSCompact.cpp +++ b/src/WorldStorage/WSSCompact.cpp @@ -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" @@ -71,14 +72,15 @@ void cJsonChunkSerializer::BlockEntity(cBlockEntity * a_BlockEntity) const char * SaveInto = NULL; switch (a_BlockEntity->GetBlockType()) { - case E_BLOCK_CHEST: SaveInto = "Chests"; break; - case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break; - case E_BLOCK_DROPPER: SaveInto = "Droppers"; break; - case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break; - case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break; - 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_CHEST: SaveInto = "Chests"; break; + case E_BLOCK_DISPENSER: SaveInto = "Dispensers"; break; + case E_BLOCK_DROPPER: SaveInto = "Droppers"; break; + case E_BLOCK_FURNACE: SaveInto = "Furnaces"; break; + case E_BLOCK_SIGN_POST: SaveInto = "Signs"; break; + 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[] + } } |