summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-10 18:46:15 +0200
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-10 18:46:15 +0200
commit273ddcbfff87676d10c04e90ba98a74035d9d30a (patch)
tree618ad418f30685a33d8c5164cc58a36688aed338 /source
parentAuthentication should work now.. (diff)
downloadcuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.tar
cuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.tar.gz
cuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.tar.bz2
cuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.tar.lz
cuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.tar.xz
cuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.tar.zst
cuberite-273ddcbfff87676d10c04e90ba98a74035d9d30a.zip
Diffstat (limited to '')
-rw-r--r--source/cPluginManager.cpp9
-rw-r--r--source/cPlugin_Squirrel.cpp44
-rw-r--r--source/squirrelbindings/SquirrelObject.h9
3 files changed, 51 insertions, 11 deletions
diff --git a/source/cPluginManager.cpp b/source/cPluginManager.cpp
index 99523183e..eea9f1c01 100644
--- a/source/cPluginManager.cpp
+++ b/source/cPluginManager.cpp
@@ -12,6 +12,7 @@
#include "cSquirrelCommandBinder.h"
#include "../iniFile/iniFile.h"
#include "tolua++.h"
+#include "cPlayer.h"
#include "squirrelbindings/SquirrelBindings.h"
#include "squirrelbindings/SquirrelFunctions.h"
@@ -206,6 +207,14 @@ bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...)
return true;
}
+ //Check if it was a standard command (starts with a slash)
+ if(Message[0] == '/')
+ {
+ Player->SendMessage("Unknown Command");
+ LOGINFO("Player \"%s\" issued command: %s", Player->GetName().c_str(), Message);
+ return true; //Cancel sending
+ }
+
if (Plugins == m_Hooks.end())
{
return false;
diff --git a/source/cPlugin_Squirrel.cpp b/source/cPlugin_Squirrel.cpp
index 892e8e433..4ce412dbf 100644
--- a/source/cPlugin_Squirrel.cpp
+++ b/source/cPlugin_Squirrel.cpp
@@ -77,6 +77,8 @@ void cPlugin_Squirrel::OnDisable()
{
cCSLock Lock(m_CriticalSection);
+ if(!m_Plugin->HasFunction("OnDisable")) return;
+
m_Plugin->GetFunction("OnDisable").Execute();
}
@@ -87,6 +89,8 @@ void cPlugin_Squirrel::OnDisable()
void cPlugin_Squirrel::Tick(float a_Dt)
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnTick")) return;
m_Plugin->GetFunction("OnTick").Execute(a_Dt);
}
@@ -98,6 +102,8 @@ void cPlugin_Squirrel::Tick(float a_Dt)
bool cPlugin_Squirrel::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnCollectItem")) return false;
return m_Plugin->GetFunction("OnCollectItem").Evaluate<bool>(a_Pickup, a_Player);
}
@@ -110,6 +116,7 @@ bool cPlugin_Squirrel::OnDisconnect(const AString & a_Reason, cPlayer* a_Player
{
cCSLock Lock( m_CriticalSection );
+ if(!m_Plugin->HasFunction("OnDisconnect")) return false;
return m_Plugin->GetFunction("OnDisconnect").Evaluate<bool>(a_Reason, a_Player);
}
@@ -121,6 +128,8 @@ bool cPlugin_Squirrel::OnDisconnect(const AString & a_Reason, cPlayer* a_Player
bool cPlugin_Squirrel::OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnBlockPlace")) return false;
return m_Plugin->GetFunction("OnBlockPlace").Evaluate<bool>(a_PacketData, a_Player);
}
@@ -133,6 +142,8 @@ bool cPlugin_Squirrel::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Pl
{
cCSLock Lock( m_CriticalSection );
+ if(!m_Plugin->HasFunction("OnBlockDig")) return false;
+
return m_Plugin->GetFunction("OnBlockDig").Evaluate<bool>(a_PacketData, a_Player, a_PickupItem);
}
@@ -143,6 +154,8 @@ bool cPlugin_Squirrel::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Pl
bool cPlugin_Squirrel::OnChat( const char* a_Chat, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnChat")) return false;
return m_Plugin->GetFunction("OnChat").Evaluate<bool>(a_Chat, a_Player);
@@ -155,6 +168,8 @@ bool cPlugin_Squirrel::OnChat( const char* a_Chat, cPlayer* a_Player )
bool cPlugin_Squirrel::OnLogin( cPacket_Login* a_PacketData )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnLogin")) return false;
return m_Plugin->GetFunction("OnLogin").Evaluate<bool>(a_PacketData);
}
@@ -166,6 +181,8 @@ bool cPlugin_Squirrel::OnLogin( cPacket_Login* a_PacketData )
void cPlugin_Squirrel::OnPlayerSpawn( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnPlayerSpawn")) return;
return m_Plugin->GetFunction("OnPlayerSpawn").Execute(a_Player);
@@ -178,6 +195,8 @@ void cPlugin_Squirrel::OnPlayerSpawn( cPlayer* a_Player )
bool cPlugin_Squirrel::OnPlayerJoin( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnPlayerJoin")) return false;
return m_Plugin->GetFunction("OnPlayerJoin").Evaluate<bool>(a_Player);
}
@@ -189,6 +208,8 @@ bool cPlugin_Squirrel::OnPlayerJoin( cPlayer* a_Player )
void cPlugin_Squirrel::OnPlayerMove( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnPlayerMove")) return;
return m_Plugin->GetFunction("OnPlayerMove").Execute(a_Player);
@@ -201,6 +222,8 @@ void cPlugin_Squirrel::OnPlayerMove( cPlayer* a_Player )
void cPlugin_Squirrel::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo )
{
cCSLock Lock( m_CriticalSection );
+
+ if(!m_Plugin->HasFunction("OnTakeDamage")) return;
return m_Plugin->GetFunction("OnTakeDamage")(a_Pawn, a_TakeDamageInfo);
}
@@ -212,7 +235,7 @@ void cPlugin_Squirrel::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamage
bool cPlugin_Squirrel::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
{
cCSLock Lock( m_CriticalSection );
-
+ if(!m_Plugin->HasFunction("OnKilled")) return false;
return m_Plugin->GetFunction("OnKilled").Evaluate<bool>(a_Killed, a_Killer);
}
@@ -223,7 +246,7 @@ bool cPlugin_Squirrel::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
void cPlugin_Squirrel::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnChunkGenerated")) return;
return m_Plugin->GetFunction("OnChunkGenerated")(a_World, a_ChunkX, a_ChunkZ);
}
@@ -234,7 +257,7 @@ void cPlugin_Squirrel::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_Ch
bool cPlugin_Squirrel::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk)
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnChunkGenerating")) return false;
return m_Plugin->GetFunction("OnChunkGenerating").Evaluate<bool>(a_World, a_ChunkX, a_ChunkZ, a_pLuaChunk);
}
@@ -245,7 +268,7 @@ bool cPlugin_Squirrel::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_C
bool cPlugin_Squirrel::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnPreCrafting")) return false;
return m_Plugin->GetFunction("OnPreCrafting").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe);
}
@@ -257,7 +280,7 @@ bool cPlugin_Squirrel::OnPreCrafting(const cPlayer * a_Player, const cCraftingGr
bool cPlugin_Squirrel::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnCraftingNoRecipe")) return false;
return m_Plugin->GetFunction("OnCraftingNoRecipe").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe);
}
@@ -269,7 +292,7 @@ bool cPlugin_Squirrel::OnPostCrafting(const cPlayer * a_Player, const cCraftingG
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnPostCrafting")) return false;
return m_Plugin->GetFunction("OnPostCrafting").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe);
}
@@ -284,7 +307,7 @@ bool cPlugin_Squirrel::OnBlockToPickup(
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnBlockToPickup")) return false;
return m_Plugin->GetFunction("OnBlockToPickup").Evaluate<bool>(a_BlockType, a_BlockMeta, (cPlayer *) a_Player, a_EquippedItem, a_Pickups);
}
@@ -297,7 +320,7 @@ bool cPlugin_Squirrel::OnWeatherChanged(cWorld * a_World)
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnWeatherChanged")) return false;
return m_Plugin->GetFunction("OnWeatherChanged").Evaluate<bool>(a_World);
}
@@ -313,7 +336,7 @@ bool cPlugin_Squirrel::OnUpdatingSign(
{
cCSLock Lock(m_CriticalSection);
-
+ if(!m_Plugin->HasFunction("OnUpdatingSign")) return false;
return m_Plugin->GetFunction("OnUpdatingSign")
.Evaluate<bool>(
a_World,
@@ -337,6 +360,9 @@ bool cPlugin_Squirrel::OnUpdatedSign(
const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4
)
{
+ cCSLock Lock(m_CriticalSection);
+
+ if(!m_Plugin->HasFunction("OnUpdatedSign")) return false;
return m_Plugin->GetFunction("OnUpdatedSign")
.Evaluate<bool>(
a_World,
diff --git a/source/squirrelbindings/SquirrelObject.h b/source/squirrelbindings/SquirrelObject.h
index 1ac6fa105..547dd4e02 100644
--- a/source/squirrelbindings/SquirrelObject.h
+++ b/source/squirrelbindings/SquirrelObject.h
@@ -9,15 +9,20 @@ public:
m_SquirrelObject = a_Obj;
}
- Sqrat::Function GetFunction(const char *methodName)
+ Sqrat::Function GetFunction(const char *a_MethodName)
{
if(m_SquirrelObject.IsNull())
return Sqrat::Function();
- Sqrat::Function method(m_SquirrelObject, methodName);
+ Sqrat::Function method(m_SquirrelObject, a_MethodName);
return method;
}
+ bool HasFunction(const char *a_MethodName)
+ {
+ return !this->GetFunction(a_MethodName).IsNull();
+ }
+
protected:
Sqrat::Object m_SquirrelObject;