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 5 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
64 changes: 64 additions & 0 deletions src/main/java/org/bukkit/event/entity/EntityDespawnEvent.java
@@ -0,0 +1,64 @@
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 {
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 creature is being despawned.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not just fired for creatures - is it?

*
* @return A DespawnReason value detailing the reason for the entity being despawned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The {@link DespawnReason}...

*/
public DespawnReason getDespawnReason() {
return despawnReason;
}

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

public static HandlerList getHandlerList() {
return handlers;
}

/**
* An enum to specify the type of despawning
*/
public enum DespawnReason {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enums generally go at the top of the file.


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line here

/**
* 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
}
}