summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-11-15 12:37:12 +0100
committerHowaner <franzi.moos@googlemail.com>2014-11-15 12:37:12 +0100
commitba1f0958e825b0c8075aa85fe23448f90c0456b3 (patch)
tree8cf3ff67bbffc470021095975c204d9abdb80fdd
parentMissing space :D (diff)
downloadcuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.tar
cuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.tar.gz
cuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.tar.bz2
cuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.tar.lz
cuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.tar.xz
cuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.tar.zst
cuberite-ba1f0958e825b0c8075aa85fe23448f90c0456b3.zip
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnPlayerAnimation.lua2
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnPlayerLeftClick.lua25
-rw-r--r--MCServer/Plugins/APIDump/Hooks/OnPlayerRightClick.lua10
-rw-r--r--src/Bindings/Plugin.h2
-rw-r--r--src/Bindings/PluginLua.cpp10
-rw-r--r--src/Bindings/PluginLua.h2
-rw-r--r--src/Bindings/PluginManager.cpp4
-rw-r--r--src/Bindings/PluginManager.h2
-rw-r--r--src/ClientHandle.cpp54
-rw-r--r--src/ClientHandle.h5
-rw-r--r--src/Protocol/Protocol18x.cpp2
11 files changed, 81 insertions, 37 deletions
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerAnimation.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerAnimation.lua
index baf99834e..9d7d5fa5a 100644
--- a/MCServer/Plugins/APIDump/Hooks/OnPlayerAnimation.lua
+++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerAnimation.lua
@@ -2,7 +2,7 @@ return
{
HOOK_PLAYER_ANIMATION =
{
- CalledWhen = "A client has sent an Animation packet (0x12)",
+ CalledWhen = "<b>DEPRECATED!</b> A client has sent an Animation packet (0x12)",
DefaultFnName = "OnPlayerAnimation", -- also used as pagename
Desc = [[
This hook is called when the server receives an Animation packet (0x12) from the client.</p>
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerLeftClick.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerLeftClick.lua
index 1d9585c55..38a998e1c 100644
--- a/MCServer/Plugins/APIDump/Hooks/OnPlayerLeftClick.lua
+++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerLeftClick.lua
@@ -2,24 +2,19 @@ return
{
HOOK_PLAYER_LEFT_CLICK =
{
- CalledWhen = "A left-click packet is received from the client. Plugin may override / refuse.",
+ CalledWhen = "A client do a left click. Plugin may override / refuse.",
DefaultFnName = "OnPlayerLeftClick", -- also used as pagename
Desc = [[
- This hook is called when MCServer receives a left-click packet from the {{cClientHandle|client}}. It
- is called before any processing whatsoever is performed on the packet, meaning that hacked /
- malicious clients may be trigerring this event very often and with unchecked parameters. Therefore
- plugin authors are advised to use extreme caution with this callback.</p>
+ This hook is called when a player do a left click to a specific block or the air.</p>
<p>
Plugins may refuse the default processing for the packet, causing MCServer to behave as if the
packet has never arrived. This may, however, create inconsistencies in the client - the client may
think that they broke a block, while the server didn't process the breaking, etc. For this reason,
if a plugin refuses the processing, MCServer sends the block specified in the packet back to the
- client (as if placed anew), if the status code specified a block-break action. For other actions,
- plugins must rectify the situation on their own.</p>
+ client (as if placed anew).</p>
<p>
- The client sends the left-click packet for several other occasions, such as dropping the held item
- (Q keypress) or shooting an arrow. This is reflected in the Status code. Consult the
- <a href="http://wiki.vg/Protocol#0x0E">protocol documentation</a> for details on the actions.
+ If BlockFace is BLOCK_FACE_NONE, the client interacts with the air and not with a specific block.
+ In this case, BlockX/Y/Z are 0.
]],
Params =
{
@@ -28,15 +23,13 @@ return
{ Name = "BlockY", Type = "number", Notes = "Y-coord of the block" },
{ Name = "BlockZ", Type = "number", Notes = "Z-coord of the block" },
{ Name = "BlockFace", Type = "number", Notes = "Face of the block upon which the player interacted. One of the BLOCK_FACE_ constants" },
- { Name = "Action", Type = "number", Notes = "Action to be performed on the block (\"status\" in the protocol docs)" },
},
Returns = [[
- If the function returns false or no value, MCServer calls other plugins' callbacks and finally sends
- the packet for further processing.</p>
+ If the function returns false or no value, MCServer calls other plugins' callbacks and finally break
+ the block.</p>
<p>
- If the function returns true, no other plugins are called, processing is halted. If the action was a
- block dig, MCServer sends the block specified in the coords back to the client. The packet is
- dropped.
+ If the function returns true, no other plugins are called, processing is halted.
+ MCServer sends the block specified in the coords back to the client. The packet is dropped.
]],
}, -- HOOK_PLAYER_LEFT_CLICK
}
diff --git a/MCServer/Plugins/APIDump/Hooks/OnPlayerRightClick.lua b/MCServer/Plugins/APIDump/Hooks/OnPlayerRightClick.lua
index de9b3662c..9f23a8039 100644
--- a/MCServer/Plugins/APIDump/Hooks/OnPlayerRightClick.lua
+++ b/MCServer/Plugins/APIDump/Hooks/OnPlayerRightClick.lua
@@ -2,17 +2,19 @@ return
{
HOOK_PLAYER_RIGHT_CLICK =
{
- CalledWhen = "A right-click packet is received from the client. Plugin may override / refuse.",
+ CalledWhen = "The client do a right click. Plugin may override / refuse.",
DefaultFnName = "OnPlayerRightClick", -- also used as pagename
Desc = [[
This hook is called when MCServer receives a right-click packet from the {{cClientHandle|client}}. It
is called before any processing whatsoever is performed on the packet, meaning that hacked /
- malicious clients may be trigerring this event very often and with unchecked parameters. Therefore
+ malicious clients may be trigerring this even very often and with unchecked parameters. Therefore
plugin authors are advised to use extreme caution with this callback.</p>
<p>
Plugins may refuse the default processing for the packet, causing MCServer to behave as if the
packet has never arrived. This may, however, create inconsistencies in the client - the client may
- think that they placed a block, while the server didn't process the placing, etc.
+ think that they placed a block, while the server didn't process the placing, etc.</p>
+ <p>
+ If BlockFace is BLOCK_FACE_NONE, the player interacts with the air and not with a specific block.
]],
Params =
{
@@ -37,4 +39,4 @@ return
-
+t
diff --git a/src/Bindings/Plugin.h b/src/Bindings/Plugin.h
index 8cc9ff0cd..75568848c 100644
--- a/src/Bindings/Plugin.h
+++ b/src/Bindings/Plugin.h
@@ -74,7 +74,7 @@ public:
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 0;
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) = 0;
virtual bool OnPlayerJoined (cPlayer & a_Player) = 0;
- virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) = 0;
+ virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) = 0;
virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition) = 0;
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
diff --git a/src/Bindings/PluginLua.cpp b/src/Bindings/PluginLua.cpp
index 391d8bcbe..004478806 100644
--- a/src/Bindings/PluginLua.cpp
+++ b/src/Bindings/PluginLua.cpp
@@ -817,14 +817,14 @@ bool cPluginLua::OnPlayerJoined(cPlayer & a_Player)
-bool cPluginLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
+bool cPluginLua::OnPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
{
cCSLock Lock(m_CriticalSection);
bool res = false;
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_LEFT_CLICK];
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
{
- m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status, cLuaState::Return, res);
+ m_LuaState.Call((int)(**itr), &a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, DIG_STATUS_STARTED, cLuaState::Return, res);
if (res)
{
return true;
@@ -1635,7 +1635,11 @@ bool cPluginLua::AddHookRef(int a_HookType, int a_FnRefIdx)
Ref = nullptr;
return false;
}
-
+
+ if (a_HookType == cPluginManager::HOOK_PLAYER_ANIMATION)
+ {
+ LOGWARNING("Plugin %s uses the deprecated HOOK_PLAYER_ANIMATION hook!", GetName().c_str());
+ }
m_HookMap[a_HookType].push_back(Ref);
return true;
}
diff --git a/src/Bindings/PluginLua.h b/src/Bindings/PluginLua.h
index 6bb134efc..267c37d4a 100644
--- a/src/Bindings/PluginLua.h
+++ b/src/Bindings/PluginLua.h
@@ -98,7 +98,7 @@ public:
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override;
virtual bool OnPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel) override;
virtual bool OnPlayerJoined (cPlayer & a_Player) override;
- virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status) override;
+ virtual bool OnPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace) override;
virtual bool OnPlayerMoving (cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition) override;
virtual bool OnPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
virtual bool OnPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index f63578885..d68f5287a 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -828,14 +828,14 @@ bool cPluginManager::CallHookPlayerJoined(cPlayer & a_Player)
-bool cPluginManager::CallHookPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status)
+bool cPluginManager::CallHookPlayerLeftClick(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace)
{
FIND_HOOK(HOOK_PLAYER_LEFT_CLICK);
VERIFY_HOOK;
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
- if ((*itr)->OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status))
+ if ((*itr)->OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
{
return true;
}
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index bc8c1f5e6..7024edb7b 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -208,7 +208,7 @@ public:
bool CallHookPlayerFoodLevelChange (cPlayer & a_Player, int a_NewFoodLevel);
bool CallHookPlayerJoined (cPlayer & a_Player);
bool CallHookPlayerMoving (cPlayer & a_Player, const Vector3d a_OldPosition, const Vector3d a_NewPosition);
- bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
+ bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace);
bool CallHookPlayerPlacedBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerPlacingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
bool CallHookPlayerRightClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index a4be87fd1..df3317270 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -7,6 +7,7 @@
#include "Bindings/PluginManager.h"
#include "Entities/Player.h"
#include "Inventory.h"
+#include "LineBlockTracer.h"
#include "BlockEntities/BeaconEntity.h"
#include "BlockEntities/ChestEntity.h"
#include "BlockEntities/CommandBlockEntity.h"
@@ -919,6 +920,45 @@ void cClientHandle::HandleCommandBlockEntityChange(int a_EntityID, const AString
+void cClientHandle::HandleSwingArm()
+{
+ m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 0, this);
+ cRoot::Get()->GetPluginManager()->CallHookPlayerAnimation(*m_Player, 1);
+
+ // Test air left click
+ class cCallback :
+ public cBlockTracer::cCallbacks
+ {
+ public:
+
+ virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
+ {
+ if (a_BlockType != E_BLOCK_AIR)
+ {
+ return true;
+ }
+ return false;
+ }
+ } Callback;
+
+ cLineBlockTracer Tracer(*m_Player->GetWorld(), Callback);
+ Vector3d Start(m_Player->GetEyePosition() + m_Player->GetLookVector());
+ Vector3d End(m_Player->GetEyePosition() + m_Player->GetLookVector() * 5);
+
+ if (Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z))
+ {
+ // Air click.
+ LOGD("%s do a left click to the air!", m_Player->GetName());
+
+ // Call the left click hook with BLOCK_FACE_NONE
+ cRoot::Get()->GetPluginManager()->CallHookPlayerLeftClick(*m_Player, 0, 0, 0, BLOCK_FACE_NONE);
+ }
+}
+
+
+
+
+
void cClientHandle::HandleAnvilItemName(const AString & a_ItemName)
{
if ((m_Player->GetWindow() == nullptr) || (m_Player->GetWindow()->GetWindowType() != cWindow::wtAnvil))
@@ -975,12 +1015,6 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
}
cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager();
- if (PlgMgr->CallHookPlayerLeftClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status))
- {
- // A plugin doesn't agree with the action, replace the block on the client and quit:
- m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
- return;
- }
switch (a_Status)
{
@@ -1018,6 +1052,13 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB
case DIG_STATUS_STARTED:
{
+ if (PlgMgr->CallHookPlayerLeftClick(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace))
+ {
+ // A plugin doesn't agree with the action, replace the block on the client and quit:
+ m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
+ return;
+ }
+
BLOCKTYPE OldBlock;
NIBBLETYPE OldMeta;
m_Player->GetWorld()->GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, OldBlock, OldMeta);
@@ -1149,6 +1190,7 @@ void cClientHandle::HandleBlockDigFinished(int a_BlockX, int a_BlockY, int a_Blo
m_LastDigBlockX, m_LastDigBlockY, m_LastDigBlockZ,
(m_HasStartedDigging ? "True" : "False")
);
+ m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player);
return;
}
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index f8b5bcb5b..f1653b344 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -246,7 +246,10 @@ public:
void PacketBufferFull(void);
void PacketUnknown(UInt32 a_PacketType);
void PacketError(unsigned char a_PacketType);
-
+
+ /** Called when the protocol receives a animation packet with id 1. */
+ void HandleSwingArm();
+
/** Called when the protocol receives a MC|ItemName plugin message, indicating that the player named
an item in the anvil UI. */
void HandleAnvilItemName(const AString & a_ItemName);
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 2fe8379fb..68191ef64 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -2203,7 +2203,7 @@ void cProtocol180::HandlePacketCreativeInventoryAction(cByteBuffer & a_ByteBuffe
void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
{
- m_Client->GetPlayer()->GetWorld()->BroadcastEntityAnimation(*m_Client->GetPlayer(), 0, m_Client);
+ m_Client->HandleSwingArm();
}