Better docs for PlayerGameModeChangeEvent (#6461)

This commit is contained in:
Jake Potrebic 2021-08-22 08:10:33 -07:00
parent 92d1ace250
commit 9169cf73cc
2 changed files with 13 additions and 1 deletions

View file

@ -8,7 +8,17 @@ diff --git a/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.jav
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java --- a/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java
+++ b/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java
@@ -0,0 +0,0 @@ public class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellabl @@ -0,0 +0,0 @@ import org.jetbrains.annotations.NotNull;
/**
* Called when the GameMode of the player is changed.
+ * <p>
+ * <b>NOTE:</b> When {@link #getCause()} is {@link Cause#DEFAULT_GAMEMODE},
+ * the Player from {@link #getPlayer()} might not be fully online at
+ * the time this event is fired. Plugins should use {@link Player#isOnline()}
+ * to check before changing player state.
*/
public class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancelled; private boolean cancelled;
private final GameMode newGameMode; private final GameMode newGameMode;

View file

@ -79,6 +79,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
} }
public void loadGameTypes(@Nullable CompoundTag nbt) { public void loadGameTypes(@Nullable CompoundTag nbt) {
+ // Paper start
+ if (this.server.getForcedGameType() != null && this.server.getForcedGameType() != ServerPlayer.readPlayerMode(nbt, "playerGameType")) { + if (this.server.getForcedGameType() != null && this.server.getForcedGameType() != ServerPlayer.readPlayerMode(nbt, "playerGameType")) {
+ if (new PlayerGameModeChangeEvent(this.getBukkitEntity(), GameMode.getByValue(this.server.getDefaultGameType().getId()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, null).callEvent()) { + if (new PlayerGameModeChangeEvent(this.getBukkitEntity(), GameMode.getByValue(this.server.getDefaultGameType().getId()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, null).callEvent()) {
+ this.gameMode.setGameModeForPlayer(this.server.getForcedGameType(), GameType.DEFAULT_MODE); + this.gameMode.setGameModeForPlayer(this.server.getForcedGameType(), GameType.DEFAULT_MODE);
@ -87,6 +88,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ return; + return;
+ } + }
+ // Paper end
this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType")); this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
} }