summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2018-03-02 11:40:48 +0100
committerGitHub <noreply@github.com>2018-03-02 11:40:48 +0100
commit4f26f653e1ae168a050f3eca3e8073eca3f10367 (patch)
tree9f43571855964c5d8fe869cd8b7d5576a6ef98ac
parentcLightingThread: Faster chunk reading (#4185) (diff)
downloadcuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.tar
cuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.tar.gz
cuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.tar.bz2
cuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.tar.lz
cuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.tar.xz
cuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.tar.zst
cuberite-4f26f653e1ae168a050f3eca3e8073eca3f10367.zip
-rw-r--r--src/Bindings/PluginManager.cpp878
-rw-r--r--src/Bindings/PluginManager.h6
2 files changed, 252 insertions, 632 deletions
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 9a9b56792..4cbc36767 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -12,13 +12,6 @@
#include "../IniFile.h"
#include "../Entities/Player.h"
-#define FIND_HOOK(a_HookName) HookMap::iterator Plugins = m_Hooks.find(a_HookName);
-#define VERIFY_HOOK \
- if (Plugins == m_Hooks.end()) \
- { \
- return false; \
- }
-
@@ -209,13 +202,15 @@ void cPluginManager::Tick(float a_Dt)
ReloadPluginsNow();
}
- FIND_HOOK(HOOK_TICK);
- if (Plugins != m_Hooks.end())
+ auto Plugins = m_Hooks.find(HOOK_TICK);
+ if (Plugins == m_Hooks.end())
{
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- (*itr)->Tick(a_Dt);
- }
+ return;
+ }
+
+ for (auto * Plugin : Plugins->second)
+ {
+ Plugin->Tick(a_Dt);
}
}
@@ -223,19 +218,29 @@ void cPluginManager::Tick(float a_Dt)
-bool cPluginManager::CallHookBlockSpread(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
+template <typename HookFunction>
+bool cPluginManager::GenericCallHook(PluginHook a_HookName, HookFunction a_HookFunction)
{
- FIND_HOOK(HOOK_BLOCK_SPREAD);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ auto Plugins = m_Hooks.find(a_HookName);
+ if (Plugins == m_Hooks.end())
{
- if ((*itr)->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source))
+ return false;
+ }
+
+ return std::any_of(Plugins->second.begin(), Plugins->second.end(), a_HookFunction);
+}
+
+
+
+
+
+bool cPluginManager::CallHookBlockSpread(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
+{
+ return GenericCallHook(HOOK_BLOCK_SPREAD, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source);
}
- }
- return false;
+ );
}
@@ -248,17 +253,11 @@ bool cPluginManager::CallHookBlockToPickups(
cItems & a_Pickups
)
{
- FIND_HOOK(HOOK_BLOCK_TO_PICKUPS);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups))
+ return GenericCallHook(HOOK_BLOCK_TO_PICKUPS, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnBlockToPickups(a_World, a_Digger, a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_BlockMeta, a_Pickups);
}
- }
- return false;
+ );
}
@@ -267,17 +266,11 @@ bool cPluginManager::CallHookBlockToPickups(
bool cPluginManager::CallHookBrewingCompleted(cWorld & a_World, cBrewingstandEntity & a_Brewingstand)
{
- FIND_HOOK(HOOK_BREWING_COMPLETED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnBrewingCompleted(a_World, a_Brewingstand))
+ return GenericCallHook(HOOK_BREWING_COMPLETED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnBrewingCompleted(a_World, a_Brewingstand);
}
- }
- return false;
+ );
}
@@ -286,17 +279,11 @@ bool cPluginManager::CallHookBrewingCompleted(cWorld & a_World, cBrewingstandEnt
bool cPluginManager::CallHookBrewingCompleting(cWorld & a_World, cBrewingstandEntity & a_Brewingstand)
{
- FIND_HOOK(HOOK_BREWING_COMPLETING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnBrewingCompleting(a_World, a_Brewingstand))
+ return GenericCallHook(HOOK_BREWING_COMPLETING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnBrewingCompleting(a_World, a_Brewingstand);
}
- }
- return false;
+ );
}
@@ -352,18 +339,11 @@ bool cPluginManager::CallHookChat(cPlayer & a_Player, AString & a_Message)
return true; // Cancel sending
}
- FIND_HOOK(HOOK_CHAT);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnChat(a_Player, a_Message))
+ return GenericCallHook(HOOK_CHAT, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnChat(a_Player, a_Message);
}
- }
-
- return false;
+ );
}
@@ -372,17 +352,11 @@ bool cPluginManager::CallHookChat(cPlayer & a_Player, AString & a_Message)
bool cPluginManager::CallHookChunkAvailable(cWorld & a_World, int a_ChunkX, int a_ChunkZ)
{
- FIND_HOOK(HOOK_CHUNK_AVAILABLE);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnChunkAvailable(a_World, a_ChunkX, a_ChunkZ))
+ return GenericCallHook(HOOK_CHUNK_AVAILABLE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnChunkAvailable(a_World, a_ChunkX, a_ChunkZ);
}
- }
- return false;
+ );
}
@@ -391,17 +365,11 @@ bool cPluginManager::CallHookChunkAvailable(cWorld & a_World, int a_ChunkX, int
bool cPluginManager::CallHookChunkGenerated(cWorld & a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
{
- FIND_HOOK(HOOK_CHUNK_GENERATED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnChunkGenerated(a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc))
+ return GenericCallHook(HOOK_CHUNK_GENERATED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnChunkGenerated(a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc);
}
- }
- return false;
+ );
}
@@ -410,17 +378,11 @@ bool cPluginManager::CallHookChunkGenerated(cWorld & a_World, int a_ChunkX, int
bool cPluginManager::CallHookChunkGenerating(cWorld & a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_ChunkDesc)
{
- FIND_HOOK(HOOK_CHUNK_GENERATING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnChunkGenerating(a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc))
+ return GenericCallHook(HOOK_CHUNK_GENERATING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnChunkGenerating(a_World, a_ChunkX, a_ChunkZ, a_ChunkDesc);
}
- }
- return false;
+ );
}
@@ -429,17 +391,11 @@ bool cPluginManager::CallHookChunkGenerating(cWorld & a_World, int a_ChunkX, int
bool cPluginManager::CallHookChunkUnloaded(cWorld & a_World, int a_ChunkX, int a_ChunkZ)
{
- FIND_HOOK(HOOK_CHUNK_UNLOADED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnChunkUnloaded(a_World, a_ChunkX, a_ChunkZ))
+ return GenericCallHook(HOOK_CHUNK_UNLOADED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnChunkUnloaded(a_World, a_ChunkX, a_ChunkZ);
}
- }
- return false;
+ );
}
@@ -448,17 +404,11 @@ bool cPluginManager::CallHookChunkUnloaded(cWorld & a_World, int a_ChunkX, int a
bool cPluginManager::CallHookChunkUnloading(cWorld & a_World, int a_ChunkX, int a_ChunkZ)
{
- FIND_HOOK(HOOK_CHUNK_UNLOADING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnChunkUnloading(a_World, a_ChunkX, a_ChunkZ))
+ return GenericCallHook(HOOK_CHUNK_UNLOADING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnChunkUnloading(a_World, a_ChunkX, a_ChunkZ);
}
- }
- return false;
+ );
}
@@ -467,17 +417,11 @@ bool cPluginManager::CallHookChunkUnloading(cWorld & a_World, int a_ChunkX, int
bool cPluginManager::CallHookCollectingPickup(cPlayer & a_Player, cPickup & a_Pickup)
{
- FIND_HOOK(HOOK_COLLECTING_PICKUP);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnCollectingPickup(a_Player, a_Pickup))
+ return GenericCallHook(HOOK_COLLECTING_PICKUP, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnCollectingPickup(a_Player, a_Pickup);
}
- }
- return false;
+ );
}
@@ -486,17 +430,11 @@ bool cPluginManager::CallHookCollectingPickup(cPlayer & a_Player, cPickup & a_Pi
bool cPluginManager::CallHookCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe)
{
- FIND_HOOK(HOOK_CRAFTING_NO_RECIPE);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnCraftingNoRecipe(a_Player, a_Grid, a_Recipe))
+ return GenericCallHook(HOOK_CRAFTING_NO_RECIPE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnCraftingNoRecipe(a_Player, a_Grid, a_Recipe);
}
- }
- return false;
+ );
}
@@ -505,17 +443,11 @@ bool cPluginManager::CallHookCraftingNoRecipe(cPlayer & a_Player, cCraftingGrid
bool cPluginManager::CallHookDisconnect(cClientHandle & a_Client, const AString & a_Reason)
{
- FIND_HOOK(HOOK_DISCONNECT);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnDisconnect(a_Client, a_Reason))
+ return GenericCallHook(HOOK_DISCONNECT, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnDisconnect(a_Client, a_Reason);
}
- }
- return false;
+ );
}
@@ -524,17 +456,11 @@ bool cPluginManager::CallHookDisconnect(cClientHandle & a_Client, const AString
bool cPluginManager::CallHookEntityAddEffect(cEntity & a_Entity, int a_EffectType, int a_EffectDurationTicks, int a_EffectIntensity, double a_DistanceModifier)
{
- FIND_HOOK(HOOK_ENTITY_ADD_EFFECT);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnEntityAddEffect(a_Entity, a_EffectType, a_EffectDurationTicks, a_EffectIntensity, a_DistanceModifier))
+ return GenericCallHook(HOOK_ENTITY_ADD_EFFECT, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnEntityAddEffect(a_Entity, a_EffectType, a_EffectDurationTicks, a_EffectIntensity, a_DistanceModifier);
}
- }
- return false;
+ );
}
@@ -543,17 +469,11 @@ bool cPluginManager::CallHookEntityAddEffect(cEntity & a_Entity, int a_EffectTyp
bool cPluginManager::CallHookEntityTeleport(cEntity & a_Entity, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition)
{
- FIND_HOOK(HOOK_ENTITY_TELEPORT);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnEntityTeleport(a_Entity, a_OldPosition, a_NewPosition))
+ return GenericCallHook(HOOK_ENTITY_TELEPORT, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnEntityTeleport(a_Entity, a_OldPosition, a_NewPosition);
}
- }
- return false;
+ );
}
@@ -561,17 +481,11 @@ bool cPluginManager::CallHookEntityTeleport(cEntity & a_Entity, const Vector3d &
bool cPluginManager::CallHookEntityChangingWorld(cEntity & a_Entity, cWorld & a_World)
{
- FIND_HOOK(HOOK_ENTITY_CHANGING_WORLD);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnEntityChangingWorld(a_Entity, a_World))
+ return GenericCallHook(HOOK_ENTITY_CHANGING_WORLD, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnEntityChangingWorld(a_Entity, a_World);
}
- }
- return false;
+ );
}
@@ -579,17 +493,11 @@ bool cPluginManager::CallHookEntityChangingWorld(cEntity & a_Entity, cWorld & a_
bool cPluginManager::CallHookEntityChangedWorld(cEntity & a_Entity, cWorld & a_World)
{
- FIND_HOOK(HOOK_ENTITY_CHANGED_WORLD);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnEntityChangedWorld(a_Entity, a_World))
+ return GenericCallHook(HOOK_ENTITY_CHANGED_WORLD, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnEntityChangedWorld(a_Entity, a_World);
}
- }
- return false;
+ );
}
@@ -621,17 +529,11 @@ bool cPluginManager::CallHookExecuteCommand(cPlayer * a_Player, const AStringVec
);
}
- FIND_HOOK(HOOK_EXECUTE_COMMAND);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnExecuteCommand(a_Player, a_Split, a_EntireCommand, a_Result))
+ return GenericCallHook(HOOK_EXECUTE_COMMAND, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnExecuteCommand(a_Player, a_Split, a_EntireCommand, a_Result);
}
- }
- return false;
+ );
}
@@ -640,17 +542,11 @@ bool cPluginManager::CallHookExecuteCommand(cPlayer * a_Player, const AStringVec
bool cPluginManager::CallHookExploded(cWorld & a_World, double a_ExplosionSize, bool a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData)
{
- FIND_HOOK(HOOK_EXPLODED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnExploded(a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData))
+ return GenericCallHook(HOOK_EXPLODED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnExploded(a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData);
}
- }
- return false;
+ );
}
@@ -659,17 +555,11 @@ bool cPluginManager::CallHookExploded(cWorld & a_World, double a_ExplosionSize,
bool cPluginManager::CallHookExploding(cWorld & a_World, double & a_ExplosionSize, bool & a_CanCauseFire, double a_X, double a_Y, double a_Z, eExplosionSource a_Source, void * a_SourceData)
{
- FIND_HOOK(HOOK_EXPLODING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnExploding(a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData))
+ return GenericCallHook(HOOK_EXPLODING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnExploding(a_World, a_ExplosionSize, a_CanCauseFire, a_X, a_Y, a_Z, a_Source, a_SourceData);
}
- }
- return false;
+ );
}
@@ -678,17 +568,11 @@ bool cPluginManager::CallHookExploding(cWorld & a_World, double & a_ExplosionSiz
bool cPluginManager::CallHookHandshake(cClientHandle & a_ClientHandle, const AString & a_Username)
{
- FIND_HOOK(HOOK_HANDSHAKE);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnHandshake(a_ClientHandle, a_Username))
+ return GenericCallHook(HOOK_HANDSHAKE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnHandshake(a_ClientHandle, a_Username);
}
- }
- return false;
+ );
}
@@ -697,17 +581,11 @@ bool cPluginManager::CallHookHandshake(cClientHandle & a_ClientHandle, const ASt
bool cPluginManager::CallHookHopperPullingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum)
{
- FIND_HOOK(HOOK_HOPPER_PULLING_ITEM);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnHopperPullingItem(a_World, a_Hopper, a_DstSlotNum, a_SrcEntity, a_SrcSlotNum))
+ return GenericCallHook(HOOK_HOPPER_PULLING_ITEM, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnHopperPullingItem(a_World, a_Hopper, a_DstSlotNum, a_SrcEntity, a_SrcSlotNum);
}
- }
- return false;
+ );
}
@@ -716,17 +594,11 @@ bool cPluginManager::CallHookHopperPullingItem(cWorld & a_World, cHopperEntity &
bool cPluginManager::CallHookHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum)
{
- FIND_HOOK(HOOK_HOPPER_PUSHING_ITEM);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnHopperPushingItem(a_World, a_Hopper, a_SrcSlotNum, a_DstEntity, a_DstSlotNum))
+ return GenericCallHook(HOOK_HOPPER_PUSHING_ITEM, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnHopperPushingItem(a_World, a_Hopper, a_SrcSlotNum, a_DstEntity, a_DstSlotNum);
}
- }
- return false;
+ );
}
@@ -735,17 +607,11 @@ bool cPluginManager::CallHookHopperPushingItem(cWorld & a_World, cHopperEntity &
bool cPluginManager::CallHookKilled(cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage)
{
- FIND_HOOK(HOOK_KILLED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnKilled(a_Victim, a_TDI, a_DeathMessage))
+ return GenericCallHook(HOOK_KILLED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnKilled(a_Victim, a_TDI, a_DeathMessage);
}
- }
- return false;
+ );
}
@@ -754,17 +620,11 @@ bool cPluginManager::CallHookKilled(cEntity & a_Victim, TakeDamageInfo & a_TDI,
bool cPluginManager::CallHookKilling(cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI)
{
- FIND_HOOK(HOOK_KILLING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnKilling(a_Victim, a_Killer, a_TDI))
+ return GenericCallHook(HOOK_KILLING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnKilling(a_Victim, a_Killer, a_TDI);
}
- }
- return false;
+ );
}
@@ -773,17 +633,11 @@ bool cPluginManager::CallHookKilling(cEntity & a_Victim, cEntity * a_Killer, Tak
bool cPluginManager::CallHookLogin(cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username)
{
- FIND_HOOK(HOOK_LOGIN);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnLogin(a_Client, a_ProtocolVersion, a_Username))
+ return GenericCallHook(HOOK_LOGIN, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnLogin(a_Client, a_ProtocolVersion, a_Username);
}
- }
- return false;
+ );
}
@@ -791,17 +645,11 @@ bool cPluginManager::CallHookLogin(cClientHandle & a_Client, UInt32 a_ProtocolVe
bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client, AStringMap & a_Mods)
{
- FIND_HOOK(HOOK_LOGIN_FORGE)
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnLoginForge(a_Client, a_Mods))
+ return GenericCallHook(HOOK_LOGIN_FORGE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnLoginForge(a_Client, a_Mods);
}
- }
- return false;
+ );
}
@@ -810,17 +658,11 @@ bool cPluginManager::CallHookLoginForge(cClientHandle & a_Client, AStringMap & a
bool cPluginManager::CallHookPlayerAnimation(cPlayer & a_Player, int a_Animation)
{
- FIND_HOOK(HOOK_PLAYER_ANIMATION);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerAnimation(a_Player, a_Animation))
+ return GenericCallHook(HOOK_PLAYER_ANIMATION, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerAnimation(a_Player, a_Animation);
}
- }
- return false;
+ );
}
@@ -829,17 +671,11 @@ bool cPluginManager::CallHookPlayerAnimation(cPlayer & a_Player, int a_Animation
bool cPluginManager::CallHookPlayerBreakingBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
- FIND_HOOK(HOOK_PLAYER_BREAKING_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerBreakingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta))
+ return GenericCallHook(HOOK_PLAYER_BREAKING_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerBreakingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta);
}
- }
- return false;
+ );
}
@@ -848,17 +684,11 @@ bool cPluginManager::CallHookPlayerBreakingBlock(cPlayer & a_Player, int a_Block
bool cPluginManager::CallHookPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{
- FIND_HOOK(HOOK_PLAYER_BROKEN_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerBrokenBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta))
+ return GenericCallHook(HOOK_PLAYER_BROKEN_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerBrokenBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_BlockType, a_BlockMeta);
}
- }
- return false;
+ );
}
@@ -867,17 +697,11 @@ bool cPluginManager::CallHookPlayerBrokenBlock(cPlayer & a_Player, int a_BlockX,
bool cPluginManager::CallHookPlayerDestroyed(cPlayer & a_Player)
{
- FIND_HOOK(HOOK_PLAYER_DESTROYED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerDestroyed(a_Player))
+ return GenericCallHook(HOOK_PLAYER_DESTROYED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerDestroyed(a_Player);
}
- }
- return false;
+ );
}
@@ -886,17 +710,11 @@ bool cPluginManager::CallHookPlayerDestroyed(cPlayer & a_Player)
bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player)
{
- FIND_HOOK(HOOK_PLAYER_EATING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerEating(a_Player))
+ return GenericCallHook(HOOK_PLAYER_EATING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerEating(a_Player);
}
- }
- return false;
+ );
}
@@ -905,17 +723,11 @@ bool cPluginManager::CallHookPlayerEating(cPlayer & a_Player)
bool cPluginManager::CallHookPlayerFoodLevelChange(cPlayer & a_Player, int a_NewFoodLevel)
{
- FIND_HOOK(HOOK_PLAYER_FOOD_LEVEL_CHANGE);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerFoodLevelChange(a_Player, a_NewFoodLevel))
+ return GenericCallHook(HOOK_PLAYER_FOOD_LEVEL_CHANGE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerFoodLevelChange(a_Player, a_NewFoodLevel);
}
- }
- return false;
+ );
}
@@ -924,17 +736,11 @@ bool cPluginManager::CallHookPlayerFoodLevelChange(cPlayer & a_Player, int a_New
bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems & a_Reward)
{
- FIND_HOOK(HOOK_PLAYER_FISHED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerFished(a_Player, a_Reward))
+ return GenericCallHook(HOOK_PLAYER_FISHED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerFished(a_Player, a_Reward);
}
- }
- return false;
+ );
}
@@ -943,17 +749,11 @@ bool cPluginManager::CallHookPlayerFished(cPlayer & a_Player, const cItems & a_R
bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward)
{
- FIND_HOOK(HOOK_PLAYER_FISHING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerFishing(a_Player, a_Reward))
+ return GenericCallHook(HOOK_PLAYER_FISHING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerFishing(a_Player, a_Reward);
}
- }
- return false;
+ );
}
@@ -962,17 +762,11 @@ bool cPluginManager::CallHookPlayerFishing(cPlayer & a_Player, cItems a_Reward)
bool cPluginManager::CallHookPlayerJoined(cPlayer & a_Player)
{
- FIND_HOOK(HOOK_PLAYER_JOINED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerJoined(a_Player))
+ return GenericCallHook(HOOK_PLAYER_JOINED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerJoined(a_Player);
}
- }
- return false;
+ );
}
@@ -981,17 +775,11 @@ 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)
{
- 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))
+ return GenericCallHook(HOOK_PLAYER_LEFT_CLICK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerLeftClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status);
}
- }
- return false;
+ );
}
@@ -1000,17 +788,11 @@ bool cPluginManager::CallHookPlayerLeftClick(cPlayer & a_Player, int a_BlockX, i
bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player, const Vector3d & a_OldPosition, const Vector3d & a_NewPosition)
{
- FIND_HOOK(HOOK_PLAYER_MOVING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerMoving(a_Player, a_OldPosition, a_NewPosition))
+ return GenericCallHook(HOOK_PLAYER_MOVING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerMoving(a_Player, a_OldPosition, a_NewPosition);
}
- }
- return false;
+ );
}
@@ -1019,17 +801,11 @@ bool cPluginManager::CallHookPlayerMoving(cPlayer & a_Player, const Vector3d & a
bool cPluginManager::CallHookPlayerOpeningWindow(cPlayer & a_Player, cWindow & a_Window)
{
- FIND_HOOK(HOOK_PLAYER_OPENING_WINDOW);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerOpeningWindow(a_Player, a_Window))
+ return GenericCallHook(HOOK_PLAYER_OPENING_WINDOW, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerOpeningWindow(a_Player, a_Window);
}
- }
- return false;
+ );
}
@@ -1038,17 +814,11 @@ bool cPluginManager::CallHookPlayerOpeningWindow(cPlayer & a_Player, cWindow & a
bool cPluginManager::CallHookPlayerPlacedBlock(cPlayer & a_Player, const sSetBlock & a_BlockChange)
{
- FIND_HOOK(HOOK_PLAYER_PLACED_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerPlacedBlock(a_Player, a_BlockChange))
+ return GenericCallHook(HOOK_PLAYER_PLACED_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerPlacedBlock(a_Player, a_BlockChange);
}
- }
- return false;
+ );
}
@@ -1057,17 +827,11 @@ bool cPluginManager::CallHookPlayerPlacedBlock(cPlayer & a_Player, const sSetBlo
bool cPluginManager::CallHookPlayerPlacingBlock(cPlayer & a_Player, const sSetBlock & a_BlockChange)
{
- FIND_HOOK(HOOK_PLAYER_PLACING_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerPlacingBlock(a_Player, a_BlockChange))
+ return GenericCallHook(HOOK_PLAYER_PLACING_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerPlacingBlock(a_Player, a_BlockChange);
}
- }
- return false;
+ );
}
@@ -1076,17 +840,11 @@ bool cPluginManager::CallHookPlayerPlacingBlock(cPlayer & a_Player, const sSetBl
bool cPluginManager::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)
{
- FIND_HOOK(HOOK_PLAYER_RIGHT_CLICK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
+ return GenericCallHook(HOOK_PLAYER_RIGHT_CLICK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerRightClick(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
}
- }
- return false;
+ );
}
@@ -1095,17 +853,11 @@ bool cPluginManager::CallHookPlayerRightClick(cPlayer & a_Player, int a_BlockX,
bool cPluginManager::CallHookPlayerRightClickingEntity(cPlayer & a_Player, cEntity & a_Entity)
{
- FIND_HOOK(HOOK_PLAYER_RIGHT_CLICKING_ENTITY);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerRightClickingEntity(a_Player, a_Entity))
+ return GenericCallHook(HOOK_PLAYER_RIGHT_CLICKING_ENTITY, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerRightClickingEntity(a_Player, a_Entity);
}
- }
- return false;
+ );
}
@@ -1114,17 +866,11 @@ bool cPluginManager::CallHookPlayerRightClickingEntity(cPlayer & a_Player, cEnti
bool cPluginManager::CallHookPlayerShooting(cPlayer & a_Player)
{
- FIND_HOOK(HOOK_PLAYER_SHOOTING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerShooting(a_Player))
+ return GenericCallHook(HOOK_PLAYER_SHOOTING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerShooting(a_Player);
}
- }
- return false;
+ );
}
@@ -1133,17 +879,11 @@ bool cPluginManager::CallHookPlayerShooting(cPlayer & a_Player)
bool cPluginManager::CallHookPlayerSpawned(cPlayer & a_Player)
{
- FIND_HOOK(HOOK_PLAYER_SPAWNED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerSpawned(a_Player))
+ return GenericCallHook(HOOK_PLAYER_SPAWNED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerSpawned(a_Player);
}
- }
- return false;
+ );
}
@@ -1152,17 +892,11 @@ bool cPluginManager::CallHookPlayerSpawned(cPlayer & a_Player)
bool cPluginManager::CallHookPlayerTossingItem(cPlayer & a_Player)
{
- FIND_HOOK(HOOK_PLAYER_TOSSING_ITEM);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerTossingItem(a_Player))
+ return GenericCallHook(HOOK_PLAYER_TOSSING_ITEM, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerTossingItem(a_Player);
}
- }
- return false;
+ );
}
@@ -1171,17 +905,11 @@ bool cPluginManager::CallHookPlayerTossingItem(cPlayer & a_Player)
bool cPluginManager::CallHookPlayerUsedBlock(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)
{
- FIND_HOOK(HOOK_PLAYER_USED_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerUsedBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta))
+ return GenericCallHook(HOOK_PLAYER_USED_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerUsedBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta);
}
- }
- return false;
+ );
}
@@ -1190,17 +918,11 @@ bool cPluginManager::CallHookPlayerUsedBlock(cPlayer & a_Player, int a_BlockX, i
bool cPluginManager::CallHookPlayerUsedItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
- FIND_HOOK(HOOK_PLAYER_USED_ITEM);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerUsedItem(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
+ return GenericCallHook(HOOK_PLAYER_USED_ITEM, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerUsedItem(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
}
- }
- return false;
+ );
}
@@ -1209,17 +931,11 @@ bool cPluginManager::CallHookPlayerUsedItem(cPlayer & a_Player, int a_BlockX, in
bool cPluginManager::CallHookPlayerUsingBlock(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)
{
- FIND_HOOK(HOOK_PLAYER_USING_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerUsingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta))
+ return GenericCallHook(HOOK_PLAYER_USING_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerUsingBlock(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ, a_BlockType, a_BlockMeta);
}
- }
- return false;
+ );
}
@@ -1228,17 +944,11 @@ bool cPluginManager::CallHookPlayerUsingBlock(cPlayer & a_Player, int a_BlockX,
bool cPluginManager::CallHookPlayerUsingItem(cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
{
- FIND_HOOK(HOOK_PLAYER_USING_ITEM);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPlayerUsingItem(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
+ return GenericCallHook(HOOK_PLAYER_USING_ITEM, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPlayerUsingItem(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ);
}
- }
- return false;
+ );
}
@@ -1247,17 +957,11 @@ bool cPluginManager::CallHookPlayerUsingItem(cPlayer & a_Player, int a_BlockX, i
bool cPluginManager::CallHookPluginMessage(cClientHandle & a_Client, const AString & a_Channel, const AString & a_Message)
{
- FIND_HOOK(HOOK_PLUGIN_MESSAGE);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPluginMessage(a_Client, a_Channel, a_Message))
+ return GenericCallHook(HOOK_PLUGIN_MESSAGE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPluginMessage(a_Client, a_Channel, a_Message);
}
- }
- return false;
+ );
}
@@ -1266,13 +970,19 @@ bool cPluginManager::CallHookPluginMessage(cClientHandle & a_Client, const AStri
bool cPluginManager::CallHookPluginsLoaded(void)
{
- FIND_HOOK(HOOK_PLUGINS_LOADED);
- VERIFY_HOOK;
+ auto Plugins = m_Hooks.find(HOOK_PLUGINS_LOADED);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
bool res = false;
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ for (auto * Plugin : Plugins->second)
{
- res = !(*itr)->OnPluginsLoaded() || res;
+ if (!Plugin->OnPluginsLoaded())
+ {
+ res = true;
+ }
}
return res;
}
@@ -1283,17 +993,11 @@ bool cPluginManager::CallHookPluginsLoaded(void)
bool cPluginManager::CallHookPostCrafting(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe)
{
- FIND_HOOK(HOOK_POST_CRAFTING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPostCrafting(a_Player, a_Grid, a_Recipe))
+ return GenericCallHook(HOOK_POST_CRAFTING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPostCrafting(a_Player, a_Grid, a_Recipe);
}
- }
- return false;
+ );
}
@@ -1302,17 +1006,11 @@ bool cPluginManager::CallHookPostCrafting(cPlayer & a_Player, cCraftingGrid & a_
bool cPluginManager::CallHookPreCrafting(cPlayer & a_Player, cCraftingGrid & a_Grid, cCraftingRecipe & a_Recipe)
{
- FIND_HOOK(HOOK_PRE_CRAFTING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnPreCrafting(a_Player, a_Grid, a_Recipe))
+ return GenericCallHook(HOOK_PRE_CRAFTING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnPreCrafting(a_Player, a_Grid, a_Recipe);
}
- }
- return false;
+ );
}
@@ -1321,17 +1019,11 @@ bool cPluginManager::CallHookPreCrafting(cPlayer & a_Player, cCraftingGrid & a_G
bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_Face, const Vector3d & a_BlockHitPos)
{
- FIND_HOOK(HOOK_PROJECTILE_HIT_BLOCK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnProjectileHitBlock(a_Projectile, a_BlockX, a_BlockY, a_BlockZ, a_Face, a_BlockHitPos))
+ return GenericCallHook(HOOK_PROJECTILE_HIT_BLOCK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnProjectileHitBlock(a_Projectile, a_BlockX, a_BlockY, a_BlockZ, a_Face, a_BlockHitPos);
}
- }
- return false;
+ );
}
@@ -1340,17 +1032,11 @@ bool cPluginManager::CallHookProjectileHitBlock(cProjectileEntity & a_Projectile
bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectile, cEntity & a_HitEntity)
{
- FIND_HOOK(HOOK_PROJECTILE_HIT_ENTITY);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnProjectileHitEntity(a_Projectile, a_HitEntity))
+ return GenericCallHook(HOOK_PROJECTILE_HIT_ENTITY, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnProjectileHitEntity(a_Projectile, a_HitEntity);
}
- }
- return false;
+ );
}
@@ -1359,17 +1045,11 @@ bool cPluginManager::CallHookProjectileHitEntity(cProjectileEntity & a_Projectil
bool cPluginManager::CallHookServerPing(cClientHandle & a_ClientHandle, AString & a_ServerDescription, int & a_OnlinePlayersCount, int & a_MaxPlayersCount, AString & a_Favicon)
{
- FIND_HOOK(HOOK_SERVER_PING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnServerPing(a_ClientHandle, a_ServerDescription, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon))
+ return GenericCallHook(HOOK_SERVER_PING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnServerPing(a_ClientHandle, a_ServerDescription, a_OnlinePlayersCount, a_MaxPlayersCount, a_Favicon);
}
- }
- return false;
+ );
}
@@ -1378,17 +1058,11 @@ bool cPluginManager::CallHookServerPing(cClientHandle & a_ClientHandle, AString
bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
{
- FIND_HOOK(HOOK_SPAWNED_ENTITY);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnSpawnedEntity(a_World, a_Entity))
+ return GenericCallHook(HOOK_SPAWNED_ENTITY, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnSpawnedEntity(a_World, a_Entity);
}
- }
- return false;
+ );
}
@@ -1396,17 +1070,11 @@ bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
bool cPluginManager::CallHookSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
{
- FIND_HOOK(HOOK_SPAWNED_MONSTER);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnSpawnedMonster(a_World, a_Monster))
+ return GenericCallHook(HOOK_SPAWNED_MONSTER, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnSpawnedMonster(a_World, a_Monster);
}
- }
- return false;
+ );
}
@@ -1414,17 +1082,11 @@ bool cPluginManager::CallHookSpawnedMonster(cWorld & a_World, cMonster & a_Monst
bool cPluginManager::CallHookSpawningEntity(cWorld & a_World, cEntity & a_Entity)
{
- FIND_HOOK(HOOK_SPAWNING_ENTITY);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnSpawningEntity(a_World, a_Entity))
+ return GenericCallHook(HOOK_SPAWNING_ENTITY, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnSpawningEntity(a_World, a_Entity);
}
- }
- return false;
+ );
}
@@ -1433,17 +1095,11 @@ bool cPluginManager::CallHookSpawningEntity(cWorld & a_World, cEntity & a_Entity
bool cPluginManager::CallHookSpawningMonster(cWorld & a_World, cMonster & a_Monster)
{
- FIND_HOOK(HOOK_SPAWNING_MONSTER);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnSpawningMonster(a_World, a_Monster))
+ return GenericCallHook(HOOK_SPAWNING_MONSTER, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnSpawningMonster(a_World, a_Monster);
}
- }
- return false;
+ );
}
@@ -1452,17 +1108,11 @@ bool cPluginManager::CallHookSpawningMonster(cWorld & a_World, cMonster & a_Mons
bool cPluginManager::CallHookTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TDI)
{
- FIND_HOOK(HOOK_TAKE_DAMAGE);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnTakeDamage(a_Receiver, a_TDI))
+ return GenericCallHook(HOOK_TAKE_DAMAGE, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnTakeDamage(a_Receiver, a_TDI);
}
- }
- return false;
+ );
}
@@ -1471,17 +1121,11 @@ bool cPluginManager::CallHookTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a
bool cPluginManager::CallHookUpdatingSign(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player)
{
- FIND_HOOK(HOOK_UPDATING_SIGN);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnUpdatingSign(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player))
+ return GenericCallHook(HOOK_UPDATING_SIGN, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnUpdatingSign(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player);
}
- }
- return false;
+ );
}
@@ -1490,17 +1134,11 @@ bool cPluginManager::CallHookUpdatingSign(cWorld & a_World, int a_BlockX, int a_
bool cPluginManager::CallHookUpdatedSign(cWorld & a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player)
{
- FIND_HOOK(HOOK_UPDATED_SIGN);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnUpdatedSign(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player))
+ return GenericCallHook(HOOK_UPDATED_SIGN, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnUpdatedSign(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Line1, a_Line2, a_Line3, a_Line4, a_Player);
}
- }
- return false;
+ );
}
@@ -1509,17 +1147,11 @@ bool cPluginManager::CallHookUpdatedSign(cWorld & a_World, int a_BlockX, int a_B
bool cPluginManager::CallHookWeatherChanged(cWorld & a_World)
{
- FIND_HOOK(HOOK_WEATHER_CHANGED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnWeatherChanged(a_World))
+ return GenericCallHook(HOOK_WEATHER_CHANGED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnWeatherChanged(a_World);
}
- }
- return false;
+ );
}
@@ -1528,17 +1160,11 @@ bool cPluginManager::CallHookWeatherChanged(cWorld & a_World)
bool cPluginManager::CallHookWeatherChanging(cWorld & a_World, eWeather & a_NewWeather)
{
- FIND_HOOK(HOOK_WEATHER_CHANGING);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnWeatherChanging(a_World, a_NewWeather))
+ return GenericCallHook(HOOK_WEATHER_CHANGING, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnWeatherChanging(a_World, a_NewWeather);
}
- }
- return false;
+ );
}
@@ -1547,17 +1173,11 @@ bool cPluginManager::CallHookWeatherChanging(cWorld & a_World, eWeather & a_NewW
bool cPluginManager::CallHookWorldStarted(cWorld & a_World)
{
- FIND_HOOK(HOOK_WORLD_STARTED);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnWorldStarted(a_World))
+ return GenericCallHook(HOOK_WORLD_STARTED, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnWorldStarted(a_World);
}
- }
- return false;
+ );
}
@@ -1566,17 +1186,11 @@ bool cPluginManager::CallHookWorldStarted(cWorld & a_World)
bool cPluginManager::CallHookWorldTick(cWorld & a_World, std::chrono::milliseconds a_Dt, std::chrono::milliseconds a_LastTickDurationMSec)
{
- FIND_HOOK(HOOK_WORLD_TICK);
- VERIFY_HOOK;
-
- for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
- {
- if ((*itr)->OnWorldTick(a_World, a_Dt, a_LastTickDurationMSec))
+ return GenericCallHook(HOOK_WORLD_TICK, [&](cPlugin * a_Plugin)
{
- return true;
+ return a_Plugin->OnWorldTick(a_World, a_Dt, a_LastTickDurationMSec);
}
- }
- return false;
+ );
}
@@ -1699,9 +1313,9 @@ bool cPluginManager::LoadPlugin(const AString & a_FolderName)
void cPluginManager::RemoveHooks(cPlugin * a_Plugin)
{
- for (HookMap::iterator itr = m_Hooks.begin(), end = m_Hooks.end(); itr != end; ++itr)
+ for (auto & Hook : m_Hooks)
{
- itr->second.remove(a_Plugin);
+ Hook.second.remove(a_Plugin);
}
}
@@ -1775,9 +1389,9 @@ bool cPluginManager::BindCommand(
bool cPluginManager::ForEachCommand(cCommandEnumCallback & a_Callback)
{
- for (CommandMap::iterator itr = m_Commands.begin(), end = m_Commands.end(); itr != end; ++itr)
+ for (auto & itr : m_Commands)
{
- if (a_Callback.Command(itr->first, itr->second.m_Plugin, itr->second.m_Permission, itr->second.m_HelpString))
+ if (a_Callback.Command(itr.first, itr.second.m_Plugin, itr.second.m_Permission, itr.second.m_HelpString))
{
return false;
}
@@ -1882,9 +1496,9 @@ bool cPluginManager::BindConsoleCommand(
bool cPluginManager::ForEachConsoleCommand(cCommandEnumCallback & a_Callback)
{
- for (CommandMap::iterator itr = m_ConsoleCommands.begin(), end = m_ConsoleCommands.end(); itr != end; ++itr)
+ for (auto & itr : m_ConsoleCommands)
{
- if (a_Callback.Command(itr->first, itr->second.m_Plugin, "", itr->second.m_HelpString))
+ if (a_Callback.Command(itr.first, itr.second.m_Plugin, "", itr.second.m_HelpString))
{
return false;
}
@@ -1944,14 +1558,14 @@ bool cPluginManager::ExecuteConsoleCommand(const AStringVector & a_Split, cComma
void cPluginManager::TabCompleteCommand(const AString & a_Text, AStringVector & a_Results, cPlayer * a_Player)
{
- for (CommandMap::iterator itr = m_Commands.begin(), end = m_Commands.end(); itr != end; ++itr)
+ for (auto & Command : m_Commands)
{
- if (NoCaseCompare(itr->first.substr(0, a_Text.length()), a_Text) != 0)
+ if (NoCaseCompare(Command.first.substr(0, a_Text.length()), a_Text) != 0)
{
// Command name doesn't match
continue;
}
- if ((a_Player != nullptr) && !a_Player->HasPermission(itr->second.m_Permission))
+ if ((a_Player != nullptr) && !a_Player->HasPermission(Command.second.m_Permission))
{
// Player doesn't have permission for the command
continue;
@@ -1968,7 +1582,7 @@ void cPluginManager::TabCompleteCommand(const AString & a_Text, AStringVector &
"/time set day". Or in other words, the position of the last space (separator)
in the strings must be equal or string::npos for both. */
size_t LastSpaceInText = a_Text.find_last_of(' ') + 1;
- size_t LastSpaceInSuggestion = itr->first.find_last_of(' ') + 1;
+ size_t LastSpaceInSuggestion = Command.first.find_last_of(' ') + 1;
if (LastSpaceInText != LastSpaceInSuggestion)
{
@@ -1976,7 +1590,7 @@ void cPluginManager::TabCompleteCommand(const AString & a_Text, AStringVector &
continue;
}
- a_Results.push_back(itr->first.substr(LastSpaceInSuggestion));
+ a_Results.push_back(Command.first.substr(LastSpaceInSuggestion));
}
}
diff --git a/src/Bindings/PluginManager.h b/src/Bindings/PluginManager.h
index fdc1d1e7a..7a54be8e1 100644
--- a/src/Bindings/PluginManager.h
+++ b/src/Bindings/PluginManager.h
@@ -444,6 +444,12 @@ private:
/** Returns the folders that are specified in the settings ini to load plugins from. */
AStringVector GetFoldersToLoad(cSettingsRepositoryInterface & a_Settings);
+
+ /** Calls a_HookFunction on each plugin registered to the hook HookName.
+ Returns false if the action is to continue or true if the plugin wants to abort.
+ Accessible only from within PluginManager.cpp */
+ template <typename HookFunction>
+ bool GenericCallHook(PluginHook a_HookName, HookFunction a_HookFunction);
} ; // tolua_export