Added isFirstSpawn() to PlayerSpawnEvent

This commit is contained in:
jglrxavpok 2020-05-08 18:03:39 +02:00
parent 9c5c6d9161
commit 8281f1c0fd
2 changed files with 14 additions and 2 deletions

View File

@ -346,6 +346,7 @@ public class Player extends LivingEntity {
if (this.instance == instance)
throw new IllegalArgumentException("Instance should be different than the current one");
boolean firstSpawn = this.instance == null; // TODO: Handle player reconnections, must be false in that case too
for (Chunk viewableChunk : viewableChunks) {
viewableChunk.removeViewer(this);
}
@ -374,7 +375,7 @@ public class Player extends LivingEntity {
if (isLast) {
// This is the last chunk to be loaded , spawn player
super.setInstance(instance);
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance);
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance, firstSpawn);
callEvent(PlayerSpawnEvent.class, spawnEvent);
updateViewPosition(chunk);
} else {

View File

@ -4,7 +4,18 @@ import net.minestom.server.event.entity.EntitySpawnEvent;
import net.minestom.server.instance.Instance;
public class PlayerSpawnEvent extends EntitySpawnEvent {
public PlayerSpawnEvent(Instance spawnInstance) {
private final boolean firstSpawn;
public PlayerSpawnEvent(Instance spawnInstance, boolean firstSpawn) {
super(spawnInstance);
this.firstSpawn = firstSpawn;
}
/**
* 'true' if the player is spawning for the first time. 'false' if this spawn event was triggered by a dimension teleport
* @return
*/
public boolean isFirstSpawn() {
return firstSpawn;
}
}