Commits

Doc authored and md_5 committed cd04a31b0db
#780: Add PlayerSpawnChangeEvent
No tags

src/main/java/org/bukkit/event/player/PlayerSpawnChangeEvent.java

Added
1 +package org.bukkit.event.player;
2 +
3 +import com.google.common.base.Preconditions;
4 +import org.bukkit.Location;
5 +import org.bukkit.entity.Player;
6 +import org.bukkit.event.Cancellable;
7 +import org.bukkit.event.HandlerList;
8 +import org.jetbrains.annotations.ApiStatus;
9 +import org.jetbrains.annotations.NotNull;
10 +import org.jetbrains.annotations.Nullable;
11 +
12 +/**
13 + * This event is fired when the spawn point of the player is changed.
14 + * @apiNote draft API
15 + */
16 +@ApiStatus.Experimental
17 +public class PlayerSpawnChangeEvent extends PlayerEvent implements Cancellable {
18 +
19 + private static final HandlerList handlers = new HandlerList();
20 + private final Cause cause;
21 + private Location newSpawn;
22 + private boolean forced;
23 + private boolean cancelled;
24 +
25 + public PlayerSpawnChangeEvent(@NotNull final Player player, @Nullable Location newSpawn, boolean forced, @NotNull final Cause cause) {
26 + super(player);
27 + this.newSpawn = newSpawn;
28 + this.cause = cause;
29 + this.forced = forced;
30 + }
31 +
32 + /**
33 + * Gets the cause of spawn change.
34 + *
35 + * @return change cause
36 + */
37 + @NotNull
38 + public Cause getCause() {
39 + return this.cause;
40 + }
41 +
42 + /**
43 + * Gets if the spawn position will be used regardless of bed obstruction
44 + * rules.
45 + *
46 + * @return true if is forced
47 + */
48 + public boolean isForced() {
49 + return this.forced;
50 + }
51 +
52 + /**
53 + * Sets if the spawn position will be used regardless of bed obstruction
54 + * rules.
55 + *
56 + * @param forced true if forced
57 + */
58 + public void setForced(boolean forced) {
59 + this.forced = forced;
60 + }
61 +
62 + /**
63 + * Gets the new spawn to be set.
64 + *
65 + * @return new spawn location
66 + */
67 + @Nullable
68 + public Location getNewSpawn() {
69 + return this.newSpawn;
70 + }
71 +
72 + /**
73 + * Sets the new spawn location.
74 + *
75 + * @param newSpawn new spawn location, with non-null world
76 + */
77 + public void setNewSpawn(@Nullable Location newSpawn) {
78 + if (newSpawn != null) {
79 + Preconditions.checkArgument(newSpawn.getWorld() != null, "Spawn location must have a world set");
80 + this.newSpawn = newSpawn.clone();
81 + } else {
82 + this.newSpawn = null;
83 + }
84 + }
85 +
86 + @Override
87 + public boolean isCancelled() {
88 + return this.cancelled;
89 + }
90 +
91 + @Override
92 + public void setCancelled(boolean cancel) {
93 + this.cancelled = cancel;
94 + }
95 +
96 + @NotNull
97 + @Override
98 + public HandlerList getHandlers() {
99 + return handlers;
100 + }
101 +
102 + @NotNull
103 + public static HandlerList getHandlerList() {
104 + return handlers;
105 + }
106 +
107 + public enum Cause {
108 +
109 + /**
110 + * Indicate the spawn was set by a command.
111 + */
112 + COMMAND,
113 + /**
114 + * Indicate the spawn was set by the player interacting with a bed.
115 + */
116 + BED,
117 + /**
118 + * Indicate the spawn was set by the player interacting with a respawn
119 + * anchor.
120 + */
121 + RESPAWN_ANCHOR,
122 + /**
123 + * Indicate the spawn was set by the use of plugins.
124 + */
125 + PLUGIN,
126 + /**
127 + * Indicate the spawn was reset by an invalid bed position or empty
128 + * respawn anchor.
129 + */
130 + RESET,
131 + /**
132 + * Indicate the spawn was caused by an unknown reason.
133 + */
134 + UNKNOWN;
135 + }
136 +}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut