summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-29 21:50:30 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-07-29 21:50:30 +0200
commit4f5d73b7704e351365a987b421c35f1384afa240 (patch)
tree88b4da666ea4723377cfa489c737618ef8cde2b1
parentMerge pull request #1061 from mc-server/portals (diff)
downloadcuberite-4f5d73b7704e351365a987b421c35f1384afa240.tar
cuberite-4f5d73b7704e351365a987b421c35f1384afa240.tar.gz
cuberite-4f5d73b7704e351365a987b421c35f1384afa240.tar.bz2
cuberite-4f5d73b7704e351365a987b421c35f1384afa240.tar.lz
cuberite-4f5d73b7704e351365a987b421c35f1384afa240.tar.xz
cuberite-4f5d73b7704e351365a987b421c35f1384afa240.tar.zst
cuberite-4f5d73b7704e351365a987b421c35f1384afa240.zip
Diffstat (limited to '')
-rw-r--r--src/Bindings/PluginManager.cpp8
-rw-r--r--src/ClientHandle.cpp3
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Generating/CompoGen.cpp2
-rw-r--r--src/World.cpp6
-rw-r--r--src/World.h5
-rw-r--r--src/WorldStorage/NBTChunkSerializer.cpp1
-rw-r--r--src/WorldStorage/WSSAnvil.cpp7
8 files changed, 14 insertions, 20 deletions
diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp
index 088b92a6d..3560b8660 100644
--- a/src/Bindings/PluginManager.cpp
+++ b/src/Bindings/PluginManager.cpp
@@ -476,11 +476,9 @@ 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)
{
- HookMap::iterator Plugins = m_Hooks.find(HOOK_ENTITY_ADD_EFFECT);
- if (Plugins == m_Hooks.end())
- {
- return false;
- }
+ 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))
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index aaed483e2..b390bf2d6 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -120,8 +120,7 @@ cClientHandle::~cClientHandle()
}
if (World != NULL)
{
- m_Player->SetWorldTravellingFrom(NULL); // Make sure that the player entity is actually removed
- World->RemovePlayer(m_Player); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
+ World->RemovePlayer(m_Player, true); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
m_Player->Destroy();
}
delete m_Player;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index ffdcca2ec..cf3322968 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1627,7 +1627,7 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
// Remove player from the old world
SetWorldTravellingFrom(GetWorld()); // cChunk handles entity removal
- GetWorld()->RemovePlayer(this);
+ GetWorld()->RemovePlayer(this, false);
// Queue adding player to the new world, including all the necessary adjustments to the object
a_World->AddPlayer(this);
diff --git a/src/Generating/CompoGen.cpp b/src/Generating/CompoGen.cpp
index 912d74248..178673e32 100644
--- a/src/Generating/CompoGen.cpp
+++ b/src/Generating/CompoGen.cpp
@@ -638,7 +638,7 @@ void cCompoGenNether::ComposeTerrain(cChunkDesc & a_ChunkDesc)
CeilingDisguise = -CeilingDisguise;
}
- int CeilingDisguiseHeight = Height - 2 - CeilingDisguise * 3;
+ int CeilingDisguiseHeight = Height - 2 - (int)CeilingDisguise * 3;
for (int y = Height - 1; y > CeilingDisguiseHeight; y--)
{
diff --git a/src/World.cpp b/src/World.cpp
index 0b0f7870b..84c0f2b93 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -2465,10 +2465,12 @@ void cWorld::AddPlayer(cPlayer * a_Player)
-void cWorld::RemovePlayer(cPlayer * a_Player)
+void cWorld::RemovePlayer(cPlayer * a_Player, bool a_RemoveFromChunk)
{
- if (!a_Player->IsWorldTravellingFrom(this))
+ if (a_RemoveFromChunk)
{
+ // To prevent iterator invalidations when an entity goes through a portal and calls this function whilst being ticked by cChunk
+ // we should not change cChunk's entity list if asked not to
m_ChunkMap->RemoveEntity(a_Player);
}
{
diff --git a/src/World.h b/src/World.h
index 4bf5a9d64..6649c4163 100644
--- a/src/World.h
+++ b/src/World.h
@@ -281,8 +281,9 @@ public:
/** Removes the player from the world.
Removes the player from the addition queue, too, if appropriate.
- If the player has a ClientHandle, the ClientHandle is removed from all chunks in the world and will not be ticked by this world anymore. */
- void RemovePlayer(cPlayer * a_Player);
+ If the player has a ClientHandle, the ClientHandle is removed from all chunks in the world and will not be ticked by this world anymore.
+ @param a_RemoveFromChunk determines if the entity should be removed from its chunk as well. Should be false when ticking from cChunk. */
+ void RemovePlayer(cPlayer * a_Player, bool a_RemoveFromChunk);
/** Calls the callback for each player in the list; returns true if all players processed, false if the callback aborted by returning true */
virtual bool ForEachPlayer(cPlayerListCallback & a_Callback) override; // >> EXPORTED IN MANUALBINDINGS <<
diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp
index b7a3d40ce..4857da1b6 100644
--- a/src/WorldStorage/NBTChunkSerializer.cpp
+++ b/src/WorldStorage/NBTChunkSerializer.cpp
@@ -486,7 +486,6 @@ void cNBTChunkSerializer::AddMonsterEntity(cMonster * a_Monster)
m_Writer.AddFloat("", a_Monster->GetDropChanceBoots());
m_Writer.EndList();
m_Writer.AddByte("CanPickUpLoot", (char)a_Monster->CanPickUpLoot());
- m_Writer.AddShort("Health", (short)a_Monster->GetHealth());
switch (a_Monster->GetMobType())
{
case cMonster::mtBat:
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 6134e2c0a..71ff3ef99 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2475,10 +2475,7 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N
// Load health:
int Health = a_NBT.FindChildByName(a_TagIdx, "Health");
- if (Health > 0)
- {
- a_Entity.SetHealth(a_NBT.GetShort(Health));
- }
+ a_Entity.SetHealth(Health > 0 ? a_NBT.GetShort(Health) : a_Entity.GetMaxHealth());
return true;
}
@@ -2507,8 +2504,6 @@ bool cWSSAnvil::LoadMonsterBaseFromNBT(cMonster & a_Monster, const cParsedNBT &
a_Monster.SetCanPickUpLoot(CanPickUpLoot);
}
- int HealthTag = a_NBT.FindChildByName(a_TagIdx, "Health");
- a_Monster.SetHealth(HealthTag > 0 ? a_NBT.GetShort(HealthTag) : a_Monster.GetMaxHealth());
return true;
}