diff options
author | andrew <xdotftw@gmail.com> | 2014-01-18 18:58:46 +0100 |
---|---|---|
committer | andrew <xdotftw@gmail.com> | 2014-01-18 18:58:46 +0100 |
commit | 02c9aa2b1e86974df4ef8ea152465719169bdac5 (patch) | |
tree | f5e8ba8560b0939e4f3bfb0fefd9e4e5e55262e2 /src/ClientHandle.cpp | |
parent | Command blocks: Execute() (diff) | |
download | cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.tar cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.tar.gz cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.tar.bz2 cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.tar.lz cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.tar.xz cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.tar.zst cuberite-02c9aa2b1e86974df4ef8ea152465719169bdac5.zip |
Diffstat (limited to '')
-rw-r--r-- | src/ClientHandle.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index c8513d516..0a97ba6c8 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -8,6 +8,7 @@ #include "Entities/Player.h" #include "Inventory.h" #include "BlockEntities/ChestEntity.h" +#include "BlockEntities/CommandBlockEntity.h" #include "BlockEntities/SignEntity.h" #include "UI/Window.h" #include "Item.h" @@ -545,6 +546,15 @@ void cClientHandle::HandlePlayerPos(double a_PosX, double a_PosY, double a_PosZ, void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString & a_Message) { + if (a_Channel == "MC|AdvCdm") // Command block + { + const char* Data = a_Message.c_str(); + + HandleCommandBlockMessage(Data, a_Message.size()); + + return; + } + cPluginManager::Get()->CallHookPluginMessage(*this, a_Channel, a_Message); } @@ -552,6 +562,60 @@ void cClientHandle::HandlePluginMessage(const AString & a_Channel, const AString +void cClientHandle::HandleCommandBlockMessage(const char* a_Data, unsigned int a_Length) +{ + if (a_Length < 14) + { + LOGD("Malformed MC|AdvCdm packet."); + return; + } + + int BlockX, BlockY, BlockZ; + + AString Command; + + switch (a_Data[0]) + { + case 0x00: + { + BlockX = GetBEInt(a_Data + 1); + BlockY = GetBEInt(a_Data + 5); + BlockZ = GetBEInt(a_Data + 9); + + Command = AString(a_Data + 14, (int)a_Data[13]); + break; + } + + default: + { + LOGD("Unhandled MC|AdvCdm packet mode."); + return; + } + } + + 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); +} + + + + + void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) { LOGD("HandleLeftClick: {%i, %i, %i}; Face: %i; Stat: %i", |