Added entity in EntitySpawnEvent

This commit is contained in:
themode 2020-09-26 21:24:10 +02:00
parent c3b1e88b83
commit 3464d27ab1
4 changed files with 19 additions and 6 deletions

View File

@ -684,7 +684,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer {
this.instance = instance;
instance.addEntity(this);
spawn();
EntitySpawnEvent entitySpawnEvent = new EntitySpawnEvent(instance);
EntitySpawnEvent entitySpawnEvent = new EntitySpawnEvent(this, instance);
callEvent(EntitySpawnEvent.class, entitySpawnEvent);
}

View File

@ -583,7 +583,7 @@ public class Player extends LivingEntity implements CommandSender {
// This is the last chunk to be loaded , spawn player
this.viewableEntities.forEach(entity -> entity.removeViewer(this));
super.setInstance(instance);
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance, firstSpawn);
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);
callEvent(PlayerSpawnEvent.class, spawnEvent);
} else {
// Increment the counter of current loaded chunks

View File

@ -1,5 +1,6 @@
package net.minestom.server.event.entity;
import net.minestom.server.entity.Entity;
import net.minestom.server.event.Event;
import net.minestom.server.instance.Instance;
@ -8,12 +9,23 @@ import net.minestom.server.instance.Instance;
*/
public class EntitySpawnEvent extends Event {
private Instance spawnInstance;
private final Entity entity;
private final Instance spawnInstance;
public EntitySpawnEvent(Instance spawnInstance) {
public EntitySpawnEvent(Entity entity, Instance spawnInstance) {
this.entity = entity;
this.spawnInstance = spawnInstance;
}
/**
* Get the entity who spawned in the instance
*
* @return the entity
*/
public Entity getEntity() {
return entity;
}
/**
* Get the entity new instance
*

View File

@ -1,5 +1,6 @@
package net.minestom.server.event.player;
import net.minestom.server.entity.Entity;
import net.minestom.server.event.entity.EntitySpawnEvent;
import net.minestom.server.instance.Instance;
@ -10,8 +11,8 @@ public class PlayerSpawnEvent extends EntitySpawnEvent {
private final boolean firstSpawn;
public PlayerSpawnEvent(Instance spawnInstance, boolean firstSpawn) {
super(spawnInstance);
public PlayerSpawnEvent(Entity entity, Instance spawnInstance, boolean firstSpawn) {
super(entity, spawnInstance);
this.firstSpawn = firstSpawn;
}