summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authortycho <work.tycho@gmail.com>2015-05-19 12:55:23 +0200
committertycho <work.tycho@gmail.com>2015-05-19 12:55:23 +0200
commit95e06ab93ff98c7bcffcf8a68a479802c8a56fe3 (patch)
tree87e8224964c12b746e34701dfffbcd3201889cdf /src/Entities
parentFixed a lot of warnings (diff)
parentMerge pull request #2019 from mc-server/OverrideArgs (diff)
downloadcuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.tar
cuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.tar.gz
cuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.tar.bz2
cuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.tar.lz
cuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.tar.xz
cuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.tar.zst
cuberite-95e06ab93ff98c7bcffcf8a68a479802c8a56fe3.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Entity.cpp11
-rw-r--r--src/Entities/Player.cpp10
2 files changed, 21 insertions, 0 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 4a909a1fd..bc2b3e93e 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1403,14 +1403,25 @@ bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
return false;
}
+ // Ask the plugins if the entity is allowed to change the world
+ if (cRoot::Get()->GetPluginManager()->CallHookEntityChangeWorld(*this, *a_World))
+ {
+ // A Plugin doesn't allow the entity to change the world
+ return false;
+ }
+
// Remove all links to the old world
SetWorldTravellingFrom(GetWorld()); // cChunk::Tick() handles entity removal
GetWorld()->BroadcastDestroyEntity(*this);
// Queue add to new world
a_World->AddEntity(this);
+ cWorld * OldWorld = cRoot::Get()->GetWorld(GetWorld()->GetName()); // Required for the hook HOOK_ENTITY_CHANGED_WORLD
SetWorld(a_World);
+ // Entity changed the world, call the hook
+ cRoot::Get()->GetPluginManager()->CallHookEntityChangedWorld(*this, *OldWorld);
+
return true;
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 607a663de..01ad26297 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1606,6 +1606,12 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
return false;
}
+ if (cRoot::Get()->GetPluginManager()->CallHookEntityChangeWorld(*this, *a_World))
+ {
+ // A Plugin doesn't allow the player to change the world
+ return false;
+ }
+
// Send the respawn packet:
if (a_ShouldSendRespawn && (m_ClientHandle != nullptr))
{
@@ -1621,6 +1627,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
// Queue adding player to the new world, including all the necessary adjustments to the object
a_World->AddPlayer(this);
+ cWorld * OldWorld = cRoot::Get()->GetWorld(GetWorld()->GetName()); // Required for the hook HOOK_ENTITY_CHANGED_WORLD
SetWorld(a_World); // Chunks may be streamed before cWorld::AddPlayer() sets the world to the new value
// Update the view distance.
@@ -1635,6 +1642,9 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
// Broadcast the player into the new world.
a_World->BroadcastSpawnEntity(*this);
+ // Player changed the world, call the hook
+ cRoot::Get()->GetPluginManager()->CallHookEntityChangedWorld(*this, *OldWorld);
+
return true;
}