2021-06-15 04:59:31 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sat, 15 May 2021 10:04:43 -0700
2024-01-19 17:54:05 +01:00
Subject: [PATCH] Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
diff --git a/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java b/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java
2024-01-19 17:54:05 +01:00
index 50e581613156cca765dfd8e3596dcb3b58520cec..21d6a2a5d1722d44146384c28a3cba2df9b42771 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java
+++ b/src/main/java/net/minecraft/server/commands/DefaultGameModeCommands.java
2022-12-07 21:16:54 +01:00
@@ -25,9 +25,13 @@ public class DefaultGameModeCommands {
2021-06-15 04:59:31 +02:00
GameType gameType = minecraftServer.getForcedGameType();
if (gameType != null) {
for(ServerPlayer serverPlayer : minecraftServer.getPlayerList().getPlayers()) {
- if (serverPlayer.setGameMode(gameType)) {
- ++i;
2024-01-19 17:54:05 +01:00
+ // Paper start - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameType, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, net.kyori.adventure.text.Component.empty());
+ if (event != null && event.isCancelled()) {
2023-06-08 22:56:13 +02:00
+ source.sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(event.cancelMessage()), false);
2021-06-15 04:59:31 +02:00
}
2024-01-19 17:54:05 +01:00
+ // Paper end - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
+ ++i;
}
}
diff --git a/src/main/java/net/minecraft/server/commands/GameModeCommand.java b/src/main/java/net/minecraft/server/commands/GameModeCommand.java
2024-01-19 17:54:05 +01:00
index aee8618e27b893b72931e925724dd683d2e6d2aa..f7c9127346261d83413ca03a1cdaa84975ae17d6 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/net/minecraft/server/commands/GameModeCommand.java
+++ b/src/main/java/net/minecraft/server/commands/GameModeCommand.java
2023-06-08 03:13:54 +02:00
@@ -48,9 +48,14 @@ public class GameModeCommand {
2021-06-15 04:59:31 +02:00
int i = 0;
for(ServerPlayer serverPlayer : targets) {
- if (serverPlayer.setGameMode(gameMode)) {
2024-01-19 17:54:05 +01:00
+ // Paper start - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = serverPlayer.setGameMode(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.COMMAND, net.kyori.adventure.text.Component.empty());
+ if (event != null && !event.isCancelled()) {
logGamemodeChange(context.getSource(), serverPlayer, gameMode);
++i;
+ } else if (event != null && event.cancelMessage() != null) {
2023-06-08 22:56:13 +02:00
+ context.getSource().sendSuccess(() -> io.papermc.paper.adventure.PaperAdventure.asVanilla(event.cancelMessage()), true);
2024-01-19 17:54:05 +01:00
+ // Paper end - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
}
}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-01-20 23:13:41 +01:00
index 8184aaff18d2372ae1de0fe1c53e63e1e6e3b2b0..68f6bb415d4b9624f147dc641543bce56bbbca09 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2023-12-29 20:57:32 +01:00
@@ -1989,8 +1989,16 @@ public class ServerPlayer extends Player {
2021-06-15 04:59:31 +02:00
}
public boolean setGameMode(GameType gameMode) {
- if (!this.gameMode.changeGameModeForPlayer(gameMode)) {
- return false;
2024-01-19 17:54:05 +01:00
+ // Paper start - Expand PlayerGameModeChangeEvent
2021-11-24 22:30:53 +01:00
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = this.setGameMode(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.UNKNOWN, null);
2021-06-15 04:59:31 +02:00
+ return event == null ? false : event.isCancelled();
+ }
2023-06-08 03:13:54 +02:00
+ @Nullable
+ public org.bukkit.event.player.PlayerGameModeChangeEvent setGameMode(GameType gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause cause, @Nullable net.kyori.adventure.text.Component message) {
2021-11-24 22:30:53 +01:00
+ org.bukkit.event.player.PlayerGameModeChangeEvent event = this.gameMode.changeGameModeForPlayer(gameMode, cause, message);
2021-06-15 04:59:31 +02:00
+ if (event == null || event.isCancelled()) {
+ return null;
2024-01-19 17:54:05 +01:00
+ // Paper end - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
} else {
this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.CHANGE_GAME_MODE, (float) gameMode.getId()));
if (gameMode == GameType.SPECTATOR) {
2023-12-29 20:57:32 +01:00
@@ -2002,7 +2010,7 @@ public class ServerPlayer extends Player {
2021-06-15 04:59:31 +02:00
this.onUpdateAbilities();
this.updateEffectVisibility();
- return true;
2024-01-19 17:54:05 +01:00
+ return event; // Paper - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
}
}
2023-12-29 20:57:32 +01:00
@@ -2414,6 +2422,16 @@ public class ServerPlayer extends Player {
2021-06-15 04:59:31 +02:00
}
public void loadGameTypes(@Nullable CompoundTag nbt) {
2024-01-19 17:54:05 +01:00
+ // Paper start - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
+ if (this.server.getForcedGameType() != null && this.server.getForcedGameType() != ServerPlayer.readPlayerMode(nbt, "playerGameType")) {
2021-11-24 22:30:53 +01:00
+ if (new org.bukkit.event.player.PlayerGameModeChangeEvent(this.getBukkitEntity(), org.bukkit.GameMode.getByValue(this.server.getDefaultGameType().getId()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.DEFAULT_GAMEMODE, null).callEvent()) {
2021-06-15 04:59:31 +02:00
+ this.gameMode.setGameModeForPlayer(this.server.getForcedGameType(), GameType.DEFAULT_MODE);
+ } else {
+ this.gameMode.setGameModeForPlayer(ServerPlayer.readPlayerMode(nbt,"playerGameType"), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
+ }
+ return;
+ }
2024-01-19 17:54:05 +01:00
+ // Paper end - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
this.gameMode.setGameModeForPlayer(this.calculateGameModeForNewPlayer(ServerPlayer.readPlayerMode(nbt, "playerGameType")), ServerPlayer.readPlayerMode(nbt, "previousPlayerGameType"));
}
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2024-01-20 23:13:41 +01:00
index 49d29e4b3395d2ebea1ed13338f26c7cfbaa5f72..d04669c1d2434c1dbc617777b769e9004359f208 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayerGameMode.java
2023-06-08 03:13:54 +02:00
@@ -73,21 +73,28 @@ public class ServerPlayerGameMode {
2021-06-15 04:59:31 +02:00
}
public boolean changeGameModeForPlayer(GameType gameMode) {
2024-01-20 23:13:41 +01:00
+ // Paper start - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
+ PlayerGameModeChangeEvent event = this.changeGameModeForPlayer(gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.UNKNOWN, null);
2023-06-08 03:13:54 +02:00
+ return event != null && event.isCancelled();
2021-06-15 04:59:31 +02:00
+ }
2023-06-08 03:13:54 +02:00
+ @Nullable
+ public PlayerGameModeChangeEvent changeGameModeForPlayer(GameType gameMode, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause cause, @Nullable net.kyori.adventure.text.Component cancelMessage) {
2024-01-19 17:54:05 +01:00
+ // Paper end - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
if (gameMode == this.gameModeForPlayer) {
- return false;
2024-01-19 17:54:05 +01:00
+ return null; // Paper - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
} else {
// CraftBukkit start
2021-07-15 23:44:59 +02:00
- PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this.player.getBukkitEntity(), GameMode.getByValue(gameMode.getId()));
+ PlayerGameModeChangeEvent event = new PlayerGameModeChangeEvent(this.player.getBukkitEntity(), GameMode.getByValue(gameMode.getId()), cause, cancelMessage); // Paper
2021-06-15 04:59:31 +02:00
this.level.getCraftServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
- return false;
2024-01-19 17:54:05 +01:00
+ return event; // Paper - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
}
// CraftBukkit end
2022-12-07 21:16:54 +01:00
this.setGameModeForPlayer(gameMode, this.previousGameModeForPlayer);
this.player.onUpdateAbilities();
this.player.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_GAME_MODE, this.player), this.player); // CraftBukkit
this.level.updateSleepingPlayerList();
2021-06-15 04:59:31 +02:00
- return true;
2024-01-19 17:54:05 +01:00
+ return event; // Paper - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
}
}
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-01-20 23:13:41 +01:00
index 5c54f56a350def1c4c7180c05e853fe10d687f74..f1a684e8af0b05c68ccb16cdb9c0e236d1a5834a 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
2024-01-20 12:50:16 +01:00
@@ -2648,7 +2648,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
2021-06-15 04:59:31 +02:00
2023-04-10 10:03:36 +02:00
this.player = this.server.getPlayerList().respawn(this.player, false, RespawnReason.DEATH);
2021-06-15 04:59:31 +02:00
if (this.server.isHardcore()) {
- this.player.setGameMode(GameType.SPECTATOR);
2024-01-19 17:54:05 +01:00
+ this.player.setGameMode(GameType.SPECTATOR, org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.HARDCORE_DEATH, null); // Paper - Expand PlayerGameModeChangeEvent
2023-06-08 03:13:54 +02:00
((GameRules.BooleanValue) this.player.level().getGameRules().getRule(GameRules.RULE_SPECTATORSGENERATECHUNKS)).set(false, this.server);
2021-06-15 04:59:31 +02:00
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
2024-01-20 12:50:16 +01:00
index 298380e217f41f01d0818767a6d8f1da5a004037..b602c6dfece70580971baedd638e465e8e25bd02 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
Updated Upstream (Bukkit/CraftBukkit) (#10034)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing
Bukkit Changes:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
@@ -1559,7 +1559,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
2023-06-13 01:51:45 +02:00
Preconditions.checkArgument(mode != null, "GameMode cannot be null");
if (this.getHandle().connection == null) return;
2021-06-15 04:59:31 +02:00
- this.getHandle().setGameMode(GameType.byId(mode.getValue()));
2024-01-19 17:54:05 +01:00
+ this.getHandle().setGameMode(GameType.byId(mode.getValue()), org.bukkit.event.player.PlayerGameModeChangeEvent.Cause.PLUGIN, null); // Paper - Expand PlayerGameModeChangeEvent
2021-06-15 04:59:31 +02:00
}
@Override