diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-07-04 17:49:24 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-07-04 17:49:24 +0200 |
commit | f4e3c01a710a2cc5118807a65f8d27519a19ef37 (patch) | |
tree | b01db2464263a6425ed39195f574523e7707fa5b /src/Entities/ProjectileEntity.h | |
parent | Eps comparison (diff) | |
download | cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.tar cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.tar.gz cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.tar.bz2 cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.tar.lz cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.tar.xz cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.tar.zst cuberite-f4e3c01a710a2cc5118807a65f8d27519a19ef37.zip |
Diffstat (limited to 'src/Entities/ProjectileEntity.h')
-rw-r--r-- | src/Entities/ProjectileEntity.h | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/Entities/ProjectileEntity.h b/src/Entities/ProjectileEntity.h index ae06b072f..e2ebe9f27 100644 --- a/src/Entities/ProjectileEntity.h +++ b/src/Entities/ProjectileEntity.h @@ -66,8 +66,15 @@ public: /// Returns the kind of the projectile (fast class identification) eKind GetProjectileKind(void) const { return m_ProjectileKind; } - /// Returns the entity who created this projectile; may be NULL - cEntity * GetCreator(void) { return m_Creator; } + /** Returns the entity who created this projectile through running its Unique ID through cWorld::DoWithEntityByID() + May return NULL; do not store the returned pointer outside the scope of the tick thread! + */ + cEntity * GetCreator(void); + + /** Returns the name of the player that created the projectile + Will be empty for non-player creators + */ + AString GetCreatorName(void) const { return m_CreatorData.m_Name; } /// Returns the string that is used as the entity type (class name) in MCA files AString GetMCAClassName(void) const; @@ -81,10 +88,29 @@ public: void SetIsInGround(bool a_IsInGround) { m_IsInGround = a_IsInGround; } protected: + + /** A structure that stores the Entity ID and Playername of the projectile's creator + Used to migitate invalid pointers caused by the creator being destroyed + */ + struct CreatorData + { + CreatorData(int a_UniqueID, AString & a_Name) : + m_UniqueID(a_UniqueID), + m_Name(a_Name) + { + } + + const int m_UniqueID; + AString m_Name; + }; + + /** The type of projectile I am */ eKind m_ProjectileKind; - /// The entity who has created this projectile; may be NULL (e. g. for dispensers) - cEntity * m_Creator; + /** The structure for containing the entity ID and name who has created this projectile + The ID and/or name may be NULL (e.g. for dispensers/mobs) + */ + CreatorData m_CreatorData; /// True if the projectile has hit the ground and is stuck there bool m_IsInGround; |