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-23 15:43:48 +01:00
index 75bd3de7bc1596a4782b82e30162d89aa3e99211..d1d7f4c3963986031ea26562549ee15c8232a5a9 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
2024-01-23 15:43:48 +01:00
@@ -1985,8 +1985,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) {
2024-01-23 15:43:48 +01:00
@@ -1998,7 +2006,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
}
}
2024-01-23 15:43:48 +01:00
@@ -2410,6 +2418,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-23 15:43:48 +01:00
index f66ce9ae705b0fbe17a1bb437bad6808ff47ed92..37513cf5714afda6c552219c2eca8134c054d2bb 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-23 12:06:27 +01:00
index cc393b070f6df598bd4523605d20900c622eac1b..e0e09e9d127cd54ece239c0c1e931bb8802c17a1 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-23 15:43:48 +01:00
index a0e33c3b6e8134ec7570a8c160da41c4a92d5040..7b5fd058817f27ffefcdc7e3667e8258a87cbb4c 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