Skip to content

Commit

Permalink
Fix #1325
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Mar 9, 2016
1 parent 1886a0a commit dcfb927
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Expand Up @@ -54,10 +54,13 @@ public EntityScriptHelper() {

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
EntityDespawnScriptEvent.instance.entity = new dEntity(event.getEntity());
Entity entity = event.getEntity();
dEntity.rememberEntity(entity);
EntityDespawnScriptEvent.instance.entity = new dEntity(entity);
EntityDespawnScriptEvent.instance.cause = new Element("DEATH");
EntityDespawnScriptEvent.instance.cancelled = false;
EntityDespawnScriptEvent.instance.fire();
dEntity.forgetEntity(entity);
unlinkEntity(event.getEntity());
}

Expand Down Expand Up @@ -94,10 +97,12 @@ public void onChunkUnload(ChunkUnloadEvent event) {
// CraftBukkit: https://github.com/Bukkit/CraftBukkit/pull/1386
for (Entity ent : event.getChunk().getEntities()) {
if (!(ent instanceof LivingEntity) || ((LivingEntity) ent).getRemoveWhenFarAway()) {
dEntity.rememberEntity(ent);
EntityDespawnScriptEvent.instance.entity = new dEntity(ent);
EntityDespawnScriptEvent.instance.cause = new Element("CHUNK_UNLOAD");
EntityDespawnScriptEvent.instance.cancelled = false;
EntityDespawnScriptEvent.instance.fire();
dEntity.forgetEntity(ent);
unlinkEntity(ent);
}
}
Expand Down
Expand Up @@ -45,16 +45,19 @@ public void a(Entity entity) {
@Override
public void b(Entity entity) {
try {
if (dEntity.isCitizensNPC(entity.getBukkitEntity())) {
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
if (dEntity.isCitizensNPC(bukkitEntity)) {
return;
}
if (entity.getBukkitEntity() instanceof LivingEntity && !((LivingEntity) entity.getBukkitEntity()).getRemoveWhenFarAway()) {
if (bukkitEntity instanceof LivingEntity && !((LivingEntity) bukkitEntity).getRemoveWhenFarAway()) {
return;
}
EntityDespawnScriptEvent.instance.entity = new dEntity(entity.getBukkitEntity());
dEntity.rememberEntity(bukkitEntity);
EntityDespawnScriptEvent.instance.entity = new dEntity(bukkitEntity);
EntityDespawnScriptEvent.instance.cause = new Element("OTHER");
EntityDespawnScriptEvent.instance.cancelled = false;
EntityDespawnScriptEvent.instance.fire();
dEntity.forgetEntity(bukkitEntity);
}
catch (Exception e) {
dB.echoError(e);
Expand Down

0 comments on commit dcfb927

Please sign in to comment.