forked from PaperMC/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerSpawnLocationEvent.java
More file actions
68 lines (59 loc) · 2.44 KB
/
PlayerSpawnLocationEvent.java
File metadata and controls
68 lines (59 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package org.spigotmc.event.player;
import com.google.common.base.Preconditions;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.Warning;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
/**
* Called when player is about to spawn in a world after joining the server.
*
* @deprecated The spawn location is selected during the configuration phase, before a player entity is normally
* created. Using the result of {@link #getPlayer()} for anything related to the player entity is unreliable and may
* cause issues. Retrieving {@link Player#getUniqueId()} and {@link Player#getName()} is safe. Prefer using
* {@link io.papermc.paper.event.player.AsyncPlayerSpawnLocationEvent}.
*/
@Warning(value = true, reason = "Listening to this event causes the player to be created early. Using the player from this event will result in undefined behavior. Prefer AsyncPlayerSpawnLocationEvent.")
@Deprecated(since = "1.21.9", forRemoval = true)
public class PlayerSpawnLocationEvent extends PlayerEvent {
private static final HandlerList HANDLER_LIST = new HandlerList();
private Location spawnLocation;
public PlayerSpawnLocationEvent(@NotNull final Player player, @NotNull Location spawnLocation) {
super(player);
this.spawnLocation = spawnLocation;
}
/**
* Gets player's spawn location.
* If the player {@link Player#hasPlayedBefore()}, it's going to default to the location inside player.dat file.
* For new players, the default spawn location is the {@link World#getSpawnLocation() spawn location}
* of the {@link Server#getRespawnWorld() respawn world}.
*
* @return the spawn location
*/
@NotNull
public Location getSpawnLocation() {
return spawnLocation;
}
/**
* Sets player's spawn location.
*
* @param location the spawn location
*/
public void setSpawnLocation(@NotNull Location location) {
Preconditions.checkArgument(location != null, "Location cannot be null");
Preconditions.checkArgument(location.getWorld() != null, "World cannot be null");
this.spawnLocation = location.clone();
}
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLER_LIST;
}
@NotNull
public static HandlerList getHandlerList() {
return HANDLER_LIST;
}
}