Better docs for PlayerGameModeChangeEvent (#6461)

Dieser Commit ist enthalten in:
Jake Potrebic 2021-08-22 08:10:33 -07:00 committet von GitHub
Ursprung 49c7564283
Commit cf037fbd3e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 17 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -5,10 +5,20 @@ Subject: [PATCH] additions to PlayerGameModeChangeEvent
diff --git a/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java b/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java diff --git a/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java b/src/main/java/org/bukkit/event/player/PlayerGameModeChangeEvent.java
index 4b96e0573c7ce32ad8c41124ee9ecab8359318a5..b71f37dc8ac00175efd9275e9d8988bb5f2d9c47 100644 index 4b96e0573c7ce32ad8c41124ee9ecab8359318a5..aee4a8b52c0d4abb655a4778575f0122acf19049 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
@@ -13,10 +13,22 @@ public class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellabl @@ -8,15 +8,32 @@ 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;
@ -31,7 +41,7 @@ index 4b96e0573c7ce32ad8c41124ee9ecab8359318a5..b71f37dc8ac00175efd9275e9d8988bb
} }
@Override @Override
@@ -49,4 +61,77 @@ public class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellabl @@ -49,4 +66,77 @@ public class PlayerGameModeChangeEvent extends PlayerEvent implements Cancellabl
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }

Datei anzeigen

@ -45,7 +45,7 @@ index d75f78d2e3fb1376e8f6a8668c98a04a693c99e1..79f6089b934124c3309c6bee2e48b36b
} }
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index b74fc226bf299e274dcf7a0e5002fea1d9886c24..592b2a22f5f971f4445c9b336d04923ba74a64b2 100644 index b74fc226bf299e274dcf7a0e5002fea1d9886c24..e426942d85cfff429e9dd3bb8f9ef6dc88524778 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java --- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java +++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -1768,8 +1768,15 @@ public class ServerPlayer extends Player { @@ -1768,8 +1768,15 @@ public class ServerPlayer extends Player {
@ -75,10 +75,11 @@ index b74fc226bf299e274dcf7a0e5002fea1d9886c24..592b2a22f5f971f4445c9b336d04923b
} }
} }
@@ -2163,6 +2170,14 @@ public class ServerPlayer extends Player { @@ -2163,6 +2170,16 @@ public class ServerPlayer extends Player {
} }
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 b74fc226bf299e274dcf7a0e5002fea1d9886c24..592b2a22f5f971f4445c9b336d04923b
+ } + }
+ 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"));
} }