Merge branch 'FishingHook'
This commit is contained in:
commit
d4e29a0d18
20
MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua
Normal file
20
MCServer/Plugins/APIDump/Hooks/OnPlayerFished.lua
Normal file
@ -0,0 +1,20 @@
|
||||
return
|
||||
{
|
||||
HOOK_PLAYER_FISHED =
|
||||
{
|
||||
CalledWhen = "A player gets a reward from fishing.",
|
||||
DefaultFnName = "OnPlayerFished", -- also used as pagename
|
||||
Desc = [[
|
||||
This hook gets called after a player reels in the fishing rod. This is a notification-only hook, the reward has already been decided. If a plugin needs to modify the reward, use the {{OnPlayerFishing|HOOK_PLAYER_FISHING}} hook.
|
||||
]],
|
||||
Params =
|
||||
{
|
||||
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." },
|
||||
{ Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, treasure and junk." },
|
||||
},
|
||||
Returns = [[
|
||||
If the function returns false or no value, the next plugin's callback is called. If the function returns true, no other
|
||||
callback is called for this event.
|
||||
]],
|
||||
}, -- HOOK_PLAYER_FISHED
|
||||
};
|
21
MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua
Normal file
21
MCServer/Plugins/APIDump/Hooks/OnPlayerFishing.lua
Normal file
@ -0,0 +1,21 @@
|
||||
return
|
||||
{
|
||||
HOOK_PLAYER_FISHING =
|
||||
{
|
||||
CalledWhen = "A player is about to get a reward from fishing.",
|
||||
DefaultFnName = "OnPlayerFishing", -- also used as pagename
|
||||
Desc = [[
|
||||
This hook gets called when a player right clicks with a fishing rod while the floater is under water. The reward is already descided, but the plugin may change it.
|
||||
]],
|
||||
Params =
|
||||
{
|
||||
{ Name = "Player", Type = "{{cPlayer}}", Notes = "The player who pulled the fish in." },
|
||||
{ Name = "Reward", Type = "{{cItems}}", Notes = "The reward the player gets. It can be a fish, treasure and junk." },
|
||||
},
|
||||
Returns = [[
|
||||
If the function returns false or no value, the next plugin's callback is called. Afterwards, the
|
||||
server gives the player his reward. If the function returns true, no other
|
||||
callback is called for this event and the player doesn't get his reward.
|
||||
]],
|
||||
}, -- HOOK_PLAYER_FISHING
|
||||
};
|
@ -468,6 +468,18 @@ void cLuaState::Push(cItems * a_Items)
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(const cItems & a_Items)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, (void *)&a_Items, "cItems");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::Push(cClientHandle * a_Client)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
@ -165,6 +165,7 @@ public:
|
||||
void Push(cMonster * a_Monster);
|
||||
void Push(cItem * a_Item);
|
||||
void Push(cItems * a_Items);
|
||||
void Push(const cItems & a_Items);
|
||||
void Push(cClientHandle * a_ClientHandle);
|
||||
void Push(cPickup * a_Pickup);
|
||||
void Push(cChunkDesc * a_ChunkDesc);
|
||||
|
@ -68,6 +68,8 @@ public:
|
||||
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
|
||||
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) = 0;
|
||||
virtual bool OnPlayerEating (cPlayer & a_Player) = 0;
|
||||
virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) = 0;
|
||||
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) = 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 OnPlayerMoved (cPlayer & a_Player) = 0;
|
||||
|
@ -630,6 +630,46 @@ bool cPluginLua::OnPlayerEating(cPlayer & a_Player)
|
||||
|
||||
|
||||
|
||||
bool cPluginLua::OnPlayerFished(cPlayer & a_Player, const cItems & a_Reward)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
bool res = false;
|
||||
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHED];
|
||||
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
||||
{
|
||||
m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res);
|
||||
if (res)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginLua::OnPlayerFishing(cPlayer & a_Player, cItems & a_Reward)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
bool res = false;
|
||||
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_PLAYER_FISHING];
|
||||
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
||||
{
|
||||
m_LuaState.Call((int)(**itr), &a_Player, a_Reward, cLuaState::Return, res);
|
||||
if (res)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginLua::OnPlayerJoined(cPlayer & a_Player)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
|
@ -65,6 +65,8 @@ public:
|
||||
virtual bool OnPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) override;
|
||||
virtual bool OnPlayerEating (cPlayer & a_Player) override;
|
||||
virtual bool OnPlayerFished (cPlayer & a_Player, const cItems & a_Reward) override;
|
||||
virtual bool OnPlayerFishing (cPlayer & a_Player, cItems & a_Reward) override;
|
||||
virtual bool OnPlayerJoined (cPlayer & a_Player) override;
|
||||
virtual bool OnPlayerMoved (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;
|
||||
|
@ -694,6 +694,48 @@ bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player)
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems a_Reward)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHED);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnPlayerFished(a_Player, a_Reward))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_FISHING);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnPlayerFishing(a_Player, a_Reward))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookPlayerJoined(cPlayer & a_Player)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_PLAYER_JOINED);
|
||||
|
@ -80,6 +80,8 @@ public: // tolua_export
|
||||
HOOK_PLAYER_BREAKING_BLOCK,
|
||||
HOOK_PLAYER_BROKEN_BLOCK,
|
||||
HOOK_PLAYER_EATING,
|
||||
HOOK_PLAYER_FISHED,
|
||||
HOOK_PLAYER_FISHING,
|
||||
HOOK_PLAYER_JOINED,
|
||||
HOOK_PLAYER_LEFT_CLICK,
|
||||
HOOK_PLAYER_MOVING,
|
||||
@ -168,6 +170,8 @@ public: // tolua_export
|
||||
bool CallHookPlayerBreakingBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerBrokenBlock (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
|
||||
bool CallHookPlayerEating (cPlayer & a_Player);
|
||||
bool CallHookPlayerFished (cPlayer & a_Player, const cItems a_Reward);
|
||||
bool CallHookPlayerFishing (cPlayer & a_Player, cItems a_Reward);
|
||||
bool CallHookPlayerJoined (cPlayer & a_Player);
|
||||
bool CallHookPlayerMoving (cPlayer & a_Player);
|
||||
bool CallHookPlayerLeftClick (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
|
||||
|
@ -9,9 +9,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Bindings/PluginManager.h"
|
||||
#include "../Entities/Floater.h"
|
||||
#include "../Entities/Entity.h"
|
||||
#include "../Item.h"
|
||||
#include "../Root.h"
|
||||
|
||||
|
||||
|
||||
@ -210,10 +212,14 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (cRoot::Get()->GetPluginManager()->CallHookPlayerFishing(*a_Player, Drops))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
Vector3d FloaterPos = FloaterInfo.GetPos();
|
||||
Vector3d FlyDirection = a_Player->GetEyePosition() - FloaterPos;
|
||||
a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.y + 1, FlyDirection.z);
|
||||
cRoot::Get()->GetPluginManager()->CallHookPlayerFished(*a_Player, Drops);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user