Skip to content

Commit

Permalink
Fire EntityRemoveFromWorldEvent (fixes part of #922) (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhg023 authored and mastercoms committed Jun 5, 2018
1 parent 8316707 commit 8058aa7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/net/glowstone/entity/EntityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.google.common.collect.Multimaps.newSetMultimap;

import com.destroystokyo.paper.event.entity.EntityRemoveFromWorldEvent;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import java.util.Collection;
Expand All @@ -12,6 +13,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import net.glowstone.EventFactory;
import net.glowstone.chunk.GlowChunk;
import net.glowstone.entity.physics.BoundingBox;
import org.bukkit.Chunk;
Expand Down Expand Up @@ -93,6 +96,7 @@ void register(GlowEntity entity) {
* @param entity The entity.
*/
void unregister(GlowEntity entity) {
EventFactory.getInstance().callEvent(new EntityRemoveFromWorldEvent(entity));
entities.remove(entity.entityId);
groupedEntities.remove(entity.getClass(), entity);
((GlowChunk) entity.location.getChunk()).getRawEntities().remove(entity);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/glowstone/entity/GlowEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ public void remove() {
world.getEntityManager().unregister(this);
server.getEntityIdManager().deallocate(this);
this.setPassenger(null);

leaveVehicle();
ImmutableList.copyOf(this.leashedEntities)
.forEach(e -> unleash(e, UnleashReason.HOLDER_GONE));

Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/glowstone/entity/GlowLivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,6 @@ public void setHealth(double health) {
world.playSound(location, deathSound, getSoundVolume(), getSoundPitch());
}
playEffect(EntityEffect.DEATH);
leaveVehicle();
if (this instanceof GlowPlayer) {
GlowPlayer player = (GlowPlayer) this;
ItemStack mainHand = player.getInventory().getItemInMainHand();
Expand Down

0 comments on commit 8058aa7

Please sign in to comment.