Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[B+C] Add and implement an EntityDespawnEvent. adds BUKKIT-5645 #1070

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/main/java/org/bukkit/event/entity/EntityDespawnEvent.java
@@ -0,0 +1,63 @@
package org.bukkit.event.entity;

import org.bukkit.entity.Entity;
import org.bukkit.event.HandlerList;

/**
* Called whenever an Entity is removed from the world.
*/
public class EntityDespawnEvent extends EntityEvent {
/**
* An enum to specify the type of despawning
*/
public enum DespawnReason {
/**
* When an entity despawns due to a chunk unload
*/
CHUNK_UNLOAD,
/**
* When a living entity despawns because it died
*/
DEATH,
/**
* When an entity despawns because a plugin or GameRule removed it,
* or a non-living entity died (EG, ender crystal destroyed)
*/
REMOVED,
/**
* When an entity is missing a DespawnReason
*/
DEFAULT
}

private static final HandlerList handlers = new HandlerList();
private final DespawnReason despawnReason;

public EntityDespawnEvent(final Entity entity) {
super(entity);
despawnReason = DespawnReason.DEFAULT;
}

public EntityDespawnEvent(final Entity entity, DespawnReason reason) {
super(entity);
despawnReason = reason;
}

/**
* Gets the reason for why the entity is being despawned.
*
* @return The {@link DespawnReason} detailing the reason for the entity being despawned
*/
public DespawnReason getDespawnReason() {
return despawnReason;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}
}