mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-15 20:51:34 +01:00
Added isFirstSpawn() to PlayerSpawnEvent
This commit is contained in:
parent
9c5c6d9161
commit
8281f1c0fd
@ -346,6 +346,7 @@ public class Player extends LivingEntity {
|
|||||||
if (this.instance == instance)
|
if (this.instance == instance)
|
||||||
throw new IllegalArgumentException("Instance should be different than the current one");
|
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) {
|
for (Chunk viewableChunk : viewableChunks) {
|
||||||
viewableChunk.removeViewer(this);
|
viewableChunk.removeViewer(this);
|
||||||
}
|
}
|
||||||
@ -374,7 +375,7 @@ public class Player extends LivingEntity {
|
|||||||
if (isLast) {
|
if (isLast) {
|
||||||
// This is the last chunk to be loaded , spawn player
|
// This is the last chunk to be loaded , spawn player
|
||||||
super.setInstance(instance);
|
super.setInstance(instance);
|
||||||
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance);
|
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(instance, firstSpawn);
|
||||||
callEvent(PlayerSpawnEvent.class, spawnEvent);
|
callEvent(PlayerSpawnEvent.class, spawnEvent);
|
||||||
updateViewPosition(chunk);
|
updateViewPosition(chunk);
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,18 @@ import net.minestom.server.event.entity.EntitySpawnEvent;
|
|||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
|
|
||||||
public class PlayerSpawnEvent extends EntitySpawnEvent {
|
public class PlayerSpawnEvent extends EntitySpawnEvent {
|
||||||
public PlayerSpawnEvent(Instance spawnInstance) {
|
private final boolean firstSpawn;
|
||||||
|
|
||||||
|
public PlayerSpawnEvent(Instance spawnInstance, boolean firstSpawn) {
|
||||||
super(spawnInstance);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user