Plugins can modify message in the OnChat() hook handler.
FS #376 git-svn-id: http://mc-server.googlecode.com/svn/trunk@1622 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
9dd0486faf
commit
943dcaea14
@ -20,6 +20,7 @@ function Initialize(Plugin)
|
|||||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
|
||||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
|
||||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TICK);
|
||||||
|
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
|
||||||
|
|
||||||
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "Shows a list of all the loaded entities");
|
PluginManager:BindCommand("/le", "debuggers", HandleListEntitiesCmd, "Shows a list of all the loaded entities");
|
||||||
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "Kills all the loaded entities");
|
PluginManager:BindCommand("/ke", "debuggers", HandleKillEntitiesCmd, "Kills all the loaded entities");
|
||||||
@ -631,3 +632,11 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function OnChat(a_Player, a_Message)
|
||||||
|
return false, "blabla " .. a_Message;
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -898,14 +898,15 @@ void cClientHandle::HandlePlaceBlock(int a_BlockX, int a_BlockY, int a_BlockZ, c
|
|||||||
|
|
||||||
void cClientHandle::HandleChat(const AString & a_Message)
|
void cClientHandle::HandleChat(const AString & a_Message)
|
||||||
{
|
{
|
||||||
if (!cRoot::Get()->GetServer()->Command(*this, a_Message))
|
AString Message(a_Message);
|
||||||
|
if (!cRoot::Get()->GetServer()->Command(*this, Message))
|
||||||
{
|
{
|
||||||
AString Msg;
|
AString Msg;
|
||||||
Printf(Msg, "<%s%s%s> %s",
|
Printf(Msg, "<%s%s%s> %s",
|
||||||
m_Player->GetColor().c_str(),
|
m_Player->GetColor().c_str(),
|
||||||
m_Player->GetName().c_str(),
|
m_Player->GetName().c_str(),
|
||||||
cChatColor::White.c_str(),
|
cChatColor::White.c_str(),
|
||||||
a_Message.c_str()
|
Message.c_str()
|
||||||
);
|
);
|
||||||
m_Player->GetWorld()->BroadcastChat(Msg);
|
m_Player->GetWorld()->BroadcastChat(Msg);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ bool cPlugin::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_Block
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlugin::OnChat(cPlayer * a_Player, const AString & a_Message)
|
bool cPlugin::OnChat(cPlayer * a_Player, AString & a_Message)
|
||||||
{
|
{
|
||||||
UNUSED(a_Player);
|
UNUSED(a_Player);
|
||||||
UNUSED(a_Message);
|
UNUSED(a_Message);
|
||||||
|
@ -49,7 +49,7 @@ public:
|
|||||||
* You can also return false, so default behavior is used.
|
* You can also return false, so default behavior is used.
|
||||||
**/
|
**/
|
||||||
virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
|
virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
|
||||||
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message);
|
virtual bool OnChat (cPlayer * a_Player, AString & a_Message);
|
||||||
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
||||||
virtual bool OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
virtual bool OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
||||||
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
||||||
|
@ -198,7 +198,7 @@ bool cPluginManager::CallHookBlockToPickups(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginManager::CallHookChat(cPlayer * a_Player, const AString & a_Message)
|
bool cPluginManager::CallHookChat(cPlayer * a_Player, AString & a_Message)
|
||||||
{
|
{
|
||||||
if (ExecuteCommand(a_Player, a_Message))
|
if (ExecuteCommand(a_Player, a_Message))
|
||||||
{
|
{
|
||||||
|
@ -112,7 +112,7 @@ public: // tolua_export
|
|||||||
unsigned int GetNumPlugins() const; // tolua_export
|
unsigned int GetNumPlugins() const; // tolua_export
|
||||||
|
|
||||||
bool CallHookBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
|
bool CallHookBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
|
||||||
bool CallHookChat (cPlayer * a_Player, const AString & a_Message);
|
bool CallHookChat (cPlayer * a_Player, AString & a_Message);
|
||||||
bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
||||||
bool CallHookChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
bool CallHookChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
||||||
bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc);
|
||||||
|
@ -228,7 +228,7 @@ bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message)
|
bool cPlugin_NewLua::OnChat(cPlayer * a_Player, AString & a_Message)
|
||||||
{
|
{
|
||||||
cCSLock Lock(m_CriticalSection);
|
cCSLock Lock(m_CriticalSection);
|
||||||
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHAT);
|
const char * FnName = GetHookFnName(cPluginManager::HOOK_CHAT);
|
||||||
@ -241,13 +241,17 @@ bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message)
|
|||||||
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
|
||||||
tolua_pushstring (m_LuaState, a_Message.c_str());
|
tolua_pushstring (m_LuaState, a_Message.c_str());
|
||||||
|
|
||||||
if (!CallFunction(2, 1, FnName))
|
if (!CallFunction(2, 2, FnName))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
bool bRetVal = (tolua_toboolean(m_LuaState, -2, 0) > 0);
|
||||||
lua_pop(m_LuaState, 1);
|
if (lua_isstring(m_LuaState, -1))
|
||||||
|
{
|
||||||
|
a_Message = tolua_tostring(m_LuaState, -1, "");
|
||||||
|
}
|
||||||
|
lua_pop(m_LuaState, 2);
|
||||||
return bRetVal;
|
return bRetVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
virtual void Tick(float a_Dt) override;
|
virtual void Tick(float a_Dt) override;
|
||||||
|
|
||||||
virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) override;
|
virtual bool OnBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) override;
|
||||||
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override;
|
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) override;
|
||||||
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
|
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
|
||||||
virtual bool OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc) override;
|
virtual bool OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc) override;
|
||||||
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc) override;
|
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc) override;
|
||||||
|
@ -413,7 +413,7 @@ bool cServer::Start(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cServer::Command(cClientHandle & a_Client, const AString & a_Cmd)
|
bool cServer::Command(cClientHandle & a_Client, AString & a_Cmd)
|
||||||
{
|
{
|
||||||
return cRoot::Get()->GetPluginManager()->CallHookChat(a_Client.GetPlayer(), a_Cmd);
|
return cRoot::Get()->GetPluginManager()->CallHookChat(a_Client.GetPlayer(), a_Cmd);
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ public: // tolua_export
|
|||||||
|
|
||||||
bool Start(void);
|
bool Start(void);
|
||||||
|
|
||||||
bool Command(cClientHandle & a_Client, const AString & a_Cmd);
|
bool Command(cClientHandle & a_Client, AString & a_Cmd);
|
||||||
void ExecuteConsoleCommand(const AString & a_Cmd);
|
void ExecuteConsoleCommand(const AString & a_Cmd);
|
||||||
|
|
||||||
/// Binds the built-in console commands with the plugin manager
|
/// Binds the built-in console commands with the plugin manager
|
||||||
|
Loading…
Reference in New Issue
Block a user