[SPIGOT-336] EntityDespawnEvent Created: 01/Jan/15  Updated: 21/Feb/24  Resolved: 21/Feb/24

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor
Reporter: Morphan1 Assignee: Unassigned
Resolution: Fixed Votes: 9
Labels: chunks, death, entity, event, metadata, removal, unload

Issue Links:
Relates
relates to SPIGOT-3366 No event called when non-living entit... Resolved

 Description   

Currently in Spigot, there is no way to listen for when entities despawn.
An example of the event can be found here: https://github.com/Bukkit/Bukkit/pull/1070

It would be extremely useful for allowing plugins to store non-metadata information that gets removed when the entity is despawned.



 Comments   
Comment by RyanTheLeach [ 06/Feb/22 ]

It would probably still be useful to be able to track entity lifetimes and when they are removed/killed for any reason.

 

But I believe that the Persistent Data Container provides API to attach data to an entity that persists as long as the entity does (for anyone that stumbles into this issue).

https://hub.spigotmc.org/javadocs/spigot/org/bukkit/persistence/PersistentDataContainer.html

Comment by Morphan1 [ 26/Apr/19 ]

The workaround mentioned above is no longer possible, as 1.14 has removed IWorldAccess. Our use case suffers from this: we require a system that attaches data to an entity which is preserved over restarts through a data file. This is not currently possible to sanely accomplish without said data file being polluted with entities that are long gone, as there is currently no way to listen for when they've been fully removed.

Comment by Morphan1 [ 16/May/15 ]

For anyone interested, this is possible via a workaround with NMS using a class like:
https://github.com/DenizenScript/Denizen-For-Bukkit/blob/4b15826263c9409d468e38cb4fd3ac98d6e4463f/src/main/java/net/aufdemrand/denizen/utilities/world/DenizenWorldAccess.java#L42-L55

by doing:
https://github.com/DenizenScript/Denizen-For-Bukkit/blob/4b15826263c9409d468e38cb4fd3ac98d6e4463f/src/main/java/net/aufdemrand/denizen/scripts/containers/core/EntityScriptHelper.java#L63-L86

Comment by Morphan1 [ 25/Jan/15 ]

For an example, how about... Any information that needs to be saved across restarts?

Comment by Llm Dl [ 15/Jan/15 ]

Personally, I'd use it in a plugin I have where one entity is riding another. One of them is considered 'hostile' and is removed from some regions/towns. I would like to make the entity riding that entity also disappear along with the riden entity.

Comment by Ryan Hamshire [ 15/Jan/15 ]

Will you please provide an example of a piece of information which you'd want to delete when an entity despawns, but couldn't or wouldn't want to store using the metadata API?

Generated at Sat Dec 13 20:50:02 UTC 2025 using Jira 10.3.13#10030013-sha1:56dd970ae30ebfeda3a697d25be1f6388b68a422.